@@ -0,0 +1,90 @@
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+class CardCreatorTest : public QObject
35+ view = new QQuickView();
36+ view->engine()->addImportPath(BUILT_PLUGINS_DIR);
37+ view->setSource(QUrl::fromLocalFile(DASHVIEWSTEST_FOLDER "/cardcreatortest.qml"));
39+ QTest::qWaitForWindowExposed(view);
47+ void testKnownCases()
49+ const QString templateString("template: ");
50+ const QString componentsString("components: ");
51+ const QString resultString("result: ");
53+ const QString testDirPath = DASHVIEWSTEST_FOLDER "/cardcreator/";
55+ const QStringList testFiles = d.entryList(QStringList() << "*.tst");
56+ foreach(const QString &testFileName, testFiles) {
57+ QFile testFile(testDirPath + testFileName);
58+ QVERIFY(testFile.open(QIODevice::ReadOnly));
59+ QTextStream ts(&testFile);
60+ const QStringList lines = ts.readAll().split("\n");
62+ QVERIFY(lines[0].startsWith(templateString));
63+ QVERIFY(lines[1].startsWith(componentsString));
64+ QVERIFY(lines[2].startsWith(resultString));
65+ const QString templateJSON = lines[0].mid(templateString.length());
66+ const QString componentsJSON = lines[1].mid(componentsString.length());
67+ const QString resultFileName = lines[2].mid(resultString.length());
69+ QVariant cardStringResult;
70+ QMetaObject::invokeMethod(view->rootObject(), "cardString", Q_RETURN_ARG(QVariant, cardStringResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON));
72+ QFile testResultFile(testDirPath + resultFileName);
73+ QVERIFY(testResultFile.open(QIODevice::ReadOnly));
74+ QTextStream ts2(&testResultFile);
75+ const QString expectedResult = ts2.readAll();
76+ QCOMPARE(cardStringResult.toString().simplified(), expectedResult.simplified());
78+ QVariant createCardComponentResult;
79+ QMetaObject::invokeMethod(view->rootObject(), "createCardComponent", Q_RETURN_ARG(QVariant, createCardComponentResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON));
80+ QVERIFY(createCardComponentResult.toBool());
88+QTEST_MAIN(CardCreatorTest)
90+#include "cardcreatortest.moc"