QTest: fix -Wformat-overflow GCC warning

Says GCC:
    In function ‘char* QTest::toString(QPair<T1, T2>&) [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 <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2021-06-30 11:25:46 +02:00
parent da914a7d47
commit eea930b4d7
7 changed files with 27 additions and 27 deletions

View File

@ -380,7 +380,7 @@ inline char *toString(const std::pair<T1, T2> &pair)
{
const QScopedArrayPointer<char> first(toString(pair.first));
const QScopedArrayPointer<char> 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 <typename Tuple, int... I>

View File

@ -8,13 +8,13 @@
<testcase name="initTestCase" result="pass" time="@TEST_DURATION@"/>
<testcase name="testQPair" result="fail" time="@TEST_DURATION@">
<failure result="fail" message="Compared values are not the same
Actual (pair1): &quot;std::pair(1,1)&quot;
Expected (pair2): &quot;std::pair(1,2)&quot;"/>
Actual (pair1): std::pair(1, 1)
Expected (pair2): std::pair(1, 2)"/>
</testcase>
<testcase name="testStdPair" result="fail" time="@TEST_DURATION@">
<failure result="fail" message="Compared values are not the same
Actual (pair1): &quot;std::pair(1,1)&quot;
Expected (pair2): &quot;std::pair(1,2)&quot;"/>
Actual (pair1): std::pair(1, 1)
Expected (pair2): std::pair(1, 2)"/>
</testcase>
<testcase name="cleanupTestCase" result="pass" time="@TEST_DURATION@"/>
<system-err/>

View File

@ -10,16 +10,16 @@
<TestFunction name="testQPair">
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp" line="0">
<Description><![CDATA[Compared values are not the same
Actual (pair1): "std::pair(1,1)"
Expected (pair2): "std::pair(1,2)"]]></Description>
Actual (pair1): std::pair(1, 1)
Expected (pair2): std::pair(1, 2)]]></Description>
</Incident>
<Duration msecs="0"/>
</TestFunction>
<TestFunction name="testStdPair">
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp" line="0">
<Description><![CDATA[Compared values are not the same
Actual (pair1): "std::pair(1,1)"
Expected (pair2): "std::pair(1,2)"]]></Description>
Actual (pair1): std::pair(1, 1)
Expected (pair2): std::pair(1, 2)]]></Description>
</Incident>
<Duration msecs="0"/>
</TestFunction>

View File

@ -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

View File

@ -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']

View File

@ -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

View File

@ -12,16 +12,16 @@
<TestFunction name="testQPair">
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp" line="0">
<Description><![CDATA[Compared values are not the same
Actual (pair1): "std::pair(1,1)"
Expected (pair2): "std::pair(1,2)"]]></Description>
Actual (pair1): std::pair(1, 1)
Expected (pair2): std::pair(1, 2)]]></Description>
</Incident>
<Duration msecs="0"/>
</TestFunction>
<TestFunction name="testStdPair">
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp" line="0">
<Description><![CDATA[Compared values are not the same
Actual (pair1): "std::pair(1,1)"
Expected (pair2): "std::pair(1,2)"]]></Description>
Actual (pair1): std::pair(1, 1)
Expected (pair2): std::pair(1, 2)]]></Description>
</Incident>
<Duration msecs="0"/>
</TestFunction>