summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/tinycbor/tests/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/tinycbor/tests/parser')
-rw-r--r--src/3rdparty/tinycbor/tests/parser/data.cpp28
-rw-r--r--src/3rdparty/tinycbor/tests/parser/parser.pro10
-rw-r--r--src/3rdparty/tinycbor/tests/parser/tst_parser.cpp52
3 files changed, 74 insertions, 16 deletions
diff --git a/src/3rdparty/tinycbor/tests/parser/data.cpp b/src/3rdparty/tinycbor/tests/parser/data.cpp
index 3523c32167..c99160ad31 100644
--- a/src/3rdparty/tinycbor/tests/parser/data.cpp
+++ b/src/3rdparty/tinycbor/tests/parser/data.cpp
@@ -1,9 +1,35 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 Intel Corporation
+**
+** Permission is hereby granted, free of charge, to any person obtaining a copy
+** of this software and associated documentation files (the "Software"), to deal
+** in the Software without restriction, including without limitation the rights
+** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+** copies of the Software, and to permit persons to whom the Software is
+** furnished to do so, subject to the following conditions:
+**
+** The above copyright notice and this permission notice shall be included in
+** all copies or substantial portions of the Software.
+**
+** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+** THE SOFTWARE.
+**
+****************************************************************************/
+
#include <QtTest>
#include <limits>
#include <cbor.h>
Q_DECLARE_METATYPE(CborError)
+namespace {
+
template <size_t N> QByteArray raw(const char (&data)[N])
{
return QByteArray::fromRawData(data, N - 1);
@@ -484,6 +510,7 @@ void addValidationData(size_t minInvalid = ~size_t(0))
QTest::newRow("map-no-break1") << raw("\x81\xbf") << 0 << CborErrorUnexpectedEOF;
QTest::newRow("map-no-break2") << raw("\x81\xbf\0\0") << 0 << CborErrorUnexpectedEOF;
QTest::newRow("map-break-after-key") << raw("\x81\xbf\0\xff") << 0 << CborErrorUnexpectedBreak;
+ QTest::newRow("map-break-after-second-key") << raw("\x81\xbf\x64xyzw\x04\x00\xff") << 0 << CborErrorUnexpectedBreak;
QTest::newRow("map-break-after-value-tag") << raw("\x81\xbf\0\xc0\xff") << 0 << CborErrorUnexpectedBreak;
QTest::newRow("map-break-after-value-tag2") << raw("\x81\xbf\0\xd8\x20\xff") << 0 << CborErrorUnexpectedBreak;
@@ -580,3 +607,4 @@ void addValidationData(size_t minInvalid = ~size_t(0))
// This test technically tests the dumper, not the parser.
QTest::newRow("string-utf8-chunk-split") << raw("\x81\x7f\x61\xc2\x61\xa0\xff") << 0 << CborErrorInvalidUtf8TextString;
}
+} // namespace
diff --git a/src/3rdparty/tinycbor/tests/parser/parser.pro b/src/3rdparty/tinycbor/tests/parser/parser.pro
deleted file mode 100644
index a61291a9e4..0000000000
--- a/src/3rdparty/tinycbor/tests/parser/parser.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-SOURCES += tst_parser.cpp ../../src/cborparser.c
-
-CONFIG += testcase parallel_test c++11
-QT = core testlib
-DEFINES += CBOR_PARSER_MAX_RECURSIONS=16
-
-INCLUDEPATH += ../../src
-msvc: POST_TARGETDEPS = ../../lib/tinycbor.lib
-else: POST_TARGETDEPS += ../../lib/libtinycbor.a
-LIBS += $$POST_TARGETDEPS
diff --git a/src/3rdparty/tinycbor/tests/parser/tst_parser.cpp b/src/3rdparty/tinycbor/tests/parser/tst_parser.cpp
index 2b10004faa..91a65a00ba 100644
--- a/src/3rdparty/tinycbor/tests/parser/tst_parser.cpp
+++ b/src/3rdparty/tinycbor/tests/parser/tst_parser.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 Intel Corporation
+** Copyright (C) 2021 Intel Corporation
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
@@ -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()