From 9924079427935f781083299d7ca030dafb4f2598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Tue, 9 Feb 2010 13:57:12 +0100 Subject: QTestLib: don't crash if data tag requested, none available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/testlib/qtestcase.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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(0) + QTestDataSetter s(curDataIndex >= dataCount ? static_cast(0) : table.testData(curDataIndex)); qInvokeTestMethodDataEntry(slot); -- cgit v0.12