on 0df89fa help sign in
unity8/tests/plugins/Dash/cardcreatortest.cpp
91 lines 3.2 kB history raw
1/*
2 * Copyright (C) 2014 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 */
17#include <QDir>
18#include <QQmlEngine>
19#include <QQuickItem>
20#include <QQuickView>
21#include <QtTestGui>
23class CardCreatorTest : public QObject
25 Q_OBJECT
27private Q_SLOTS:
29 void initTestCase()
30 {
31 }
33 void init()
34 {
35 view = new QQuickView();
36 view->engine()->addImportPath(BUILT_PLUGINS_DIR);
37 view->setSource(QUrl::fromLocalFile(DASHVIEWSTEST_FOLDER "/cardcreatortest.qml"));
38 view->show();
39 QTest::qWaitForWindowExposed(view);
40 }
42 void cleanup()
43 {
44 delete view;
45 }
47 void testKnownCases()
48 {
49 const QString templateString("template: ");
50 const QString componentsString("components: ");
51 const QString resultString("result: ");
53 const QString testDirPath = DASHVIEWSTEST_FOLDER "/cardcreator/";
54 QDir d(testDirPath);
55 const QStringList testFiles = d.entryList(QStringList() << "*.tst");
56 foreach(const QString &testFileName, testFiles) {
57 qDebug() << testFileName;
58 QFile testFile(testDirPath + testFileName);
59 QVERIFY(testFile.open(QIODevice::ReadOnly));
60 QTextStream ts(&testFile);
61 const QStringList lines = ts.readAll().split("\n");
63 QVERIFY(lines[0].startsWith(templateString));
64 QVERIFY(lines[1].startsWith(componentsString));
65 QVERIFY(lines[2].startsWith(resultString));
66 const QString templateJSON = lines[0].mid(templateString.length());
67 const QString componentsJSON = lines[1].mid(componentsString.length());
68 const QString resultFileName = lines[2].mid(resultString.length());
70 QVariant cardStringResult;
71 QMetaObject::invokeMethod(view->rootObject(), "cardString", Q_RETURN_ARG(QVariant, cardStringResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON));
73 QFile testResultFile(testDirPath + resultFileName);
74 QVERIFY(testResultFile.open(QIODevice::ReadOnly));
75 QTextStream ts2(&testResultFile);
76 const QString expectedResult = ts2.readAll();
77 QCOMPARE(cardStringResult.toString().simplified(), expectedResult.simplified());
79 QVariant createCardComponentResult;
80 QMetaObject::invokeMethod(view->rootObject(), "createCardComponent", Q_RETURN_ARG(QVariant, createCardComponentResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON));
81 QVERIFY(createCardComponentResult.toBool());
82 }
83 }
85private:
86 QQuickView *view;
87};
89QTEST_MAIN(CardCreatorTest)
91#include "cardcreatortest.moc"