summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/tinycbor/tests/parser/tst_parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/tinycbor/tests/parser/tst_parser.cpp')
-rw-r--r--src/3rdparty/tinycbor/tests/parser/tst_parser.cpp52
1 files changed, 46 insertions, 6 deletions
diff --git a/src/3rdparty/tinycbor/tests/parser/tst_parser.cpp b/src/3rdparty/tinycbor/tests/parser/tst_parser.cpp
index d3ae4faa8e..b8e51619b8 100644
--- a/src/3rdparty/tinycbor/tests/parser/tst_parser.cpp
+++ b/src/3rdparty/tinycbor/tests/parser/tst_parser.cpp
@@ -24,7 +24,7 @@
#define _XOPEN_SOURCE 700
#define _DARWIN_C_SOURCE 1 /* need MAP_ANON */
-#include <QTest>
+#include <QtTest>
#include "cbor.h"
#include <stdio.h>
#include <stdarg.h>
@@ -894,22 +894,44 @@ static void chunkedStringTest(const QByteArray &data, const QString &concatenate
err = cbor_value_calculate_string_length(&copy, &n);
QVERIFY2(!err, QByteArray("Got error \"") + cbor_error_string(err) + "\"");
- QByteArray buffer(n, Qt::Uninitialized);
+ size_t nn = n;
+ QByteArray buffer(n + 1, Qt::Uninitialized);
+ QByteArray buffer2(n + 1, Qt::Uninitialized);
+ buffer[int(n)] = 0xff;
+ buffer2[int(n)] = 0xff;
QString formatted;
if (cbor_value_is_byte_string(&copy)) {
- err = cbor_value_copy_byte_string(&copy, (uint8_t *)buffer.data(), &n, nullptr);
+ err = cbor_value_copy_byte_string(&copy, (uint8_t *)buffer.data(), &nn, nullptr);
QVERIFY2(!err, QByteArray("Got error \"") + cbor_error_string(err) + "\"");
- QCOMPARE(int(n), buffer.size());
+ QCOMPARE(nn, n);
- formatted = QString::fromLatin1("h'" + buffer.toHex() + '\'');
+ formatted = QString::fromLatin1("h'" + QByteArray::fromRawData(buffer.data(), n).toHex() + '\'');
+
+ // repeat by allowing the null termination
+ nn = n + 1;
+ err = cbor_value_copy_byte_string(&copy, (uint8_t *)buffer2.data(), &nn, nullptr);
} else {
err = cbor_value_copy_text_string(&copy, buffer.data(), &n, nullptr);
QVERIFY2(!err, QByteArray("Got error \"") + cbor_error_string(err) + "\"");
- QCOMPARE(int(n), buffer.size());
+ QCOMPARE(nn, n);
formatted = '"' + QString::fromUtf8(buffer.data(), n) + '"';
+
+ // repeat by allowing the null termination
+ nn = n + 1;
+ err = cbor_value_copy_text_string(&copy, buffer2.data(), &nn, nullptr);
}
+ QVERIFY2(!err, QByteArray("Got error \"") + cbor_error_string(err) + "\"");
QCOMPARE(formatted, concatenated);
+
+ // verify terminators
+ QCOMPARE(buffer.at(n), char(0xff));
+ QCOMPARE(buffer2.at(n), '\0');
+ QCOMPARE(nn, n);
+
+ buffer.truncate(n);
+ buffer2.truncate(n);
+ QCOMPARE(buffer2, buffer);
}
// confirm that the extra string we appended is still here
@@ -1340,6 +1362,24 @@ void tst_Parser::validation()
QCOMPARE(err2, expectedError);
QCOMPARE(err3, expectedError);
}
+
+ // see if we've got a map
+ if (QByteArray(QTest::currentDataTag()).startsWith("map")) {
+ w.init(data, uint32_t(flags)); // reinit
+ QVERIFY(cbor_value_is_array(&w.first));
+
+ CborValue map;
+ CborError err = cbor_value_enter_container(&w.first, &map);
+ if (err == CborNoError) {
+ QVERIFY(cbor_value_is_map(&map));
+ CborValue element;
+ err = cbor_value_map_find_value(&map, "foobar", &element);
+ if (err == CborNoError)
+ QVERIFY(!cbor_value_is_valid(&element));
+ }
+
+ QCOMPARE(err, expectedError);
+ }
}
void tst_Parser::strictValidation_data()