virtual void addMessage(MessageTypes type, const char *message,
const char *file = 0, int line = 0) = 0;
- virtual void registerRandomSeed(unsigned int seed) = 0;
-
void outputString(const char *msg);
private:
}
QPlainTestLogger::QPlainTestLogger()
-: randomSeed(9), hasRandomSeed(false)
{
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
InitializeCriticalSection(&QTest::outputCriticalSection);
QTest::qt_snprintf(buf, sizeof(buf), "Testing %s\n",
QTestResult::currentTestObjectName());
} else {
- 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::qt_snprintf(buf, sizeof(buf),
+ "********* Start testing of %s *********\n"
+ "Config: Using QTest library " QTEST_VERSION_STR
+ ", Qt %s\n", QTestResult::currentTestObjectName(), qVersion());
}
outputMessage(buf);
}
printMessage(QTest::messageType2String(type), message, file, line);
}
-void QPlainTestLogger::registerRandomSeed(unsigned int seed)
-{
- randomSeed = seed;
- hasRandomSeed = true;
-}
-
QT_END_NAMESPACE
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;
+private:
void printMessage(const char *type, const char *msg, const char *file = 0, int line = 0);
void outputMessage(const char *str);
void printBenchmarkResult(const QBenchmarkResult &result);
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
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;
- }
-}
-
-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()
" -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"
#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) {
- fprintf(stderr, "-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) {
fprintf(stderr, "-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n");
QTEST_ASSERT(QTest::testFuncCount < 512);
}
}
-
- if (QTest::seedSet && !QTest::randomOrder) {
- fprintf(stderr, "-seed requires -random\n");
- exit(1);
- }
}
QBenchmarkResult qMedian(const QList<QBenchmarkResult> &container)
{
const QMetaObject *metaObject = testObject->metaObject();
QTEST_ASSERT(metaObject);
- if (QTest::randomOrder) {
- QTestLog::startLogging(QTest::seed);
- } else {
- QTestLog::startLogging();
- }
+ QTestLog::startLogging();
QTestResult::setCurrentTestFunction("initTestCase");
QTestResult::setCurrentTestLocation(QTestResult::DataFunc);
QTestTable::globalTestTable();
if(!QTestResult::skipCurrentTest() && !previousFailed) {
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())) {
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;
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());
void QTestLightXmlStreamer::output(QTestElement *element) const
{
QTestCharBuffer buf;
- 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",
+ 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");
QTest::testLogger->addBenchmarkResult(result);
}
-void QTestLog::startLogging(unsigned int randomSeed)
-{
- QTEST_ASSERT(!QTest::testLogger);
- QTest::initLogger();
- QTest::testLogger->registerRandomSeed(randomSeed);
- QTest::testLogger->startLogging(QTest::outFile);
- QTest::oldMessageHandler = qInstallMsgHandler(QTest::messageHandler);
-}
-
void QTestLog::startLogging()
{
QTEST_ASSERT(!QTest::testLogger);
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);
, testCounter(0)
, failureCounter(0)
, errorCounter(0)
- , randomSeed_(0)
- , hasRandomSeed_(false)
{
}
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);
}
}
-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
void addMessage(MessageTypes type, const char *message,
const char *file = 0, int line = 0);
- void registerRandomSeed(unsigned int seed);
- unsigned int randomSeed() const;
- bool hasRandomSeed() const;
-
private:
QTestElement *listOfTestcases;
QTestElement *currentLogElement;
int testCounter;
int failureCounter;
int errorCounter;
- unsigned int randomSeed_;
- bool hasRandomSeed_;
};
QT_END_NAMESPACE
quotedTc.constData());
outputString(buf.constData());
- 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 );
- }
+ 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");
QXmlTestLogger::QXmlTestLogger(XmlMode mode )
- :xmlmode(mode), randomSeed(0), hasRandomSeed(false)
+ : xmlmode(mode)
{
-
}
QXmlTestLogger::~QXmlTestLogger()
outputString(buf.constData());
}
- 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,
+ QTest::qt_asprintf(&buf,
"<Environment>\n"
" <QtVersion>%s</QtVersion>\n"
" <QTestVersion>"QTEST_VERSION_STR"</QTestVersion>\n"
"</Environment>\n", qVersion());
- }
outputString(buf.constData());
}
return allocateStringFn(str, src, QXmlTestLogger::xmlCdata);
}
-void QXmlTestLogger::registerRandomSeed(unsigned int seed)
-{
- randomSeed = seed;
- hasRandomSeed = true;
-}
-
QT_END_NAMESPACE
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);
private:
XmlMode xmlmode;
- unsigned int randomSeed;
- bool hasRandomSeed;
};
QT_END_NAMESPACE