Skip to content

Commit 9e6d24c

Browse files
author
Laurence Lundblade
committed
Improve tests
1 parent d1e29af commit 9e6d24c

File tree

1 file changed

+26
-43
lines changed

1 file changed

+26
-43
lines changed

test/qcbor_decode_tests.c

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3999,7 +3999,7 @@ struct TestInput {
39993999
* but still nice to organize into an array with descriptions. */
40004000
static const struct TestInput spTagInput2[] = {
40014001
/* 0 */
4002-
"55799([4([1, 3])]), CBOR magic number in from of decimal fraction",
4002+
"55799([4([1, 3])]), CBOR magic number in front of decimal fraction",
40034003
{
40044004
(uint8_t[]){0xd9, 0xd9, 0xf7, // CBOR magic number
40054005
0x81, // Array of one
@@ -4346,16 +4346,11 @@ int32_t TagNumberDecodeTest(void)
43464346
return -10;
43474347
}
43484348

4349-
/* Testing with v2 */
4350-
QCBORDecode_Init(&DCtx,
4351-
UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spTagInput),
4352-
QCBOR_DECODE_MODE_NORMAL);
43534349

4354-
/*
4355-
This test matches the magic number tag and the fraction tag
4356-
55799([...])
4357-
*/
4350+
/* V2 tag mode testing */
43584351
uint64_t uTagNumber;
4352+
4353+
QCBORDecode_Init(&DCtx, spTagInput2[0].EncodedCBOR, QCBOR_DECODE_MODE_NORMAL);
43594354
uError = QCBORDecode_GetNextTagNumber(&DCtx, &uTagNumber);
43604355
if(uError != QCBOR_SUCCESS) {
43614356
return -200;
@@ -4375,45 +4370,35 @@ int32_t TagNumberDecodeTest(void)
43754370
return -500;
43764371
}
43774372

4373+
/* More than 4 tag numbers */
4374+
QCBORDecode_Init(&DCtx, spTagInput2[1].EncodedCBOR, QCBOR_DECODE_MODE_NORMAL);
4375+
uError = QCBORDecode_GetNextTagNumber(&DCtx, &uTagNumber);
4376+
if(uError != QCBOR_ERR_TOO_MANY_TAGS) {
4377+
return -2;
4378+
}
43784379

4379-
4380-
/*
4381-
4([1,3])
4382-
*/
4380+
/* An array with for big tag numbers on it */
4381+
QCBORDecode_Init(&DCtx, spTagInput2[2].EncodedCBOR, QCBOR_DECODE_MODE_NORMAL);
43834382
uError = QCBORDecode_GetNextTagNumber(&DCtx, &uTagNumber);
4384-
if(uError != QCBOR_SUCCESS) {
4385-
return -200;
4383+
if(uError != QCBOR_SUCCESS || uTagNumber != 10489608748473423768ULL) {
4384+
return -81;
43864385
}
4387-
if(uTagNumber != CBOR_TAG_DECIMAL_FRACTION) {
4388-
return -300;
4386+
uError = QCBORDecode_GetNextTagNumber(&DCtx, &uTagNumber);
4387+
if(uError != QCBOR_SUCCESS || uTagNumber != 2442302356ULL) {
4388+
return -81;
43894389
}
4390-
4391-
4392-
uError = QCBORDecode_GetNext(&DCtx, &Item);
4393-
if(uError != QCBOR_SUCCESS ||
4394-
Item.uDataType != QCBOR_TYPE_ARRAY ||
4395-
QCBORDecode_GetNthTag(&DCtx, &Item, 0) != CBOR_TAG_DECIMAL_FRACTION ||
4396-
QCBORDecode_GetNthTag(&DCtx, &Item, 1) != CBOR_TAG_INVALID64 ||
4397-
QCBORDecode_GetNthTag(&DCtx, &Item, 2) != CBOR_TAG_INVALID64 ||
4398-
QCBORDecode_GetNthTag(&DCtx, &Item, 3) != CBOR_TAG_INVALID64 ||
4399-
QCBORDecode_GetNthTag(&DCtx, &Item, 4) != CBOR_TAG_INVALID64 ||
4400-
Item.val.uCount != 2) {
4401-
return -4;
4390+
uError = QCBORDecode_GetNextTagNumber(&DCtx, &uTagNumber);
4391+
if(uError != QCBOR_SUCCESS || uTagNumber != 21590ULL) {
4392+
return -81;
44024393
}
4403-
// consume the items in the array
4404-
uError = QCBORDecode_GetNext(&DCtx, &Item);
4405-
uError = QCBORDecode_GetNext(&DCtx, &Item);
4406-
4407-
4408-
/*
4409-
More than 4 tags on an item 225(226(227(228(229([])))))
4410-
*/
44114394
uError = QCBORDecode_GetNextTagNumber(&DCtx, &uTagNumber);
4412-
if(uError != QCBOR_ERR_TOO_MANY_TAGS) {
4413-
return -2;
4395+
if(uError != QCBOR_SUCCESS || uTagNumber != 240ULL) {
4396+
return -81;
4397+
}
4398+
uError = QCBORDecode_GetNext(&DCtx, &Item);
4399+
if(uError != QCBOR_SUCCESS || Item.uDataType != QCBOR_TYPE_ARRAY) {
4400+
return -81;
44144401
}
4415-
4416-
44174402

44184403

44194404
/* Decode the four tag numbers and see success */
@@ -4463,9 +4448,7 @@ int32_t TagNumberDecodeTest(void)
44634448
return -9;
44644449
}
44654450

4466-
44674451
/* The input is a bad decimal frac with extra tag number */
4468-
/* TODO: maybe look into how this behaved internally more */
44694452
QCBORDecode_Init(&DCtx, spTagInput2[5].EncodedCBOR, QCBOR_DECODE_MODE_NORMAL);
44704453
QCBORDecode_InstallTagDecoders(&DCtx, QCBORDecode_TagDecoderTablev1, NULL);
44714454
uError = QCBORDecode_GetNextTagNumber(&DCtx, &uTagNumber);

0 commit comments

Comments
 (0)