improve enter map test
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 39a5c7a..a0f8dc2 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -3794,7 +3794,8 @@
Some basic CBOR with map and array used in a lot of tests.
The map labels are all strings
- {"first integer": 42,
+ {
+ "first integer": 42,
"an array of two strings": [
"string1", "string2"
],
@@ -3839,56 +3840,43 @@
}
}
+
int32_t EnterMapTest()
{
-
+ QCBORItem Item1, Item2, Item3;
+ int64_t nDecodedInt1, nDecodedInt2;
+ UsefulBufC B1, B2, S1, S2, S3;
QCBORDecodeContext DCtx;
QCBORError nCBORError;
QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapEncoded), 0);
-
- /* do {
- QCBORItem Item;
-
- nCBORError = QCBORDecode_GetNext(&DCtx, &Item);
-
- PrintItem(Item);
- //printf("type: %d, nest %d, next: %d\n", Item.uDataType, Item.uNestingLevel, Item.uNextNestLevel);
- } while(nCBORError == 0); */
-
-
-
-
QCBORDecode_EnterMap(&DCtx);
-
- int64_t nDecodedInt1, nDecodedInt2;
- UsefulBufC B1, B2, S1;
-
- QCBORDecode_GetIntInMapSZ(&DCtx, "first integer", &nDecodedInt1);
-
- QCBORDecode_EnterMapFromMapSZ(&DCtx, "map in a map");
-
- QCBORDecode_GetIntInMapSZ(&DCtx, "another int", &nDecodedInt2);
- QCBORDecode_GetBstrInMapSZ(&DCtx, "bytes 1", &B1);
- QCBORDecode_GetBstrInMapSZ(&DCtx, "bytes 2", &B2);
- QCBORDecode_GetTextInMapSZ(&DCtx, "text 2", &S1);
- QCBORDecode_ExitMap(&DCtx);
+ QCBORDecode_GetIntInMapSZ(&DCtx, "first integer", &nDecodedInt1);
- QCBORDecode_EnterArrayFromMapSZ(&DCtx, "an array of two strings");
+ QCBORDecode_EnterMapFromMapSZ(&DCtx, "map in a map");
+ QCBORDecode_GetIntInMapSZ(&DCtx, "another int", &nDecodedInt2);
+ QCBORDecode_GetBstrInMapSZ(&DCtx, "bytes 1", &B1);
+ QCBORDecode_GetBstrInMapSZ(&DCtx, "bytes 2", &B2);
+ QCBORDecode_GetTextInMapSZ(&DCtx, "text 2", &S1);
+ QCBORDecode_ExitMap(&DCtx);
- QCBORItem Item1, Item2, Item3;
- QCBORDecode_GetNext(&DCtx, &Item1);
- QCBORDecode_GetNext(&DCtx, &Item2);
- if(QCBORDecode_GetNext(&DCtx, &Item3) != QCBOR_ERR_NO_MORE_ITEMS) {
- return -400;
- }
+ QCBORDecode_EnterArrayFromMapSZ(&DCtx, "an array of two strings");
+ QCBORDecode_GetNext(&DCtx, &Item1);
+ QCBORDecode_GetNext(&DCtx, &Item2);
+ if(QCBORDecode_GetNext(&DCtx, &Item3) != QCBOR_ERR_NO_MORE_ITEMS) {
+ return -400;
+ }
+ QCBORDecode_ExitArray(&DCtx);
-
- QCBORDecode_ExitArray(&DCtx);
-
+ // Parse the same array again using GetText() instead of GetItem()
+ QCBORDecode_EnterArrayFromMapSZ(&DCtx, "an array of two strings");
+ QCBORDecode_GetText(&DCtx, &S2);
+ QCBORDecode_GetText(&DCtx, &S3);
+ // TODO, check for end of array?
+ QCBORDecode_ExitArray(&DCtx);
QCBORDecode_ExitMap(&DCtx);
@@ -3899,13 +3887,43 @@
}
if(nDecodedInt1 != 42) {
- return 1000;
+ return 1001;
}
if(nDecodedInt2 != 98) {
- return 2000;
+ return 1002;
+ }
+
+ if(Item1.uDataType != QCBOR_TYPE_TEXT_STRING ||
+ UsefulBuf_Compare(Item1.val.string, UsefulBuf_FromSZ("string1"))){
+ return 1003;
+ }
+
+ if(Item1.uDataType != QCBOR_TYPE_TEXT_STRING ||
+ UsefulBuf_Compare(Item2.val.string, UsefulBuf_FromSZ("string2"))){
+ return 1004;
+ }
+
+ if(UsefulBuf_Compare(S1, UsefulBuf_FromSZ("lies, damn lies and statistics"))){
+ return 1005;
}
+ if(UsefulBuf_Compare(B1, UsefulBuf_FromSZ("xxxx"))){
+ return 1006;
+ }
+
+ if(UsefulBuf_Compare(B2, UsefulBuf_FromSZ("yyyy"))){
+ return 1007;
+ }
+
+ if(UsefulBuf_Compare(S2, UsefulBuf_FromSZ("string1"))){
+ return 1008;
+ }
+
+ if(UsefulBuf_Compare(S3, UsefulBuf_FromSZ("string2"))){
+ return 1009;
+ }
+
return 0;
}