@@ -0,0 +1,142 @@
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("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+ }
99+
100+ void testIsPC()
101+ {
102+ QFETCH(QString, chassis);
103+ QFETCH(bool, result);
104+
105+ registerLogin1(true, true);
106+ registerHostname1(chassis);
107+ startServices();
108+
109+ Platform p;
110+ QCOMPARE(p.isPC(), result);
111+ QCOMPARE(p.chassis(), chassis);
112+ }
113+
114+ void testIsMultiSession_data()
115+ {
116+ QTest::addColumn<bool>("canMultiSession");
117+ QTest::addColumn<bool>("canGraphical");
118+ QTest::addColumn<bool>("result");
119+
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+ }
125+
126+ void testIsMultiSession()
127+ {
128+ QFETCH(bool, canMultiSession);
129+ QFETCH(bool, canGraphical);
130+ QFETCH(bool, result);
131+
132+ registerLogin1(canMultiSession, canGraphical);
133+ registerHostname1("desktop");
134+ startServices();
135+
136+ Platform p;
137+ QCOMPARE(p.isMultiSession(), result);
138+ }
139+};
140+
141+QTEST_GUILESS_MAIN(PlatformTest)
142+#include "platformtest.moc"