From eea930b4d7cabb6ada6155b66b5b143b73a10344 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 30 Jun 2021 11:25:46 +0200 Subject: [PATCH] QTest: fix -Wformat-overflow GCC warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Says GCC: In function ‘char* QTest::toString(QPair&) [with T1 = QWidget*; T2 = QEvent::Type]’, warning: ‘%s’ directive argument is null [-Wformat-overflow=] Fix by re-using formatString(), once introduced for std::tuple. As a side-effect, this gets rid of the funny double-quotes around the output. Change-Id: I2dd5f10fa2b3a392370bf487c1b7e98f3d190978 Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot --- src/testlib/qtest.h | 2 +- .../selftests/expected_pairdiagnostics.junitxml | 8 ++++---- .../selftests/expected_pairdiagnostics.lightxml | 8 ++++---- .../selftests/expected_pairdiagnostics.tap | 16 ++++++++-------- .../selftests/expected_pairdiagnostics.teamcity | 4 ++-- .../selftests/expected_pairdiagnostics.txt | 8 ++++---- .../selftests/expected_pairdiagnostics.xml | 8 ++++---- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index 4bf5e018a7..cee01e7217 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -380,7 +380,7 @@ inline char *toString(const std::pair &pair) { const QScopedArrayPointer first(toString(pair.first)); const QScopedArrayPointer second(toString(pair.second)); - return toString(QString::asprintf("std::pair(%s,%s)", first.data(), second.data())); + return formatString("std::pair(", ")", 2, first.data(), second.data()); } template diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.junitxml b/tests/auto/testlib/selftests/expected_pairdiagnostics.junitxml index 4086bd8273..1f6ce0ba06 100644 --- a/tests/auto/testlib/selftests/expected_pairdiagnostics.junitxml +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.junitxml @@ -8,13 +8,13 @@ + Actual (pair1): std::pair(1, 1) + Expected (pair2): std::pair(1, 2)"/> + Actual (pair1): std::pair(1, 1) + Expected (pair2): std::pair(1, 2)"/> diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.lightxml b/tests/auto/testlib/selftests/expected_pairdiagnostics.lightxml index e4ceacc9e3..2770b4394a 100644 --- a/tests/auto/testlib/selftests/expected_pairdiagnostics.lightxml +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.lightxml @@ -10,16 +10,16 @@ + Actual (pair1): std::pair(1, 1) + Expected (pair2): std::pair(1, 2)]]> + Actual (pair1): std::pair(1, 1) + Expected (pair2): std::pair(1, 2)]]> diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.tap b/tests/auto/testlib/selftests/expected_pairdiagnostics.tap index 25718d0d4c..a5ffbc31ef 100644 --- a/tests/auto/testlib/selftests/expected_pairdiagnostics.tap +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.tap @@ -5,10 +5,10 @@ not ok 2 - testQPair() --- type: QCOMPARE message: Compared values are not the same - wanted: "std::pair(1,2)" (pair2) - found: "std::pair(1,1)" (pair1) - expected: "std::pair(1,2)" (pair2) - actual: "std::pair(1,1)" (pair1) + wanted: std::pair(1, 2) (pair2) + found: std::pair(1, 1) (pair1) + expected: std::pair(1, 2) (pair2) + actual: std::pair(1, 1) (pair1) at: tst_PairDiagnostics::testQPair() (qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp:0) file: qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp line: 0 @@ -17,10 +17,10 @@ not ok 3 - testStdPair() --- type: QCOMPARE message: Compared values are not the same - wanted: "std::pair(1,2)" (pair2) - found: "std::pair(1,1)" (pair1) - expected: "std::pair(1,2)" (pair2) - actual: "std::pair(1,1)" (pair1) + wanted: std::pair(1, 2) (pair2) + found: std::pair(1, 1) (pair1) + expected: std::pair(1, 2) (pair2) + actual: std::pair(1, 1) (pair1) at: tst_PairDiagnostics::testStdPair() (qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp:0) file: qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp line: 0 diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.teamcity b/tests/auto/testlib/selftests/expected_pairdiagnostics.teamcity index a86f4fa254..01f4a232e2 100644 --- a/tests/auto/testlib/selftests/expected_pairdiagnostics.teamcity +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.teamcity @@ -2,10 +2,10 @@ ##teamcity[testStarted name='initTestCase()' flowId='tst_PairDiagnostics'] ##teamcity[testFinished name='initTestCase()' flowId='tst_PairDiagnostics'] ##teamcity[testStarted name='testQPair()' flowId='tst_PairDiagnostics'] -##teamcity[testFailed name='testQPair()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(0)|]' details='Compared values are not the same|n Actual (pair1): "std::pair(1,1)"|n Expected (pair2): "std::pair(1,2)"' flowId='tst_PairDiagnostics'] +##teamcity[testFailed name='testQPair()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(0)|]' details='Compared values are not the same|n Actual (pair1): std::pair(1, 1)|n Expected (pair2): std::pair(1, 2)' flowId='tst_PairDiagnostics'] ##teamcity[testFinished name='testQPair()' flowId='tst_PairDiagnostics'] ##teamcity[testStarted name='testStdPair()' flowId='tst_PairDiagnostics'] -##teamcity[testFailed name='testStdPair()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(0)|]' details='Compared values are not the same|n Actual (pair1): "std::pair(1,1)"|n Expected (pair2): "std::pair(1,2)"' flowId='tst_PairDiagnostics'] +##teamcity[testFailed name='testStdPair()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(0)|]' details='Compared values are not the same|n Actual (pair1): std::pair(1, 1)|n Expected (pair2): std::pair(1, 2)' flowId='tst_PairDiagnostics'] ##teamcity[testFinished name='testStdPair()' flowId='tst_PairDiagnostics'] ##teamcity[testStarted name='cleanupTestCase()' flowId='tst_PairDiagnostics'] ##teamcity[testFinished name='cleanupTestCase()' flowId='tst_PairDiagnostics'] diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.txt b/tests/auto/testlib/selftests/expected_pairdiagnostics.txt index cbb8b764ff..b225b4c55f 100644 --- a/tests/auto/testlib/selftests/expected_pairdiagnostics.txt +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.txt @@ -2,12 +2,12 @@ Config: Using QtTest library PASS : tst_PairDiagnostics::initTestCase() FAIL! : tst_PairDiagnostics::testQPair() Compared values are not the same - Actual (pair1): "std::pair(1,1)" - Expected (pair2): "std::pair(1,2)" + Actual (pair1): std::pair(1, 1) + Expected (pair2): std::pair(1, 2) Loc: [qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(0)] FAIL! : tst_PairDiagnostics::testStdPair() Compared values are not the same - Actual (pair1): "std::pair(1,1)" - Expected (pair2): "std::pair(1,2)" + Actual (pair1): std::pair(1, 1) + Expected (pair2): std::pair(1, 2) Loc: [qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(0)] PASS : tst_PairDiagnostics::cleanupTestCase() Totals: 2 passed, 2 failed, 0 skipped, 0 blacklisted, 0ms diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.xml b/tests/auto/testlib/selftests/expected_pairdiagnostics.xml index 89e8ca49a6..503ea937aa 100644 --- a/tests/auto/testlib/selftests/expected_pairdiagnostics.xml +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.xml @@ -12,16 +12,16 @@ + Actual (pair1): std::pair(1, 1) + Expected (pair2): std::pair(1, 2)]]> + Actual (pair1): std::pair(1, 1) + Expected (pair2): std::pair(1, 2)]]>