qtestcase.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11static bool installCoverageTool(const char * appname, const char * testname) -
12{ -
13 -
14 if (!qEnvironmentVariableIsEmpty("QT_TESTCOCOON_ACTIVE"))
-
15 return false;
-
16 -
17 -
18 qputenv("QT_TESTCOCOON_ACTIVE", "1"); -
19 -
20 -
21 __coveragescanner_install(appname); -
22 __coveragescanner_testname(testname); -
23 __coveragescanner_clear(); -
24 return true;
-
25 -
26 -
27 -
28 -
29 -
30} -
31 -
32namespace QTest -
33{ -
34 static QObject *currentTestObject = 0; -
35 -
36 class TestFunction { -
37 public: -
38 TestFunction() : function_(-1), data_(0) {}
-
39 void set(int function, char *data) { function_ = function; data_ = data; }
-
40 char *data() const { return data_; }
-
41 int function() const { return function_; }
-
42 ~TestFunction() { delete[] data_; }
-
43 private: -
44 int function_; -
45 char *data_; -
46 }; -
47 -
48 -
49 -
50 -
51 -
52 -
53 static TestFunction * testFuncs = 0; -
54 static int testFuncCount = 0; -
55 -
56 -
57 static struct TestFuncCleanup -
58 { -
59 void cleanup() -
60 { -
61 delete[] testFuncs; -
62 testFuncCount = 0; -
63 testFuncs = 0; -
64 }
-
65 -
66 ~TestFuncCleanup() { cleanup(); }
-
67 } testFuncCleaner; -
68 -
69 static int keyDelay = -1; -
70 static int mouseDelay = -1; -
71 static int eventDelay = -1; -
72 -
73 static bool noCrashHandler = false; -
74 -
75 -
76 -
77 -
78 -
79static void invokeMethod(QObject *obj, const char *methodName) -
80{ -
81 const QMetaObject *metaObject = obj->metaObject(); -
82 int funcIndex = metaObject->indexOfMethod(methodName); -
83 if (funcIndex >= 0) {
-
84 QMetaMethod method = metaObject->method(funcIndex); -
85 method.invoke(obj, Qt::DirectConnection); -
86 }
-
87}
-
88 -
89int defaultEventDelay() -
90{ -
91 if (eventDelay == -1) {
-
92 const QByteArray env = qgetenv("QTEST_EVENT_DELAY"); -
93 if (!env.isEmpty())
-
94 eventDelay = atoi(env.constData());
-
95 else -
96 eventDelay = 0;
-
97 } -
98 return eventDelay;
-
99} -
100 -
101int __attribute__((visibility("default"))) defaultMouseDelay() -
102{ -
103 if (mouseDelay == -1) {
-
104 const QByteArray env = qgetenv("QTEST_MOUSEEVENT_DELAY"); -
105 if (!env.isEmpty())
-
106 mouseDelay = atoi(env.constData());
-
107 else -
108 mouseDelay = defaultEventDelay();
-
109 } -
110 return mouseDelay;
-
111} -
112 -
113int __attribute__((visibility("default"))) defaultKeyDelay() -
114{ -
115 if (keyDelay == -1) {
-
116 const QByteArray env = qgetenv("QTEST_KEYEVENT_DELAY"); -
117 if (!env.isEmpty())
-
118 keyDelay = atoi(env.constData());
-
119 else -
120 keyDelay = defaultEventDelay();
-
121 } -
122 return keyDelay;
-
123} -
124 -
125static bool isValidSlot(const QMetaMethod &sl) -
126{ -
127 if (sl.access() != QMetaMethod::Private || sl.parameterCount() != 0
-
128 || sl.returnType() != QMetaType::Void || sl.methodType() != QMetaMethod::Slot)
-
129 return false;
-
130 QByteArray name = sl.name(); -
131 if (name.isEmpty())
-
132 return false;
-
133 if (name.endsWith("_data"))
-
134 return false;
-
135 if (name == "initTestCase" || name == "cleanupTestCase"
-
136 || name == "cleanup" || name == "init")
-
137 return false;
-
138 return true;
-
139} -
140 -
141__attribute__((visibility("default"))) bool printAvailableFunctions = false; -
142__attribute__((visibility("default"))) QStringList testFunctions; -
143__attribute__((visibility("default"))) QStringList testTags; -
144 -
145static void qPrintTestSlots(FILE *stream, const char *filter = 0) -
146{ -
147 for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) {
-
148 QMetaMethod sl = QTest::currentTestObject->metaObject()->method(i); -
149 if (isValidSlot(sl)) {
-
150 const QByteArray signature = sl.methodSignature(); -
151 if (!filter || QString::fromLatin1(signature).contains(QLatin1String(filter), Qt::CaseInsensitive))
-
152 fprintf(stream, "%s\n", signature.constData());
-
153 }
-
154 }
-
155}
-
156 -
157static void qPrintDataTags(FILE *stream) -
158{ -
159 -
160 QTestLog::setPrintAvailableTagsMode(); -
161 -
162 -
163 QTestTable::globalTestTable(); -
164 invokeMethod(QTest::currentTestObject, "initTestCase_data()"); -
165 const QTestTable *gTable = QTestTable::globalTestTable(); -
166 -
167 const QMetaObject *currTestMetaObj = QTest::currentTestObject->metaObject(); -
168 -
169 -
170 for (int i = 0; i < currTestMetaObj->methodCount(); ++i) {
-
171 QMetaMethod tf = currTestMetaObj->method(i); -
172 -
173 if (isValidSlot(tf)) {
-
174 -
175 -
176 QStringList localTags; -
177 QTestTable table; -
178 char *slot = qstrdup(tf.methodSignature().constData()); -
179 slot[strlen(slot) - 2] = '\0'; -
180 QByteArray member; -
181 member.resize(qstrlen(slot) + qstrlen("_data()") + 1); -
182 qsnprintf(member.data(), member.size(), "%s_data()", slot); -
183 invokeMethod(QTest::currentTestObject, member.constData()); -
184 for (int j = 0; j < table.dataCount(); ++j)
-
185 localTags << QLatin1String(table.testData(j)->dataTag());
-
186 -
187 -
188 if (gTable->dataCount() == 0) {
-
189 if (localTags.count() == 0) {
-
190 -
191 fprintf(stream, "%s %s\n", currTestMetaObj->className(), slot); -
192 } else {
-
193 -
194 for (int k = 0; k < localTags.size(); ++k)
-
195 fprintf( -
196 stream, "%s %s %s\n", -
197 currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data());
-
198 }
-
199 } else { -
200 for (int j = 0; j < gTable->dataCount(); ++j) {
-
201 if (localTags.count() == 0) {
-
202 -
203 fprintf( -
204 stream, "%s %s __global__ %s\n", -
205 currTestMetaObj->className(), slot, gTable->testData(j)->dataTag()); -
206 } else {
-
207 -
208 -
209 for (int k = 0; k < localTags.size(); ++k)
-
210 fprintf( -
211 stream, "%s %s %s __global__ %s\n", currTestMetaObj->className(), slot, -
212 localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag());
-
213 }
-
214 } -
215 }
-
216 -
217 delete[] slot; -
218 }
-
219 }
-
220}
-
221 -
222static int qToInt(char *str) -
223{ -
224 char *pEnd; -
225 int l = (int)strtol(str, &pEnd, 10); -
226 if (*pEnd != 0) {
-
227 fprintf(stderr, "Invalid numeric parameter: '%s'\n", str); -
228 exit(1);
-
229 } -
230 return l;
-
231} -
232 -
233__attribute__((visibility("default"))) void qtest_qParseArgs(int argc, char *argv[], bool qml) -
234{ -
235 QTestLog::LogMode logFormat = QTestLog::Plain; -
236 const char *logFilename = 0; -
237 -
238 const char *testOptions = -
239 " New-style logging options:\n" -
240 " -o filename,format : Output results to file in the specified format\n" -
241 " Use - to output to stdout\n" -
242 " Valid formats are:\n" -
243 " txt : Plain text\n" -
244 " xunitxml : XML XUnit document\n" -
245 " xml : XML document\n" -
246 " lightxml : A stream of XML tags\n" -
247 "\n" -
248 " *** Multiple loggers can be specified, but at most one can log to stdout.\n" -
249 "\n" -
250 " Old-style logging options:\n" -
251 " -o filename : Write the output into file\n" -
252 " -txt : Output results in Plain Text\n" -
253 " -xunitxml : Output results as XML XUnit document\n" -
254 " -xml : Output results as XML document\n" -
255 " -lightxml : Output results as stream of XML tags\n" -
256 "\n" -
257 " *** If no output file is specified, stdout is assumed.\n" -
258 " *** If no output format is specified, -txt is assumed.\n" -
259 "\n" -
260 " Test log detail options:\n" -
261 " -silent : Log failures and fatal errors only\n" -
262 " -v1 : Log the start of each testfunction\n" -
263 " -v2 : Log each QVERIFY/QCOMPARE/QTEST (implies -v1)\n" -
264 " -vs : Log every signal emission and resulting slot invocations\n" -
265 "\n" -
266 " *** The -silent and -v1 options only affect plain text output.\n" -
267 "\n" -
268 " Testing options:\n" -
269 " -functions : Returns a list of current testfunctions\n" -
270 " -datatags : Returns a list of current data tags.\n" -
271 " A global data tag is preceded by ' __global__ '.\n" -
272 " -eventdelay ms : Set default delay for mouse and keyboard simulation to ms milliseconds\n" -
273 " -keydelay ms : Set default delay for keyboard simulation to ms milliseconds\n" -
274 " -mousedelay ms : Set default delay for mouse simulation to ms milliseconds\n" -
275 " -maxwarnings n : Sets the maximum amount of messages to output.\n" -
276 " 0 means unlimited, default: 2000\n" -
277 -
278 " -nocrashhandler : Disables the crash handler\n" -
279 -
280 "\n" -
281 " Benchmarking options:\n" -
282 -
283 " -callgrind : Use callgrind to time benchmarks\n" -
284 -
285 -
286 " -tickcounter : Use CPU tick counters to time benchmarks\n" -
287 -
288 " -eventcounter : Counts events received during benchmarks\n" -
289 " -minimumvalue n : Sets the minimum acceptable measurement value\n" -
290 " -iterations n : Sets the number of accumulation iterations.\n" -
291 " -median n : Sets the number of median iterations.\n" -
292 " -vb : Print out verbose benchmarking information.\n"; -
293 -
294 for (int i = 1; i < argc; ++i) {
-
295 if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0
-
296 || strcmp(argv[i], "/?") == 0) {
-
297 printf(" Usage: %s [options] [testfunction[:testdata]]...\n" -
298 " By default, all testfunctions will be run.\n\n" -
299 "%s", argv[0], testOptions); -
300 -
301 if (qml) {
-
302 printf ("\n" -
303 " QmlTest options:\n" -
304 " -import dir : Specify an import directory.\n" -
305 " -input dir/file : Specify the root directory for test cases or a single test case file.\n" -
306 " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" -
307 " -translation file : Specify the translation file.\n" -
308 ); -
309 }
-
310 -
311 printf("\n" -
312 " -help : This help\n"); -
313 exit(0);
-
314 } else if (strcmp(argv[i], "-functions") == 0) {
-
315 if (qml) {
-
316 QTest::printAvailableFunctions = true; -
317 } else {
-
318 qPrintTestSlots(stdout); -
319 exit(0);
-
320 } -
321 } else if (strcmp(argv[i], "-datatags") == 0) {
-
322 if (!qml) {
-
323 qPrintDataTags(stdout); -
324 exit(0);
-
325 } -
326 } else if (strcmp(argv[i], "-txt") == 0) {
-
327 logFormat = QTestLog::Plain; -
328 } else if (strcmp(argv[i], "-xunitxml") == 0) {
-
329 logFormat = QTestLog::XunitXML; -
330 } else if (strcmp(argv[i], "-xml") == 0) {
-
331 logFormat = QTestLog::XML; -
332 } else if (strcmp(argv[i], "-lightxml") == 0) {
-
333 logFormat = QTestLog::LightXML; -
334 } else if (strcmp(argv[i], "-silent") == 0) {
-
335 QTestLog::setVerboseLevel(-1); -
336 } else if (strcmp(argv[i], "-v1") == 0) {
-
337 QTestLog::setVerboseLevel(1); -
338 } else if (strcmp(argv[i], "-v2") == 0) {
-
339 QTestLog::setVerboseLevel(2); -
340 } else if (strcmp(argv[i], "-vs") == 0) {
-
341 QSignalDumper::startDump(); -
342 } else if (strcmp(argv[i], "-o") == 0) {
-
343 if (i + 1 >= argc) {
-
344 fprintf(stderr, "-o needs an extra parameter specifying the filename and optional format\n"); -
345 exit(1);
-
346 } -
347 ++i; -
348 -
349 char *filename = new char[strlen(argv[i])+1]; -
350 char *format = new char[strlen(argv[i])+1]; -
351 if (sscanf(argv[i], "%[^,],%s", filename, format) == 1) {
-
352 -
353 logFilename = argv[i]; -
354 } else {
-
355 -
356 if (strcmp(format, "txt") == 0)
-
357 logFormat = QTestLog::Plain;
-
358 else if (strcmp(format, "lightxml") == 0)
-
359 logFormat = QTestLog::LightXML;
-
360 else if (strcmp(format, "xml") == 0)
-
361 logFormat = QTestLog::XML;
-
362 else if (strcmp(format, "xunitxml") == 0)
-
363 logFormat = QTestLog::XunitXML;
-
364 else { -
365 fprintf(stderr, "output format must be one of txt, lightxml, xml or xunitxml\n"); -
366 exit(1);
-
367 } -
368 if (strcmp(filename, "-") == 0 && QTestLog::loggerUsingStdout()) {
-
369 fprintf(stderr, "only one logger can log to stdout\n"); -
370 exit(1);
-
371 } -
372 QTestLog::addLogger(logFormat, filename); -
373 }
-
374 delete [] filename; -
375 delete [] format; -
376 } else if (strcmp(argv[i], "-eventdelay") == 0) {
-
377 if (i + 1 >= argc) {
-
378 fprintf(stderr, "-eventdelay needs an extra parameter to indicate the delay(ms)\n"); -
379 exit(1);
-
380 } else { -
381 QTest::eventDelay = qToInt(argv[++i]); -
382 }
-
383 } else if (strcmp(argv[i], "-keydelay") == 0) {
-
384 if (i + 1 >= argc) {
-
385 fprintf(stderr, "-keydelay needs an extra parameter to indicate the delay(ms)\n"); -
386 exit(1);
-
387 } else { -
388 QTest::keyDelay = qToInt(argv[++i]); -
389 }
-
390 } else if (strcmp(argv[i], "-mousedelay") == 0) {
-
391 if (i + 1 >= argc) {
-
392 fprintf(stderr, "-mousedelay needs an extra parameter to indicate the delay(ms)\n"); -
393 exit(1);
-
394 } else { -
395 QTest::mouseDelay = qToInt(argv[++i]); -
396 }
-
397 } else if (strcmp(argv[i], "-maxwarnings") == 0) {
-
398 if (i + 1 >= argc) {
-
399 fprintf(stderr, "-maxwarnings needs an extra parameter with the amount of warnings\n"); -
400 exit(1);
-
401 } else { -
402 QTestLog::setMaxWarnings(qToInt(argv[++i])); -
403 }
-
404 -
405 } else if (strcmp(argv[i], "-nocrashhandler") == 0) {
-
406 QTest::noCrashHandler = true; -
407 -
408 -
409 } else if (strcmp(argv[i], "-callgrind") == 0) {
-
410 if (QBenchmarkValgrindUtils::haveValgrind())
-
411 if (QFileInfo(QDir::currentPath()).isWritable()) {
-
412 QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::CallgrindParentProcess); -
413 } else {
-
414 fprintf(stderr, "WARNING: Current directory not writable. Using the walltime measurer.\n"); -
415 }
-
416 else { -
417 fprintf(stderr, "WARNING: Valgrind not found or too old. Make sure it is installed and in your path. " -
418 "Using the walltime measurer.\n"); -
419 }
-
420 } else if (strcmp(argv[i], "-callgrindchild") == 0) {
-
421 QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::CallgrindChildProcess); -
422 QBenchmarkGlobalData::current->callgrindOutFileBase = -
423 QBenchmarkValgrindUtils::outFileBase(); -
424 -
425 -
426 } else if (strcmp(argv[i], "-tickcounter") == 0) {
-
427 QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::TickCounter); -
428 -
429 } else if (strcmp(argv[i], "-eventcounter") == 0) {
-
430 QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::EventCounter); -
431 } else if (strcmp(argv[i], "-minimumvalue") == 0) {
-
432 if (i + 1 >= argc) {
-
433 fprintf(stderr, "-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n"); -
434 exit(1);
-
435 } else { -
436 QBenchmarkGlobalData::current->walltimeMinimum = qToInt(argv[++i]); -
437 }
-
438 } else if (strcmp(argv[i], "-iterations") == 0) {
-
439 if (i + 1 >= argc) {
-
440 fprintf(stderr, "-iterations needs an extra parameter to indicate the number of iterations\n"); -
441 exit(1);
-
442 } else { -
443 QBenchmarkGlobalData::current->iterationCount = qToInt(argv[++i]); -
444 }
-
445 } else if (strcmp(argv[i], "-median") == 0) {
-
446 if (i + 1 >= argc) {
-
447 fprintf(stderr, "-median needs an extra parameter to indicate the number of median iterations\n"); -
448 exit(1);
-
449 } else { -
450 QBenchmarkGlobalData::current->medianIterationCount = qToInt(argv[++i]); -
451 }
-
452 -
453 } else if (strcmp(argv[i], "-vb") == 0) {
-
454 QBenchmarkGlobalData::current->verboseOutput = true; -
455 } else if (argv[i][0] == '-') {
-
456 fprintf(stderr, "Unknown option: '%s'\n\n%s", argv[i], testOptions); -
457 if (qml) {
-
458 fprintf(stderr, "\nqmltest related options:\n" -
459 " -import : Specify an import directory.\n" -
460 " -input : Specify the root directory for test cases.\n" -
461 " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" -
462 ); -
463 }
-
464 -
465 fprintf(stderr, "\n" -
466 " -help : This help\n"); -
467 exit(1);
-
468 } else if (qml) {
-
469 -
470 -
471 int colon = -1; -
472 int offset; -
473 for (offset = 0; *(argv[i]+offset); ++offset) {
-
474 if (*(argv[i]+offset) == ':') {
-
475 if (*(argv[i]+offset+1) == ':') {
-
476 -
477 -
478 ++offset; -
479 } else {
-
480 colon = offset; -
481 break;
-
482 } -
483 } -
484 }
-
485 if (colon == -1) {
-
486 QTest::testFunctions += QString::fromLatin1(argv[i]); -
487 QTest::testTags += QString(); -
488 } else {
-
489 QTest::testFunctions += -
490 QString::fromLatin1(argv[i], colon); -
491 QTest::testTags += -
492 QString::fromLatin1(argv[i] + colon + 1); -
493 }
-
494 } else { -
495 if (!QTest::testFuncs) {
-
496 QTest::testFuncs = new QTest::TestFunction[512]; -
497 }
-
498 -
499 int colon = -1; -
500 char buf[512], *data=0; -
501 int off; -
502 for (off = 0; *(argv[i]+off); ++off) {
-
503 if (*(argv[i]+off) == ':') {
-
504 colon = off; -
505 break;
-
506 } -
507 }
-
508 if (colon != -1) {
-
509 data = qstrdup(argv[i]+colon+1); -
510 }
-
511 qsnprintf(buf, qMin(512, off + 1), "%s", argv[i]); -
512 qsnprintf(buf + off, qMin(512 - off, 3), "()"); -
513 int idx = QTest::currentTestObject->metaObject()->indexOfMethod(buf); -
514 if (idx < 0 || !isValidSlot(QTest::currentTestObject->metaObject()->method(idx))) {
-
515 fprintf(stderr, "Unknown test function: '%s'. Possible matches:\n", buf); -
516 buf[off] = 0; -
517 qPrintTestSlots(stderr, buf); -
518 fprintf(stderr, "\n%s -functions\nlists all available test functions.\n", argv[0]); -
519 exit(1);
-
520 } -
521 testFuncs[testFuncCount].set(idx, data); -
522 testFuncCount++; -
523 do { if (!(QTest::testFuncCount < 512)) qt_assert("QTest::testFuncCount < 512","qtestcase.cpp",1582); } while (0);
-
524 }
-
525 } -
526 -
527 bool installedTestCoverage = installCoverageTool(QTestResult::currentAppname(), QTestResult::currentTestObjectName()); -
528 QTestLog::setInstalledTestCoverage(installedTestCoverage); -
529 -
530 -
531 -
532 -
533 if (QTestLog::loggerCount() == 0)
-
534 QTestLog::addLogger(logFormat, logFilename);
-
535}
-
536 -
537QBenchmarkResult qMedian(const QList<QBenchmarkResult> &container) -
538{ -
539 const int count = container.count(); -
540 if (count == 0)
-
541 return QBenchmarkResult();
-
542 -
543 if (count == 1)
-
544 return container.at(0);
-
545 -
546 QList<QBenchmarkResult> containerCopy = container; -
547 qSort(containerCopy); -
548 -
549 const int middle = count / 2; -
550 -
551 -
552 return containerCopy.at(middle);
-
553} -
554 -
555struct QTestDataSetter -
556{ -
557 QTestDataSetter(QTestData *data) -
558 { -
559 QTestResult::setCurrentTestData(data); -
560 }
-
561 ~QTestDataSetter() -
562 { -
563 QTestResult::setCurrentTestData(0); -
564 }
-
565}; -
566 -
567static void qInvokeTestMethodDataEntry(char *slot) -
568{ -
569 -
570 -
571 bool isBenchmark = false; -
572 int i = (QBenchmarkGlobalData::current->measurer->needsWarmupIteration()) ? -1 : 0;
-
573 -
574 QList<QBenchmarkResult> results; -
575 do { -
576 QBenchmarkTestMethodData::current->beginDataRun(); -
577 -
578 -
579 bool invokeOk; -
580 do { -
581 invokeMethod(QTest::currentTestObject, "init()"); -
582 if (QTestResult::skipCurrentTest() || QTestResult::currentTestFailed())
-
583 break;
-
584 -
585 QBenchmarkTestMethodData::current->result = QBenchmarkResult(); -
586 QBenchmarkTestMethodData::current->resultAccepted = false; -
587 -
588 QBenchmarkGlobalData::current->context.tag = -
589 QLatin1String( -
590 QTestResult::currentDataTag() -
591 ? QTestResult::currentDataTag() : ""); -
592 -
593 invokeOk = QMetaObject::invokeMethod(QTest::currentTestObject, slot, -
594 Qt::DirectConnection); -
595 if (!invokeOk)
-
596 QTestResult::addFailure("Unable to execute slot", "qtestcase.cpp", 1655);
-
597 -
598 isBenchmark = QBenchmarkTestMethodData::current->isBenchmark(); -
599 -
600 QTestResult::finishedCurrentTestData(); -
601 -
602 invokeMethod(QTest::currentTestObject, "cleanup()"); -
603 -
604 -
605 if (!isBenchmark)
-
606 QTestResult::finishedCurrentTestDataCleanup();
-
607 -
608 -
609 -
610 -
611 -
612 } while (invokeOk && isBenchmark
-
613 && QBenchmarkTestMethodData::current->resultsAccepted() == false
-
614 && !QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed());
-
615 -
616 QBenchmarkTestMethodData::current->endDataRun(); -
617 if (!QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed()) {
-
618 if (i > -1)
-
619 results.append(QBenchmarkTestMethodData::current->result);
-
620 -
621 if (isBenchmark && QBenchmarkGlobalData::current->verboseOutput) {
-
622 if (i == -1) {
-
623 QTestLog::info(QString(QString::fromLatin1("warmup stage result : %1") .arg(QBenchmarkTestMethodData::current->result.value)).toLocal8Bit().constData(), 0, 0); -
624 -
625 -
626 } else {
-
627 QTestLog::info(QString(QString::fromLatin1("accumulation stage result: %1") .arg(QBenchmarkTestMethodData::current->result.value)).toLocal8Bit().constData(), 0, 0); -
628 -
629 -
630 }
-
631 } -
632 }
-
633 } while (isBenchmark
-
634 && (++i < QBenchmarkGlobalData::current->adjustMedianIterationCount())
-
635 && !QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed());
-
636 -
637 -
638 if (isBenchmark) {
-
639 bool testPassed = !QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed();
-
640 QTestResult::finishedCurrentTestDataCleanup(); -
641 -
642 if (testPassed && QBenchmarkTestMethodData::current->resultsAccepted())
-
643 QTestLog::addBenchmarkResult(qMedian(results));
-
644 }
-
645}
-
646static bool qInvokeTestMethod(const char *slotName, const char *data=0) -
647{ -
648 do { if (!(slotName)) qt_assert("slotName","qtestcase.cpp",1717); } while (0);
-
649 -
650 QBenchmarkTestMethodData benchmarkData; -
651 QBenchmarkTestMethodData::current = &benchmarkData; -
652 -
653 QBenchmarkGlobalData::current->context.slotName = QLatin1String(slotName); -
654 -
655 char member[512]; -
656 QTestTable table; -
657 -
658 char *slot = qstrdup(slotName); -
659 slot[strlen(slot) - 2] = '\0'; -
660 QTestResult::setCurrentTestFunction(slot); -
661 -
662 const QTestTable *gTable = QTestTable::globalTestTable(); -
663 const int globalDataCount = gTable->dataCount(); -
664 int curGlobalDataIndex = 0; -
665 -
666 -
667 do { -
668 if (!gTable->isEmpty())
-
669 QTestResult::setCurrentGlobalTestData(gTable->testData(curGlobalDataIndex));
-
670 -
671 if (curGlobalDataIndex == 0) {
-
672 qsnprintf(member, 512, "%s_data()", slot); -
673 invokeMethod(QTest::currentTestObject, member); -
674 }
-
675 -
676 bool foundFunction = false; -
677 if (!QTestResult::skipCurrentTest()) {
-
678 int curDataIndex = 0; -
679 const int dataCount = table.dataCount(); -
680 -
681 -
682 if (data && !dataCount) {
-
683 -
684 if (!*data)
-
685 data = 0;
-
686 else { -
687 fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName, data); -
688 fprintf(stderr, "Function has no testdata.\n"); -
689 return false;
-
690 } -
691 } -
692 -
693 -
694 do { -
695 QTestResult::setSkipCurrentTest(false); -
696 if (!data || !qstrcmp(data, table.testData(curDataIndex)->dataTag())) {
-
697 foundFunction = true; -
698 QTestDataSetter s(curDataIndex >= dataCount ? static_cast<QTestData *>(0) -
699 : table.testData(curDataIndex)); -
700 -
701 qInvokeTestMethodDataEntry(slot); -
702 -
703 if (data)
-
704 break;
-
705 }
-
706 ++curDataIndex; -
707 } while (curDataIndex < dataCount);
-
708 }
-
709 -
710 if (data && !foundFunction) {
-
711 fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName, data); -
712 fprintf(stderr, "Available testdata:\n"); -
713 for (int i = 0; i < table.dataCount(); ++i)
-
714 fprintf(stderr, "%s\n", table.testData(i)->dataTag());
-
715 return false;
-
716 } -
717 -
718 QTestResult::setCurrentGlobalTestData(0); -
719 ++curGlobalDataIndex; -
720 } while (curGlobalDataIndex < globalDataCount);
-
721 -
722 QTestResult::finishedCurrentTestFunction(); -
723 QTestResult::setSkipCurrentTest(false); -
724 QTestResult::setCurrentTestData(0); -
725 delete[] slot; -
726 -
727 return true;
-
728} -
729 -
730void *fetchData(QTestData *data, const char *tagName, int typeId) -
731{ -
732 do { if (!(typeId)) qt_assert("typeId","qtestcase.cpp",1801); } while (0);
-
733 do { if (!(data)) qt_assert_x("QTest::fetchData()", "Test data requested, but no testdata available.","qtestcase.cpp",1802); } while (0);
-
734 do { if (!(data->parent())) qt_assert("data->parent()","qtestcase.cpp",1803); } while (0);
-
735 -
736 int idx = data->parent()->indexOf(tagName); -
737 -
738 if (idx == -1 || idx >= data->dataCount()) {
-
739 QMessageLogger("qtestcase.cpp", 1808, __PRETTY_FUNCTION__).fatal("QFETCH: Requested testdata '%s' not available, check your _data function.", -
740 tagName); -
741 }
-
742 -
743 if (typeId != data->parent()->elementTypeId(idx)) {
-
744 QMessageLogger("qtestcase.cpp", 1813, __PRETTY_FUNCTION__).fatal("Requested type '%s' does not match available type '%s'.", -
745 QMetaType::typeName(typeId), -
746 QMetaType::typeName(data->parent()->elementTypeId(idx))); -
747 }
-
748 -
749 return data->data(idx);
-
750} -
751char *toHexRepresentation(const char *ba, int length) -
752{ -
753 if (length == 0)
-
754 return qstrdup("");
-
755 const int maxLen = 50; -
756 const int len = qMin(maxLen, length); -
757 char *result = 0; -
758 -
759 if (length > maxLen) {
-
760 const int size = len * 3 + 4; -
761 result = new char[size]; -
762 -
763 char *const forElipsis = result + size - 5; -
764 forElipsis[0] = ' '; -
765 forElipsis[1] = '.'; -
766 forElipsis[2] = '.'; -
767 forElipsis[3] = '.'; -
768 result[size - 1] = '\0'; -
769 }
-
770 else { -
771 const int size = len * 3; -
772 result = new char[size]; -
773 result[size - 1] = '\0'; -
774 }
-
775 -
776 const char toHex[] = "0123456789ABCDEF"; -
777 int i = 0; -
778 int o = 0; -
779 -
780 while (true) {
-
781 const char at = ba[i]; -
782 -
783 result[o] = toHex[(at >> 4) & 0x0F]; -
784 ++o; -
785 result[o] = toHex[at & 0x0F]; -
786 -
787 ++i; -
788 ++o; -
789 if (i == len)
-
790 break;
-
791 else { -
792 result[o] = ' '; -
793 ++o; -
794 }
-
795 } -
796 -
797 return result;
-
798} -
799 -
800static void qInvokeTestMethods(QObject *testObject) -
801{ -
802 const QMetaObject *metaObject = testObject->metaObject(); -
803 do { if (!(metaObject)) qt_assert("metaObject","qtestcase.cpp",1891); } while (0);
-
804 QTestLog::startLogging(); -
805 QTestResult::setCurrentTestFunction("initTestCase"); -
806 QTestTable::globalTestTable(); -
807 invokeMethod(testObject, "initTestCase_data()"); -
808 -
809 if (!QTestResult::skipCurrentTest() && !QTest::currentTestFailed()) {
-
810 invokeMethod(testObject, "initTestCase()"); -
811 -
812 -
813 const bool previousFailed = QTestResult::currentTestFailed(); -
814 QTestResult::finishedCurrentTestData(); -
815 QTestResult::finishedCurrentTestDataCleanup(); -
816 QTestResult::finishedCurrentTestFunction(); -
817 -
818 if (!QTestResult::skipCurrentTest() && !previousFailed) {
-
819 -
820 if (QTest::testFuncs) {
-
821 for (int i = 0; i != QTest::testFuncCount; i++) {
-
822 if (!qInvokeTestMethod(metaObject->method(QTest::testFuncs[i].function()).methodSignature().constData(), -
823 QTest::testFuncs[i].data())) {
-
824 break;
-
825 } -
826 }
-
827 testFuncCleaner.cleanup(); -
828 } else {
-
829 int methodCount = metaObject->methodCount(); -
830 QMetaMethod *testMethods = new QMetaMethod[methodCount]; -
831 for (int i = 0; i != methodCount; i++)
-
832 testMethods[i] = metaObject->method(i);
-
833 for (int i = 0; i != methodCount; i++) {
-
834 if (!isValidSlot(testMethods[i]))
-
835 continue;
-
836 if (!qInvokeTestMethod(testMethods[i].methodSignature().constData()))
-
837 break;
-
838 }
-
839 delete[] testMethods; -
840 testMethods = 0; -
841 }
-
842 } -
843 -
844 QTestResult::setSkipCurrentTest(false); -
845 QTestResult::setCurrentTestFunction("cleanupTestCase"); -
846 invokeMethod(testObject, "cleanupTestCase()"); -
847 QTestResult::finishedCurrentTestData(); -
848 QTestResult::finishedCurrentTestDataCleanup(); -
849 }
-
850 QTestResult::finishedCurrentTestFunction(); -
851 QTestResult::setCurrentTestFunction(0); -
852 QTestTable::clearGlobalTestTable(); -
853 -
854 QTestLog::stopLogging(); -
855}
-
856 -
857 -
858class FatalSignalHandler -
859{ -
860public: -
861 FatalSignalHandler(); -
862 ~FatalSignalHandler(); -
863 -
864private: -
865 static void signal(int); -
866 sigset_t handledSignals; -
867}; -
868 -
869void FatalSignalHandler::signal(int signum) -
870{ -
871 QMessageLogger("qtestcase.cpp", 1959, __PRETTY_FUNCTION__).fatal("Received signal %d", signum); -
872}
-
873 -
874FatalSignalHandler::FatalSignalHandler() -
875{ -
876 sigemptyset(&handledSignals); -
877 -
878 const int fatalSignals[] = { -
879 1, 2, 3, 4, 8, 11, 13, 15, 0 }; -
880 -
881 struct sigaction act; -
882 memset(&act, 0, sizeof(act)); -
883 act.__sigaction_handler.sa_handler = FatalSignalHandler::signal; -
884 -
885 -
886 -
887 act.sa_flags = 0x80000000; -
888 -
889 -
890 -
891 sigemptyset(&act.sa_mask); -
892 for (int i = 0; fatalSignals[i]; ++i)
-
893 sigaddset(&act.sa_mask, fatalSignals[i]);
-
894 -
895 struct sigaction oldact; -
896 -
897 for (int i = 0; fatalSignals[i]; ++i) {
-
898 sigaction(fatalSignals[i], &act, &oldact); -
899 if ( -
900 -
901 oldact.sa_flags & 4 ||
-
902 -
903 oldact.__sigaction_handler.sa_handler != ((__sighandler_t) 0)) {
-
904 sigaction(fatalSignals[i], &oldact, 0); -
905 } else
-
906 { -
907 sigaddset(&handledSignals, fatalSignals[i]); -
908 }
-
909 } -
910}
-
911 -
912 -
913FatalSignalHandler::~FatalSignalHandler() -
914{ -
915 -
916 struct sigaction act; -
917 memset(&act, 0, sizeof(act)); -
918 act.__sigaction_handler.sa_handler = ((__sighandler_t) 0); -
919 -
920 struct sigaction oldact; -
921 -
922 for (int i = 1; i < 32; ++i) {
-
923 if (!sigismember(&handledSignals, i))
-
924 continue;
-
925 sigaction(i, &act, &oldact); -
926 -
927 -
928 if (oldact.__sigaction_handler.sa_handler != FatalSignalHandler::signal)
-
929 sigaction(i, &oldact, 0);
-
930 }
-
931}
-
932 -
933 -
934 -
935 -
936} -
937int QTest::qExec(QObject *testObject, int argc, char **argv) -
938{ -
939 QBenchmarkGlobalData benchmarkData; -
940 QBenchmarkGlobalData::current = &benchmarkData; -
941 -
942 -
943 int callgrindChildExitCode = 0; -
944 -
945 -
946 -
947 -
948 -
949 -
950 -
951 try { -
952 QTestResult::reset(); -
953 -
954 do { if (!(testObject)) qt_assert("testObject","qtestcase.cpp",2108); } while (0);
-
955 do { if (!(!currentTestObject)) qt_assert("!currentTestObject","qtestcase.cpp",2109); } while (0);
-
956 currentTestObject = testObject; -
957 -
958 const QMetaObject *metaObject = testObject->metaObject(); -
959 do { if (!(metaObject)) qt_assert("metaObject","qtestcase.cpp",2113); } while (0);
-
960 -
961 QTestResult::setCurrentTestObject(metaObject->className()); -
962 if (argc > 0)
-
963 QTestResult::setCurrentAppname(argv[0]);
-
964 -
965 qtest_qParseArgs(argc, argv, false); -
966 -
967 -
968 if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) {
-
969 const QStringList origAppArgs(QCoreApplication::arguments()); -
970 if (!QBenchmarkValgrindUtils::rerunThroughCallgrind(origAppArgs, callgrindChildExitCode))
-
971 return -1;
-
972 -
973 QBenchmarkValgrindUtils::cleanup(); -
974 -
975 } else
-
976 -
977 { -
978 -
979 QScopedPointer<FatalSignalHandler> handler; -
980 if (!noCrashHandler)
-
981 handler.reset(new FatalSignalHandler);
-
982 -
983 qInvokeTestMethods(testObject); -
984 }
-
985 -
986 -
987 } catch (...) { -
988 QTestResult::addFailure("Caught unhandled exception", "qtestcase.cpp", 2142); -
989 if (QTestResult::currentTestFunction()) {
-
990 QTestResult::finishedCurrentTestFunction(); -
991 QTestResult::setCurrentTestFunction(0); -
992 }
-
993 -
994 QTestLog::stopLogging(); -
995 -
996 -
997 -
998 -
999 -
1000 currentTestObject = 0; -
1001 -
1002 -
1003 throw;
-
1004 return 1;
dead code: return 1;
-
1005 } -
1006 -
1007 -
1008 currentTestObject = 0; -
1009 -
1010 QSignalDumper::endDump(); -
1011 if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess)
-
1012 return callgrindChildExitCode;
-
1013 -
1014 -
1015 -
1016 return qMin(QTestLog::failCount(), 127);
-
1017} -
1018int QTest::qExec(QObject *testObject, const QStringList &arguments) -
1019{ -
1020 const int argc = arguments.count(); -
1021 QVarLengthArray<char *> argv(argc); -
1022 -
1023 QVector<QByteArray> args; -
1024 args.reserve(argc); -
1025 -
1026 for (int i = 0; i < argc; ++i)
-
1027 { -
1028 args.append(arguments.at(i).toLocal8Bit().constData()); -
1029 argv[i] = args.last().data(); -
1030 }
-
1031 -
1032 return qExec(testObject, argc, argv.data());
-
1033} -
1034 -
1035 -
1036 -
1037void QTest::qFail(const char *statementStr, const char *file, int line) -
1038{ -
1039 QTestResult::addFailure(statementStr, file, line); -
1040}
-
1041 -
1042 -
1043 -
1044bool QTest::qVerify(bool statement, const char *statementStr, const char *description, -
1045 const char *file, int line) -
1046{ -
1047 return QTestResult::verify(statement, statementStr, description, file, line);
-
1048} -
1049 -
1050 -
1051 -
1052 -
1053void QTest::qSkip(const char *message, const char *file, int line) -
1054{ -
1055 QTestResult::addSkip(message, file, line); -
1056 QTestResult::setSkipCurrentTest(true); -
1057}
-
1058 -
1059 -
1060 -
1061 -
1062bool QTest::qExpectFail(const char *dataIndex, const char *comment, -
1063 QTest::TestFailMode mode, const char *file, int line) -
1064{ -
1065 return QTestResult::expectFail(dataIndex, qstrdup(comment), mode, file, line);
-
1066} -
1067 -
1068 -
1069 -
1070void QTest::qWarn(const char *message, const char *file, int line) -
1071{ -
1072 QTestLog::warn(message, file, line); -
1073}
-
1074void QTest::ignoreMessage(QtMsgType type, const char *message) -
1075{ -
1076 QTestLog::ignoreMessage(type, message); -
1077}
-
1078QString QTest::qFindTestData(const QString& base, const char *file, int line, const char *builddir) -
1079{ -
1080 QString found; -
1081 -
1082 -
1083 -
1084 -
1085 if (QCoreApplication::instance()) {
-
1086 QDir binDirectory(QCoreApplication::applicationDirPath()); -
1087 if (binDirectory.exists(base)) {
-
1088 found = binDirectory.absoluteFilePath(base); -
1089 }
-
1090 else if (QTestLog::verboseLevel() >= 2) {
-
1091 const QString candidate = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + QLatin1Char('/') + base); -
1092 QTestLog::info(QString(QString::fromLatin1("testdata %1 not found relative to test binary [%2]; " "checking next location").arg(base, candidate)).toLocal8Bit().constData(), -
1093 -
1094 -
1095 file, line); -
1096 }
-
1097 } -
1098 -
1099 -
1100 if (found.isEmpty()) {
-
1101 const char *testObjectName = QTestResult::currentTestObjectName(); -
1102 if (testObjectName) {
-
1103 QString testsPath = QLibraryInfo::location(QLibraryInfo::TestsPath); -
1104 QString candidate = QString::fromLatin1("%1/%2/%3") -
1105 .arg(testsPath, QFile::decodeName(testObjectName).toLower(), base); -
1106 if (QFileInfo(candidate).exists()) {
-
1107 found = candidate; -
1108 }
-
1109 else if (QTestLog::verboseLevel() >= 2) {
-
1110 QTestLog::info(QString(QString::fromLatin1("testdata %1 not found in tests install path [%2]; " "checking next location") .arg(base, QDir::toNativeSeparators(candidate))).toLocal8Bit().constData(), -
1111 -
1112 -
1113 -
1114 file, line); -
1115 }
-
1116 } -
1117 }
-
1118 -
1119 -
1120 if (found.isEmpty()) {
-
1121 -
1122 QFileInfo srcdir = QFileInfo(QFile::decodeName(file)).path(); -
1123 -
1124 -
1125 -
1126 if (!srcdir.isAbsolute() && builddir) {
-
1127 srcdir.setFile(QFile::decodeName(builddir) + QLatin1String("/") + srcdir.filePath()); -
1128 }
-
1129 -
1130 QString candidate = QString::fromLatin1("%1/%2").arg(srcdir.canonicalFilePath(), base); -
1131 if (QFileInfo(candidate).exists()) {
-
1132 found = candidate; -
1133 }
-
1134 else if (QTestLog::verboseLevel() >= 2) {
-
1135 QTestLog::info(QString(QString::fromLatin1("testdata %1 not found relative to source path [%2]") .arg(base, QDir::toNativeSeparators(candidate))).toLocal8Bit().constData(), -
1136 -
1137 -
1138 file, line); -
1139 }
-
1140 } -
1141 -
1142 if (found.isEmpty()) {
-
1143 QTest::qWarn(QString(QString::fromLatin1("testdata %1 could not be located!").arg(base)).toLocal8Bit().constData(), -
1144 -
1145 file, line); -
1146 }
-
1147 else if (QTestLog::verboseLevel() >= 1) {
-
1148 QTestLog::info(QString(QString::fromLatin1("testdata %1 was located at %2").arg(base, QDir::toNativeSeparators(found))).toLocal8Bit().constData(), -
1149 -
1150 file, line); -
1151 }
-
1152 -
1153 return found;
-
1154} -
1155 -
1156 -
1157 -
1158QString QTest::qFindTestData(const char *base, const char *file, int line, const char *builddir) -
1159{ -
1160 return qFindTestData(QFile::decodeName(base), file, line, builddir);
-
1161} -
1162 -
1163 -
1164 -
1165void *QTest::qData(const char *tagName, int typeId) -
1166{ -
1167 return fetchData(QTestResult::currentTestData(), tagName, typeId);
-
1168} -
1169 -
1170 -
1171 -
1172void *QTest::qGlobalData(const char *tagName, int typeId) -
1173{ -
1174 return fetchData(QTestResult::currentGlobalTestData(), tagName, typeId);
-
1175} -
1176 -
1177 -
1178 -
1179void *QTest::qElementData(const char *tagName, int metaTypeId) -
1180{ -
1181 do { if (!(tagName)) qt_assert("tagName","qtestcase.cpp",2388); } while (0);
-
1182 QTestData *data = QTestResult::currentTestData(); -
1183 do { if (!(data)) qt_assert("data","qtestcase.cpp",2390); } while (0);
-
1184 do { if (!(data->parent())) qt_assert("data->parent()","qtestcase.cpp",2391); } while (0);
-
1185 -
1186 int idx = data->parent()->indexOf(tagName); -
1187 do { if (!(idx != -1)) qt_assert("idx != -1","qtestcase.cpp",2394); } while (0);
-
1188 do { if (!(data->parent()->elementTypeId(idx) == metaTypeId)) qt_assert("data->parent()->elementTypeId(idx) == metaTypeId","qtestcase.cpp",2395); } while (0);
-
1189 -
1190 return data->data(data->parent()->indexOf(tagName));
-
1191} -
1192 -
1193 -
1194 -
1195void QTest::addColumnInternal(int id, const char *name) -
1196{ -
1197 QTestTable *tbl = QTestTable::currentTestTable(); -
1198 do { if (!(tbl)) qt_assert_x("QTest::addColumn()", "Cannot add testdata outside of a _data slot.","qtestcase.cpp",2405); } while (0);
-
1199 -
1200 tbl->addColumn(id, name); -
1201}
-
1202QTestData &QTest::newRow(const char *dataTag) -
1203{ -
1204 do { if (!(dataTag)) qt_assert_x("QTest::newRow()", "Data tag can not be null","qtestcase.cpp",2428); } while (0);
-
1205 QTestTable *tbl = QTestTable::currentTestTable(); -
1206 do { if (!(tbl)) qt_assert_x("QTest::newRow()", "Cannot add testdata outside of a _data slot.","qtestcase.cpp",2430); } while (0);
-
1207 do { if (!(tbl->elementCount())) qt_assert_x("QTest::newRow()", "Must add columns before attempting to add rows.","qtestcase.cpp",2431); } while (0);
-
1208 -
1209 return *tbl->newData(dataTag);
-
1210} -
1211const char *QTest::currentTestFunction() -
1212{ -
1213 return QTestResult::currentTestFunction();
-
1214} -
1215 -
1216 -
1217 -
1218 -
1219 -
1220const char *QTest::currentDataTag() -
1221{ -
1222 return QTestResult::currentDataTag();
-
1223} -
1224 -
1225 -
1226 -
1227 -
1228bool QTest::currentTestFailed() -
1229{ -
1230 return QTestResult::currentTestFailed();
-
1231} -
1232void QTest::qSleep(int ms) -
1233{ -
1234 do { if (!(ms > 0)) qt_assert("ms > 0","qtestcase.cpp",2508); } while (0);
-
1235 -
1236 -
1237 -
1238 -
1239 struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; -
1240 nanosleep(&ts, __null); -
1241 -
1242}
-
1243 -
1244 -
1245 -
1246QObject *QTest::testObject() -
1247{ -
1248 return currentTestObject;
-
1249} -
1250bool QTest::compare_helper(bool success, const char *failureMsg, -
1251 char *val1, char *val2, -
1252 const char *actual, const char *expected, -
1253 const char *file, int line) -
1254{ -
1255 return QTestResult::compare(success, failureMsg, val1, val2, actual, expected, file, line);
-
1256} -
1257 -
1258 -
1259 -
1260 -
1261bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const char *expected, -
1262 const char *file, int line) -
1263{ -
1264 return compare_helper(qFuzzyCompare(t1, t2), "Compared floats are not the same (fuzzy compare)", -
1265 toString(t1), toString(t2), actual, expected, file, line);
-
1266} -
1267 -
1268 -
1269 -
1270 -
1271bool QTest::qCompare(double const &t1, double const &t2, const char *actual, const char *expected, -
1272 const char *file, int line) -
1273{ -
1274 return compare_helper(qFuzzyCompare(t1, t2), "Compared doubles are not the same (fuzzy compare)", -
1275 toString(t1), toString(t2), actual, expected, file, line);
-
1276} -
1277template <> __attribute__((visibility("default"))) char *QTest::toString<short >(const short &t) { char *msg = new char[128]; qsnprintf(msg, 128, "%hd", t); return msg; }
-
1278template <> __attribute__((visibility("default"))) char *QTest::toString<ushort >(const ushort &t) { char *msg = new char[128]; qsnprintf(msg, 128, "%hu", t); return msg; }
-
1279template <> __attribute__((visibility("default"))) char *QTest::toString<int >(const int &t) { char *msg = new char[128]; qsnprintf(msg, 128, "%d", t); return msg; }
-
1280template <> __attribute__((visibility("default"))) char *QTest::toString<uint >(const uint &t) { char *msg = new char[128]; qsnprintf(msg, 128, "%u", t); return msg; }
-
1281template <> __attribute__((visibility("default"))) char *QTest::toString<long >(const long &t) { char *msg = new char[128]; qsnprintf(msg, 128, "%ld", t); return msg; }
-
1282template <> __attribute__((visibility("default"))) char *QTest::toString<ulong >(const ulong &t) { char *msg = new char[128]; qsnprintf(msg, 128, "%lu", t); return msg; }
-
1283 -
1284 -
1285 -
1286 -
1287template <> __attribute__((visibility("default"))) char *QTest::toString<qint64 >(const qint64 &t) { char *msg = new char[128]; qsnprintf(msg, 128, "%lld", t); return msg; }
-
1288template <> __attribute__((visibility("default"))) char *QTest::toString<quint64 >(const quint64 &t) { char *msg = new char[128]; qsnprintf(msg, 128, "%llu", t); return msg; }
-
1289 -
1290template <> __attribute__((visibility("default"))) char *QTest::toString<bool >(const bool &t) { char *msg = new char[128]; qsnprintf(msg, 128, "%d", t); return msg; }
-
1291template <> __attribute__((visibility("default"))) char *QTest::toString<char >(const char &t) { char *msg = new char[128]; qsnprintf(msg, 128, "%c", t); return msg; }
-
1292template <> __attribute__((visibility("default"))) char *QTest::toString<float >(const float &t) { char *msg = new char[128]; qsnprintf(msg, 128, "%g", t); return msg; }
-
1293template <> __attribute__((visibility("default"))) char *QTest::toString<double >(const double &t) { char *msg = new char[128]; qsnprintf(msg, 128, "%lg", t); return msg; }
-
1294 -
1295 -
1296 -
1297char *QTest::toString(const char *str) -
1298{ -
1299 if (!str)
-
1300 return 0;
-
1301 char *msg = new char[strlen(str) + 1]; -
1302 return qstrcpy(msg, str);
-
1303} -
1304 -
1305 -
1306 -
1307char *QTest::toString(const void *p) -
1308{ -
1309 char *msg = new char[128]; -
1310 qsnprintf(msg, 128, "%p", p); -
1311 return msg;
-
1312} -
1313 -
1314 -
1315 -
1316bool QTest::compare_string_helper(const char *t1, const char *t2, const char *actual, -
1317 const char *expected, const char *file, int line) -
1318{ -
1319 return compare_helper(qstrcmp(t1, t2) == 0, "Compared strings are not the same", -
1320 toString(t1), toString(t2), actual, expected, file, line);
-
1321} -
1322 -
1323 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial