summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorJoão Abecasis <joao@trolltech.com>2010-02-09 12:57:12 (GMT)
committerJoão Abecasis <joao@trolltech.com>2010-02-12 16:15:56 (GMT)
commit9924079427935f781083299d7ca030dafb4f2598 (patch)
tree9214dff39c3a244a741b09b39f54a2065dc04b1a /src/testlib
parentf25099f400e7379f0a6e00500e990948b9785e63 (diff)
downloadQt-9924079427935f781083299d7ca030dafb4f2598.zip
Qt-9924079427935f781083299d7ca030dafb4f2598.tar.gz
Qt-9924079427935f781083299d7ca030dafb4f2598.tar.bz2
QTestLib: don't crash if data tag requested, none available
When specific test functions and data tags are requested from the command line, a non-existing data tag will produce error output *iif* data tags are available for the function. However, if no data tags are available, element 0 in testData would be dereferenced, resulting in a crash. Special case the empty data tag, even if no tags are available, because some loggers (e.g., the QXmlTestLogger) will output results with no tag the same way as those with an empty data tag. Reviewed-by: Morten Sørvig
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qtestcase.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index ecdcca8..1c2db2f 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -1298,11 +1298,23 @@ static bool qInvokeTestMethod(const char *slotName, const char *data=0)
const int dataCount = table.dataCount();
QTestResult::setSkipCurrentTest(false);
+ // Data tag requested but none available?
+ if (data && !dataCount) {
+ // Let empty data tag through.
+ if (!*data)
+ data = 0;
+ else {
+ printf("Unknown testdata for function %s: '%s'\n", slotName, data);
+ printf("Function has no testdata.\n");
+ return false;
+ }
+ }
+
/* For each entry in the data table, do: */
do {
if (!data || !qstrcmp(data, table.testData(curDataIndex)->dataTag())) {
foundFunction = true;
- QTestDataSetter s(table.isEmpty() ? static_cast<QTestData *>(0)
+ QTestDataSetter s(curDataIndex >= dataCount ? static_cast<QTestData *>(0)
: table.testData(curDataIndex));
qInvokeTestMethodDataEntry(slot);