2
* Copyright 2013 Canonical Ltd.
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of version 3 of the GNU Lesser General Public
6
* License as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public
14
* License along with this library; if not, write to the
15
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
* Boston, MA 02110-1301, USA.
23
#include "bluetooth.h"
24
#include "devicemodel.h"
25
#include "fakebluez.h"
27
using namespace Bluez;
29
class DeviceModelTest: public QObject
34
FakeBluez *m_bluezMock;
35
DeviceModel *m_devicemodel;
36
QDBusConnection *m_dbus;
40
void testDeviceFoundOnStart();
41
void testDeviceFound();
42
void testGetDeviceFromAddress();
43
void testGetDeviceFromPath();
48
void DeviceModelTest::init()
50
m_bluezMock = new FakeBluez();
52
m_bluezMock->addAdapter("new0", "bluetoothTest");
53
m_bluezMock->addDevice("My Phone", "00:00:de:ad:be:ef");
55
m_dbus = new QDBusConnection(m_bluezMock->dbus());
56
m_devicemodel = new DeviceModel(*m_dbus);
59
void DeviceModelTest::cleanup()
65
void DeviceModelTest::testDeviceFoundOnStart()
67
QCOMPARE(m_devicemodel->rowCount(), 1);
70
void DeviceModelTest::testDeviceFound()
72
QSKIP("TODO: Finish me.", SkipAll);
74
m_bluezMock->addDevice("My New Phone", "00:0b:ad:c0:ff:ee");
75
QCOMPARE(m_devicemodel->rowCount(), 2);
78
void DeviceModelTest::testGetDeviceFromAddress()
80
auto device = m_devicemodel->getDeviceFromAddress("00:00:de:ad:be:ef");
83
QVERIFY(!device->getPath().isEmpty());
86
void DeviceModelTest::testGetDeviceFromPath()
88
QList<QString> devices = m_bluezMock->devices();
90
auto device = m_devicemodel->getDeviceFromPath(devices.at(0));
93
QVERIFY(!device->getPath().isEmpty());
96
QTEST_MAIN(DeviceModelTest);
97
#include "tst_devicemodel.moc"