Changeset View
Changeset View
Standalone View
Standalone View
libtaskmanager/autotests/launchertasksmodeltest.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2016 Eike Hein <hein@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | | ||||
21 | #include <QObject> | ||||
22 | #include <QSignalSpy> | ||||
23 | #include <QTest> | ||||
24 | | ||||
25 | #include "launchertasksmodel.h" | ||||
26 | | ||||
27 | using namespace TaskManager; | ||||
28 | | ||||
29 | class LauncherTasksModelTest : public QObject | ||||
30 | { | ||||
31 | Q_OBJECT | ||||
32 | | ||||
33 | private Q_SLOTS: | ||||
34 | void initTestCase(); | ||||
35 | | ||||
36 | void shouldRoundTripLauncherUrlList(); | ||||
37 | void shouldIgnoreInvalidUrls(); | ||||
38 | void shouldRejectDuplicates(); | ||||
39 | void shouldAddRemoveLauncher(); | ||||
40 | void shouldReturnValidLauncherPositions(); | ||||
41 | void shouldReturnValidData(); | ||||
42 | | ||||
43 | private: | ||||
44 | QStringList m_urlStrings; | ||||
45 | }; | ||||
46 | | ||||
47 | void LauncherTasksModelTest::initTestCase() | ||||
48 | { | ||||
49 | m_urlStrings << QLatin1String("file:///usr/share/applications/org.kde.dolphin.desktop"); | ||||
50 | m_urlStrings << QLatin1String("file:///usr/share/applications/org.kde.konsole.desktop"); | ||||
51 | } | ||||
52 | | ||||
53 | void LauncherTasksModelTest::shouldRoundTripLauncherUrlList() | ||||
54 | { | ||||
55 | LauncherTasksModel m; | ||||
56 | | ||||
57 | QSignalSpy launcherListChangedSpy(&m, &LauncherTasksModel::launcherListChanged); | ||||
58 | QVERIFY(launcherListChangedSpy.isValid()); | ||||
59 | | ||||
60 | m.setLauncherList(m_urlStrings); | ||||
61 | | ||||
62 | QCOMPARE(launcherListChangedSpy.count(), 1); | ||||
63 | | ||||
64 | QCOMPARE(m.launcherList(), m_urlStrings); | ||||
65 | | ||||
66 | QCOMPARE(m.data(m.index(0, 0), AbstractTasksModel::LauncherUrl).toString(), m_urlStrings.at(0)); | ||||
67 | QCOMPARE(m.data(m.index(1, 0), AbstractTasksModel::LauncherUrl).toString(), m_urlStrings.at(1)); | ||||
68 | } | ||||
69 | | ||||
70 | void LauncherTasksModelTest::shouldIgnoreInvalidUrls() | ||||
71 | { | ||||
72 | LauncherTasksModel m; | ||||
73 | | ||||
74 | QStringList urlStrings; | ||||
75 | urlStrings << QLatin1String("GARBAGE URL"); | ||||
76 | | ||||
77 | QSignalSpy launcherListChangedSpy(&m, &LauncherTasksModel::launcherListChanged); | ||||
78 | QVERIFY(launcherListChangedSpy.isValid()); | ||||
79 | | ||||
80 | m.setLauncherList(urlStrings); | ||||
81 | | ||||
82 | QCOMPARE(launcherListChangedSpy.count(), 0); | ||||
83 | | ||||
84 | bool added = m.requestAddLauncher(QUrl(urlStrings.at(0))); | ||||
85 | | ||||
86 | QVERIFY(!added); | ||||
87 | QCOMPARE(launcherListChangedSpy.count(), 0); | ||||
88 | | ||||
89 | QCOMPARE(m.launcherList(), QStringList()); | ||||
90 | } | ||||
91 | | ||||
92 | void LauncherTasksModelTest::shouldRejectDuplicates() | ||||
93 | { | ||||
94 | LauncherTasksModel m; | ||||
95 | | ||||
96 | QStringList urlStrings; | ||||
97 | urlStrings << QLatin1String("file:///usr/share/applications/org.kde.dolphin.desktop"); | ||||
98 | urlStrings << QLatin1String("file:///usr/share/applications/org.kde.dolphin.desktop"); | ||||
99 | | ||||
100 | QSignalSpy launcherListChangedSpy(&m, &LauncherTasksModel::launcherListChanged); | ||||
101 | QVERIFY(launcherListChangedSpy.isValid()); | ||||
102 | | ||||
103 | m.setLauncherList(urlStrings); | ||||
104 | | ||||
105 | QCOMPARE(launcherListChangedSpy.count(), 1); | ||||
106 | | ||||
107 | bool added = m.requestAddLauncher(urlStrings.at(0)); | ||||
108 | | ||||
109 | QVERIFY(!added); | ||||
110 | QCOMPARE(launcherListChangedSpy.count(), 1); | ||||
111 | | ||||
112 | QCOMPARE(m.launcherList(), QStringList() << urlStrings.at(0)); | ||||
113 | } | ||||
114 | | ||||
115 | void LauncherTasksModelTest::shouldAddRemoveLauncher() | ||||
116 | { | ||||
117 | LauncherTasksModel m; | ||||
118 | | ||||
119 | QSignalSpy launcherListChangedSpy(&m, &LauncherTasksModel::launcherListChanged); | ||||
120 | QVERIFY(launcherListChangedSpy.isValid()); | ||||
121 | | ||||
122 | bool added = m.requestAddLauncher(m_urlStrings.at(0)); | ||||
123 | | ||||
124 | QVERIFY(added); | ||||
125 | QCOMPARE(launcherListChangedSpy.count(), 1); | ||||
126 | | ||||
127 | QCOMPARE(m.launcherList().at(0), m_urlStrings.at(0)); | ||||
128 | | ||||
129 | bool removed = m.requestRemoveLauncher(m_urlStrings.at(0)); | ||||
130 | | ||||
131 | QVERIFY(removed); | ||||
132 | QCOMPARE(launcherListChangedSpy.count(), 2); | ||||
133 | | ||||
134 | removed = m.requestRemoveLauncher(m_urlStrings.at(0)); | ||||
135 | | ||||
136 | QVERIFY(!removed); | ||||
137 | | ||||
138 | QCOMPARE(m.launcherList(), QStringList()); | ||||
139 | } | ||||
140 | | ||||
141 | void LauncherTasksModelTest::shouldReturnValidLauncherPositions() | ||||
142 | { | ||||
143 | LauncherTasksModel m; | ||||
144 | | ||||
145 | QSignalSpy launcherListChangedSpy(&m, &LauncherTasksModel::launcherListChanged); | ||||
146 | QVERIFY(launcherListChangedSpy.isValid()); | ||||
147 | | ||||
148 | m.setLauncherList(m_urlStrings); | ||||
149 | | ||||
150 | QCOMPARE(launcherListChangedSpy.count(), 1); | ||||
151 | | ||||
152 | QCOMPARE(m.launcherPosition(m_urlStrings.at(0)), 0); | ||||
153 | QCOMPARE(m.launcherPosition(m_urlStrings.at(1)), 1); | ||||
154 | } | ||||
155 | | ||||
156 | void LauncherTasksModelTest::shouldReturnValidData() | ||||
157 | { | ||||
158 | // FIXME Reuse TaskToolsTest app link setup, then run URLs through model. | ||||
159 | } | ||||
160 | | ||||
161 | QTEST_MAIN(LauncherTasksModelTest) | ||||
162 | | ||||
163 | #include "launchertasksmodeltest.moc" |