From 5456784005655ec9277832f0a07beda4e3d0a55f Mon Sep 17 00:00:00 2001 From: Caroline Chao Date: Tue, 29 Nov 2011 10:48:21 +0100 Subject: [PATCH] Integrate testcocoon support into QtQuickTest. Add support to install and save coverage data when a test is run using quick_test_main. Change-Id: I39ddd678d748979c335139b3f8bda43b3d05720d Reviewed-by: Rohan McGovern --- src/qmltest/quicktest.cpp | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-) diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp index 65107ee..2f0f7ef 100644 --- a/src/qmltest/quicktest.cpp +++ b/src/qmltest/quicktest.cpp @@ -68,6 +68,35 @@ #include 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(); -- 1.7.2.5