tst_QCborValue: port to QTEST_THROW_ON_FAIL

Dogfooding the new QtTest 6.8 feature.

Change-Id: I1415e6af94eab3bb47d3f8d319f84554faa52d45
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
(cherry picked from commit c8e33fc4fd1151edb3df4815f5fbae03eb1ea353)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2024-01-10 16:22:48 +01:00 committed by Qt Cherry-pick Bot
parent 5ba8e27800
commit df055c0256
3 changed files with 9 additions and 33 deletions

View File

@ -10,6 +10,7 @@ if(QT_FEATURE_cborstreamwriter)
add_subdirectory(qcborstreamwriter)
endif()
endif()
# also (but not only!) QTBUG-121822:
if(NOT WASM)
add_subdirectory(qcborvalue)
endif()

View File

@ -17,6 +17,10 @@ qt_internal_add_test(tst_qcborvalue
INCLUDE_DIRECTORIES
../../../../../src/3rdparty/tinycbor/src
../../../../../src/3rdparty/tinycbor/tests/parser
NO_BATCH # QTBUG-121815
DEFINES
QTEST_THROW_ON_FAIL
QTEST_THROW_ON_SKIP
LIBRARIES
Qt::CorePrivate
Qt::TestPrivate

View File

@ -14,6 +14,10 @@
#include <QtEndian>
#include <QTimeZone>
#ifndef QTEST_THROW_ON_FAIL
# error This test requires QTEST_THROW_ON_FAIL being active.
#endif
Q_DECLARE_METATYPE(QCborKnownTags)
Q_DECLARE_METATYPE(QCborValue)
Q_DECLARE_METATYPE(QCborValue::EncodingOptions)
@ -1348,8 +1352,6 @@ void tst_QCborValue::arrayValueRef()
};
iteratorCheck(a.begin());
if (QTest::currentTestFailed())
return;
iteratorCheck(a.constBegin());
}
@ -1412,8 +1414,6 @@ void tst_QCborValue::mapValueRef()
};
iteratorCheck(m.begin());
if (QTest::currentTestFailed())
return;
iteratorCheck(m.constBegin());
}
@ -2410,53 +2410,29 @@ void fromCbor_common(void (*doCheck)(const QCborValue &, const QByteArray &))
QFETCH(QByteArray, result);
doCheck(v, result);
if (QTest::currentTestFailed())
return;
// in an array
doCheck(QCborArray{v}, "\x81" + result);
if (QTest::currentTestFailed())
return;
doCheck(QCborArray{v, v}, "\x82" + result + result);
if (QTest::currentTestFailed())
return;
// in a map
doCheck(QCborMap{{1, v}}, "\xa1\1" + result);
if (QTest::currentTestFailed())
return;
// undefined-length arrays and maps
doCheck(QCborArray{v}, "\x9f" + result + "\xff");
if (QTest::currentTestFailed())
return;
doCheck(QCborArray{v, v}, "\x9f" + result + result + "\xff");
if (QTest::currentTestFailed())
return;
doCheck(QCborMap{{1, v}}, "\xbf\1" + result + "\xff");
if (QTest::currentTestFailed())
return;
// tagged
QCborValue t(QCborKnownTags::Signature, v);
doCheck(t, "\xd9\xd9\xf7" + result);
if (QTest::currentTestFailed())
return;
// in an array
doCheck(QCborArray{t}, "\x81\xd9\xd9\xf7" + result);
if (QTest::currentTestFailed())
return;
doCheck(QCborArray{t, t}, "\x82\xd9\xd9\xf7" + result + "\xd9\xd9\xf7" + result);
if (QTest::currentTestFailed())
return;
// in a map
doCheck(QCborMap{{1, t}}, "\xa1\1\xd9\xd9\xf7" + result);
if (QTest::currentTestFailed())
return;
}
void tst_QCborValue::fromCbor()
@ -3116,14 +3092,9 @@ void tst_QCborValue::cborValueRefMutatingMapIntKey()
};
// accessing a negative index causes it to become a map
executeTest(-1);
if (QTest::currentTestFailed())
return;
// if the index is bigger than 0x10000, the array becomes a map
executeTest(0x10000);
if (QTest::currentTestFailed())
return;
if (type != QCborValue::Array)
executeTest(5);
}