add more boolean tests
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 27e6e6c..d1be74d 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -3679,12 +3679,8 @@
-
-
-
-
static inline void
-InterpretBool(QCBORDecodeContext *pMe, const QCBORItem *pItem, bool *pBool)
+ProcessBool(QCBORDecodeContext *pMe, const QCBORItem *pItem, bool *pBool)
{
if(pMe->uLastError != QCBOR_SUCCESS) {
/* Already in error state, do nothing */
@@ -3722,7 +3718,7 @@
pMe->uLastError = (uint8_t)QCBORDecode_GetNext(pMe, &Item);
- InterpretBool(pMe, &Item, pValue);
+ ProcessBool(pMe, &Item, pValue);
}
@@ -3734,7 +3730,7 @@
QCBORItem Item;
QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, &Item);
- InterpretBool(pMe, &Item, pValue);
+ ProcessBool(pMe, &Item, pValue);
}
@@ -3746,7 +3742,7 @@
QCBORItem Item;
QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item);
- InterpretBool(pMe, &Item, pValue);
+ ProcessBool(pMe, &Item, pValue);
}
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index dc31661..01a87e5 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -7768,11 +7768,24 @@
}
+
+
static const uint8_t spBooleansInMap[] =
{
- 0xa3, 0x08, 0xf5
+ 0xa1, 0x08, 0xf5
};
+static const uint8_t spBooleansInMapWrongType[] =
+{
+ 0xa1, 0x08, 0xf6
+};
+
+static const uint8_t spBooleansInMapNWF[] =
+{
+ 0xa1, 0x08, 0x1a
+};
+
+
int32_t BoolTest(void)
{
QCBORDecodeContext DCtx;
@@ -7782,12 +7795,41 @@
QCBORDecode_EnterMap(&DCtx, NULL);
QCBORDecode_GetBool(&DCtx, &b);
- if(QCBORDecode_GetError(&DCtx) || !b) {
+ if(QCBORDecode_GetAndResetError(&DCtx) || !b) {
return 1;
}
- // TODO: add more tests
+ QCBORDecode_GetBoolInMapN(&DCtx, 7, &b);
+ if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_LABEL_NOT_FOUND) {
+ return 2;
+ }
+ QCBORDecode_GetBoolInMapN(&DCtx, 8, &b);
+ if(QCBORDecode_GetAndResetError(&DCtx) || !b) {
+ return 3;
+ }
+
+
+ QCBORDecode_GetBoolInMapSZ(&DCtx, "xx", &b);
+ if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_LABEL_NOT_FOUND) {
+ return 4;
+ }
+
+ QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMapWrongType), 0);
+
+ QCBORDecode_EnterMap(&DCtx, NULL);
+ QCBORDecode_GetBool(&DCtx, &b);
+ if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_UNEXPECTED_TYPE) {
+ return 5;
+ }
+
+ QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMapNWF), 0);
+
+ QCBORDecode_EnterMap(&DCtx, NULL);
+ QCBORDecode_GetBool(&DCtx, &b);
+ if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_HIT_END) {
+ return 6;
+ }
return 0;
}