diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-07-30 15:55:08 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-02 23:40:56 +0200 |
commit | 260168d9d7547a2e7586bff6cb42e11d54c9d06e (patch) | |
tree | 72860cea2402575fe3f325520cc035bbfb385a06 /tests/auto/corelib/text/qbytearray | |
parent | 74083c239db8ac65f143187ba9cafa11262d427b (diff) |
QByteArray: don't coerce negative to unsigned for any base
This follows up on commit 98666c8afc80cccb80ca4426b97ec52916c6e610,
which did the same for QString. If someone wants to get formatting
suitable to an unsigned value, they can cast the value to that
unsigned type and the correct overload shall pick it up.
[ChangeLog][Important Behavior Changes] QByteArray's formatting of
negative whole numbers to bases other than ten now, like QString's
(since Qt 6.0), formats the absolute value and prepends a minus sign.
Task-number: QTBUG-53706
Pick-to: 6.2
Change-Id: I91fee23d25ac0d5d5bcfcbeccbac1386627c004a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/text/qbytearray')
-rw-r--r-- | tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp index e9d0cf8236..0db139b518 100644 --- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp @@ -425,18 +425,17 @@ void tst_QByteArray::setNum() QCOMPARE(a.setNum(37, 2), QByteArray("100101")); QCOMPARE(a.setNum(37, 36), QByteArray("11")); - // Negative numbers are only properly supported for base 10. - QCOMPARE(a.setNum(short(-1), 16), QByteArray("ffff")); - QCOMPARE(a.setNum(int(-1), 16), QByteArray("ffffffff")); - QCOMPARE(a.setNum(qlonglong(-1), 16), QByteArray("ffffffffffffffff")); + QCOMPARE(a.setNum(short(-1), 16), QByteArray("-1")); + QCOMPARE(a.setNum(int(-1), 16), QByteArray("-1")); + QCOMPARE(a.setNum(qlonglong(-1), 16), QByteArray("-1")); QCOMPARE(a.setNum(short(-1), 10), QByteArray("-1")); QCOMPARE(a.setNum(int(-1), 10), QByteArray("-1")); QCOMPARE(a.setNum(qlonglong(-1), 10), QByteArray("-1")); QCOMPARE(a.setNum(-123), QByteArray("-123")); - QCOMPARE(a.setNum(0x123,16), QByteArray("123")); - QCOMPARE(a.setNum((short)123), QByteArray("123")); + QCOMPARE(a.setNum(0x123, 16), QByteArray("123")); + QCOMPARE(a.setNum(short(123)), QByteArray("123")); QCOMPARE(a.setNum(1.23), QByteArray("1.23")); QCOMPARE(a.setNum(1.234567), QByteArray("1.23457")); |