2 * This file is part of system-settings
4 * Copyright (C) 2014 Canonical Ltd.
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
23#include <QTemporaryDir>
26#define PAGES_PATH "ubuntu/settings/wizard/qml/Pages"
28class PageListTest: public QObject
38 void testIgnoreNonNumbered();
39 void testIgnoreNonQml();
40 void testIgnoreDuplicates();
44 void fillRoot(const QTemporaryDir &root);
45 void makeFile(const QTemporaryDir &root, const QString &dir, const QString &filename);
48void PageListTest::fillRoot(const QTemporaryDir &root)
50 QVERIFY(root.isValid());
51 QDir rootDir = root.path();
52 QVERIFY(rootDir.mkpath(QString("a/") + PAGES_PATH));
53 QVERIFY(rootDir.mkpath(QString("b/") + PAGES_PATH));
54 QVERIFY(rootDir.mkpath(QString("c/") + PAGES_PATH));
55 qputenv("XDG_DATA_DIRS", QString(rootDir.path() + "/a:" +
56 rootDir.path() + "/b:" +
57 rootDir.path() + "/c").toLatin1());
60void PageListTest::makeFile(const QTemporaryDir &root, const QString &dir, const QString &filename)
62 QFile file(root.path() + "/" + dir + "/" + PAGES_PATH + "/" + filename);
63 QVERIFY(file.open(QIODevice::WriteOnly));
65 QVERIFY(file.exists());
68void PageListTest::testCollect()
72 makeFile(root, "a", "3.qml");
73 makeFile(root, "b", "1.qml");
74 makeFile(root, "c", "2.qml");
77 QCOMPARE(pageList.entries(), QStringList() << "1.qml" << "2.qml" << "3.qml");
78 QCOMPARE(pageList.paths(), QStringList() << root.path() + "/b/" + PAGES_PATH + "/1.qml"
79 << root.path() + "/c/" + PAGES_PATH + "/2.qml"
80 << root.path() + "/a/" + PAGES_PATH + "/3.qml");
83void PageListTest::testIterate()
87 makeFile(root, "a", "1.qml");
88 makeFile(root, "a", "2.qml");
89 makeFile(root, "a", "3.qml");
92 QCOMPARE(pageList.index(), -1);
93 QCOMPARE(pageList.next(), root.path() + "/a/" + PAGES_PATH + "/1.qml");
94 QCOMPARE(pageList.prev(), QString());
95 QCOMPARE(pageList.next(), root.path() + "/a/" + PAGES_PATH + "/2.qml");
96 QCOMPARE(pageList.prev(), root.path() + "/a/" + PAGES_PATH + "/1.qml");
97 QCOMPARE(pageList.index(), 0);
98 QCOMPARE(pageList.next(), root.path() + "/a/" + PAGES_PATH + "/2.qml");
99 QCOMPARE(pageList.next(), root.path() + "/a/" + PAGES_PATH + "/3.qml");
100 QCOMPARE(pageList.index(), 2);
101 QCOMPARE(pageList.next(), QString());
102 QCOMPARE(pageList.index(), 2);
105void PageListTest::testIgnoreNonNumbered()
109 makeFile(root, "a", "1.qml");
110 makeFile(root, "a", "nope.qml");
113 QCOMPARE(pageList.entries(), QStringList() << "1.qml");
116void PageListTest::testIgnoreNonQml()
120 makeFile(root, "a", "1.qml");
121 makeFile(root, "a", "2");
122 makeFile(root, "a", "2.txt");
125 QCOMPARE(pageList.entries(), QStringList() << "1.qml");
128void PageListTest::testIgnoreDuplicates()
132 makeFile(root, "a", "1.qml");
133 makeFile(root, "b", "1.qml");
136 QCOMPARE(pageList.paths(), QStringList() << root.path() + "/a/" + PAGES_PATH + "/1.qml");
139void PageListTest::testDisabled()
143 makeFile(root, "a", "1.qml.disabled"); // before the fact
144 makeFile(root, "b", "1.qml");
145 makeFile(root, "b", "2.qml");
146 makeFile(root, "b", "2.qml.disabled"); // same dir
147 makeFile(root, "b", "3.qml");
148 makeFile(root, "b", "4.qml"); // only survivor
149 makeFile(root, "c", "3.qml.disabled"); // after the fact
152 QCOMPARE(pageList.entries(), QStringList() << "4.qml");
155QTEST_MAIN(PageListTest)
156#include "tst_pagelist.moc"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list