Skip to content

Commit

Permalink
more tests; tidiness
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurence Lundblade committed Aug 12, 2024
1 parent fb9e65d commit 61224b4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
2 changes: 0 additions & 2 deletions inc/qcbor/qcbor_encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -4129,8 +4129,6 @@ QCBOREncode_Tell(QCBOREncodeContext *pMe)
return UsefulOutBuf_GetEndPosition(&(pMe->OutBuf));
}



/* ========================================================================
END OF PRIVATE INLINE IMPLEMENTATION
======================================================================== */
Expand Down
2 changes: 1 addition & 1 deletion inc/qcbor/qcbor_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ extern "C" {
*/
typedef struct __QCBORTrackNesting {
/* PRIVATE DATA STRUCTURE */
struct QCBORNestEntry {
struct {
/* See QCBOREncode_OpenMapOrArray() for details on how this works */
uint32_t uStart; /* uStart is the position where the array starts */
uint16_t uCount; /* Number of items in the arrary or map; counts items
Expand Down
1 change: 0 additions & 1 deletion src/qcbor_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ Nesting_IsInNest(QCBORTrackNesting *pNesting)
{
return pNesting->pCurrentNesting == &pNesting->pArrays[0] ? false : true;
}

#endif /* ! QCBOR_DISABLE_ENCODE_USAGE_GUARDS */


Expand Down
37 changes: 31 additions & 6 deletions test/UsefulBuf_Tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,23 @@ const char * UOBTest_NonAdversarial(void)
if(UsefulBuf_IsNULLC(Out) ||
UsefulBuf_Compare(UsefulBuf_FROM_SZ_LITERAL("unbounce"), Out) ||
UsefulOutBuf_GetError(&UOB)) {
szReturn = "SubString";
szReturn = "SubString substring";
goto Done;
}

Out = UsefulOutBuf_SubString(&UOB, 0, Expected.len);
if(UsefulBuf_IsNULLC(Out) ||
UsefulBuf_Compare(Expected, Out) ||
UsefulOutBuf_GetError(&UOB)) {
szReturn = "SubString all";
goto Done;
}

Out = UsefulOutBuf_SubString(&UOB, Expected.len, 0);
if(UsefulBuf_IsNULLC(Out) ||
UsefulBuf_Compare(UsefulBuf_FROM_SZ_LITERAL(""), Out) ||
UsefulOutBuf_GetError(&UOB)) {
szReturn = "SubString empty";
goto Done;
}

Expand Down Expand Up @@ -273,14 +289,24 @@ const char *UOBTest_BoundaryConditionsTest(void)

UsefulBufC Out = UsefulOutBuf_SubString(&UOB, 7, 1);
if(!UsefulBuf_IsNULLC(Out)) {
return "SubString start should fail off end";
return "SubString start should fail off end 1";
}
Out = UsefulOutBuf_SubString(&UOB, 5, 3);
if(!UsefulBuf_IsNULLC(Out)) {
return "SubString len should fail off end";
return "SubString len should fail off end 2";
}
Out = UsefulOutBuf_SubString(&UOB, 0, 7);
if(!UsefulBuf_IsNULLC(Out)) {
return "SubString len should fail off end 3";
}
Out = UsefulOutBuf_SubString(&UOB, 7, 0);
if(!UsefulBuf_IsNULLC(Out)) {
return "SubString len should fail off end 4";
}
Out = UsefulOutBuf_SubString(&UOB, 6, 1);
if(!UsefulBuf_IsNULLC(Out)) {
return "SubString len should fail off end 5";
}
// TODO: more thorough boundary condition testing of SubString


UsefulOutBuf_Init(&UOB, (UsefulBuf){NULL, SIZE_MAX - 5});
UsefulOutBuf_AppendData(&UOB, "123456789", SIZE_MAX -6);
Expand All @@ -294,7 +320,6 @@ const char *UOBTest_BoundaryConditionsTest(void)
return "insert in huge should have succeeded";
}


UsefulOutBuf_Init(&UOB, (UsefulBuf){NULL, SIZE_MAX - 5});
UsefulOutBuf_AppendData(&UOB, "123456789", SIZE_MAX - 4);
if(!UsefulOutBuf_GetError(&UOB)) {
Expand Down
2 changes: 2 additions & 0 deletions test/qcbor_encode_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -3168,12 +3168,14 @@ int32_t SubStringTest(void)
return 11;
}

#ifndef QCBOR_DISABLE_ENCODE_USAGE_GUARDS
/* Now cause an error */
QCBOREncode_OpenMap(&EC);
QCBOREncode_CloseArray(&EC);
if(!UsefulBuf_IsNULLC(QCBOREncode_SubString(&EC, uStart))) {
return 15;
}
#endif /* ! QCBOR_DISABLE_ENCODE_USAGE_GUARDS */


QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
Expand Down

0 comments on commit 61224b4

Please sign in to comment.