Qt 4.8
qtestcase.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtTest module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "QtTest/qtestcase.h"
43 #include "QtTest/qtestassert.h"
44 
45 #include <QtCore/qbytearray.h>
46 #include <QtCore/qmetaobject.h>
47 #include <QtCore/qobject.h>
48 #include <QtCore/qstringlist.h>
49 #include <QtCore/qvector.h>
50 #include <QtCore/qvarlengtharray.h>
51 #include <QtCore/qcoreapplication.h>
52 #include <QtCore/qfile.h>
53 #include <QtCore/qfileinfo.h>
54 #include <QtCore/qdir.h>
55 #include <QtCore/qprocess.h>
56 #include <QtCore/qdebug.h>
57 
58 #include "QtTest/private/qtestlog_p.h"
59 #include "QtTest/private/qtesttable_p.h"
60 #include "QtTest/qtestdata.h"
61 #include "QtTest/private/qtestresult_p.h"
62 #include "QtTest/private/qsignaldumper_p.h"
63 #include "QtTest/private/qbenchmark_p.h"
64 #include "3rdparty/cycle_p.h"
65 
66 #include <stdarg.h>
67 #include <stdio.h>
68 #include <stdlib.h>
69 
70 #ifdef Q_OS_WIN
71 #include <windows.h> // for Sleep
72 #endif
73 #ifdef Q_OS_UNIX
74 #include <errno.h>
75 #include <signal.h>
76 #include <time.h>
77 #endif
78 
79 #ifdef Q_WS_MAC
80 #include <Carbon/Carbon.h> // for SetFrontProcess
81 #ifdef QT_MAC_USE_COCOA
82 #include <IOKit/pwr_mgt/IOPMLib.h>
83 #else
84 #include <Security/AuthSession.h>
85 #endif
86 #undef verify
87 #endif
88 
90 
901 namespace QTest
902 {
904 
905  class TestFunction {
906  public:
907  TestFunction() : function_(-1), data_(0) {}
908  void set(int function, char *data) { function_ = function; data_ = data; }
909  char *data() const { return data_; }
910  int function() const { return function_; }
911  ~TestFunction() { delete[] data_; }
912  private:
914  char *data_;
915  };
922  static TestFunction * testFuncs = 0;
923  static int testFuncCount = 0;
924 
926  static struct TestFuncCleanup
927  {
928  void cleanup()
929  {
930  delete[] testFuncs;
931  testFuncCount = 0;
932  testFuncs = 0;
933  }
934 
936  } testFuncCleaner;
937 
938  static int keyDelay = -1;
939  static int mouseDelay = -1;
940  static int eventDelay = -1;
941  static bool randomOrder = false;
942  static int keyVerbose = -1;
943  static unsigned int seed = 0;
944  static bool seedSet = false;
945 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
946  static bool noCrashHandler = false;
947 #endif
948 
949 void filter_unprintable(char *str)
950 {
951  char *idx = str;
952  while (*idx) {
953  if (((*idx < 0x20 && *idx != '\n' && *idx != '\t') || *idx > 0x7e))
954  *idx = '?';
955  ++idx;
956  }
957 }
958 
961 int qt_snprintf(char *str, int size, const char *format, ...)
962 {
963  va_list ap;
964  int res = 0;
965 
966  va_start(ap, format);
967  qvsnprintf(str, size, format, ap);
968  va_end(ap);
969  str[size - 1] = '\0';
970 
971  filter_unprintable(str);
972 
973  return res;
974 }
975 
979 static void invokeMethod(QObject *obj, const char *methodName)
980 {
981  const QMetaObject *metaObject = obj->metaObject();
982  int funcIndex = metaObject->indexOfMethod(methodName);
983  if (funcIndex >= 0) {
984  QMetaMethod method = metaObject->method(funcIndex);
985  method.invoke(obj, Qt::DirectConnection);
986  }
987 }
988 
990 {
991  if (keyVerbose == -1) {
992  keyVerbose = qgetenv("QTEST_KEYEVENT_VERBOSE").constData() ? 1 : 0;
993  }
994  return keyVerbose == 1;
995 }
996 
998 {
999  if (eventDelay == -1) {
1000  if (qgetenv("QTEST_EVENT_DELAY").constData())
1001  eventDelay = atoi(qgetenv("QTEST_EVENT_DELAY"));
1002  else
1003  eventDelay = 0;
1004  }
1005  return eventDelay;
1006 }
1007 
1009 {
1010  if (mouseDelay == -1) {
1011  if (qgetenv("QTEST_MOUSEEVENT_DELAY").constData())
1012  mouseDelay = atoi((qgetenv("QTEST_MOUSEEVENT_DELAY")));
1013  else
1014  mouseDelay = defaultEventDelay();
1015  }
1016  return mouseDelay;
1017 }
1018 
1020 {
1021  if (keyDelay == -1) {
1022  if (qgetenv("QTEST_KEYEVENT_DELAY").constData())
1023  keyDelay = atoi(qgetenv("QTEST_KEYEVENT_DELAY").constData());
1024  else
1025  keyDelay = defaultEventDelay();
1026  }
1027  return keyDelay;
1028 }
1029 
1031 {
1032  static bool randomSeeded = false;
1033  if (!randomSeeded) {
1034  if (!QTest::seedSet) {
1036  timer.start();
1037  QTest::seed = timer.msecsSinceReference();
1038  }
1040  randomSeeded = true;
1041  }
1042 }
1043 
1045 {
1047  return QTest::seed;
1048 }
1049 
1050 template<typename T>
1051 void swap(T * array, int pos, int otherPos)
1052 {
1053  T tmp = array[pos];
1054  array[pos] = array[otherPos];
1055  array[otherPos] = tmp;
1056 }
1057 
1058 template<typename T>
1059 static void randomizeList(T * array, int size)
1060 {
1061  for (int i = 0; i != size; i++) {
1062  int pos = qrand() % size;
1063  swap(array, pos, i);
1064  }
1065 }
1066 
1067 static bool isValidSlot(const QMetaMethod &sl)
1068 {
1069  if (sl.access() != QMetaMethod::Private || !sl.parameterTypes().isEmpty()
1070  || qstrlen(sl.typeName()) || sl.methodType() != QMetaMethod::Slot)
1071  return false;
1072  const char *sig = sl.signature();
1073  int len = qstrlen(sig);
1074  if (len < 2)
1075  return false;
1076  if (sig[len - 2] != '(' || sig[len - 1] != ')')
1077  return false;
1078  if (len > 7 && strcmp(sig + (len - 7), "_data()") == 0)
1079  return false;
1080  if (strcmp(sig, "initTestCase()") == 0 || strcmp(sig, "cleanupTestCase()") == 0
1081  || strcmp(sig, "cleanup()") == 0 || strcmp(sig, "init()") == 0)
1082  return false;
1083  return true;
1084 }
1085 
1090 
1091 static void qPrintTestSlots()
1092 {
1093  for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) {
1095  if (isValidSlot(sl))
1096  printf("%s\n", sl.signature());
1097  }
1098 }
1099 
1100 static void qPrintDataTags()
1101 {
1102  // Get global data tags:
1104  invokeMethod(QTest::currentTestObject, "initTestCase_data()");
1105  const QTestTable *gTable = QTestTable::globalTestTable();
1106 
1107  const QMetaObject *currTestMetaObj = QTest::currentTestObject->metaObject();
1108 
1109  // Process test functions:
1110  for (int i = 0; i < currTestMetaObj->methodCount(); ++i) {
1111  QMetaMethod tf = currTestMetaObj->method(i);
1112  if (isValidSlot(tf)) {
1113  // Retrieve local tags:
1114  QStringList localTags;
1115  QTestTable table;
1116  char member[512];
1117  char *slot = qstrdup(tf.signature());
1118  slot[strlen(slot) - 2] = '\0';
1119  QTest::qt_snprintf(member, 512, "%s_data()", slot);
1121  for (int j = 0; j < table.dataCount(); ++j)
1122  localTags << QLatin1String(table.testData(j)->dataTag());
1123 
1124  // Print all tag combinations:
1125  if (gTable->dataCount() == 0) {
1126  if (localTags.count() == 0) {
1127  // No tags at all, so just print the test function:
1128  printf("%s %s\n", currTestMetaObj->className(), slot);
1129  } else {
1130  // Only local tags, so print each of them:
1131  for (int k = 0; k < localTags.size(); ++k)
1132  printf(
1133  "%s %s %s\n",
1134  currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data());
1135  }
1136  } else {
1137  for (int j = 0; j < gTable->dataCount(); ++j) {
1138  if (localTags.count() == 0) {
1139  // Only global tags, so print the current one:
1140  printf(
1141  "%s %s __global__ %s\n",
1142  currTestMetaObj->className(), slot, gTable->testData(j)->dataTag());
1143  } else {
1144  // Local and global tags, so print each of the local ones and
1145  // the current global one:
1146  for (int k = 0; k < localTags.size(); ++k)
1147  printf(
1148  "%s %s %s __global__ %s\n", currTestMetaObj->className(), slot,
1149  localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag());
1150  }
1151  }
1152  }
1153 
1154  delete[] slot;
1155  }
1156  }
1157 }
1158 
1159 static int qToInt(char *str)
1160 {
1161  char *pEnd;
1162  int l = (int)strtol(str, &pEnd, 10);
1163  if (*pEnd != 0) {
1164  printf("Invalid numeric parameter: '%s'\n", str);
1165  exit(1);
1166  }
1167  return l;
1168 }
1169 
1170 Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
1171 {
1172  const char *testOptions =
1173  " options:\n"
1174  " -functions : Returns a list of current testfunctions\n"
1175  " -datatags : Returns a list of current data tags.\n"
1176  " A global data tag is preceded by ' __global__ '.\n"
1177  " -xunitxml : Outputs results as XML XUnit document\n"
1178  " -xml : Outputs results as XML document\n"
1179  " -lightxml : Outputs results as stream of XML tags\n"
1180  " -flush : Flushes the results\n"
1181  " -o filename: Writes all output into a file\n"
1182  " -silent : Only outputs warnings and failures\n"
1183  " -v1 : Print enter messages for each testfunction\n"
1184  " -v2 : Also print out each QVERIFY/QCOMPARE/QTEST\n"
1185  " -vs : Print every signal emitted\n"
1186  " -random : Run testcases within each test in random order\n"
1187  " -seed n : Positive integer to be used as seed for -random. If not specified,\n"
1188  " the current time will be used as seed.\n"
1189  " -eventdelay ms : Set default delay for mouse and keyboard simulation to ms milliseconds\n"
1190  " -keydelay ms : Set default delay for keyboard simulation to ms milliseconds\n"
1191  " -mousedelay ms : Set default delay for mouse simulation to ms milliseconds\n"
1192  " -keyevent-verbose : Turn on verbose messages for keyboard simulation\n"
1193  " -maxwarnings n : Sets the maximum amount of messages to output.\n"
1194  " 0 means unlimited, default: 2000\n"
1195 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
1196  " -nocrashhandler : Disables the crash handler\n"
1197 #endif
1198  "\n"
1199  " Benchmark related options:\n"
1200 #ifdef QTESTLIB_USE_VALGRIND
1201  " -callgrind : Use callgrind to time benchmarks\n"
1202 #endif
1203 #ifdef HAVE_TICK_COUNTER
1204  " -tickcounter : Use CPU tick counters to time benchmarks\n"
1205 #endif
1206  " -eventcounter : Counts events received during benchmarks\n"
1207  " -minimumvalue n : Sets the minimum acceptable measurement value\n"
1208  " -iterations n : Sets the number of accumulation iterations.\n"
1209  " -median n : Sets the number of median iterations.\n"
1210  " -vb : Print out verbose benchmarking information.\n"
1211  "\n"
1212  " -help : This help\n";
1213 
1214  for (int i = 1; i < argc; ++i) {
1215  if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0
1216  || strcmp(argv[i], "/?") == 0) {
1217  printf(" Usage: %s [options] [testfunction[:testdata]]...\n"
1218  " By default, all testfunctions will be run.\n\n"
1219  "%s", argv[0], testOptions);
1220  exit(0);
1221  } else if (strcmp(argv[i], "-functions") == 0) {
1222  if (qml) {
1224  } else {
1225  qPrintTestSlots();
1226  exit(0);
1227  }
1228  } else if (strcmp(argv[i], "-datatags") == 0) {
1230  if (!qml) {
1231  qPrintDataTags();
1232  exit(0);
1233  }
1234  } else if(strcmp(argv[i], "-xunitxml") == 0){
1236  } else if (strcmp(argv[i], "-xml") == 0) {
1238  } else if (strcmp(argv[i], "-lightxml") == 0) {
1240  }else if(strcmp(argv[i], "-flush") == 0){
1242  } else if (strcmp(argv[i], "-silent") == 0) {
1244  } else if (strcmp(argv[i], "-v1") == 0) {
1246  } else if (strcmp(argv[i], "-v2") == 0) {
1248  } else if (strcmp(argv[i], "-vs") == 0) {
1250  } else if (strcmp(argv[i], "-o") == 0) {
1251  if (i + 1 >= argc) {
1252  printf("-o needs an extra parameter specifying the filename\n");
1253  exit(1);
1254  } else {
1255  QTestLog::redirectOutput(argv[++i]);
1256  }
1257  } else if (strcmp(argv[i], "-eventdelay") == 0) {
1258  if (i + 1 >= argc) {
1259  printf("-eventdelay needs an extra parameter to indicate the delay(ms)\n");
1260  exit(1);
1261  } else {
1262  QTest::eventDelay = qToInt(argv[++i]);
1263  }
1264  } else if (strcmp(argv[i], "-keydelay") == 0) {
1265  if (i + 1 >= argc) {
1266  printf("-keydelay needs an extra parameter to indicate the delay(ms)\n");
1267  exit(1);
1268  } else {
1269  QTest::keyDelay = qToInt(argv[++i]);
1270  }
1271  } else if (strcmp(argv[i], "-mousedelay") == 0) {
1272  if (i + 1 >= argc) {
1273  printf("-mousedelay needs an extra parameter to indicate the delay(ms)\n");
1274  exit(1);
1275  } else {
1276  QTest::mouseDelay = qToInt(argv[++i]);
1277  }
1278  } else if (strcmp(argv[i], "-maxwarnings") == 0) {
1279  if (i + 1 >= argc) {
1280  printf("-maxwarnings needs an extra parameter with the amount of warnings\n");
1281  exit(1);
1282  } else {
1283  QTestLog::setMaxWarnings(qToInt(argv[++i]));
1284  }
1285 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
1286  } else if (strcmp(argv[i], "-nocrashhandler") == 0) {
1287  QTest::noCrashHandler = true;
1288 #endif
1289  } else if (strcmp(argv[i], "-keyevent-verbose") == 0) {
1290  QTest::keyVerbose = 1;
1291 #ifdef QTESTLIB_USE_VALGRIND
1292  } else if (strcmp(argv[i], "-callgrind") == 0) {
1294  if (QFileInfo(QDir::currentPath()).isWritable()) {
1296  } else {
1297  printf("WARNING: Current directory not writable. Using the walltime measurer.\n");
1298  }
1299  else {
1300  printf("WARNING: Valgrind not found or too old. Make sure it is installed and in your path. "
1301  "Using the walltime measurer.\n");
1302  }
1303  } else if (strcmp(argv[i], "-callgrindchild") == 0) { // "private" option
1307 #endif
1308 #ifdef HAVE_TICK_COUNTER
1309  } else if (strcmp(argv[i], "-tickcounter") == 0) {
1311 #endif
1312  } else if (strcmp(argv[i], "-eventcounter") == 0) {
1314  } else if (strcmp(argv[i], "-random") == 0) {
1315  QTest::randomOrder = true;
1316  } else if (strcmp(argv[i], "-seed") == 0) {
1317  bool argumentOk = false;
1318  if (i + 1 < argc) {
1319  char * endpt = 0;
1320  long longSeed = strtol(argv[++i], &endpt, 10);
1321  argumentOk = (*endpt == '\0' && longSeed >= 0);
1322  QTest::seed = longSeed;
1323  }
1324  if (!argumentOk) {
1325  printf("-seed needs an extra positive integer parameter to specify the seed\n");
1326  exit(1);
1327  } else {
1328  QTest::seedSet = true;
1329  }
1330  } else if (strcmp(argv[i], "-minimumvalue") == 0) {
1331  if (i + 1 >= argc) {
1332  printf("-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n");
1333  exit(1);
1334  } else {
1336  }
1337  } else if (strcmp(argv[i], "-iterations") == 0) {
1338  if (i + 1 >= argc) {
1339  printf("-iterations needs an extra parameter to indicate the number of iterations\n");
1340  exit(1);
1341  } else {
1343  }
1344  } else if (strcmp(argv[i], "-median") == 0) {
1345  if (i + 1 >= argc) {
1346  printf("-median needs an extra parameter to indicate the number of median iterations\n");
1347  exit(1);
1348  } else {
1350  }
1351 
1352  } else if (strcmp(argv[i], "-vb") == 0) {
1354  } else if (strcmp(argv[i], "-chart") == 0) {
1355  fprintf(stderr, "Warning: `-chart' option is not available\n");
1356  } else if (strcmp(argv[i], "-qws") == 0) {
1357  // do nothing
1358  } else if (strcmp(argv[i], "-graphicssystem") == 0) {
1359  // do nothing
1360  if (i + 1 >= argc) {
1361  printf("-graphicssystem needs an extra parameter specifying the graphics system\n");
1362  exit(1);
1363  } else {
1364  ++i;
1365  }
1366  } else if (argv[i][0] == '-') {
1367  printf("Unknown option: '%s'\n\n%s", argv[i], testOptions);
1368  exit(1);
1369  } else if (qml) {
1370  // We can't check the availability of test functions until
1371  // we load the QML files. So just store the data for now.
1372  int colon = -1;
1373  int offset;
1374  for(offset = 0; *(argv[i]+offset); ++offset) {
1375  if (*(argv[i]+offset) == ':') {
1376  if (*(argv[i]+offset+1) == ':') {
1377  // "::" is used as a test name separator.
1378  // e.g. "ClickTests::test_click:row1".
1379  ++offset;
1380  } else {
1381  colon = offset;
1382  break;
1383  }
1384  }
1385  }
1386  if (colon == -1) {
1388  QTest::testTags += QString();
1389  } else {
1391  QString::fromLatin1(argv[i], colon);
1392  QTest::testTags +=
1393  QString::fromLatin1(argv[i] + colon + 1);
1394  }
1395  } else {
1396  if (!QTest::testFuncs) {
1398  }
1399 
1400  int colon = -1;
1401  char buf[512], *data=0;
1402  int off;
1403  for(off = 0; *(argv[i]+off); ++off) {
1404  if (*(argv[i]+off) == ':') {
1405  colon = off;
1406  break;
1407  }
1408  }
1409  if(colon != -1) {
1410  data = qstrdup(argv[i]+colon+1);
1411  }
1412  QTest::qt_snprintf(buf, qMin(512, off + 1), "%s", argv[i]); // copy text before the ':' into buf
1413  QTest::qt_snprintf(buf + off, qMin(512 - off, 3), "()"); // append "()"
1415  if (idx < 0 || !isValidSlot(QTest::currentTestObject->metaObject()->method(idx))) {
1416  printf("Unknown testfunction: '%s'\n", buf);
1417  printf("Available testfunctions:\n");
1418  qPrintTestSlots();
1419  exit(1);
1420  }
1421  testFuncs[testFuncCount].set(idx, data);
1422  testFuncCount++;
1424  }
1425  }
1426 
1428  printf("-seed requires -random\n");
1429  exit(1);
1430  }
1431 }
1432 
1434 {
1435  const int count = container.count();
1436  if (count == 0)
1437  return QBenchmarkResult();
1438 
1439  if (count == 1)
1440  return container.at(0);
1441 
1442  QList<QBenchmarkResult> containerCopy = container;
1443  qSort(containerCopy);
1444 
1445  const int middle = count / 2;
1446 
1447  // ### handle even-sized containers here by doing an aritmetic mean of the two middle items.
1448  return containerCopy.at(middle);
1449 }
1450 
1452 {
1454  {
1456  }
1458  {
1460  }
1461 };
1462 
1463 static void qInvokeTestMethodDataEntry(char *slot)
1464 {
1465  /* Benchmarking: for each median iteration*/
1466 
1468 
1469  QList<QBenchmarkResult> results;
1470  do {
1472 
1473  /* Benchmarking: for each accumulation iteration*/
1474  bool invokeOk;
1475  do {
1479  break;
1480 
1482 
1485 
1487  QLatin1String(
1489  ? QTestResult::currentDataTag() : "");
1490 
1493  if (!invokeOk)
1494  QTestResult::addFailure("Unable to execute slot", __FILE__, __LINE__);
1495 
1497  invokeMethod(QTest::currentTestObject, "cleanup()");
1499 
1500  // If this test method has a benchmark, repeat until all measurements are
1501  // acceptable.
1502  // The QBENCHMARK macro increases the number of iterations for each run until
1503  // this happens.
1504  } while (invokeOk
1505  && QBenchmarkTestMethodData::current->isBenchmark()
1506  && QBenchmarkTestMethodData::current->resultsAccepted() == false);
1507 
1509  if (i > -1) // iteration -1 is the warmup iteration.
1510  results.append(QBenchmarkTestMethodData::current->result);
1511 
1512  if (QBenchmarkTestMethodData::current->isBenchmark() &&
1513  QBenchmarkGlobalData::current->verboseOutput) {
1514  if (i == -1) {
1515  qDebug() << "warmup stage result :" << QBenchmarkTestMethodData::current->result.value;
1516  } else {
1517  qDebug() << "accumulation stage result:" << QBenchmarkTestMethodData::current->result.value;
1518  }
1519  }
1520  } while (QBenchmarkTestMethodData::current->isBenchmark()
1521  && (++i < QBenchmarkGlobalData::current->adjustMedianIterationCount()));
1522 
1523  if (QBenchmarkTestMethodData::current->isBenchmark()
1524  && QBenchmarkTestMethodData::current->resultsAccepted())
1526 }
1527 
1540 static bool qInvokeTestMethod(const char *slotName, const char *data=0)
1541 {
1542  QTEST_ASSERT(slotName);
1543 
1544  QBenchmarkTestMethodData benchmarkData;
1545  QBenchmarkTestMethodData::current = &benchmarkData;
1546 
1548 
1549  char member[512];
1550  QTestTable table;
1551 
1552  char *slot = qstrdup(slotName);
1553  slot[strlen(slot) - 2] = '\0';
1555 
1556  const QTestTable *gTable = QTestTable::globalTestTable();
1557  const int globalDataCount = gTable->dataCount();
1558  int curGlobalDataIndex = 0;
1559 
1560  /* For each test function that has a *_data() table/function, do: */
1561  do {
1562  if (!gTable->isEmpty())
1563  QTestResult::setCurrentGlobalTestData(gTable->testData(curGlobalDataIndex));
1564 
1565  if (curGlobalDataIndex == 0) {
1567  QTest::qt_snprintf(member, 512, "%s_data()", slot);
1569 
1570  // if we encounter a SkipAll in the _data slot, we skip the whole
1571  // testfunction, no matter how much global data exists
1574  break;
1575  }
1576  }
1577 
1578  bool foundFunction = false;
1580  int curDataIndex = 0;
1581  const int dataCount = table.dataCount();
1583 
1584  // Data tag requested but none available?
1585  if (data && !dataCount) {
1586  // Let empty data tag through.
1587  if (!*data)
1588  data = 0;
1589  else {
1590  printf("Unknown testdata for function %s: '%s'\n", slotName, data);
1591  printf("Function has no testdata.\n");
1592  return false;
1593  }
1594  }
1595 
1596  /* For each entry in the data table, do: */
1597  do {
1598  if (!data || !qstrcmp(data, table.testData(curDataIndex)->dataTag())) {
1599  foundFunction = true;
1600  QTestDataSetter s(curDataIndex >= dataCount ? static_cast<QTestData *>(0)
1601  : table.testData(curDataIndex));
1602 
1604 
1606  // check whether SkipAll was requested
1607  break;
1608  if (data)
1609  break;
1610  }
1611  ++curDataIndex;
1612  } while (curDataIndex < dataCount);
1613  }
1614 
1615  if (data && !foundFunction) {
1616  printf("Unknown testdata for function %s: '%s'\n", slotName, data);
1617  printf("Available testdata:\n");
1618  for(int i = 0; i < table.dataCount(); ++i)
1619  printf("%s\n", table.testData(i)->dataTag());
1620  return false;
1621  }
1622 
1624  ++curGlobalDataIndex;
1625  } while (curGlobalDataIndex < globalDataCount);
1626 
1630  delete[] slot;
1631 
1632  return true;
1633 }
1634 
1635 void *fetchData(QTestData *data, const char *tagName, int typeId)
1636 {
1637  QTEST_ASSERT(typeId);
1638  QTEST_ASSERT_X(data, "QTest::fetchData()", "Test data requested, but no testdata available.");
1639  QTEST_ASSERT(data->parent());
1640 
1641  int idx = data->parent()->indexOf(tagName);
1642 
1643  if (idx == -1 || idx >= data->dataCount()) {
1644  qFatal("QFETCH: Requested testdata '%s' not available, check your _data function.",
1645  tagName);
1646  }
1647 
1648  if (typeId != data->parent()->elementTypeId(idx)) {
1649  qFatal("Requested type '%s' does not match available type '%s'.",
1650  QMetaType::typeName(typeId),
1651  QMetaType::typeName(data->parent()->elementTypeId(idx)));
1652  }
1653 
1654  return data->data(idx);
1655 }
1656 
1667 char *toHexRepresentation(const char *ba, int length)
1668 {
1669  if(length == 0)
1670  return qstrdup("");
1671 
1672  /* We output at maximum about maxLen characters in order to avoid
1673  * running out of memory and flooding things when the byte array
1674  * is large.
1675  *
1676  * maxLen can't be for example 200 because QTestLib is sprinkled with fixed
1677  * size char arrays.
1678  * */
1679  const int maxLen = 50;
1680  const int len = qMin(maxLen, length);
1681  char *result = 0;
1682 
1683  if(length > maxLen) {
1684  const int size = len * 3 + 4;
1685  result = new char[size];
1686 
1687  char *const forElipsis = result + size - 5;
1688  forElipsis[0] = ' ';
1689  forElipsis[1] = '.';
1690  forElipsis[2] = '.';
1691  forElipsis[3] = '.';
1692  result[size - 1] = '\0';
1693  }
1694  else {
1695  const int size = len * 3;
1696  result = new char[size];
1697  result[size - 1] = '\0';
1698  }
1699 
1700  const char toHex[] = "0123456789ABCDEF";
1701  int i = 0;
1702  int o = 0;
1703 
1704  while(true) {
1705  const char at = ba[i];
1706 
1707  result[o] = toHex[(at >> 4) & 0x0F];
1708  ++o;
1709  result[o] = toHex[at & 0x0F];
1710 
1711  ++i;
1712  ++o;
1713  if(i == len)
1714  break;
1715  else {
1716  result[o] = ' ';
1717  ++o;
1718  }
1719  }
1720 
1721  return result;
1722 }
1723 
1725 {
1726  const QMetaObject *metaObject = testObject->metaObject();
1727  QTEST_ASSERT(metaObject);
1728  if (QTest::randomOrder) {
1730  } else {
1732  }
1733  QTestResult::setCurrentTestFunction("initTestCase");
1736  invokeMethod(testObject, "initTestCase_data()");
1737 
1740  invokeMethod(testObject, "initTestCase()");
1741 
1742  // finishedCurrentTestFunction() resets QTestResult::testFailed(), so use a local copy.
1743  const bool previousFailed = QTestResult::testFailed();
1745 
1746  if(!QTestResult::skipCurrentTest() && !previousFailed) {
1747 
1748  if (QTest::testFuncs) {
1749  if (QTest::randomOrder)
1751  for (int i = 0; i != QTest::testFuncCount; i++) {
1752  if (!qInvokeTestMethod(metaObject->method(QTest::testFuncs[i].function()).signature(),
1753  QTest::testFuncs[i].data())) {
1754  break;
1755  }
1756  }
1758  } else {
1759  int methodCount = metaObject->methodCount();
1760  QMetaMethod *testMethods = new QMetaMethod[methodCount];
1761  for (int i = 0; i != methodCount; i++)
1762  testMethods[i] = metaObject->method(i);
1763  if (QTest::randomOrder)
1764  randomizeList(testMethods, methodCount);
1765  for (int i = 0; i != methodCount; i++) {
1766  if (!isValidSlot(testMethods[i]))
1767  continue;
1768  if (!qInvokeTestMethod(testMethods[i].signature()))
1769  break;
1770  }
1771  delete[] testMethods;
1772  testMethods = 0;
1773  }
1774  }
1775 
1777  QTestResult::setCurrentTestFunction("cleanupTestCase");
1778  invokeMethod(testObject, "cleanupTestCase()");
1779  }
1783 
1785 }
1786 
1787 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
1789 {
1790 public:
1792  ~FatalSignalHandler();
1793 
1794 private:
1795  static void signal(int);
1796  sigset_t handledSignals;
1797 };
1798 
1800 {
1801  qFatal("Received signal %d", signum);
1802 #if defined(Q_OS_INTEGRITY)
1803  {
1804  struct sigaction act;
1805  memset(&act, 0, sizeof(struct sigaction));
1806  act.sa_handler = SIG_DFL;
1807  sigaction(signum, &act, NULL);
1808  }
1809 #endif
1810 }
1811 
1813 {
1814  sigemptyset(&handledSignals);
1815 
1816  const int fatalSignals[] = {
1817  SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGFPE, SIGSEGV, SIGPIPE, SIGTERM, 0 };
1818 
1819  struct sigaction act;
1820  memset(&act, 0, sizeof(act));
1821  act.sa_handler = FatalSignalHandler::signal;
1822 
1823  // Remove the handler after it is invoked.
1824 #if !defined(Q_OS_INTEGRITY)
1825  act.sa_flags = SA_RESETHAND;
1826 #endif
1827  // Block all fatal signals in our signal handler so we don't try to close
1828  // the testlog twice.
1829  sigemptyset(&act.sa_mask);
1830  for (int i = 0; fatalSignals[i]; ++i)
1831  sigaddset(&act.sa_mask, fatalSignals[i]);
1832 
1833  struct sigaction oldact;
1834 
1835  for (int i = 0; fatalSignals[i]; ++i) {
1836  sigaction(fatalSignals[i], &act, &oldact);
1837 #ifndef Q_WS_QWS
1838  // Don't overwrite any non-default handlers
1839  // however, we need to replace the default QWS handlers
1840  if (
1841 #ifdef SA_SIGINFO
1842  oldact.sa_flags & SA_SIGINFO ||
1843 #endif
1844  oldact.sa_handler != SIG_DFL) {
1845  sigaction(fatalSignals[i], &oldact, 0);
1846  } else
1847 #endif
1848  {
1849  sigaddset(&handledSignals, fatalSignals[i]);
1850  }
1851  }
1852 }
1853 
1854 
1856 {
1857  // Unregister any of our remaining signal handlers
1858  struct sigaction act;
1859  memset(&act, 0, sizeof(act));
1860  act.sa_handler = SIG_DFL;
1861 
1862  struct sigaction oldact;
1863 
1864  for (int i = 1; i < 32; ++i) {
1865  if (!sigismember(&handledSignals, i))
1866  continue;
1867  sigaction(i, &act, &oldact);
1868 
1869  // If someone overwrote it in the mean time, put it back
1870  if (oldact.sa_handler != FatalSignalHandler::signal)
1871  sigaction(i, &oldact, 0);
1872  }
1873 }
1874 
1875 #endif
1876 
1877 
1878 } // namespace
1879 
1913 int QTest::qExec(QObject *testObject, int argc, char **argv)
1914 {
1915  QBenchmarkGlobalData benchmarkData;
1916  QBenchmarkGlobalData::current = &benchmarkData;
1917 
1918 #ifdef QTESTLIB_USE_VALGRIND
1919  int callgrindChildExitCode = 0;
1920 #endif
1921 
1922 #ifdef Q_WS_MAC
1923  bool macNeedsActivate = qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0);
1924 #ifdef QT_MAC_USE_COCOA
1925  IOPMAssertionID powerID;
1926 #endif
1927 #endif
1928 #ifndef QT_NO_EXCEPTIONS
1929  try {
1930 #endif
1931 
1932  #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
1933  SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX);
1934  #endif
1935 
1936 #ifdef Q_WS_MAC
1937  // Starting with Qt 4.4, applications launched from the command line
1938  // no longer get focus automatically. Since some tests might depend
1939  // on this, call SetFrontProcess here to get the pre 4.4 behavior.
1940  if (macNeedsActivate) {
1941  ProcessSerialNumber psn = { 0, kCurrentProcess };
1942  SetFrontProcess(&psn);
1943 # ifdef QT_MAC_USE_COCOA
1944  IOReturn ok = IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &powerID);
1945  if (ok != kIOReturnSuccess)
1946  macNeedsActivate = false; // no need to release the assertion on exit.
1947 # else
1948  UpdateSystemActivity(1); // Wake the display.
1949 # endif
1950  }
1951 #endif
1952 
1953 #if defined(Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86)
1954  // Delay execution of tests in Symbian emulator.
1955  // Needed to allow worst of other higher priority apps and services launched by emulator
1956  // to get out of the way before we run our test. Otherwise some of the timing sensitive tests
1957  // will not work properly.
1958  qSleep(3000);
1959 #endif
1960 
1962 
1963  QTEST_ASSERT(testObject);
1966 
1967  const QMetaObject *metaObject = testObject->metaObject();
1968  QTEST_ASSERT(metaObject);
1969 
1971  if (argc > 0)
1973 
1974  qtest_qParseArgs(argc, argv, false);
1975  if (QTest::randomOrder) {
1976  seedRandom();
1977  }
1978 #ifdef QTESTLIB_USE_VALGRIND
1980  const QStringList origAppArgs(QCoreApplication::arguments());
1981  if (!QBenchmarkValgrindUtils::rerunThroughCallgrind(origAppArgs, callgrindChildExitCode))
1982  return -1;
1983 
1985 
1986  } else
1987 #endif
1988  {
1989 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
1991  if (!noCrashHandler)
1992  handler.reset(new FatalSignalHandler);
1993 #endif
1994  qInvokeTestMethods(testObject);
1995  }
1996 
1997 #ifndef QT_NO_EXCEPTIONS
1998  } catch (...) {
1999  QTestResult::addFailure("Caught unhandled exception", __FILE__, __LINE__);
2003  }
2004 
2006 #ifdef QT_MAC_USE_COCOA
2007  if (macNeedsActivate) {
2008  IOPMAssertionRelease(powerID);
2009  }
2010 #endif
2011  currentTestObject = 0;
2012 
2013  // Rethrow exception to make debugging easier.
2014  throw;
2015  return 1;
2016  }
2017 # endif
2018 
2019  currentTestObject = 0;
2020 #ifdef QT_MAC_USE_COCOA
2021  if (macNeedsActivate) {
2022  IOPMAssertionRelease(powerID);
2023  }
2024 #endif
2025 
2026 #if defined(QTEST_NOEXITCODE)
2027  return 0;
2028 #else
2029 
2030 #ifdef QTESTLIB_USE_VALGRIND
2032  return callgrindChildExitCode;
2033 #endif
2034  // make sure our exit code is never going above 127
2035  // since that could wrap and indicate 0 test fails
2036  return qMin(QTestResult::failCount(), 127);
2037 
2038 #endif
2039 }
2040 
2049 {
2050  const int argc = arguments.count();
2051  QVarLengthArray<char *> argv(argc);
2052 
2053  QVector<QByteArray> args;
2054  args.reserve(argc);
2055 
2056  for(int i = 0; i < argc; ++i)
2057  {
2058  args.append(arguments.at(i).toLocal8Bit().constData());
2059  argv[i] = args.last().data();
2060  }
2061 
2062  return qExec(testObject, argc, argv.data());
2063 }
2064 
2067 void QTest::qFail(const char *statementStr, const char *file, int line)
2068 {
2069  QTestResult::addFailure(statementStr, file, line);
2070 }
2071 
2074 bool QTest::qVerify(bool statement, const char *statementStr, const char *description,
2075  const char *file, int line)
2076 {
2077  return QTestResult::verify(statement, statementStr, description, file, line);
2078 }
2079 
2083 void QTest::qSkip(const char *message, QTest::SkipMode mode,
2084  const char *file, int line)
2085 {
2086  QTestResult::addSkip(message, mode, file, line);
2087  if (mode == QTest::SkipAll)
2089 }
2090 
2094 bool QTest::qExpectFail(const char *dataIndex, const char *comment,
2095  QTest::TestFailMode mode, const char *file, int line)
2096 {
2097  return QTestResult::expectFail(dataIndex, qstrdup(comment), mode, file, line);
2098 }
2099 
2102 void QTest::qWarn(const char *message)
2103 {
2104  QTestLog::warn(message);
2105 }
2106 
2123 void QTest::ignoreMessage(QtMsgType type, const char *message)
2124 {
2125  QTestResult::ignoreMessage(type, message);
2126 }
2127 
2130 void *QTest::qData(const char *tagName, int typeId)
2131 {
2132  return fetchData(QTestResult::currentTestData(), tagName, typeId);
2133 }
2134 
2137 void *QTest::qGlobalData(const char *tagName, int typeId)
2138 {
2139  return fetchData(QTestResult::currentGlobalTestData(), tagName, typeId);
2140 }
2141 
2144 void *QTest::qElementData(const char *tagName, int metaTypeId)
2145 {
2146  QTEST_ASSERT(tagName);
2148  QTEST_ASSERT(data);
2149  QTEST_ASSERT(data->parent());
2150 
2151  int idx = data->parent()->indexOf(tagName);
2152  QTEST_ASSERT(idx != -1);
2153  QTEST_ASSERT(data->parent()->elementTypeId(idx) == metaTypeId);
2154 
2155  return data->data(data->parent()->indexOf(tagName));
2156 }
2157 
2160 void QTest::addColumnInternal(int id, const char *name)
2161 {
2163  QTEST_ASSERT_X(tbl, "QTest::addColumn()", "Cannot add testdata outside of a _data slot.");
2164 
2165  tbl->addColumn(id, name);
2166 }
2167 
2183 QTestData &QTest::newRow(const char *dataTag)
2184 {
2186  QTEST_ASSERT_X(tbl, "QTest::addColumn()", "Cannot add testdata outside of a _data slot.");
2187 
2188  return *tbl->newData(dataTag);
2189 }
2190 
2219 {
2220  return QTestResult::currentAppName();
2221 }
2222 
2231 {
2233 }
2234 
2240 {
2241  return QTestResult::currentDataTag();
2242 }
2243 
2248 {
2250 }
2251 
2269 void QTest::qSleep(int ms)
2270 {
2271  QTEST_ASSERT(ms > 0);
2272 
2273 #ifdef Q_OS_WIN
2274  Sleep(uint(ms));
2275 #else
2276  struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
2277  nanosleep(&ts, NULL);
2278 #endif
2279 }
2280 
2284 {
2285  return currentTestObject;
2286 }
2287 
2290 bool QTest::compare_helper(bool success, const char *msg, const char *file, int line)
2291 {
2292  return QTestResult::compare(success, msg, file, line);
2293 }
2294 
2297 bool QTest::compare_helper(bool success, const char *msg, char *val1, char *val2,
2298  const char *actual, const char *expected, const char *file, int line)
2299 {
2300  return QTestResult::compare(success, msg, val1, val2, actual, expected, file, line);
2301 }
2302 
2306 template <>
2307 Q_TESTLIB_EXPORT bool QTest::qCompare<float>(float const &t1, float const &t2, const char *actual, const char *expected,
2308  const char *file, int line)
2309 {
2310  return qFuzzyCompare(t1, t2)
2311  ? compare_helper(true, "COMPARE()", file, line)
2312  : compare_helper(false, "Compared floats are not the same (fuzzy compare)",
2313  toString(t1), toString(t2), actual, expected, file, line);
2314 }
2315 
2319 template <>
2320 Q_TESTLIB_EXPORT bool QTest::qCompare<double>(double const &t1, double const &t2, const char *actual, const char *expected,
2321  const char *file, int line)
2322 {
2323  return qFuzzyCompare(t1, t2)
2324  ? compare_helper(true, "COMPARE()", file, line)
2325  : compare_helper(false, "Compared doubles are not the same (fuzzy compare)",
2326  toString(t1), toString(t2), actual, expected, file, line);
2327 }
2328 
2329 #define COMPARE_IMPL2(TYPE, FORMAT) \
2330 template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE >(const TYPE &t) \
2331 { \
2332  char *msg = new char[128]; \
2333  qt_snprintf(msg, 128, #FORMAT, t); \
2334  return msg; \
2335 }
2336 
2337 COMPARE_IMPL2(short, %hd)
2338 COMPARE_IMPL2(ushort, %hu)
2339 COMPARE_IMPL2(int, %d)
2340 COMPARE_IMPL2(uint, %u)
2341 COMPARE_IMPL2(long, %ld)
2342 COMPARE_IMPL2(ulong, %lu)
2343 #if defined(Q_OS_WIN)
2344 COMPARE_IMPL2(qint64, %I64d)
2345 COMPARE_IMPL2(quint64, %I64u)
2346 #else
2347 COMPARE_IMPL2(qint64, %lld)
2348 COMPARE_IMPL2(quint64, %llu)
2349 #endif
2350 COMPARE_IMPL2(bool, %d)
2351 COMPARE_IMPL2(char, %c)
2352 COMPARE_IMPL2(float, %g)
2353 COMPARE_IMPL2(double, %lg)
2354 
2355 
2357 char *QTest::toString(const char *str)
2358 {
2359  if (!str)
2360  return 0;
2361  char *msg = new char[strlen(str) + 1];
2362  return qstrcpy(msg, str);
2363 }
2364 
2367 char *QTest::toString(const void *p)
2368 {
2369  char *msg = new char[128];
2370  qt_snprintf(msg, 128, "%p", p);
2371  return msg;
2372 }
2373 
2376 bool QTest::compare_string_helper(const char *t1, const char *t2, const char *actual,
2377  const char *expected, const char *file, int line)
2378 {
2379  return (qstrcmp(t1, t2) == 0)
2380  ? compare_helper(true, "COMPARE()", file, line)
2381  : compare_helper(false, "Compared strings are not the same",
2382  toString(t1), toString(t2), actual, expected, file, line);
2383 }
2384 
static bool rerunThroughCallgrind(const QStringList &origAppArgs, int &exitCode)
double d
Definition: qnumeric_p.h:62
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
#define Q_TESTLIB_EXPORT
Definition: qtest_global.h:56
static void setMaxWarnings(int max)
Definition: qtestlog.cpp:394
static const char * currentTestFunction()
#define COMPARE_IMPL2(TYPE, FORMAT)
Definition: qtestcase.cpp:2329
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static QString outFileBase(qint64 pid=-1)
static QBenchmarkGlobalData * current
Definition: qbenchmark_p.h:136
void filter_unprintable(char *str)
Definition: qtestcase.cpp:949
int type
Definition: qmetatype.cpp:239
QTestData * testData(int index) const
Definition: qtesttable.cpp:228
Q_CORE_EXPORT char * qstrcpy(char *dst, const char *src)
static int keyVerbose
Definition: qtestcase.cpp:942
static TestFunction * testFuncs
Definition: qtestcase.cpp:922
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static void addBenchmarkResult(const QBenchmarkResult &result)
Definition: qtestlog.cpp:299
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static bool testFailed()
static const char * currentAppName
Definition: qtestresult.cpp:72
Q_TESTLIB_EXPORT const char * currentTestFunction()
Returns the name of the test function that is currently executed.
Definition: qtestcase.cpp:2230
QBenchmarkResult result
Definition: qbenchmark_p.h:181
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static void invokeMethod(QObject *obj, const char *methodName)
Definition: qtestcase.cpp:979
static int eventDelay
Definition: qtestcase.cpp:940
Q_TESTLIB_EXPORT QObject * testObject()
Definition: qtestcase.cpp:2283
Q_TESTLIB_EXPORT void ignoreMessage(QtMsgType type, const char *message)
Ignores messages created by qDebug() or qWarning().
Definition: qtestcase.cpp:2123
SkipMode
This enum describes the modes for skipping tests during execution of the test data.
Definition: qtest_global.h:82
static void setCurrentTestLocation(TestLocation loc)
static int failCount()
#define at(className, varName)
static QObject * currentTestObject
Definition: qtestcase.cpp:903
const char * dataTag() const
Definition: qtestdata.cpp:112
static bool randomOrder
Definition: qtestcase.cpp:941
static void startDump()
static void ignoreMessage(QtMsgType type, const char *msg)
static bool isValidSlot(const QMetaMethod &sl)
Definition: qtestcase.cpp:1067
static void clearGlobalTestTable()
Definition: qtesttable.cpp:255
Q_TESTLIB_EXPORT void * qElementData(const char *elementName, int metaTypeId)
Definition: qtestcase.cpp:2144
static void setCurrentTestFunction(const char *func)
Q_TESTLIB_EXPORT bool qExpectFail(const char *dataIndex, const char *comment, TestFailMode mode, const char *file, int line)
Definition: qtestcase.cpp:2094
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static void addFailure(const char *message, const char *file, int line)
static void addSkip(const char *message, QTest::SkipMode mode, const char *file, int line)
quint16 u
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
EventLoopTimerRef timer
static void qInvokeTestMethodDataEntry(char *slot)
Definition: qtestcase.cpp:1463
char * data() const
Definition: qtestcase.cpp:909
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * typeName() const
Returns the return type of this method, or an empty string if the return type is void.
Q_CORE_EXPORT int qrand()
static QString currentPath()
Returns the absolute path of the application&#39;s current directory.
Definition: qdir.cpp:1875
QBenchmarkMeasurerBase * measurer
Definition: qbenchmark_p.h:146
Q_TESTLIB_EXPORT void addColumnInternal(int id, const char *name)
Definition: qtestcase.cpp:2160
Q_TESTLIB_EXPORT int qExec(QObject *testObject, int argc=0, char **argv=0)
Executes tests declared in testObject.
Definition: qtestcase.cpp:1913
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static void redirectOutput(const char *fileName)
Definition: qtestlog.cpp:382
QtMsgType
This enum describes the messages that can be sent to a message handler (QtMsgHandler).
Definition: qglobal.h:1881
Q_TESTLIB_EXPORT void qFail(const char *statementStr, const char *file, int line)
Definition: qtestcase.cpp:2067
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
static void qPrintTestSlots()
Definition: qtestcase.cpp:1091
int defaultEventDelay()
Definition: qtestcase.cpp:997
static int keyDelay
Definition: qtestcase.cpp:938
static bool seedSet
Definition: qtestcase.cpp:944
QTestData * newData(const char *tag)
Definition: qtesttable.cpp:193
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
static struct QTest::TestFuncCleanup testFuncCleaner
static bool expectFail(const char *dataIndex, const char *comment, QTest::TestFailMode mode, const char *file, int line)
static int testFuncCount
Definition: qtestcase.cpp:923
Q_CORE_EXPORT void qDebug(const char *,...)
Q_TESTLIB_EXPORT void * qData(const char *tagName, int typeId)
Definition: qtestcase.cpp:2130
static char toHex(quint8 c)
Definition: qurl.cpp:4440
static void finishedCurrentTestFunction()
QBenchmarkResult qMedian(const QList< QBenchmarkResult > &container)
Definition: qtestcase.cpp:1433
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static void warn(const char *msg)
Definition: qtestlog.cpp:332
QString callgrindOutFileBase
Definition: qbenchmark_p.h:153
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QTestTable * parent() const
Definition: qtestdata.cpp:107
static QTestData * currentTestData()
static bool verify(bool statement, const char *statementStr, const char *extraInfo, const char *file, int line)
unsigned __int64 quint64
Definition: qglobal.h:943
int dataCount() const
Definition: qtesttable.cpp:177
static void qPrintDataTags()
Definition: qtestcase.cpp:1100
#define qApp
static const char * currentAppName()
char * toHexRepresentation(const char *ba, int length)
Returns a pointer to a string that is the string ba represented as a space-separated sequence of hex ...
Definition: qtestcase.cpp:1667
const char * name
void set(int function, char *data)
Definition: qtestcase.cpp:908
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
char * toString(const QLatin1String &str)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtest.h:73
int function() const
Definition: qtestcase.cpp:910
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
unsigned int uint
Definition: qglobal.h:996
static QTestData * currentGlobalTestData()
Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
__int64 qint64
Definition: qglobal.h:942
unsigned long ulong
Definition: qglobal.h:997
static bool noCrashHandler
Definition: qtestcase.cpp:946
int elementTypeId(int index) const
Definition: qtesttable.cpp:212
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
static QTestTable * globalTestTable()
Definition: qtesttable.cpp:248
static void reset()
Definition: qtestresult.cpp:75
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
static void startLogging()
Definition: qtestlog.cpp:314
static void setFlushMode(FlushMode mode)
Definition: qtestlog.cpp:399
static bool compare(bool success, const char *msg, const char *file, int line)
#define SetErrorMode(a)
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
MethodType methodType() const
Returns the type of this method (signal, slot, or method).
int Q_TESTLIB_EXPORT qt_snprintf(char *str, int size, const char *format,...)
Definition: qtestcase.cpp:961
void seedRandom()
Definition: qtestcase.cpp:1030
void setMode(Mode mode)
Definition: qbenchmark.cpp:77
Q_TESTLIB_EXPORT bool qCompare< double >(double const &t1, double const &t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtestcase.cpp:2320
static void stopLogging()
Definition: qtestlog.cpp:322
Q_TESTLIB_EXPORT const char * currentDataTag()
Returns the name of the current test data.
Definition: qtestcase.cpp:2239
void * data(int index) const
Definition: qtestdata.cpp:100
static bool qInvokeTestMethod(const char *slotName, const char *data=0)
Call init(), slot_data(), slot(), slot(), slot().
Definition: qtestcase.cpp:1540
uint qstrlen(const char *str)
Definition: qbytearray.h:79
Q_CORE_EXPORT void qFatal(const char *,...)
QList< QByteArray > parameterTypes() const
Returns a list of parameter types.
void addColumn(int elementType, const char *elementName)
Definition: qtesttable.cpp:157
static void setCurrentGlobalTestData(QTestData *data)
bool Q_TESTLIB_EXPORT defaultKeyVerbose()
Definition: qtestcase.cpp:989
void * fetchData(QTestData *data, const char *tagName, int typeId)
Definition: qtestcase.cpp:1635
Q_TESTLIB_EXPORT void qWarn(const char *message)
Definition: qtestcase.cpp:2102
static void setCurrentTestData(QTestData *data)
static const char * typeName(int type)
Returns the type name associated with the given type, or 0 if no matching type was found...
Definition: qmetatype.cpp:406
Q_CORE_EXPORT char * qstrdup(const char *)
unsigned short ushort
Definition: qglobal.h:995
Q_TESTLIB_EXPORT bool qCompare< float >(float const &t1, float const &t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtestcase.cpp:2307
int indexOf(const char *elementName) const
Definition: qtesttable.cpp:233
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
Q_TESTLIB_EXPORT bool printAvailableTags
Definition: qtestcase.cpp:1087
static unsigned int seed
Definition: qtestcase.cpp:943
int indexOfMethod(const char *method) const
Finds method and returns its index; otherwise returns -1.
int sigaction(int, const struct sigaction *, struct sigaction *)
qint64 msecsSinceReference() const
Returns the number of milliseconds between last time this QElapsedTimer object was started and its re...
static int qToInt(char *str)
Definition: qtestcase.cpp:1159
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
T & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262
Q_TESTLIB_EXPORT bool qVerify(bool statement, const char *statementStr, const char *description, const char *file, int line)
Definition: qtestcase.cpp:2074
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
Q_TESTLIB_EXPORT bool printAvailableFunctions
Definition: qtestcase.cpp:1086
static void setSkipCurrentTest(bool value)
int dataCount() const
Definition: qtestdata.cpp:117
static void setCurrentAppName(const char *appName)
Q_TESTLIB_EXPORT QStringList testTags
Definition: qtestcase.cpp:1089
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
static QByteArray methodName(const char *signature, int nameLength)
Makes a deep copy of the first nameLength characters of the given method signature and returns the co...
Q_TESTLIB_EXPORT void qSkip(const char *message, SkipMode mode, const char *file, int line)
Definition: qtestcase.cpp:2083
static void cleanup()
Definition: qpicture.cpp:1508
static QTestTable * currentTestTable()
Definition: qtesttable.cpp:261
QFactoryLoader * l
TestFailMode
This enum describes the modes for handling an expected failure of the QVERIFY() or QCOMPARE() macros...
Definition: qtest_global.h:83
#define QTEST_ASSERT_X(cond, where, what)
Definition: qtestassert.h:55
static const char * currentDataTag()
static bool skipCurrentTest()
Q_TESTLIB_EXPORT bool compare_helper(bool success, const char *msg, const char *file, int line)
Definition: qtestcase.cpp:2290
int Q_TESTLIB_EXPORT defaultMouseDelay()
Definition: qtestcase.cpp:1008
int Q_TESTLIB_EXPORT defaultKeyDelay()
Definition: qtestcase.cpp:1019
static void qInvokeTestMethods(QObject *testObject)
Definition: qtestcase.cpp:1724
Q_TESTLIB_EXPORT void * qGlobalData(const char *tagName, int typeId)
Definition: qtestcase.cpp:2137
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
static QBenchmarkTestMethodData * current
Definition: qbenchmark_p.h:167
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
QBenchmarkContext context
Definition: qbenchmark_p.h:147
static QStringList arguments()
Returns the list of command-line arguments.
Q_CORE_EXPORT void qsrand(uint seed)
static bool currentTestFailed()
Definition: qtestresult.cpp:98
static void setVerboseLevel(int level)
Definition: qtestlog.cpp:358
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
bool isEmpty() const
Definition: qtesttable.cpp:188
Access access() const
Returns the access specification of this method (private, protected, or public).
Q_TESTLIB_EXPORT QStringList testFunctions
Definition: qtestcase.cpp:1088
static void signal(int)
Definition: qtestcase.cpp:1799
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
QImageIOHandler * handler
Q_TESTLIB_EXPORT bool currentTestFailed()
Returns true if the current test function failed, otherwise false.
Definition: qtestcase.cpp:2247
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Appends a new row to the current test data.
Definition: qtestcase.cpp:2183
bool invoke(QObject *object, Qt::ConnectionType connectionType, QGenericReturnArgument returnValue, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
Invokes this method on the object object.
Q_TESTLIB_EXPORT bool compare_string_helper(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtestcase.cpp:2376
int qTestRandomSeed()
Definition: qtestcase.cpp:1044
static void setCurrentTestObject(const char *name)
int methodCount() const
Returns the number of methods known to the meta-object system in this class, including the number of ...
void start()
Starts this timer.
The QTest namespace contains all the functions and declarations that are related to the QTestLib tool...
void swap(T *array, int pos, int otherPos)
Definition: qtestcase.cpp:1051
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
static int mouseDelay
Definition: qtestcase.cpp:939
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
static void randomizeList(T *array, int size)
Definition: qtestcase.cpp:1059
Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
Definition: qtestcase.cpp:1170
Q_TESTLIB_EXPORT void qSleep(int ms)
Sleeps for ms milliseconds, blocking execution of the test.
Definition: qtestcase.cpp:2269
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static void setLogMode(LogMode mode)
Definition: qtestlog.cpp:348
QTestDataSetter(QTestData *data)
Definition: qtestcase.cpp:1453