From 459933708a2ead6bedb0e2a47fcea474edfa07b8 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 24 May 2016 15:53:04 +0200 Subject: Do an actual toString conversion for QVariant test failures A cast is not a conversion. If the value is not already a string type we are just getting an empty string for all metatypes that can be converted to string. Change-Id: I4643cc9fd509c21568fdc2133403c3ed8cb38a10 Reviewed-by: Simon Hausmann --- src/testlib/qtest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/testlib') diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index c35b767875..6ab8d3d96b 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -160,7 +160,7 @@ template<> inline char *toString(const QVariant &v) if (!v.isNull()) { vstring.append(','); if (v.canConvert(QVariant::String)) { - vstring.append(qvariant_cast(v).toLocal8Bit()); + vstring.append(v.toString().toLocal8Bit()); } else { vstring.append(""); -- cgit v1.2.3 From 832715a67908683241b8da524f6aa0c1a8a4267e Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 24 May 2016 16:13:02 +0200 Subject: qtestblacklist: only generate the distro and version once We were looking up distro and version, in order to conditionally add them to keywords if missing, on every keyword line of each BLACKLIST that we parsed. In particular, this meant the static holding the list of keywords couldn't be const. Move the distro-handling to an intemediary function that adds to the raw keywords and supplies one-off initialization for the list of conditions to match. Change-Id: Ia383ec060e24b7f72d2c8fd6ae65816318daafd0 Reviewed-by: Lars Knoll --- src/testlib/qtestblacklist.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/testlib') diff --git a/src/testlib/qtestblacklist.cpp b/src/testlib/qtestblacklist.cpp index 04c6aa2717..da98b88989 100644 --- a/src/testlib/qtestblacklist.cpp +++ b/src/testlib/qtestblacklist.cpp @@ -135,19 +135,26 @@ static QSet keywords() return set; } -static bool checkCondition(const QByteArray &condition) +static QSet activeConditions() { - static QSet matchedConditions = keywords(); - QList conds = condition.split(' '); + QSet result = keywords(); QByteArray distributionName = QSysInfo::productType().toLower().toUtf8(); QByteArray distributionRelease = QSysInfo::productVersion().toLower().toUtf8(); if (!distributionName.isEmpty()) { - if (matchedConditions.find(distributionName) == matchedConditions.end()) - matchedConditions.insert(distributionName); - matchedConditions.insert(distributionName + "-" + distributionRelease); + if (result.find(distributionName) == result.end()) + result.insert(distributionName); + result.insert(distributionName + "-" + distributionRelease); } + return result; +} + +static bool checkCondition(const QByteArray &condition) +{ + static const QSet matchedConditions = activeConditions(); + QList conds = condition.split(' '); + for (int i = 0; i < conds.size(); ++i) { QByteArray c = conds.at(i); bool result = c.startsWith('!'); -- cgit v1.2.3 From 6f59926e670d68b27a387651a466f47ca9e8fd37 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 24 May 2016 16:16:56 +0200 Subject: qtestblacklist: check against duplicating versioned distro Also check the version is non-empty. Probably makes no difference, but it's obviously more correct. Change-Id: I05eee5623ac432d2ea02f7aad874513beeb2ceeb Reviewed-by: Lars Knoll --- src/testlib/qtestblacklist.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/testlib') diff --git a/src/testlib/qtestblacklist.cpp b/src/testlib/qtestblacklist.cpp index da98b88989..9300cb58af 100644 --- a/src/testlib/qtestblacklist.cpp +++ b/src/testlib/qtestblacklist.cpp @@ -144,7 +144,11 @@ static QSet activeConditions() if (!distributionName.isEmpty()) { if (result.find(distributionName) == result.end()) result.insert(distributionName); - result.insert(distributionName + "-" + distributionRelease); + if (!distributionRelease.isEmpty()) { + QByteArray versioned = distributionName + "-" + distributionRelease; + if (result.find(versioned) == result.end()) + result.insert(versioned); + } } return result; -- cgit v1.2.3 From b057fdbb12341da9e972bcd16c5c4f1b751cac01 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 24 May 2016 15:32:43 +0200 Subject: Improve documentation of BLACKLIST file format. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In particular, make sure the word BLACKLIST appears in it so it can actually be *found*. Mention the comment format, mention version suffixes, mention negation; expand and clarify the description. Break it up into paragraphs for ease of reading. Corrected the example to use osx, not its old platform name. Gave it a comment that I wish I'd found in the BLACKLIST file that obliged me to come looking for this in the first place. Illustrated the use of comments to document reasons for ignoring tests. Change-Id: I78d49b4706c0f70b714f7a410f850fb42ebb77c0 Reviewed-by: Lars Knoll Reviewed-by: Timur Pocheptsov Reviewed-by: Jędrzej Nowacki --- src/testlib/qtestblacklist.cpp | 47 ++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'src/testlib') diff --git a/src/testlib/qtestblacklist.cpp b/src/testlib/qtestblacklist.cpp index 9300cb58af..9dfd5065ad 100644 --- a/src/testlib/qtestblacklist.cpp +++ b/src/testlib/qtestblacklist.cpp @@ -46,21 +46,38 @@ QT_BEGIN_NAMESPACE /* - The file format is simply a grouped listing of keywords - Ungrouped entries at the beginning apply to the whole testcase - Groups define testfunctions or specific test data to ignore. - After the groups come a list of entries (one per line) that define - for which platform/os combination to ignore the test result. - All keys in a single line have to match to blacklist the test. - - mac - [testFunction] - linux - windows 64bit - [testfunction2:testData] - msvc - - The known keys are listed below: + The BLACKLIST file format is a grouped listing of keywords. + + Blank lines and lines starting with # are simply ignored. An initial #-line + referring to this documentation is kind to readers. Comments can also be used + to indicate the reasons for ignoring particular cases. + + A key names a platform, O/S, distribution, tool-chain or architecture; a ! + prefix reverses what it checks. A version, joined to a key (at present, only + for distributions and for msvc) with a hyphen, limits the key to the specific + version. A keyword line matches if every key on it applies to the present + run. Successive lines are alternate conditions for ignoring a test. + + Ungrouped lines at the beginning of a file apply to the whole testcase. + A group starts with a [square-bracketed] identification of a test function, + optionally with (after a colon, the name of) a specific data set, to ignore. + Subsequent lines give conditions for ignoring this test. + + # See qtbase/src/testlib/qtestblacklist.cpp for format + osx + + # QTBUG-12345 + [testFunction] + linux + windows 64bit + + # Needs basic C++11 support + [testfunction2:testData] + msvc-2010 + + Keys are lower-case. Distribution name and version are supported if + QSysInfo's productType() and productVersion() return them. + The other known keys are listed below: */ static QSet keywords() -- cgit v1.2.3 From 28db26f6917174d787bd4c6eadbecebc952d59dc Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 30 May 2016 15:25:06 +0200 Subject: qtestcase: Fix buffer over-run, '\0' appended beyond buffer end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Noticed by Coverity (CID 161673). If the file being read contains enough to fill the buffer, read() shall do that and return the nbytes it was passed; as this was the size of the buffer, subsequently writing a '\0' at this index in buffer is out of bounds. Fortunately, /proc/self/status is typically < 1k so fits well inside the 2k buffer. All the same, we can safely pass sizeof(buffer) - 1 as nbytes and *be sure* of not getting a buffer over-run. Change-Id: Ib620a330fbc94f0579c953737f7c4417ca449968 Reviewed-by: Jędrzej Nowacki --- src/testlib/qtestcase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/testlib') diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 62649441db..eae490e278 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -2514,7 +2514,7 @@ static bool debuggerPresent() if (fd == -1) return false; char buffer[2048]; - ssize_t size = read(fd, buffer, sizeof(buffer)); + ssize_t size = read(fd, buffer, sizeof(buffer) - 1); if (size == -1) { close(fd); return false; -- cgit v1.2.3 From c2d4c3588c8b0f65923c1b3dd98826a99c589495 Mon Sep 17 00:00:00 2001 From: Leena Miettinen Date: Thu, 2 Jun 2016 16:03:02 +0200 Subject: Doc: Fix examples install path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The example directory name for Qt Test module is qtestlib. Without this change, Qt Creator cannot find the tutorial files and tags them "broken" in the Welcome mode. Change-Id: Ib2de0cd2263aa1651abb697f9f03ecd8eb871ca2 Reviewed-by: Topi Reiniö --- src/testlib/doc/qttestlib.qdocconf | 2 +- src/testlib/doc/src/qttestlib-manual.qdoc | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/testlib') diff --git a/src/testlib/doc/qttestlib.qdocconf b/src/testlib/doc/qttestlib.qdocconf index 0fafc733b1..899f94ec53 100644 --- a/src/testlib/doc/qttestlib.qdocconf +++ b/src/testlib/doc/qttestlib.qdocconf @@ -4,7 +4,7 @@ project = QtTestLib description = Qt Test Reference Documentation version = $QT_VERSION -examplesinstallpath = testlib +examplesinstallpath = qtestlib qhp.projects = QtTestLib diff --git a/src/testlib/doc/src/qttestlib-manual.qdoc b/src/testlib/doc/src/qttestlib-manual.qdoc index 82651d5cba..781eec0560 100644 --- a/src/testlib/doc/src/qttestlib-manual.qdoc +++ b/src/testlib/doc/src/qttestlib-manual.qdoc @@ -484,6 +484,7 @@ \nextpage {Chapter 2: Data Driven Testing}{Chapter 2} \title Chapter 1: Writing a Unit Test + \brief How to write a unit test. In this first chapter we will see how to write a simple unit test for a class, and how to execute it. @@ -559,6 +560,7 @@ \nextpage {Chapter 3: Simulating Gui Events}{Chapter 3} \title Chapter 2: Data Driven Testing + \brief How to create data driven tests. In this chapter we will demonstrate how to execute a test multiple times with different test data. @@ -664,6 +666,7 @@ \nextpage {Chapter 4: Replaying GUI Events}{Chapter 4} \title Chapter 3: Simulating GUI Events + \brief Howe to simulate GUI events. Qt Test features some mechanisms to test graphical user interfaces. Instead of simulating native window system events, @@ -724,6 +727,7 @@ \nextpage {Chapter 5: Writing a Benchmark}{Chapter 5} \title Chapter 4: Replaying GUI Events + \brief How to replay GUI events. In this chapter, we will show how to simulate a GUI event, and how to store a series of GUI events as well as replay them on @@ -803,6 +807,7 @@ \contentspage {Qt Test Tutorial}{Contents} \title Chapter 5: Writing a Benchmark + \brief How to write a benchmark. In this final chapter we will demonstrate how to write benchmarks using Qt Test. -- cgit v1.2.3