completed tests for string only labels decoder mode
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 34c8b1c..558074f 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -38,8 +38,6 @@
#include <stdlib.h>
-// TODO: test other than the normal decoder mode
-
static void printencoded(const char *szLabel, const uint8_t *pEncoded, size_t nLen)
{
if(szLabel) {
@@ -704,13 +702,13 @@
Decode and thoroughly check a moderately complex
set of maps
*/
-static int ParseMapTest1()
+static int ParseMapTest1(QCBORDecodeMode nMode)
{
QCBORDecodeContext DCtx;
QCBORItem Item;
int nCBORError;
- QCBORDecode_Init(&DCtx, (UsefulBufC){pValidMapEncoded, sizeof(pValidMapEncoded)}, QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx, (UsefulBufC){pValidMapEncoded, sizeof(pValidMapEncoded)}, nMode);
if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item))) {
return nCBORError;
@@ -1232,8 +1230,10 @@
int ParseMapTest()
{
// Parse a moderatly complex map structure very thoroughl
- int n = ParseMapTest1();
-
+ int n = ParseMapTest1(QCBOR_DECODE_MODE_NORMAL);
+
+ n = ParseMapTest1(QCBOR_DECODE_MODE_MAP_STRINGS_ONLY);
+
if(!n) {
for(int i = 0; i < 10; i++) {
n = ExtraBytesTest(i);
@@ -2105,6 +2105,33 @@
return CheckCSRMaps(&DCtx);
}
+
+
+int StringDecoderModeFailTest()
+{
+ QCBORDecodeContext DCtx;
+
+ QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCSRInput), QCBOR_DECODE_MODE_MAP_STRINGS_ONLY);
+
+ QCBORItem Item;
+ QCBORError nCBORError;
+
+ if(QCBORDecode_GetNext(&DCtx, &Item)) {
+ return -1;
+ }
+ if(Item.uDataType != QCBOR_TYPE_MAP) {
+ return -2;
+ }
+
+ nCBORError = QCBORDecode_GetNext(&DCtx, &Item);
+ if(nCBORError != QCBOR_ERR_MAP_LABEL_TYPE) {
+ return -3;
+ }
+
+ return 0;
+}
+
+
// Same map as above, but using indefinite lengths
static uint8_t spCSRInputIndefLen[] = {
0xbf, 0x36, 0xbf, 0x33, 0xbf, 0x31, 0x6c, 0x4f,
diff --git a/test/qcbor_decode_tests.h b/test/qcbor_decode_tests.h
index 862e79d..398a8af 100644
--- a/test/qcbor_decode_tests.h
+++ b/test/qcbor_decode_tests.h
@@ -161,6 +161,9 @@
int BignumParseTest(void);
+int StringDecoderModeFailTest(void);
+
+
/*
Parse some nested maps
*/
diff --git a/test/run_tests.c b/test/run_tests.c
index bd9d1cd..dea81d7 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -154,6 +154,7 @@
TEST_ENTRY(BstrWrapErrorTest),
TEST_ENTRY(BstrWrapNestTest),
TEST_ENTRY(CoseSign1TBSTest),
+ TEST_ENTRY(StringDecoderModeFailTest),
//TEST_ENTRY(fail_test),
};