on bionic help sign in
unity8/tests/plugins/Unity/Platform/platformtest.cpp
142 lines 3.5 kB history raw
1/*
2 * Copyright (C) 2017 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
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
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Pete Woods <pete.woods@canonical.com>
18 */
20#include "platform.h"
22#include <libqtdbustest/DBusTestRunner.h>
23#include <libqtdbusmock/DBusMock.h>
25#include <QtTest>
26#include <QDebug>
28using namespace QtDBusTest;
29using namespace QtDBusMock;
31class PlatformTest: public QObject
34Q_OBJECT
36private:
37 struct TestFixture
38 {
39 TestFixture() :
40 mock(dbus)
41 {
42 }
44 DBusTestRunner dbus;
45 DBusMock mock;
46 };
48 QScopedPointer<TestFixture> m_data;
50 void registerLogin1(bool canMultiSession, bool canGraphical)
51 {
52 m_data->mock.registerLogin1({{"DefaultSeat", QVariantMap
53 {
54 {"CanMultiSession", canMultiSession},
55 {"CanGraphical", canGraphical}
56 }}}
57 );
58 }
60 void registerHostname1(const QString& chassis)
61 {
62 m_data->mock.registerHostname1({
63 {"Chassis", chassis}
64 });
65 }
67 void startServices()
68 {
69 m_data->dbus.startServices();
70 }
72private Q_SLOTS:
74 void init()
75 {
76 m_data.reset(new TestFixture);
77 }
79 void cleanup()
80 {
81 m_data.reset();
82 }
84 void testIsPC_data()
85 {
86 QTest::addColumn<QString>("chassis");
87 QTest::addColumn<bool>("result");
89 QTest::newRow("vm") << "vm" << true;
90 QTest::newRow("container") << "container" << true;
91 QTest::newRow("desktop") << "desktop" << true;
92 QTest::newRow("laptop") << "laptop" << true;
93 QTest::newRow("server") << "server" << true;
94 QTest::newRow("tablet") << "tablet" << false;
95 QTest::newRow("handset") << "handset" << false;
96 QTest::newRow("watch") << "watch" << false;
97 QTest::newRow("embedded") << "embedded" << true;
98 }
100 void testIsPC()
101 {
102 QFETCH(QString, chassis);
103 QFETCH(bool, result);
105 registerLogin1(true, true);
106 registerHostname1(chassis);
107 startServices();
109 Platform p;
110 QCOMPARE(p.isPC(), result);
111 QCOMPARE(p.chassis(), chassis);
112 }
114 void testIsMultiSession_data()
115 {
116 QTest::addColumn<bool>("canMultiSession");
117 QTest::addColumn<bool>("canGraphical");
118 QTest::addColumn<bool>("result");
120 QTest::newRow("") << true << true << true;
121 QTest::newRow("") << true << false << false;
122 QTest::newRow("") << false << true << false;
123 QTest::newRow("") << false << false << false;
124 }
126 void testIsMultiSession()
127 {
128 QFETCH(bool, canMultiSession);
129 QFETCH(bool, canGraphical);
130 QFETCH(bool, result);
132 registerLogin1(canMultiSession, canGraphical);
133 registerHostname1("desktop");
134 startServices();
136 Platform p;
137 QCOMPARE(p.isMultiSession(), result);
138 }
139};
141QTEST_GUILESS_MAIN(PlatformTest)
142#include "platformtest.moc"