on ed593dc help sign in
unity8/tests/plugins/Wizard/tst_pagelist.cpp
154 lines 4.7 kB history raw
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "PageList.h"
19#include <QDebug>
20#include <QObject>
21#include <QTemporaryDir>
22#include <QTest>
24#define PAGES_PATH "Wizard/Pages"
26class PageListTest: public QObject
28 Q_OBJECT
30public:
31 PageListTest() {};
33private Q_SLOTS:
34 void testCollect();
35 void testIterate();
36 void testIgnoreNonNumbered();
37 void testIgnoreNonQml();
38 void testIgnoreDuplicates();
39 void testDisabled();
41private:
42 void fillRoot(const QTemporaryDir &root);
43 void makeFile(const QTemporaryDir &root, const QString &dir, const QString &filename);
44};
46void PageListTest::fillRoot(const QTemporaryDir &root)
48 QVERIFY(root.isValid());
49 QDir rootDir = root.path();
50 QVERIFY(rootDir.mkpath(QString("a/") + PAGES_PATH));
51 QVERIFY(rootDir.mkpath(QString("b/") + PAGES_PATH));
52 QVERIFY(rootDir.mkpath(QString("c/") + PAGES_PATH));
53 qputenv("XDG_DATA_DIRS", QString(rootDir.path() + "/a:" +
54 rootDir.path() + "/b:" +
55 rootDir.path() + "/c").toLatin1());
58void PageListTest::makeFile(const QTemporaryDir &root, const QString &dir, const QString &filename)
60 QFile file(root.path() + "/" + dir + "/" + PAGES_PATH + "/" + filename);
61 QVERIFY(file.open(QIODevice::WriteOnly));
62 file.close();
63 QVERIFY(file.exists());
66void PageListTest::testCollect()
68 QTemporaryDir root;
69 fillRoot(root);
70 makeFile(root, "a", "3.qml");
71 makeFile(root, "b", "1.qml");
72 makeFile(root, "c", "2.qml");
74 PageList pageList;
75 QCOMPARE(pageList.entries(), QStringList() << "1.qml" << "2.qml" << "3.qml");
76 QCOMPARE(pageList.paths(), QStringList() << root.path() + "/b/" + PAGES_PATH + "/1.qml"
77 << root.path() + "/c/" + PAGES_PATH + "/2.qml"
78 << root.path() + "/a/" + PAGES_PATH + "/3.qml");
81void PageListTest::testIterate()
83 QTemporaryDir root;
84 fillRoot(root);
85 makeFile(root, "a", "1.qml");
86 makeFile(root, "a", "2.qml");
87 makeFile(root, "a", "3.qml");
89 PageList pageList;
90 QCOMPARE(pageList.index(), -1);
91 QCOMPARE(pageList.next(), QString(root.path() + "/a/" + PAGES_PATH + "/1.qml"));
92 QCOMPARE(pageList.prev(), QString());
93 QCOMPARE(pageList.next(), QString(root.path() + "/a/" + PAGES_PATH + "/2.qml"));
94 QCOMPARE(pageList.prev(), QString(root.path() + "/a/" + PAGES_PATH + "/1.qml"));
95 QCOMPARE(pageList.index(), 0);
96 QCOMPARE(pageList.next(), QString(root.path() + "/a/" + PAGES_PATH + "/2.qml"));
97 QCOMPARE(pageList.next(), QString(root.path() + "/a/" + PAGES_PATH + "/3.qml"));
98 QCOMPARE(pageList.index(), 2);
99 QCOMPARE(pageList.next(), QString());
100 QCOMPARE(pageList.index(), 2);
103void PageListTest::testIgnoreNonNumbered()
105 QTemporaryDir root;
106 fillRoot(root);
107 makeFile(root, "a", "1.qml");
108 makeFile(root, "a", "nope.qml");
110 PageList pageList;
111 QCOMPARE(pageList.entries(), QStringList() << "1.qml");
114void PageListTest::testIgnoreNonQml()
116 QTemporaryDir root;
117 fillRoot(root);
118 makeFile(root, "a", "1.qml");
119 makeFile(root, "a", "2");
120 makeFile(root, "a", "2.txt");
122 PageList pageList;
123 QCOMPARE(pageList.entries(), QStringList() << "1.qml");
126void PageListTest::testIgnoreDuplicates()
128 QTemporaryDir root;
129 fillRoot(root);
130 makeFile(root, "a", "1.qml");
131 makeFile(root, "b", "1.qml");
133 PageList pageList;
134 QCOMPARE(pageList.paths(), QStringList() << root.path() + "/a/" + PAGES_PATH + "/1.qml");
137void PageListTest::testDisabled()
139 QTemporaryDir root;
140 fillRoot(root);
141 makeFile(root, "a", "1.qml.disabled"); // before the fact
142 makeFile(root, "b", "1.qml");
143 makeFile(root, "b", "2.qml");
144 makeFile(root, "b", "2.qml.disabled"); // same dir
145 makeFile(root, "b", "3.qml");
146 makeFile(root, "b", "4.qml"); // only survivor
147 makeFile(root, "c", "3.qml.disabled"); // after the fact
149 PageList pageList;
150 QCOMPARE(pageList.entries(), QStringList() << "4.qml");
153QTEST_MAIN(PageListTest)
154#include "tst_pagelist.moc"