2 * Copyright (C) 2014 Canonical, Ltd.
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.
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.
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/>.
23#include <QTemporaryFile>
25class CardCreatorTest : public QObject
37 view = new QQuickView();
38 view->setSource(QUrl::fromLocalFile(DASHVIEWSTEST_FOLDER "/cardcreatortest.qml"));
40 QTest::qWaitForWindowExposed(view);
48 void compareFileContents(const QString &filePath, const QString cardStringResult)
50 QFile testResultFile(filePath);
51 QVERIFY(testResultFile.open(QIODevice::ReadOnly));
52 QTextStream ts2(&testResultFile);
54 // Record failed results to /tmp
55 const QString executedResult = cardStringResult;
56 QTemporaryFile tmpFile(QDir::tempPath() + QDir::separator() + "testCardCreatorFailedResultXXXXXX");
58 tmpFile.setAutoRemove(false);
59 tmpFile.write(executedResult.toUtf8().constData());
61 // Line by line comparison
62 const QStringList expectedLines = ts2.readAll().trimmed().replace(QRegExp("\n\\s*\n"),"\n").split("\n");
63 const QStringList cardStringResultLines = cardStringResult.trimmed().replace(QRegExp("\n\\s*\n"),"\n").split("\n");
64 for (int i = 0; i < expectedLines.size(); ++i) {
65 QCOMPARE(cardStringResultLines[i].simplified(), expectedLines[i].simplified());
68 // Remove the result if it passed
69 tmpFile.setAutoRemove(true);
74 const QString templateString("template: ");
75 const QString componentsString("components: ");
76 const QString artShapeStyleString("artShapeStyle: ");
77 const QString resultString("result: ");
79 const QString testDirPath = DASHVIEWSTEST_FOLDER "/cardcreator/";
81 const QStringList testFiles = d.entryList(QStringList() << "*.tst");
82 foreach(const QString &testFileName, testFiles) {
83 qDebug() << testFileName;
84 QFile testFile(testDirPath + testFileName);
85 QVERIFY(testFile.open(QIODevice::ReadOnly));
86 QTextStream ts(&testFile);
87 const QStringList lines = ts.readAll().split("\n");
89 QVERIFY(lines[0].startsWith(templateString));
90 QVERIFY(lines[1].startsWith(componentsString));
91 QVERIFY(lines[2].startsWith(artShapeStyleString));
92 QVERIFY(lines[3].startsWith(resultString));
94 const QString templateJSON = lines[0].mid(templateString.length());
95 const QString componentsJSON = lines[1].mid(componentsString.length());
96 const QString artShapeStyle = lines[2].mid(artShapeStyleString.length());
97 const QString resultFileName = lines[3].mid(resultString.length());
98 QVariant cardStringResult;
99 QVariant createCardComponentResult;
101 QMetaObject::invokeMethod(view->rootObject(), "cardString", Q_RETURN_ARG(QVariant, cardStringResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON), Q_ARG(QVariant, false), Q_ARG(QVariant, artShapeStyle));
102 compareFileContents(testDirPath + resultFileName, cardStringResult.toString());
104 QMetaObject::invokeMethod(view->rootObject(), "cardString", Q_RETURN_ARG(QVariant, cardStringResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON), Q_ARG(QVariant, true), Q_ARG(QVariant, artShapeStyle));
105 compareFileContents(testDirPath + resultFileName + ".cardcreator", cardStringResult.toString());
107 QMetaObject::invokeMethod(view->rootObject(), "createCardComponent", Q_RETURN_ARG(QVariant, createCardComponentResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON), Q_ARG(QVariant, false), Q_ARG(QVariant, artShapeStyle));
108 QVERIFY(createCardComponentResult.toBool());
110 QMetaObject::invokeMethod(view->rootObject(), "createCardComponent", Q_RETURN_ARG(QVariant, createCardComponentResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON), Q_ARG(QVariant, true), Q_ARG(QVariant, artShapeStyle));
111 QVERIFY(createCardComponentResult.toBool());
119QTEST_MAIN(CardCreatorTest)
121#include "cardcreatortest.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