summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2010-12-15 12:44:44 +1000
committerRhys Weatherley <rhys.weatherley@nokia.com>2010-12-15 12:44:44 +1000
commitca2133ab144a78269b27231bbc3cfd75c5911df6 (patch)
treeef8c6f5311e8f5cb14c2bc0dbe2c4218ea491c67
parent55959eddf9286ce76f25c7e157f7b726862b328e (diff)
Deprecate running tests from resources
Too much house-keeping is needed to run tests from resources, so start the process of removing support to discourage the creation of poor test harnesses.
-rw-r--r--README5
-rw-r--r--doc/src/index.qdoc56
-rw-r--r--src/quicktestlib/quicktest.cpp20
-rw-r--r--tests/qmlexample/qmlexample.pro2
-rw-r--r--tests/qmlexample/qmlexample.qrc6
5 files changed, 40 insertions, 49 deletions
diff --git a/README b/README
index 245bedc..94282c0 100644
--- a/README
+++ b/README
@@ -13,10 +13,9 @@ Qt 4.7 as follows:
The "make install" step copies the necessary libraries, plugins,
and QML module definitions into the Qt build tree.
-There is an example test case in the "tests/qmlexample" directory that
+There is an example test case in the "tests/qmlauto" directory that
shows how to integrate QML unit tests into a qmake-based build system.
-Also see "doc/testcases.txt" for an introduction to writing unit tests.
You can also run "make check" to verify that the example tests pass
correctly, and "make docs" to generate the HTML documentation under
-"doc/html".
+"doc/html" using the qdoc3 tool from Qt.
diff --git a/doc/src/index.qdoc b/doc/src/index.qdoc
index 3e0939e..69aa496 100644
--- a/doc/src/index.qdoc
+++ b/doc/src/index.qdoc
@@ -83,53 +83,39 @@
\code
#include <QtQuickTest/quicktest.h>
- QUICK_TEST_MAIN(qmlexample)
+ QUICK_TEST_MAIN(example)
\endcode
- Where "qmlexample" is an identifier to use to uniquely identify
- this set of tests. You should add \c{CONFIG += qmltestcase} to your
- .pro file; for example:
+ Where "example" is an identifier to use to uniquely identify
+ this set of tests. You should add \c{CONFIG += qmltestcase} and
+ a definition for \c{QUICK_TEST_SOURCE_DIR} to your .pro file;
+ for example:
\code
TEMPLATE = app
- TARGET = tst_qmlexample
+ TARGET = tst_example
CONFIG += warn_on qmltestcase
- SOURCES += tst_qmlexample.cpp
- RESOURCES += qmlexample.qrc
- \endcode
-
- The test harness scans recursively for "tst_*.qml" files in the qrc
- resources that are bound into the test harness binary. The following
- is an example .qrc file:
-
- \code
- <!DOCTYPE RCC><RCC version="1.0">
- <qresource>
- <file>tst_basic.qml</file>
- <file>tst_item.qml</file>
- </qresource>
- </RCC>
- \endcode
-
- The \c{QUICK_TEST_SOURCE_DIR} macro can be defined at compile time to
- run tests from plain files without binding them into resources.
- Modify your .pro file to include the following line:
-
- \code
+ SOURCES += tst_example.cpp
DEFINES += QUICK_TEST_SOURCE_DIR=\"\\\"$$PWD\\\"\"
\endcode
- The \c{QUICK_TEST_SOURCE_DIR} environment variable can also be set
- at runtime to run test cases from a different directory. This may
- be needed to run tests on a target device where the compiled-in
- directory name refers to a host.
-
+ The test harness scans the specified source directory recursively
+ for "tst_*.qml" files. If \c{QUICK_TEST_SOURCE_DIR} is not defined,
+ then the current directory will be scanned when the harness is run.
Other *.qml files may appear for auxillary QML components that are
used by the test.
+
+ The \c{-input} command-line option can be set at runtime to run
+ test cases from a different directory. This may be needed to run
+ tests on a target device where the compiled-in directory name refers
+ to a host. For example:
+
+ \code
+ tst_example -input /mnt/SDCard/qmltests
+ \endcode
- See \c{tests/qmlexample} in the source tree for an example of creating a
- test harness that uses resources and \c{tests/qmlauto} for an example
- that uses the \c{QUICK_TEST_SOURCE_DIR} macro.
+ See \c{tests/qmlauto} in the source tree for an example of creating a
+ test harness that uses the \c{QUICK_TEST_SOURCE_DIR} macro.
If your test case needs QML imports, then you can add them as
\c{-import} options to the the test program command-line by adding
diff --git a/src/quicktestlib/quicktest.cpp b/src/quicktestlib/quicktest.cpp
index 19e8605..bed13b1 100644
--- a/src/quicktestlib/quicktest.cpp
+++ b/src/quicktestlib/quicktest.cpp
@@ -134,10 +134,7 @@ int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport
argv[outargc] = 0;
argc = outargc;
- // Determine where to look for the test data. If QUICK_TEST_SOURCE_DIR
- // is set, then use that. Otherwise scan the application's resources.
- if (testPath.isEmpty())
- testPath = QString::fromLocal8Bit(qgetenv("QUICK_TEST_SOURCE_DIR"));
+ // Determine where to look for the test data.
if (testPath.isEmpty() && sourceDir)
testPath = QString::fromLocal8Bit(sourceDir);
if (testPath.isEmpty())
@@ -152,6 +149,21 @@ int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport
QDirIterator::FollowSymlinks);
while (iter.hasNext())
files += iter.next();
+ if (testPath == QLatin1String(":/")) {
+ if (files.isEmpty()) {
+ // No QML tests in the program resources - search "." instead.
+ testPath = QLatin1String(".");
+ QDirIterator iter(testPath, filters, QDir::Files,
+ QDirIterator::Subdirectories |
+ QDirIterator::FollowSymlinks);
+ while (iter.hasNext())
+ files += iter.next();
+ } else {
+ qWarning() << argv[0]
+ << ": test cases in resources are deprecated and will "
+ "be removed soon";
+ }
+ }
files.sort();
// Bail out if we didn't find any test cases.
diff --git a/tests/qmlexample/qmlexample.pro b/tests/qmlexample/qmlexample.pro
index 502d16a..c101b98 100644
--- a/tests/qmlexample/qmlexample.pro
+++ b/tests/qmlexample/qmlexample.pro
@@ -2,5 +2,5 @@ TEMPLATE=app
TARGET=tst_qmlexample
CONFIG += warn_on testcase
SOURCES += tst_qmlexample.cpp
-RESOURCES += qmlexample.qrc
+DEFINES += QUICK_TEST_SOURCE_DIR=\"\\\"$$PWD\\\"\"
include(../../src/quicktestlib/quicktestlib_dep.pri)
diff --git a/tests/qmlexample/qmlexample.qrc b/tests/qmlexample/qmlexample.qrc
deleted file mode 100644
index ee7c380..0000000
--- a/tests/qmlexample/qmlexample.qrc
+++ /dev/null
@@ -1,6 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>tst_basic.qml</file>
- <file>tst_item.qml</file>
-</qresource>
-</RCC>