~osomon/ubuntu-system-settings/autopkgtest

« back to all changes in this revision

Viewing changes to tests/plugins/bluetooth/tst_devicemodel.cpp

  • Committer: CI bot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2014-08-01 17:09:43 UTC
  • mfrom: (806.1.27 ubuntu-system-settings)
  • Revision ID: ps-jenkins@lists.canonical.com-20140801170943-v2wcmrfuz1lfrn0q
Bluetooth UI redesign Fixes: 1272317, 1287293, 1336197
Approved by: Manuel de la Peña

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 */
 
18
 
 
19
#include <QTest>
 
20
#include <QSignalSpy>
 
21
#include <QThread>
 
22
 
 
23
#include "bluetooth.h"
 
24
#include "devicemodel.h"
 
25
#include "fakebluez.h"
 
26
 
 
27
using namespace Bluez;
 
28
 
 
29
class DeviceModelTest: public QObject
 
30
{
 
31
    Q_OBJECT
 
32
 
 
33
private:
 
34
    FakeBluez *m_bluezMock;
 
35
    DeviceModel *m_devicemodel;
 
36
    QDBusConnection *m_dbus;
 
37
 
 
38
private Q_SLOTS:
 
39
    void init();
 
40
    void testDeviceFoundOnStart();
 
41
    void testDeviceFound();
 
42
    void testGetDeviceFromAddress();
 
43
    void testGetDeviceFromPath();
 
44
    void cleanup();
 
45
 
 
46
};
 
47
 
 
48
void DeviceModelTest::init()
 
49
{
 
50
    m_bluezMock = new FakeBluez();
 
51
 
 
52
    m_bluezMock->addAdapter("new0", "bluetoothTest");
 
53
    m_bluezMock->addDevice("My Phone", "00:00:de:ad:be:ef");
 
54
 
 
55
    m_dbus = new QDBusConnection(m_bluezMock->dbus());
 
56
    m_devicemodel = new DeviceModel(*m_dbus);
 
57
}
 
58
 
 
59
void DeviceModelTest::cleanup()
 
60
{
 
61
    delete m_bluezMock;
 
62
    delete m_devicemodel;
 
63
}
 
64
 
 
65
void DeviceModelTest::testDeviceFoundOnStart()
 
66
{
 
67
    QCOMPARE(m_devicemodel->rowCount(), 1);
 
68
}
 
69
 
 
70
void DeviceModelTest::testDeviceFound()
 
71
{
 
72
    QSKIP("TODO: Finish me.", SkipAll);
 
73
 
 
74
    m_bluezMock->addDevice("My New Phone", "00:0b:ad:c0:ff:ee");
 
75
    QCOMPARE(m_devicemodel->rowCount(), 2);
 
76
}
 
77
 
 
78
void DeviceModelTest::testGetDeviceFromAddress()
 
79
{
 
80
    auto device = m_devicemodel->getDeviceFromAddress("00:00:de:ad:be:ef");
 
81
 
 
82
    QVERIFY(device);
 
83
    QVERIFY(!device->getPath().isEmpty());
 
84
}
 
85
 
 
86
void DeviceModelTest::testGetDeviceFromPath()
 
87
{
 
88
    QList<QString> devices = m_bluezMock->devices();
 
89
 
 
90
    auto device = m_devicemodel->getDeviceFromPath(devices.at(0));
 
91
 
 
92
    QVERIFY(device);
 
93
    QVERIFY(!device->getPath().isEmpty());
 
94
}
 
95
 
 
96
QTEST_MAIN(DeviceModelTest);
 
97
#include "tst_devicemodel.moc"