Integrate testcocoon support into QtQuickTest.
authorCaroline Chao <caroline.chao@nokia.com>
Tue, 29 Nov 2011 09:48:21 +0000 (10:48 +0100)
committerQt by Nokia <qt-info@nokia.com>
Fri, 9 Dec 2011 12:08:36 +0000 (13:08 +0100)
Add support to install and save coverage data when a test is run
using quick_test_main.

Change-Id: I39ddd678d748979c335139b3f8bda43b3d05720d
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>

src/qmltest/quicktest.cpp

index 65107ee..2f0f7ef 100644 (file)
 #include <QtCore/QTranslator>
 QT_BEGIN_NAMESPACE
 
+static void installCoverageTool(const char * appname, const char * testname)
+{
+#ifdef __COVERAGESCANNER__
+    // Install Coverage Tool
+    __coveragescanner_install(appname);
+    __coveragescanner_testname(testname);
+    __coveragescanner_clear();
+#else
+    Q_UNUSED(appname);
+    Q_UNUSED(testname);
+#endif
+}
+
+static void saveCoverageTool(const char * appname, bool testfailed)
+{
+#ifdef __COVERAGESCANNER__
+    // install again to make sure the filename is correct.
+    // without this, a plugin or similar may have changed the filename.
+    __coveragescanner_install(appname);
+    __coveragescanner_teststate(testfailed ? "FAILED" : "PASSED");
+    __coveragescanner_save();
+    __coveragescanner_testname("");
+    __coveragescanner_clear();
+#else
+    Q_UNUSED(appname);
+    Q_UNUSED(testfailed);
+#endif
+}
+
 
 class QTestRootObject : public QObject
 {
@@ -152,6 +181,8 @@ int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport
     QuickTestResult::parseArgs(argc, argv);
     QuickTestResult::setProgramName(name);
 
+    installCoverageTool(argv[0], name);
+
     QTranslator translator;
     if (!translationFile.isEmpty()) {
         if (translator.load(translationFile)) {
@@ -313,6 +344,8 @@ int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport
     // Flush the current logging stream.
     QuickTestResult::setProgramName(0);
 
+    saveCoverageTool(argv[0], QuickTestResult::exitCode());
+
     delete app;
     // Return the number of failures as the exit code.
     return QuickTestResult::exitCode();