summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorRohan McGovern <rohan.mcgovern@nokia.com>2011-09-14 07:45:44 (GMT)
committerRohan McGovern <rohan.mcgovern@nokia.com>2011-09-14 07:45:44 (GMT)
commit1b30b3a6726adf806ae221357393e562285e8346 (patch)
treec650ff836d3abdf5890726354ee6e2b9bce11304 /src/testlib
parent1c1a5fe0e2d9e28be5e0e14732d79d34c9bb2a74 (diff)
parent704dd92581783d91ccd234d58896d7078eed14a5 (diff)
downloadQt-1b30b3a6726adf806ae221357393e562285e8346.zip
Qt-1b30b3a6726adf806ae221357393e562285e8346.tar.gz
Qt-1b30b3a6726adf806ae221357393e562285e8346.tar.bz2
Merge remote branch 'origin/4.8' into 4.8-from-4.7
Conflicts: src/gui/text/qtextengine_p.h src/network/ssl/qsslsocket_openssl.cpp
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qabstracttestlogger.cpp10
-rw-r--r--src/testlib/qabstracttestlogger_p.h2
-rw-r--r--src/testlib/qbenchmarkvalgrind.cpp11
-rw-r--r--src/testlib/qplaintestlogger.cpp22
-rw-r--r--src/testlib/qplaintestlogger_p.h4
-rw-r--r--src/testlib/qtest.h2
-rw-r--r--src/testlib/qtest_global.h2
-rw-r--r--src/testlib/qtestcase.cpp240
-rw-r--r--src/testlib/qtestlightxmlstreamer.cpp8
-rw-r--r--src/testlib/qtestlog.cpp66
-rw-r--r--src/testlib/qtestlog_p.h2
-rw-r--r--src/testlib/qtestlogger.cpp27
-rw-r--r--src/testlib/qtestlogger_p.h5
-rw-r--r--src/testlib/qtestmouse.h4
-rw-r--r--src/testlib/qtestresult.cpp5
-rw-r--r--src/testlib/qtestxmlstreamer.cpp10
-rw-r--r--src/testlib/qxmltestlogger.cpp27
-rw-r--r--src/testlib/qxmltestlogger_p.h4
-rw-r--r--src/testlib/testlib.pro10
19 files changed, 385 insertions, 76 deletions
diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp
index cb58642..735ad01 100644
--- a/src/testlib/qabstracttestlogger.cpp
+++ b/src/testlib/qabstracttestlogger.cpp
@@ -104,8 +104,16 @@ void QAbstractTestLogger::startLogging()
void QAbstractTestLogger::stopLogging()
{
QTEST_ASSERT(QTest::stream);
- if (QTest::stream != stdout)
+ if (QTest::stream != stdout) {
fclose(QTest::stream);
+ } else {
+#ifdef Q_OS_SYMBIAN
+ // Convenience sleep for Symbian and TRK. Without this sleep depending on the timing the
+ // user would not see the complete output because it is still pending in any of the buffers
+ // before arriving via the USB port on the development PC
+ User::AfterHighRes(2*1000*1000);
+#endif
+ }
QTest::stream = 0;
}
diff --git a/src/testlib/qabstracttestlogger_p.h b/src/testlib/qabstracttestlogger_p.h
index 755cec5..847c144 100644
--- a/src/testlib/qabstracttestlogger_p.h
+++ b/src/testlib/qabstracttestlogger_p.h
@@ -95,6 +95,8 @@ public:
virtual void addMessage(MessageTypes type, const char *message,
const char *file = 0, int line = 0) = 0;
+ virtual void registerRandomSeed(unsigned int seed) = 0;
+
static void outputString(const char *msg);
static bool isTtyOutput();
};
diff --git a/src/testlib/qbenchmarkvalgrind.cpp b/src/testlib/qbenchmarkvalgrind.cpp
index 4b260e8..22c7c37 100644
--- a/src/testlib/qbenchmarkvalgrind.cpp
+++ b/src/testlib/qbenchmarkvalgrind.cpp
@@ -225,6 +225,12 @@ bool QBenchmarkValgrindUtils::runCallgrindSubProcess(const QStringList &origAppA
return finishedOk;
}
+#if defined(Q_CC_GNU) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)
+// the callgrind macros below generate warnings
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+
void QBenchmarkCallgrindMeasurer::start()
{
CALLGRIND_ZERO_STATS;
@@ -237,6 +243,11 @@ qint64 QBenchmarkCallgrindMeasurer::checkpoint()
return result;
}
+#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)
+// the callgrind macros above generate warnings
+# pragma GCC diagnostic pop
+#endif
+
qint64 QBenchmarkCallgrindMeasurer::stop()
{
return checkpoint();
diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp
index 8d456a7..5656ac6 100644
--- a/src/testlib/qplaintestlogger.cpp
+++ b/src/testlib/qplaintestlogger.cpp
@@ -384,6 +384,7 @@ namespace QTest {
}
QPlainTestLogger::QPlainTestLogger()
+: randomSeed(9), hasRandomSeed(false)
{
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
InitializeCriticalSection(&QTest::outputCriticalSection);
@@ -415,10 +416,17 @@ void QPlainTestLogger::startLogging()
QTest::qt_snprintf(buf, sizeof(buf), "Testing %s\n",
QTestResult::currentTestObjectName());
} else {
- QTest::qt_snprintf(buf, sizeof(buf),
- "********* Start testing of %s *********\n"
- "Config: Using QTest library " QTEST_VERSION_STR
- ", Qt %s\n", QTestResult::currentTestObjectName(), qVersion());
+ if (hasRandomSeed) {
+ QTest::qt_snprintf(buf, sizeof(buf),
+ "********* Start testing of %s *********\n"
+ "Config: Using QTest library " QTEST_VERSION_STR
+ ", Qt %s, Random seed %d\n", QTestResult::currentTestObjectName(), qVersion(), randomSeed);
+ } else {
+ QTest::qt_snprintf(buf, sizeof(buf),
+ "********* Start testing of %s *********\n"
+ "Config: Using QTest library " QTEST_VERSION_STR
+ ", Qt %s\n", QTestResult::currentTestObjectName(), qVersion());
+ }
}
QTest::outputMessage(buf);
}
@@ -480,4 +488,10 @@ void QPlainTestLogger::addMessage(MessageTypes type, const char *message,
QTest::printMessage(QTest::messageType2String(type), message, file, line);
}
+void QPlainTestLogger::registerRandomSeed(unsigned int seed)
+{
+ randomSeed = seed;
+ hasRandomSeed = true;
+}
+
QT_END_NAMESPACE
diff --git a/src/testlib/qplaintestlogger_p.h b/src/testlib/qplaintestlogger_p.h
index 421ed39..aa9df83 100644
--- a/src/testlib/qplaintestlogger_p.h
+++ b/src/testlib/qplaintestlogger_p.h
@@ -75,6 +75,10 @@ public:
void addMessage(MessageTypes type, const char *message,
const char *file = 0, int line = 0);
+ void registerRandomSeed(unsigned int seed);
+private:
+ unsigned int randomSeed;
+ bool hasRandomSeed;
};
QT_END_NAMESPACE
diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h
index 9843b83..386f154 100644
--- a/src/testlib/qtest.h
+++ b/src/testlib/qtest.h
@@ -159,7 +159,7 @@ template<> inline char *toString(const QVariant &v)
if (!v.isNull()) {
vstring.append(',');
if (v.canConvert(QVariant::String)) {
- vstring.append(qVariantValue<QString>(v).toLatin1());
+ vstring.append(qvariant_cast<QString>(v).toLatin1());
}
else {
vstring.append("<value not representable as string>");
diff --git a/src/testlib/qtest_global.h b/src/testlib/qtest_global.h
index ecb47f1..85b9d6e 100644
--- a/src/testlib/qtest_global.h
+++ b/src/testlib/qtest_global.h
@@ -62,7 +62,7 @@ QT_MODULE(Test)
# endif
#endif
-#if (defined (Q_CC_MSVC) && _MSC_VER < 1310) || defined (Q_CC_SUN) || defined (Q_CC_XLC) || (defined (Q_CC_GNU) && (__GNUC__ - 0 < 3)) || defined (Q_CC_NOKIAX86)
+#if defined (Q_CC_SUN) || defined (Q_CC_XLC) || (defined (Q_CC_GNU) && (__GNUC__ - 0 < 3)) || defined (Q_CC_NOKIAX86)
# define QTEST_NO_SPECIALIZATIONS
#endif
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 544ba78..d2ea988 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -833,25 +833,46 @@ namespace QTest
{
static QObject *currentTestObject = 0;
- static struct TestFunction {
- TestFunction():function(0), data(0) {}
- ~TestFunction() { delete [] data; }
- int function;
- char *data;
- } *testFuncs;
-
+ class TestFunction {
+ public:
+ TestFunction() : function_(-1), data_(0) {}
+ void set(int function, char *data) { function_ = function; data_ = data; }
+ char *data() const { return data_; }
+ int function() const { return function_; }
+ ~TestFunction() { delete[] data_; }
+ private:
+ int function_;
+ char *data_;
+ };
/**
- * Contains the count of test functions that was supplied
- * on the command line, if any. Hence, if lastTestFuncIdx is
- * more than zero, those functions should be run instead of
+ * Contains the list of test functions that was supplied
+ * on the command line, if any. Hence, if not empty,
+ * those functions should be run instead of
* all appearing in the test case.
*/
- static int lastTestFuncIdx = -1;
+ static TestFunction * testFuncs = 0;
+ static int testFuncCount = 0;
+
+ /** Don't leak testFuncs on exit even on error */
+ static struct TestFuncCleanup
+ {
+ void cleanup()
+ {
+ delete[] testFuncs;
+ testFuncCount = 0;
+ testFuncs = 0;
+ }
+
+ ~TestFuncCleanup() { cleanup(); }
+ } testFuncCleaner;
static int keyDelay = -1;
static int mouseDelay = -1;
static int eventDelay = -1;
+ static bool randomOrder = false;
static int keyVerbose = -1;
+ static unsigned int seed = 0;
+ static bool seedSet = false;
#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
static bool noCrashHandler = false;
#endif
@@ -937,6 +958,43 @@ int Q_TESTLIB_EXPORT defaultKeyDelay()
return keyDelay;
}
+void seedRandom()
+{
+ static bool randomSeeded = false;
+ if (!randomSeeded) {
+ if (!QTest::seedSet) {
+ QElapsedTimer timer;
+ timer.start();
+ QTest::seed = timer.msecsSinceReference();
+ }
+ qsrand(QTest::seed);
+ randomSeeded = true;
+ }
+}
+
+int qTestRandomSeed()
+{
+ Q_ASSERT(QTest::seedSet);
+ return QTest::seed;
+}
+
+template<typename T>
+void swap(T * array, int pos, int otherPos)
+{
+ T tmp = array[pos];
+ array[pos] = array[otherPos];
+ array[otherPos] = tmp;
+}
+
+template<typename T>
+static void randomizeList(T * array, int size)
+{
+ for (int i = 0; i != size; i++) {
+ int pos = qrand() % size;
+ swap(array, pos, i);
+ }
+}
+
static bool isValidSlot(const QMetaMethod &sl)
{
if (sl.access() != QMetaMethod::Private || !sl.parameterTypes().isEmpty()
@@ -957,6 +1015,7 @@ static bool isValidSlot(const QMetaMethod &sl)
}
Q_TESTLIB_EXPORT bool printAvailableFunctions = false;
+Q_TESTLIB_EXPORT bool printAvailableTags = false;
Q_TESTLIB_EXPORT QStringList testFunctions;
Q_TESTLIB_EXPORT QStringList testTags;
@@ -969,6 +1028,65 @@ static void qPrintTestSlots()
}
}
+static void qPrintDataTags()
+{
+ // Get global data tags:
+ QTestTable::globalTestTable();
+ invokeMethod(QTest::currentTestObject, "initTestCase_data()");
+ const QTestTable *gTable = QTestTable::globalTestTable();
+
+ const QMetaObject *currTestMetaObj = QTest::currentTestObject->metaObject();
+
+ // Process test functions:
+ for (int i = 0; i < currTestMetaObj->methodCount(); ++i) {
+ QMetaMethod tf = currTestMetaObj->method(i);
+ if (isValidSlot(tf)) {
+ // Retrieve local tags:
+ QStringList localTags;
+ QTestTable table;
+ char member[512];
+ char *slot = qstrdup(tf.signature());
+ slot[strlen(slot) - 2] = '\0';
+ QTest::qt_snprintf(member, 512, "%s_data()", slot);
+ invokeMethod(QTest::currentTestObject, member);
+ for (int j = 0; j < table.dataCount(); ++j)
+ localTags << QLatin1String(table.testData(j)->dataTag());
+
+ // Print all tag combinations:
+ if (gTable->dataCount() == 0) {
+ if (localTags.count() == 0) {
+ // No tags at all, so just print the test function:
+ printf("%s %s\n", currTestMetaObj->className(), slot);
+ } else {
+ // Only local tags, so print each of them:
+ for (int k = 0; k < localTags.size(); ++k)
+ printf(
+ "%s %s %s\n",
+ currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data());
+ }
+ } else {
+ for (int j = 0; j < gTable->dataCount(); ++j) {
+ if (localTags.count() == 0) {
+ // Only global tags, so print the current one:
+ printf(
+ "%s %s __global__ %s\n",
+ currTestMetaObj->className(), slot, gTable->testData(j)->dataTag());
+ } else {
+ // Local and global tags, so print each of the local ones and
+ // the current global one:
+ for (int k = 0; k < localTags.size(); ++k)
+ printf(
+ "%s %s %s __global__ %s\n", currTestMetaObj->className(), slot,
+ localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag());
+ }
+ }
+ }
+
+ delete[] slot;
+ }
+ }
+}
+
static int qToInt(char *str)
{
char *pEnd;
@@ -982,11 +1100,11 @@ static int qToInt(char *str)
Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
{
- lastTestFuncIdx = -1;
-
const char *testOptions =
" options:\n"
" -functions : Returns a list of current testfunctions\n"
+ " -datatags : Returns a list of current data tags.\n"
+ " A global data tag is preceded by ' __global__ '.\n"
" -xunitxml : Outputs results as XML XUnit document\n"
" -xml : Outputs results as XML document\n"
" -lightxml : Outputs results as stream of XML tags\n"
@@ -996,6 +1114,9 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
" -v1 : Print enter messages for each testfunction\n"
" -v2 : Also print out each QVERIFY/QCOMPARE/QTEST\n"
" -vs : Print every signal emitted\n"
+ " -random : Run testcases within each test in random order\n"
+ " -seed n : Positive integer to be used as seed for -random. If not specified,\n"
+ " the current time will be used as seed.\n"
" -eventdelay ms : Set default delay for mouse and keyboard simulation to ms milliseconds\n"
" -keydelay ms : Set default delay for keyboard simulation to ms milliseconds\n"
" -mousedelay ms : Set default delay for mouse simulation to ms milliseconds\n"
@@ -1035,6 +1156,12 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
qPrintTestSlots();
exit(0);
}
+ } else if (strcmp(argv[i], "-datatags") == 0) {
+ QTest::printAvailableTags = true;
+ if (!qml) {
+ qPrintDataTags();
+ exit(0);
+ }
} else if(strcmp(argv[i], "-xunitxml") == 0){
QTestLog::setLogMode(QTestLog::XunitXML);
} else if (strcmp(argv[i], "-xml") == 0) {
@@ -1115,6 +1242,22 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
#endif
} else if (strcmp(argv[i], "-eventcounter") == 0) {
QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::EventCounter);
+ } else if (strcmp(argv[i], "-random") == 0) {
+ QTest::randomOrder = true;
+ } else if (strcmp(argv[i], "-seed") == 0) {
+ bool argumentOk = false;
+ if (i + 1 < argc) {
+ char * endpt = 0;
+ long longSeed = strtol(argv[++i], &endpt, 10);
+ argumentOk = (*endpt == '\0' && longSeed >= 0);
+ QTest::seed = longSeed;
+ }
+ if (!argumentOk) {
+ printf("-seed needs an extra positive integer parameter to specify the seed\n");
+ exit(1);
+ } else {
+ QTest::seedSet = true;
+ }
} else if (strcmp(argv[i], "-minimumvalue") == 0) {
if (i + 1 >= argc) {
printf("-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n");
@@ -1181,6 +1324,10 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
QString::fromLatin1(argv[i] + colon + 1);
}
} else {
+ if (!QTest::testFuncs) {
+ QTest::testFuncs = new QTest::TestFunction[512];
+ }
+
int colon = -1;
char buf[512], *data=0;
int off;
@@ -1202,17 +1349,16 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
qPrintTestSlots();
exit(1);
}
- ++QTest::lastTestFuncIdx;
- if (!QTest::testFuncs) {
- struct Cleanup { ~Cleanup() { delete[] QTest::testFuncs; } };
- static Cleanup cleanup;
- QTest::testFuncs = new TestFunction[512];
- }
- QTest::testFuncs[QTest::lastTestFuncIdx].function = idx;
- QTest::testFuncs[QTest::lastTestFuncIdx].data = data;
- QTEST_ASSERT(QTest::lastTestFuncIdx < 512);
+ testFuncs[testFuncCount].set(idx, data);
+ testFuncCount++;
+ QTEST_ASSERT(QTest::testFuncCount < 512);
}
}
+
+ if (QTest::seedSet && !QTest::randomOrder) {
+ printf("-seed requires -random\n");
+ exit(1);
+ }
}
QBenchmarkResult qMedian(const QList<QBenchmarkResult> &container)
@@ -1507,9 +1653,11 @@ static void qInvokeTestMethods(QObject *testObject)
{
const QMetaObject *metaObject = testObject->metaObject();
QTEST_ASSERT(metaObject);
-
- QTestLog::startLogging();
-
+ if (QTest::randomOrder) {
+ QTestLog::startLogging(QTest::seed);
+ } else {
+ QTestLog::startLogging();
+ }
QTestResult::setCurrentTestFunction("initTestCase");
QTestResult::setCurrentTestLocation(QTestResult::DataFunc);
QTestTable::globalTestTable();
@@ -1525,21 +1673,31 @@ static void qInvokeTestMethods(QObject *testObject)
if(!QTestResult::skipCurrentTest() && !previousFailed) {
- if (lastTestFuncIdx >= 0) {
- for (int i = 0; i <= lastTestFuncIdx; ++i) {
- if (!qInvokeTestMethod(metaObject->method(testFuncs[i].function).signature(),
- testFuncs[i].data))
+ if (QTest::testFuncs) {
+ if (QTest::randomOrder)
+ randomizeList(QTest::testFuncs, QTest::testFuncCount);
+ for (int i = 0; i != QTest::testFuncCount; i++) {
+ if (!qInvokeTestMethod(metaObject->method(QTest::testFuncs[i].function()).signature(),
+ QTest::testFuncs[i].data())) {
break;
+ }
}
+ testFuncCleaner.cleanup();
} else {
int methodCount = metaObject->methodCount();
- for (int i = 0; i < methodCount; ++i) {
- QMetaMethod slotMethod = metaObject->method(i);
- if (!isValidSlot(slotMethod))
+ QMetaMethod *testMethods = new QMetaMethod[methodCount];
+ for (int i = 0; i != methodCount; i++)
+ testMethods[i] = metaObject->method(i);
+ if (QTest::randomOrder)
+ randomizeList(testMethods, methodCount);
+ for (int i = 0; i != methodCount; i++) {
+ if (!isValidSlot(testMethods[i]))
continue;
- if (!qInvokeTestMethod(slotMethod.signature()))
+ if (!qInvokeTestMethod(testMethods[i].signature()))
break;
}
+ delete[] testMethods;
+ testMethods = 0;
}
}
@@ -1569,6 +1727,14 @@ private:
void FatalSignalHandler::signal(int signum)
{
qFatal("Received signal %d", signum);
+#if defined(Q_OS_INTEGRITY)
+ {
+ struct sigaction act;
+ memset(&act, 0, sizeof(struct sigaction));
+ act.sa_handler = SIG_DFL;
+ sigaction(signum, &act, NULL);
+ }
+#endif
}
FatalSignalHandler::FatalSignalHandler()
@@ -1583,8 +1749,9 @@ FatalSignalHandler::FatalSignalHandler()
act.sa_handler = FatalSignalHandler::signal;
// Remove the handler after it is invoked.
+#if !defined(Q_OS_INTEGRITY)
act.sa_flags = SA_RESETHAND;
-
+#endif
// Block all fatal signals in our signal handler so we don't try to close
// the testlog twice.
sigemptyset(&act.sa_mask);
@@ -1730,6 +1897,9 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
QTestResult::setCurrentTestObject(metaObject->className());
qtest_qParseArgs(argc, argv, false);
+ if (QTest::randomOrder) {
+ seedRandom();
+ }
#ifdef QTESTLIB_USE_VALGRIND
if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) {
const QStringList origAppArgs(QCoreApplication::arguments());
@@ -1763,6 +1933,8 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
IOPMAssertionRelease(powerID);
}
#endif
+ currentTestObject = 0;
+
// Rethrow exception to make debugging easier.
throw;
return 1;
diff --git a/src/testlib/qtestlightxmlstreamer.cpp b/src/testlib/qtestlightxmlstreamer.cpp
index fabe927..5a8f96d 100644
--- a/src/testlib/qtestlightxmlstreamer.cpp
+++ b/src/testlib/qtestlightxmlstreamer.cpp
@@ -42,6 +42,7 @@
#include "qtestlightxmlstreamer.h"
#include "qtestelement.h"
#include "qtestelementattribute.h"
+#include "qtestlogger_p.h"
#include "QtTest/private/qtestlog_p.h"
#include "QtTest/private/qtestresult_p.h"
@@ -164,8 +165,13 @@ void QTestLightXmlStreamer::formatBeforeAttributes(const QTestElement *element,
void QTestLightXmlStreamer::output(QTestElement *element) const
{
QTestCharBuffer buf;
- QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n",
+ if (logger()->hasRandomSeed()) {
+ QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n <RandomSeed>%d</RandomSeed>\n",
+ qVersion(), QTEST_VERSION_STR, logger()->randomSeed() );
+ } else {
+ QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n",
qVersion(), QTEST_VERSION_STR );
+ }
outputString(buf.constData());
QTest::qt_asprintf(&buf, "</Environment>\n");
diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp
index b59db88..03fafe0 100644
--- a/src/testlib/qtestlog.cpp
+++ b/src/testlib/qtestlog.cpp
@@ -168,6 +168,31 @@ namespace QTest {
}
}
+void initLogger()
+{
+ switch (QTest::logMode) {
+ case QTestLog::Plain:
+ QTest::testLogger = new QPlainTestLogger;
+ break;
+ case QTestLog::XML:{
+ if(QTest::flushMode == QTestLog::FLushOn)
+ QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Complete);
+ else
+ QTest::testLogger = new QTestLogger(QTestLogger::TLF_XML);
+ break;
+ }case QTestLog::LightXML:{
+ if(QTest::flushMode == QTestLog::FLushOn)
+ QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Light);
+ else
+ QTest::testLogger = new QTestLogger(QTestLogger::TLF_LightXml);
+ break;
+ }case QTestLog::XunitXML:
+ QTest::testLogger = new QTestLogger(QTestLogger::TLF_XunitXml);
+ }
+}
+
+extern Q_TESTLIB_EXPORT bool printAvailableTags;
+
}
QTestLog::QTestLog()
@@ -180,6 +205,9 @@ QTestLog::~QTestLog()
void QTestLog::enterTestFunction(const char* function)
{
+ if (QTest::printAvailableTags)
+ return;
+
QTEST_ASSERT(QTest::testLogger);
QTEST_ASSERT(function);
@@ -199,6 +227,9 @@ int QTestLog::unhandledIgnoreMessages()
void QTestLog::leaveTestFunction()
{
+ if (QTest::printAvailableTags)
+ return;
+
QTEST_ASSERT(QTest::testLogger);
QTest::IgnoreResultList::clearList(QTest::ignoreResultList);
@@ -221,6 +252,9 @@ void QTestLog::printUnhandledIgnoreMessages()
void QTestLog::addPass(const char *msg)
{
+ if (QTest::printAvailableTags)
+ return;
+
QTEST_ASSERT(QTest::testLogger);
QTEST_ASSERT(msg);
@@ -268,32 +302,20 @@ void QTestLog::addBenchmarkResult(const QBenchmarkResult &result)
QTest::testLogger->addBenchmarkResult(result);
}
-void QTestLog::startLogging()
+void QTestLog::startLogging(unsigned int randomSeed)
{
QTEST_ASSERT(!QTest::testLogger);
-
- switch (QTest::logMode) {
- case QTestLog::Plain:
- QTest::testLogger = new QPlainTestLogger;
- break;
- case QTestLog::XML:{
- if(QTest::flushMode == QTestLog::FLushOn)
- QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Complete);
- else
- QTest::testLogger = new QTestLogger(QTestLogger::TLF_XML);
- break;
- }case QTestLog::LightXML:{
- if(QTest::flushMode == QTestLog::FLushOn)
- QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Light);
- else
- QTest::testLogger = new QTestLogger(QTestLogger::TLF_LightXml);
- break;
- }case QTestLog::XunitXML:
- QTest::testLogger = new QTestLogger(QTestLogger::TLF_XunitXml);
- }
-
+ QTest::initLogger();
+ QTest::testLogger->registerRandomSeed(randomSeed);
QTest::testLogger->startLogging();
+ QTest::oldMessageHandler = qInstallMsgHandler(QTest::messageHandler);
+}
+void QTestLog::startLogging()
+{
+ QTEST_ASSERT(!QTest::testLogger);
+ QTest::initLogger();
+ QTest::testLogger->startLogging();
QTest::oldMessageHandler = qInstallMsgHandler(QTest::messageHandler);
}
diff --git a/src/testlib/qtestlog_p.h b/src/testlib/qtestlog_p.h
index f481831..20c731f 100644
--- a/src/testlib/qtestlog_p.h
+++ b/src/testlib/qtestlog_p.h
@@ -83,6 +83,7 @@ public:
static void info(const char *msg, const char *file, int line);
static void startLogging();
+ static void startLogging(unsigned int randomSeed);
static void stopLogging();
static void setLogMode(LogMode mode);
@@ -97,7 +98,6 @@ public:
static void setMaxWarnings(int max);
static void setFlushMode(FlushMode mode);
-
private:
QTestLog();
~QTestLog();
diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp
index ef92003..2c81a4b 100644
--- a/src/testlib/qtestlogger.cpp
+++ b/src/testlib/qtestlogger.cpp
@@ -62,7 +62,8 @@ QTestLogger::QTestLogger(int fm)
warningCounter(0), skipCounter(0),
systemCounter(0), qdebugCounter(0),
qwarnCounter(0), qfatalCounter(0),
- infoCounter(0)
+ infoCounter(0), randomSeed_(0),
+ hasRandomSeed_(false)
{
}
@@ -133,6 +134,14 @@ void QTestLogger::stopLogging()
property->addAttribute(QTest::AI_PropertyValue, qVersion());
properties->addLogElement(property);
+ if (hasRandomSeed()) {
+ property = new QTestElement(QTest::LET_Property);
+ property->addAttribute(QTest::AI_Name, "RandomSeed");
+ QTest::qt_snprintf(buf, sizeof(buf), "%i", randomSeed());
+ property->addAttribute(QTest::AI_PropertyValue, buf);
+ properties->addLogElement(property);
+ }
+
currentLogElement->addLogElement(properties);
currentLogElement->addLogElement(iterator);
@@ -420,5 +429,21 @@ int QTestLogger::infoCount() const
return infoCounter;
}
+void QTestLogger::registerRandomSeed(unsigned int seed)
+{
+ randomSeed_ = seed;
+ hasRandomSeed_ = true;
+}
+
+unsigned int QTestLogger::randomSeed() const
+{
+ return randomSeed_;
+}
+
+bool QTestLogger::hasRandomSeed() const
+{
+ return hasRandomSeed_;
+}
+
QT_END_NAMESPACE
diff --git a/src/testlib/qtestlogger_p.h b/src/testlib/qtestlogger_p.h
index ab1d448..1d27b63 100644
--- a/src/testlib/qtestlogger_p.h
+++ b/src/testlib/qtestlogger_p.h
@@ -101,6 +101,9 @@ class QTestLogger : public QAbstractTestLogger
int qwarnCount() const;
int qfatalCount() const;
int infoCount() const;
+ void registerRandomSeed(unsigned int seed);
+ unsigned int randomSeed() const;
+ bool hasRandomSeed() const;
private:
QTestElement *listOfTestcases;
@@ -121,6 +124,8 @@ class QTestLogger : public QAbstractTestLogger
int qwarnCounter;
int qfatalCounter;
int infoCounter;
+ unsigned int randomSeed_;
+ bool hasRandomSeed_;
};
QT_END_NAMESPACE
diff --git a/src/testlib/qtestmouse.h b/src/testlib/qtestmouse.h
index 6f799c2..cc07636 100644
--- a/src/testlib/qtestmouse.h
+++ b/src/testlib/qtestmouse.h
@@ -107,7 +107,11 @@ namespace QTest
break;
case MouseMove:
QCursor::setPos(widget->mapToGlobal(pos));
+#ifdef QT_MAC_USE_COCOA
+ QTest::qWait(20);
+#else
qApp->processEvents();
+#endif
return;
default:
QTEST_ASSERT(false);
diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp
index 85826eb..7fb0208 100644
--- a/src/testlib/qtestresult.cpp
+++ b/src/testlib/qtestresult.cpp
@@ -191,10 +191,13 @@ bool QTestResult::expectFail(const char *dataIndex, const char *comment,
QTEST_ASSERT(comment);
QTEST_ASSERT(mode > 0);
- if (!isExpectFailData(dataIndex))
+ if (!isExpectFailData(dataIndex)) {
+ delete[] comment;
return true; // we don't care
+ }
if (QTest::expectFailMode) {
+ delete[] comment;
clearExpectFail();
addFailure("Already expecting a fail", file, line);
return false;
diff --git a/src/testlib/qtestxmlstreamer.cpp b/src/testlib/qtestxmlstreamer.cpp
index 6c1006d..6a7f9ae 100644
--- a/src/testlib/qtestxmlstreamer.cpp
+++ b/src/testlib/qtestxmlstreamer.cpp
@@ -42,6 +42,7 @@
#include "qtestxmlstreamer.h"
#include "qtestelement.h"
#include "qtestelementattribute.h"
+#include "qtestlogger_p.h"
#include "QtTest/private/qtestlog_p.h"
#include "QtTest/private/qtestresult_p.h"
@@ -204,8 +205,13 @@ void QTestXmlStreamer::output(QTestElement *element) const
quotedTc.constData());
outputString(buf.constData());
- QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n",
- qVersion(), QTEST_VERSION_STR );
+ if (logger()->hasRandomSeed()) {
+ QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n <RandomSeed>%d</RandomSeed>\n",
+ qVersion(), QTEST_VERSION_STR, logger()->randomSeed() );
+ } else {
+ QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n",
+ qVersion(), QTEST_VERSION_STR );
+ }
outputString(buf.constData());
QTest::qt_asprintf(&buf, "</Environment>\n");
diff --git a/src/testlib/qxmltestlogger.cpp b/src/testlib/qxmltestlogger.cpp
index 40ce797..2c8ba6c 100644
--- a/src/testlib/qxmltestlogger.cpp
+++ b/src/testlib/qxmltestlogger.cpp
@@ -93,7 +93,7 @@ namespace QTest {
QXmlTestLogger::QXmlTestLogger(XmlMode mode )
- :xmlmode(mode)
+ :xmlmode(mode), randomSeed(0), hasRandomSeed(false)
{
}
@@ -116,11 +116,20 @@ void QXmlTestLogger::startLogging()
outputString(buf.constData());
}
- QTest::qt_asprintf(&buf,
- "<Environment>\n"
- " <QtVersion>%s</QtVersion>\n"
- " <QTestVersion>"QTEST_VERSION_STR"</QTestVersion>\n"
- "</Environment>\n", qVersion());
+ if (hasRandomSeed) {
+ QTest::qt_asprintf(&buf,
+ "<Environment>\n"
+ " <QtVersion>%s</QtVersion>\n"
+ " <QTestVersion>"QTEST_VERSION_STR"</QTestVersion>\n"
+ " <RandomSeed>%d</RandomSeed>\n"
+ "</Environment>\n", qVersion(), randomSeed);
+ } else {
+ QTest::qt_asprintf(&buf,
+ "<Environment>\n"
+ " <QtVersion>%s</QtVersion>\n"
+ " <QTestVersion>"QTEST_VERSION_STR"</QTestVersion>\n"
+ "</Environment>\n", qVersion());
+ }
outputString(buf.constData());
}
@@ -441,4 +450,10 @@ int QXmlTestLogger::xmlCdata(QTestCharBuffer* str, char const* src)
return allocateStringFn(str, src, QXmlTestLogger::xmlCdata);
}
+void QXmlTestLogger::registerRandomSeed(unsigned int seed)
+{
+ randomSeed = seed;
+ hasRandomSeed = true;
+}
+
QT_END_NAMESPACE
diff --git a/src/testlib/qxmltestlogger_p.h b/src/testlib/qxmltestlogger_p.h
index 2233c67..dc2f4b8 100644
--- a/src/testlib/qxmltestlogger_p.h
+++ b/src/testlib/qxmltestlogger_p.h
@@ -79,6 +79,8 @@ public:
void addMessage(MessageTypes type, const char *message,
const char *file = 0, int line = 0);
+ void registerRandomSeed(unsigned int seed);
+
static int xmlCdata(QTestCharBuffer *dest, char const* src);
static int xmlQuote(QTestCharBuffer *dest, char const* src);
static int xmlCdata(QTestCharBuffer *dest, char const* src, size_t n);
@@ -86,6 +88,8 @@ public:
private:
XmlMode xmlmode;
+ unsigned int randomSeed;
+ bool hasRandomSeed;
};
QT_END_NAMESPACE
diff --git a/src/testlib/testlib.pro b/src/testlib/testlib.pro
index a8186d8..c25d23d 100644
--- a/src/testlib/testlib.pro
+++ b/src/testlib/testlib.pro
@@ -70,8 +70,16 @@ wince*::LIBS += libcmt.lib \
coredll.lib \
winsock.lib
mac:LIBS += -framework IOKit \
- -framework ApplicationServices \
-framework Security
+!qpa:mac: LIBS += -framework ApplicationServices
+qpa:mac: {
+ contains(QT_CONFIG, coreservices) {
+ LIBS_PRIVATE += -framework CoreServices
+ } else {
+ LIBS_PRIVATE += -framework CoreFoundation
+ }
+}
+
include(../qbase.pri)
QMAKE_TARGET_PRODUCT = QTestLib
QMAKE_TARGET_DESCRIPTION = Qt \