summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-09-21 08:05:27 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-09-21 08:05:47 (GMT)
commitad93c27e91e17a06b13a1e612720261b9d1caa38 (patch)
tree13382fa3b5307050df614b5a32f347c879fbaafb /tests
parentc774d78c350294118c8cd7e075063290dc690a9a (diff)
downloadQt-ad93c27e91e17a06b13a1e612720261b9d1caa38.zip
Qt-ad93c27e91e17a06b13a1e612720261b9d1caa38.tar.gz
Qt-ad93c27e91e17a06b13a1e612720261b9d1caa38.tar.bz2
Add an autotest to ensure all our examples/demos launch
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/examples/data/dummytest.qml5
-rw-r--r--tests/auto/declarative/examples/examples.pro4
-rw-r--r--tests/auto/declarative/examples/tst_examples.cpp138
3 files changed, 147 insertions, 0 deletions
diff --git a/tests/auto/declarative/examples/data/dummytest.qml b/tests/auto/declarative/examples/data/dummytest.qml
new file mode 100644
index 0000000..cd9d8fb
--- /dev/null
+++ b/tests/auto/declarative/examples/data/dummytest.qml
@@ -0,0 +1,5 @@
+import Qt.VisualTest 4.6
+
+VisualTest {
+ Frame { msec: 0 }
+}
diff --git a/tests/auto/declarative/examples/examples.pro b/tests/auto/declarative/examples/examples.pro
new file mode 100644
index 0000000..c50018e
--- /dev/null
+++ b/tests/auto/declarative/examples/examples.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+contains(QT_CONFIG,declarative): QT += declarative
+SOURCES += tst_examples.cpp
+macx:CONFIG -= app_bundle
diff --git a/tests/auto/declarative/examples/tst_examples.cpp b/tests/auto/declarative/examples/tst_examples.cpp
new file mode 100644
index 0000000..d65247a
--- /dev/null
+++ b/tests/auto/declarative/examples/tst_examples.cpp
@@ -0,0 +1,138 @@
+#include <qtest.h>
+#include <QLibraryInfo>
+#include <QDir>
+#include <QProcess>
+
+class tst_examples : public QObject
+{
+ Q_OBJECT
+public:
+ tst_examples();
+
+private slots:
+ void examples_data();
+ void examples();
+
+ void namingConvention();
+private:
+ QString qmlviewer;
+
+ void namingConvention(const QDir &);
+ QStringList findQmlFiles(const QDir &);
+};
+
+tst_examples::tst_examples()
+{
+ QString binaries = QLibraryInfo::location(QLibraryInfo::BinariesPath);
+
+#if defined(Q_WS_MAC)
+ qmlviewer = QDir(binaries).absoluteFilePath("qmlviewer.app/Contents/MacOS/qmlviewer");
+#elif defined(Q_WS_WIN)
+ qmlviewer = QDir(binaries).absoluteFilePath("qmlviewer.exe");
+#else
+ qmlviewer = QDir(binaries).absoluteFilePath("qmlviewer");
+#endif
+}
+
+/*
+This tests that the demos and examples follow the naming convention required
+to have them tested by the examples() test.
+*/
+void tst_examples::namingConvention(const QDir &d)
+{
+ QStringList files = d.entryList(QStringList() << QLatin1String("*.qml"),
+ QDir::Files);
+
+ bool seenQml = !files.isEmpty();
+ bool seenLowercase = false;
+
+ foreach (const QString &file, files) {
+ if (file.at(0).isLower())
+ seenLowercase = true;
+ }
+
+ if (!seenQml) {
+ QStringList dirs = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot |
+ QDir::NoSymLinks);
+ foreach (const QString &dir, dirs) {
+ QDir sub = d;
+ sub.cd(dir);
+ namingConvention(sub);
+ }
+ } else if(!seenLowercase) {
+ QTest::qFail(QString("Directory " + d.absolutePath() + " violates naming convention").toLatin1().constData(), __FILE__, __LINE__);
+ }
+}
+
+void tst_examples::namingConvention()
+{
+ QString examples = QLibraryInfo::location(QLibraryInfo::ExamplesPath);
+ QString demos = QLibraryInfo::location(QLibraryInfo::DemosPath);
+
+ namingConvention(QDir(examples));
+ namingConvention(QDir(demos));
+}
+
+QStringList tst_examples::findQmlFiles(const QDir &d)
+{
+ QStringList rv;
+
+ QStringList files = d.entryList(QStringList() << QLatin1String("*.qml"),
+ QDir::Files);
+ foreach (const QString &file, files) {
+ if (file.at(0).isLower()) {
+ rv << d.absoluteFilePath(file);
+ }
+ }
+
+ QStringList dirs = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot |
+ QDir::NoSymLinks);
+ foreach (const QString &dir, dirs) {
+ QDir sub = d;
+ sub.cd(dir);
+ rv << findQmlFiles(sub);
+ }
+
+ return rv;
+}
+
+/*
+This test runs all the examples in the declarative UI source tree and ensures
+that they start and exit cleanly.
+
+Examples are any .qml files under the examples/ or demos/ directory that start
+with a lower case letter.
+*/
+void tst_examples::examples_data()
+{
+ QTest::addColumn<QString>("file");
+
+ QString examples = QLibraryInfo::location(QLibraryInfo::ExamplesPath);
+ QString demos = QLibraryInfo::location(QLibraryInfo::DemosPath);
+
+ QStringList files;
+ files << findQmlFiles(QDir(examples));
+ files << findQmlFiles(QDir(demos));
+
+ foreach (const QString &file, files)
+ QTest::newRow(file.toLatin1().constData()) << file;
+}
+
+void tst_examples::examples()
+{
+ QFETCH(QString, file);
+
+ QStringList arguments;
+ arguments << "-script" << "data/dummytest"
+ << "-scriptopts" << "play,exitoncomplete,exitonfailure"
+ << file;
+ QProcess p;
+ p.start(qmlviewer, arguments);
+ QVERIFY(p.waitForFinished());
+ QCOMPARE(p.exitStatus(), QProcess::NormalExit);
+ QCOMPARE(p.exitCode(), 0);
+}
+
+QTEST_MAIN(tst_examples)
+
+#include "tst_examples.moc"