summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qbytearray
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-07-28 13:27:48 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2021-08-04 23:45:47 +0200
commite00928e48ccef084052b927ee1de1e5a557acf0b (patch)
tree3ca3f35e7df3a1547ee4b87b450b0ee3aed2ccff /tests/auto/corelib/text/qbytearray
parent861feef2bfd879f4cb62ca67cff42314b355e03a (diff)
QByteArray::number(double): Extend the test
Move out and share the test data from the QString::number_double() test and re-use it for this one. Task-number: QTBUG-88484 Change-Id: I6502d1d360657f6077e5c46636f537ddfdde3a83 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.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
index 0db139b518..7d4b7eafa2 100644
--- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
@@ -35,6 +35,8 @@
#include <limits.h>
#include <private/qtools_p.h>
+#include "../shared/test_number_shared.h"
+
class tst_QByteArray : public QObject
{
Q_OBJECT
@@ -96,6 +98,8 @@ private slots:
void toULongLong();
void number();
+ void number_double_data();
+ void number_double();
void toShort();
void toUShort();
void toInt_data();
@@ -1296,6 +1300,35 @@ void tst_QByteArray::number()
QString(QByteArray("-9223372036854775808")));
}
+void tst_QByteArray::number_double_data()
+{
+ QTest::addColumn<double>("value");
+ QTest::addColumn<char>("format");
+ QTest::addColumn<int>("precision");
+ QTest::addColumn<QByteArray>("expected");
+
+ // This function is implemented in ../shared/test_number_shared.h
+ add_number_double_shared_data([](NumberDoubleTestData datum) {
+ QByteArray ba(datum.expected.data(), datum.expected.size());
+ QTest::addRow("%s, format '%c', precision %d", ba.data(), datum.f, datum.p)
+ << datum.d << datum.f << datum.p << ba;
+ if (datum.f != 'f') { // Also test uppercase format
+ datum.f = toupper(datum.f);
+ QByteArray upper = ba.toUpper();
+ QTest::addRow("%s, format '%c', precision %d", upper.data(), datum.f, datum.p)
+ << datum.d << datum.f << datum.p << upper;
+ }
+ });
+}
+
+void tst_QByteArray::number_double()
+{
+ QFETCH(double, value);
+ QFETCH(char, format);
+ QFETCH(int, precision);
+ QTEST(QByteArray::number(value, format, precision), "expected");
+}
+
void tst_QByteArray::toShort()
{
bool ok = true; // opposite to the next expected result