summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
diff options
context:
space:
mode:
authorLars Schmertmann <Lars.Schmertmann@governikus.de>2016-12-18 21:15:10 +0100
committerLars Schmertmann <lars.schmertmann@governikus.de>2016-12-25 08:24:18 +0000
commit5882866768ae24ef31f9feda4765fea17375fbcb (patch)
tree4cf9c7b57e25d7969aac27c45126d8bde7908714 /tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
parent615027129d3d5e12a6e2f5d02d2af8320cc58ea7 (diff)
Extend qChecksum calculation
ISO 14443-3 is for nfc communication and uses 2 different checksums. The existing one is from ISO 3309 and the other one is from ITU-V.41. Both are needed to implement an own transport layer defined in ISO 14443-4 to allow nfc commands with a length above 250 byte independent from the smartphone. This change will avoid code duplication in QNearFieldTarget. The private function qNfcChecksum is a copy of qChecksum. Change-Id: I790ffec8e2ea46f88b2db6f48b64fdcb140e7b70 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp')
-rw-r--r--tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
index 324086dbab..16a9c03351 100644
--- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
@@ -43,6 +43,8 @@ public:
tst_QByteArray();
private slots:
void swap();
+ void qChecksum_data();
+ void qChecksum();
void qCompress_data();
#ifndef QT_NO_COMPRESS
void qCompress();
@@ -239,6 +241,34 @@ tst_QByteArray::tst_QByteArray()
{
}
+void tst_QByteArray::qChecksum_data()
+{
+ QTest::addColumn<QByteArray>("data");
+ QTest::addColumn<uint>("len");
+ QTest::addColumn<Qt::ChecksumType>("standard");
+ QTest::addColumn<uint>("checksum");
+
+ // Examples from ISO 14443-3
+ QTest::newRow("1") << QByteArray("\x00\x00") << 2U << Qt::ChecksumItuV41 << 0x1EA0U;
+ QTest::newRow("2") << QByteArray("\x12\x34") << 2U << Qt::ChecksumItuV41 << 0xCF26U;
+ QTest::newRow("3") << QByteArray("\x00\x00\x00") << 3U << Qt::ChecksumIso3309 << 0xC6CCU;
+ QTest::newRow("4") << QByteArray("\x0F\xAA\xFF") << 3U << Qt::ChecksumIso3309 << 0xD1FCU;
+ QTest::newRow("5") << QByteArray("\x0A\x12\x34\x56") << 4U << Qt::ChecksumIso3309 << 0xF62CU;
+}
+
+void tst_QByteArray::qChecksum()
+{
+ QFETCH(QByteArray, data);
+ QFETCH(uint, len);
+ QFETCH(Qt::ChecksumType, standard);
+ QFETCH(uint, checksum);
+
+ if (standard == Qt::ChecksumIso3309) {
+ QCOMPARE(::qChecksum(data.constData(), len), static_cast<quint16>(checksum));
+ }
+ QCOMPARE(::qChecksum(data.constData(), len, standard), static_cast<quint16>(checksum));
+}
+
void tst_QByteArray::qCompress_data()
{
QTest::addColumn<QByteArray>("ba");