@@ -0,0 +1,140 @@
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+ */
19+
20+#include "platform.h"
21+
22+#include <libqtdbustest/DBusTestRunner.h>
23+#include <libqtdbusmock/DBusMock.h>
24+
25+#include <QtTest>
26+#include <QDebug>
27+
28+using namespace QtDBusTest;
29+using namespace QtDBusMock;
30+
31+class PlatformTest: public QObject
32+{
33+
34+Q_OBJECT
35+
36+private:
37+ struct TestFixture
38+ {
39+ TestFixture() :
40+ mock(dbus)
41+ {
42+ }
43+
44+ DBusTestRunner dbus;
45+ DBusMock mock;
46+ };
47+
48+ QScopedPointer<TestFixture> m_data;
49+
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+ }
59+
60+ void registerHostname1(const QString& chassis)
61+ {
62+ m_data->mock.registerHostname1({
63+ {"Chassis", chassis}
64+ });
65+ }
66+
67+ void startServices()
68+ {
69+ m_data->dbus.startServices();
70+ }
71+
72+private Q_SLOTS:
73+
74+ void init()
75+ {
76+ m_data.reset(new TestFixture);
77+ }
78+
79+ void cleanup()
80+ {
81+ m_data.reset();
82+ }
83+
84+ void testIsPC_data()
85+ {
86+ QTest::addColumn<QString>("chassis");
87+ QTest::addColumn<bool>("result");
88+
89+ QTest::newRow("desktop") << "desktop" << true;
90+ QTest::newRow("laptop") << "laptop" << true;
91+ QTest::newRow("server") << "server" << true;
92+ QTest::newRow("tablet") << "tablet" << false;
93+ QTest::newRow("handset") << "handset" << false;
94+ QTest::newRow("vm") << "vm" << true;
95+ QTest::newRow("container") << "container" << true;
96+ }
97+
98+ void testIsPC()
99+ {
100+ QFETCH(QString, chassis);
101+ QFETCH(bool, result);
102+
103+ registerLogin1(true, true);
104+ registerHostname1(chassis);
105+ startServices();
106+
107+ Platform p;
108+ QCOMPARE(p.isPC(), result);
109+ QCOMPARE(p.chassis(), chassis);
110+ }
111+
112+ void testIsMultiSession_data()
113+ {
114+ QTest::addColumn<bool>("canMultiSession");
115+ QTest::addColumn<bool>("canGraphical");
116+ QTest::addColumn<bool>("result");
117+
118+ QTest::newRow("") << true << true << true;
119+ QTest::newRow("") << true << false << false;
120+ QTest::newRow("") << false << true << false;
121+ QTest::newRow("") << false << false << false;
122+ }
123+
124+ void testIsMultiSession()
125+ {
126+ QFETCH(bool, canMultiSession);
127+ QFETCH(bool, canGraphical);
128+ QFETCH(bool, result);
129+
130+ registerLogin1(canMultiSession, canGraphical);
131+ registerHostname1("desktop");
132+ startServices();
133+
134+ Platform p;
135+ QCOMPARE(p.isMultiSession(), result);
136+ }
137+};
138+
139+QTEST_GUILESS_MAIN(PlatformTest)
140+#include "platformtest.moc"