Documentation, comments and code formatting improvements
Small documentation corrections.
Improve comments in codes, spelling corrections, comment formatting
Wrap long source code lines so there are fewer lines over 80 columns and very few over 120 columns
NO changes to actual source or interface
diff --git a/test/UsefulBuf_Tests.c b/test/UsefulBuf_Tests.c
index f53693a..d8ccbac 100644
--- a/test/UsefulBuf_Tests.c
+++ b/test/UsefulBuf_Tests.c
@@ -1,6 +1,6 @@
/*==============================================================================
Copyright (c) 2016-2018, The Linux Foundation.
- Copyright (c) 2018-2019, Laurence Lundblade.
+ Copyright (c) 2018-2020, Laurence Lundblade.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -28,7 +28,7 @@
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ==============================================================================*/
+ =============================================================================*/
#include "UsefulBuf.h"
@@ -79,7 +79,8 @@
UsefulBufC UBC2 = {"unbounce ", 9};
UsefulOutBuf_InsertUsefulBuf(&UOB, UBC2, 10);
- // Make it a null terminated string (because all the appends and inserts above not strcpy !)
+ // Make it a null terminated string (because all the appends and
+ // inserts above not strcpy !)
UsefulOutBuf_AppendByte(&UOB, '\0');
@@ -160,7 +161,8 @@
- around MAX size_t
- Test these for the buffer size and the cursor, the insert amount, the append amount and the insert position
+ Test these for the buffer size and the cursor, the insert amount, the
+ append amount and the insert position
*/
diff --git a/test/float_tests.c b/test/float_tests.c
index eaf75aa..10ac012 100644
--- a/test/float_tests.c
+++ b/test/float_tests.c
@@ -1,14 +1,14 @@
/*==============================================================================
float_tests.c -- tests for float and conversion to/from half-precision
- Copyright (c) 2018-2019, Laurence Lundblade. All rights reserved.
+ Copyright (c) 2018-2020, Laurence Lundblade. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
See BSD-3-Clause license in README.md
Created on 9/19/18
- ==============================================================================*/
+ =============================================================================*/
#include "float_tests.h"
#include "qcbor.h"
@@ -26,7 +26,8 @@
0x69, 0x6E, 0x66, 0x69, 0x6E, 0x69, 0x74, 0x69, 0x74, 0x79,
0xF9, 0x7C, 0x00, // Infinity
0x73,
- 0x6E, 0x65, 0x67, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x69, 0x6E, 0x66, 0x69, 0x6E, 0x69, 0x74, 0x69, 0x74, 0x79,
+ 0x6E, 0x65, 0x67, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x69, 0x6E,
+ 0x66, 0x69, 0x6E, 0x69, 0x74, 0x69, 0x74, 0x79,
0xF9, 0xFC, 0x00, // -Inifinity
0x63,
0x4E, 0x61, 0x4E,
@@ -38,21 +39,29 @@
0x6F, 0x6E, 0x65, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64,
0xF9, 0x35, 0x55, // 0.333251953125
0x76,
- 0x6C, 0x61, 0x72, 0x67, 0x65, 0x73, 0x74, 0x20, 0x68, 0x61, 0x6C, 0x66, 0x2D, 0x70, 0x72, 0x65, 0x63, 0x69, 0x73, 0x69, 0x6F, 0x6E,
+ 0x6C, 0x61, 0x72, 0x67, 0x65, 0x73, 0x74, 0x20, 0x68, 0x61, 0x6C,
+ 0x66, 0x2D, 0x70, 0x72, 0x65, 0x63, 0x69, 0x73, 0x69, 0x6F, 0x6E,
0xF9, 0x7B, 0xFF, // 65504.0
- 0x78, 0x18, 0x74, 0x6F, 0x6F, 0x2D, 0x6C, 0x61, 0x72, 0x67, 0x65, 0x20, 0x68, 0x61, 0x6C, 0x66, 0x2D, 0x70, 0x72, 0x65, 0x63, 0x69, 0x73, 0x69, 0x6F, 0x6E,
+ 0x78, 0x18,
+ 0x74, 0x6F, 0x6F, 0x2D, 0x6C, 0x61, 0x72, 0x67, 0x65, 0x20, 0x68,
+ 0x61, 0x6C, 0x66, 0x2D, 0x70, 0x72, 0x65, 0x63, 0x69, 0x73, 0x69,
+ 0x6F, 0x6E,
0xF9, 0x7C, 0x00, // Infinity
0x72,
- 0x73, 0x6D, 0x61, 0x6C, 0x6C, 0x65, 0x73, 0x74, 0x20, 0x73, 0x75, 0x62, 0x6E, 0x6F, 0x72, 0x6D, 0x61, 0x6C,
+ 0x73, 0x6D, 0x61, 0x6C, 0x6C, 0x65, 0x73, 0x74, 0x20, 0x73, 0x75,
+ 0x62, 0x6E, 0x6F, 0x72, 0x6D, 0x61, 0x6C,
0xF9, 0x00, 0x01, // 0.000000059604
0x6F,
- 0x73, 0x6D, 0x61, 0x6C, 0x6C, 0x65, 0x73, 0x74, 0x20, 0x6E, 0x6F, 0x72, 0x6D, 0x61, 0x6C,
+ 0x73, 0x6D, 0x61, 0x6C, 0x6C, 0x65, 0x73, 0x74, 0x20, 0x6E, 0x6F,
+ 0x72, 0x6D, 0x61, 0x6C,
0xF9, 0x03, 0xFF, // 0.0000609755516
0x71,
- 0x62, 0x69, 0x67, 0x67, 0x65, 0x73, 0x74, 0x20, 0x73, 0x75, 0x62, 0x6E, 0x6F, 0x72, 0x6D, 0x61, 0x6C,
+ 0x62, 0x69, 0x67, 0x67, 0x65, 0x73, 0x74, 0x20, 0x73, 0x75, 0x62,
+ 0x6E, 0x6F, 0x72, 0x6D, 0x61, 0x6C,
0xF9, 0x04, 0x00, // 0.000061988
0x70,
- 0x73, 0x75, 0x62, 0x6E, 0x6F, 0x72, 0x6D, 0x61, 0x6C, 0x20, 0x73, 0x69, 0x6E, 0x67, 0x6C, 0x65,
+ 0x73, 0x75, 0x62, 0x6E, 0x6F, 0x72, 0x6D, 0x61, 0x6C, 0x20, 0x73,
+ 0x69, 0x6E, 0x67, 0x6C, 0x65,
0xF9, 0x00, 0x00,
0x03,
0xF9, 0xC0, 0x00, // -2
@@ -97,7 +106,9 @@
return -4;
}
- QCBORDecode_GetNext(&DC, &Item); // TODO, is this really converting right? It is carrying payload, but this confuses things.
+ // TODO, is this really converting right? It is carrying payload, but
+ // this confuses things.
+ QCBORDecode_GetNext(&DC, &Item);
if(Item.uDataType != QCBOR_TYPE_DOUBLE || !isnan(Item.val.dfnum)) {
return -5;
}
@@ -149,19 +160,23 @@
// TODO: double check these four tests
QCBORDecode_GetNext(&DC, &Item); // qNaN
- if(Item.uDataType != QCBOR_TYPE_DOUBLE || UsefulBufUtil_CopyDoubleToUint64(Item.val.dfnum) != 0x7ff8000000000000ULL) {
+ if(Item.uDataType != QCBOR_TYPE_DOUBLE ||
+ UsefulBufUtil_CopyDoubleToUint64(Item.val.dfnum) != 0x7ff8000000000000ULL) {
return -15;
}
QCBORDecode_GetNext(&DC, &Item); // sNaN
- if(Item.uDataType != QCBOR_TYPE_DOUBLE || UsefulBufUtil_CopyDoubleToUint64(Item.val.dfnum) != 0x7ff0000000000001ULL) {
+ if(Item.uDataType != QCBOR_TYPE_DOUBLE ||
+ UsefulBufUtil_CopyDoubleToUint64(Item.val.dfnum) != 0x7ff0000000000001ULL) {
return -16;
}
QCBORDecode_GetNext(&DC, &Item); // qNaN with payload 0x0f
- if(Item.uDataType != QCBOR_TYPE_DOUBLE || UsefulBufUtil_CopyDoubleToUint64(Item.val.dfnum) != 0x7ff800000000000fULL) {
+ if(Item.uDataType != QCBOR_TYPE_DOUBLE ||
+ UsefulBufUtil_CopyDoubleToUint64(Item.val.dfnum) != 0x7ff800000000000fULL) {
return -17;
}
QCBORDecode_GetNext(&DC, &Item); // sNaN with payload 0x0f
- if(Item.uDataType != QCBOR_TYPE_DOUBLE || UsefulBufUtil_CopyDoubleToUint64(Item.val.dfnum) != 0x7ff000000000000fULL) {
+ if(Item.uDataType != QCBOR_TYPE_DOUBLE ||
+ UsefulBufUtil_CopyDoubleToUint64(Item.val.dfnum) != 0x7ff000000000000fULL) {
return -18;
}
@@ -192,7 +207,8 @@
UsefulOutBuf_AppendByte(&UOB, uHalfPrecInitialByte); // The initial byte for a half-precision float
UsefulOutBuf_AppendUint16(&UOB, (uint16_t)uHalfP);
- // Now parse the hand-constructed CBOR. This will invoke the conversion to a float
+ // Now parse the hand-constructed CBOR. This will invoke the
+ // conversion to a float
QCBORDecodeContext DC;
QCBORDecode_Init(&DC, UsefulOutBuf_OutUBuf(&UOB), 0);
@@ -203,7 +219,8 @@
return -1;
}
- //printf("%04x QCBOR:%15.15f RFC: %15.15f (%8x)\n", uHalfP,Item.val.fnum, d , UsefulBufUtil_CopyFloatToUint32(d));
+ //printf("%04x QCBOR:%15.15f RFC: %15.15f (%8x)\n",
+ // uHalfP, Item.val.fnum, d , UsefulBufUtil_CopyFloatToUint32(d));
if(isnan(d)) {
// The RFC code uses the native instructions which may or may not
@@ -340,16 +357,17 @@
QCBOREncode_AddDoubleAsSmallestToMap(&EC, "one third", 0.333251953125);
// 76 # text(22)
- // 6C6172676573742068616C662D707265636973696F6E # "largest half-precision"
+ // 6C6172676573742068616C662D707265636973696F6E # "largest half-precision"
// F9 7BFF # primitive(31743)
QCBOREncode_AddDoubleAsSmallestToMap(&EC, "largest half-precision",65504.0);
// 76 # text(22)
- // 6C6172676573742068616C662D707265636973696F6E # "largest half-precision"
+ // 6C6172676573742068616C662D707265636973696F6E # "largest half-precision"
// F9 7BFF # primitive(31743)
QCBOREncode_AddDoubleAsSmallestToMap(&EC, "largest half-precision point one",65504.1);
- // Float 65536.0F is 0x47800000 in hex. It has an exponent of 16, which is larger than 15, the largest half-precision exponent
+ // Float 65536.0F is 0x47800000 in hex. It has an exponent of 16, which
+ // is larger than 15, the largest half-precision exponent
// 78 18 # text(24)
// 746F6F2D6C617267652068616C662D707265636973696F6E # "too-large half-precision"
// FA 47800000 # primitive(31743)
@@ -395,17 +413,20 @@
// 746F6F2D6C617267652073696E676C6520657870 # "too-large single exp"
// FB 47F8000000000000 # primitive(5185894970917126144)
// (0x01LL << (DOUBLE_NUM_SIGNIFICAND_BITS-1)) | ((128LL + DOUBLE_EXPONENT_BIAS) << DOUBLE_EXPONENT_SHIFT);
- QCBOREncode_AddDoubleAsSmallestToMap(&EC, "too-large single exp", 5.104235503814077E+38); // Exponent too large for single
+ // Exponent too large for single
+ QCBOREncode_AddDoubleAsSmallestToMap(&EC, "too-large single exp", 5.104235503814077E+38);
// 66 # text(6)
// 646664666465 # "dfdfde"
// FA 4B800000 # primitive(1266679808)
- QCBOREncode_AddDoubleAsSmallestToMap(&EC, "biggest single with prec",16777216); // Single with no precision loss
+ // Single with no precision loss
+ QCBOREncode_AddDoubleAsSmallestToMap(&EC, "biggest single with prec", 16777216);
// 78 18 # text(24)
// 626967676573742073696E676C6520776974682070726563 # "biggest single with prec"
// FA 4B800000 # primitive(1266679808)
- QCBOREncode_AddDoubleAsSmallestToMap(&EC, "first single with prec loss",16777217); // Double becuase of precision loss
+ // Double becuase of precision loss
+ QCBOREncode_AddDoubleAsSmallestToMap(&EC, "first single with prec loss", 16777217);
// Just a convenient marker when cutting and pasting encoded CBOR
QCBOREncode_AddSZStringToMapN(&EC, 1, "fin");
diff --git a/test/float_tests.h b/test/float_tests.h
index b7174c8..f3acb71 100644
--- a/test/float_tests.h
+++ b/test/float_tests.h
@@ -1,14 +1,14 @@
/*==============================================================================
float_tests.h -- tests for float and conversion to/from half-precision
- Copyright (c) 2018-2019, Laurence Lundblade. All rights reserved.
+ Copyright (c) 2018-2020, Laurence Lundblade. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
See BSD-3-Clause license in README.md
Created on 9/19/18
- ==============================================================================*/
+ =============================================================================*/
#ifndef float_tests_h
#define float_tests_h
diff --git a/test/half_to_double_from_rfc7049.c b/test/half_to_double_from_rfc7049.c
index 6380e51..d1e2f39 100644
--- a/test/half_to_double_from_rfc7049.c
+++ b/test/half_to_double_from_rfc7049.c
@@ -22,7 +22,7 @@
b) the license may be an issue
QCBOR does support half-precision, but rather than using
- floating point math like this, it does it with bit shifting
+ floating-point math like this, it does it with bit shifting
and masking.
This code is here to test that code.
diff --git a/test/half_to_double_from_rfc7049.h b/test/half_to_double_from_rfc7049.h
index 9f69e35..4642f04 100644
--- a/test/half_to_double_from_rfc7049.h
+++ b/test/half_to_double_from_rfc7049.h
@@ -1,14 +1,14 @@
/*==============================================================================
half_to_double_from_rfc7049.h -- interface to IETF float conversion code.
- Copyright (c) 2018-2019, Laurence Lundblade. All rights reserved.
+ Copyright (c) 2018-2020, Laurence Lundblade. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
See BSD-3-Clause license in README.md
Created on 9/23/18
- ==============================================================================*/
+ ============================================================================*/
#ifndef half_to_double_from_rfc7049_h
#define half_to_double_from_rfc7049_h
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index f0a614d..8c2f093 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -1,6 +1,6 @@
/*==============================================================================
Copyright (c) 2016-2018, The Linux Foundation.
- Copyright (c) 2018-2019, Laurence Lundblade.
+ Copyright (c) 2018-2020, Laurence Lundblade.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -28,7 +28,7 @@
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ==============================================================================*/
+ =============================================================================*/
#include "qcbor_decode_tests.h"
#include "qcbor.h"
@@ -55,11 +55,6 @@
fflush(stdout);
}
-
-/*static void printencoded(const char *szLabel, const uint8_t *pEncoded, size_t nLen)
-{
- PrintUsefulBufC(szLabel, (UsefulBufC){pEncoded, nLen});
-}*/
#endif
@@ -104,7 +99,7 @@
if((nCBORError = QCBORDecode_GetNext(pDCtx, &Item)))
return nCBORError;
- if(Item.uDataType != QCBOR_TYPE_INT64 || // Todo; fix this for 32-bit machines
+ if(Item.uDataType != QCBOR_TYPE_INT64 || // Todo; fix for 32-bit machines
Item.val.int64 != -9223372036854775807LL - 1)
return -1;
@@ -460,8 +455,8 @@
/*
- Creates a simple CBOR array and returns it in *pEncoded. The array is malloced
- and needs to be freed. This is used by several tests.
+ Creates a simple CBOR array and returns it in *pEncoded. The array is
+ malloced and needs to be freed. This is used by several tests.
Two of the inputs can be set. Two other items in the array are fixed.
@@ -542,13 +537,22 @@
0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63,
0x73 } ;
-static int ParseOrderedArray(const uint8_t *pEncoded, size_t nLen, int64_t *pInt1, int64_t *pInt2, const uint8_t **pBuf3, size_t *pBuf3Len, const uint8_t **pBuf4, size_t *pBuf4Len)
+static int ParseOrderedArray(const uint8_t *pEncoded,
+ size_t nLen,
+ int64_t *pInt1,
+ int64_t *pInt2,
+ const uint8_t **pBuf3,
+ size_t *pBuf3Len,
+ const uint8_t **pBuf4,
+ size_t *pBuf4Len)
{
QCBORDecodeContext DCtx;
QCBORItem Item;
int nReturn = -1; // assume error until success
- QCBORDecode_Init(&DCtx, (UsefulBufC){pEncoded, nLen}, QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ (UsefulBufC){pEncoded, nLen},
+ QCBOR_DECODE_MODE_NORMAL);
// Make sure the first thing is a map
if(QCBORDecode_GetNext(&DCtx, &Item) != 0 || Item.uDataType != QCBOR_TYPE_ARRAY)
@@ -641,7 +645,9 @@
QCBORDecodeContext DCtx;
QCBORItem Item;
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(sEmpties), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(sEmpties),
+ QCBOR_DECODE_MODE_NORMAL);
// Array with 3 items
if(QCBORDecode_GetNext(&DCtx, &Item) != 0 ||
@@ -759,7 +765,8 @@
}
-static uint8_t spDeepArrays[] = {0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x80};
+static uint8_t spDeepArrays[] = {0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+ 0x81, 0x81, 0x81, 0x80};
int ParseDeepArrayTest()
{
@@ -767,7 +774,9 @@
int nReturn = 0;
int i;
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spDeepArrays), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spDeepArrays),
+ QCBOR_DECODE_MODE_NORMAL);
for(i = 0; i < 10; i++) {
QCBORItem Item;
@@ -784,10 +793,10 @@
}
// Big enough to test nesting to the depth of 24
-static uint8_t spTooDeepArrays[] = {0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
- 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
- 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
- 0x80};
+static uint8_t spTooDeepArrays[] = {0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+ 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+ 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+ 0x81, 0x81, 0x81, 0x80};
int ParseTooDeepArrayTest()
{
@@ -797,7 +806,9 @@
QCBORItem Item;
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spTooDeepArrays), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spTooDeepArrays),
+ QCBOR_DECODE_MODE_NORMAL);
for(i = 0; i < QCBOR_MAX_ARRAY_NESTING1; i++) {
@@ -825,7 +836,9 @@
for(int nNum = sizeof(spExpectedEncodedInts)-1; nNum; nNum--) {
QCBORDecodeContext DCtx;
- QCBORDecode_Init(&DCtx, (UsefulBufC){spExpectedEncodedInts, nNum}, QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ (UsefulBufC){spExpectedEncodedInts, nNum},
+ QCBOR_DECODE_MODE_NORMAL);
const QCBORError nErr = IntegerValuesParseTestInternal(&DCtx);
@@ -876,7 +889,9 @@
QCBORItem Item;
int nCBORError;
- QCBORDecode_Init(&DCtx, (UsefulBufC){pValidMapEncoded, sizeof(pValidMapEncoded)}, nMode);
+ QCBORDecode_Init(&DCtx,
+ (UsefulBufC){pValidMapEncoded, sizeof(pValidMapEncoded)},
+ nMode);
if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item))) {
return nCBORError;
@@ -1001,7 +1016,9 @@
QCBORItem Item;
int nCBORError;
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapEncoded), QCBOR_DECODE_MODE_MAP_AS_ARRAY);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapEncoded),
+ QCBOR_DECODE_MODE_MAP_AS_ARRAY);
if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item))) {
return nCBORError;
@@ -1208,7 +1225,9 @@
QCBORItem Item;
int nCBORError;
- QCBORDecode_Init(&DCtx, (UsefulBufC){pValidMapEncoded, sizeof(pValidMapEncoded)}, QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ (UsefulBufC){pValidMapEncoded, sizeof(pValidMapEncoded)},
+ QCBOR_DECODE_MODE_NORMAL);
if(nLevel < 1) {
if(QCBORDecode_Finish(&DCtx) != QCBOR_ERR_EXTRA_BYTES) {
@@ -1415,7 +1434,9 @@
}
-static uint8_t spSimpleValues[] = {0x8a, 0xf4, 0xf5, 0xf6, 0xf7, 0xff, 0xe0, 0xf3, 0xf8, 0x00, 0xf8, 0x13, 0xf8, 0x1f, 0xf8, 0x20, 0xf8, 0xff};
+static uint8_t spSimpleValues[] = {0x8a, 0xf4, 0xf5, 0xf6, 0xf7, 0xff,
+ 0xe0, 0xf3, 0xf8, 0x00, 0xf8, 0x13,
+ 0xf8, 0x1f, 0xf8, 0x20, 0xf8, 0xff};
int ParseSimpleTest()
{
@@ -1424,7 +1445,9 @@
int nCBORError;
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spSimpleValues), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spSimpleValues),
+ QCBOR_DECODE_MODE_NORMAL);
if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item)))
@@ -1518,7 +1541,8 @@
const struct someBinaryBytes *pBytes = &paNotWellFormedCBOR[nIterate];
const UsefulBufC Input = (UsefulBufC){pBytes->p, pBytes->n};
- // Set up decoder context. String allocator needed for indefinite string test cases
+ // Set up decoder context. String allocator needed for indefinite
+ // string test cases
QCBORDecodeContext DCtx;
QCBORDecode_Init(&DCtx, Input, QCBOR_DECODE_MODE_NORMAL);
UsefulBuf_MAKE_STACK_UB(Pool, 100);
@@ -1653,9 +1677,11 @@
// Deeply nested indefinite length arrays with deepest one unclosed
{ {(uint8_t[]){0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff}, 9}, QCBOR_ERR_HIT_END },
// Mixed nesting with indefinite unclosed
- { {(uint8_t[]){0x9f, 0x81, 0x9f, 0x81, 0x9f, 0x9f, 0xff, 0xff, 0xff}, 9}, QCBOR_ERR_BAD_BREAK }, // TODO: think through this one
+ // TODO: think through this one
+ { {(uint8_t[]){0x9f, 0x81, 0x9f, 0x81, 0x9f, 0x9f, 0xff, 0xff, 0xff}, 9}, QCBOR_ERR_BAD_BREAK },
// Mixed nesting with definite unclosed
- { {(uint8_t[]){0x9f, 0x82, 0x9f, 0x81, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff}, 10}, QCBOR_ERR_BAD_BREAK }, // TODO: think through this one
+ // TODO: think through this one
+ { {(uint8_t[]){0x9f, 0x82, 0x9f, 0x81, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff}, 10}, QCBOR_ERR_BAD_BREAK },
// The "argument" for the data item is incomplete
@@ -1852,10 +1878,14 @@
// In addition to not-well-formed, some invalid CBOR
- { {(uint8_t[]){0xc0, 0x00}, 2}, QCBOR_ERR_BAD_OPT_TAG }, // Text-based date, with an integer
- { {(uint8_t[]){0xc1, 0x41, 0x33}, 3}, QCBOR_ERR_BAD_OPT_TAG }, // Epoch date, with an byte string
- { {(uint8_t[]){0xc1, 0xc0, 0x00}, 3}, QCBOR_ERR_BAD_OPT_TAG }, // tagged as both epoch and string dates
- { {(uint8_t[]){0xc2, 0x00}, 2}, QCBOR_ERR_BAD_OPT_TAG }, // big num tagged an int, not a byte string
+ // Text-based date, with an integer
+ { {(uint8_t[]){0xc0, 0x00}, 2}, QCBOR_ERR_BAD_OPT_TAG },
+ // Epoch date, with an byte string
+ { {(uint8_t[]){0xc1, 0x41, 0x33}, 3}, QCBOR_ERR_BAD_OPT_TAG },
+ // tagged as both epoch and string dates
+ { {(uint8_t[]){0xc1, 0xc0, 0x00}, 3}, QCBOR_ERR_BAD_OPT_TAG },
+ // big num tagged an int, not a byte string
+ { {(uint8_t[]){0xc2, 0x00}, 2}, QCBOR_ERR_BAD_OPT_TAG },
};
int DecodeFailureTests()
@@ -2014,7 +2044,9 @@
QCBORItem Item;
int nCBORError;
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spDateTestInput), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spDateTestInput),
+ QCBOR_DECODE_MODE_NORMAL);
const uint64_t uTags[] = {15};
QCBORTagListIn TagList = {1, uTags};
@@ -2080,7 +2112,8 @@
Item.val.epochDate.nSeconds == 0) {
return -12;
}
- // TODO: could use a few more tests with float, double, and half precsion and negative (but coverage is still pretty good)
+ // TODO: could use a few more tests with float, double, and half precsion
+ // and negative (but coverage is still pretty good)
return 0;
}
@@ -2096,7 +2129,8 @@
DB 9192939495969798 # tag(10489608748473423768)
80 # array(0)
*/
-static uint8_t spEncodedLargeTag[] = {0xdb, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x80};
+static uint8_t spEncodedLargeTag[] = {0xdb, 0x91, 0x92, 0x93, 0x94, 0x95,
+ 0x96, 0x97, 0x98, 0x80};
/*
DB 9192939495969798 # tag(10489608748473423768)
@@ -2105,7 +2139,8 @@
C7 # tag(7)
80 # array(0)
*/
-static uint8_t spLotsOfTags[] = {0xdb, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0xd8, 0x88, 0xc6, 0xc7, 0x80};
+static uint8_t spLotsOfTags[] = {0xdb, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
+ 0x97, 0x98, 0xd8, 0x88, 0xc6, 0xc7, 0x80};
/*
The cbor.me parse of this.
@@ -2158,7 +2193,9 @@
QCBORDecodeContext DCtx;
QCBORItem Item;
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spOptTestInput), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spOptTestInput),
+ QCBOR_DECODE_MODE_NORMAL);
//-------------------------
// This text matches the magic number tag and the fraction tag
@@ -2189,7 +2226,9 @@
// --------------------------------
// This test decodes the very large tag, but it is not in
// any list so it is ignored.
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spEncodedLargeTag), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spEncodedLargeTag),
+ QCBOR_DECODE_MODE_NORMAL);
if(QCBORDecode_GetNext(&DCtx, &Item)) {
return -6;
}
@@ -2198,8 +2237,11 @@
}
// ----------------------------------
- // This test sets up a caller-config list that includes the very large tage and then matches it.
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spEncodedLargeTag), QCBOR_DECODE_MODE_NORMAL);
+ // This test sets up a caller-config list that includes the very large
+ // tage and then matches it.
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spEncodedLargeTag),
+ QCBOR_DECODE_MODE_NORMAL);
const uint64_t puList[] = {0x9192939495969798, 257};
const QCBORTagListIn TL = {2, puList};
QCBORDecode_SetCallerConfiguredTagList(&DCtx, &TL);
@@ -2216,10 +2258,12 @@
}
//------------------------
- // This test sets up a caller-configured list, and looks up something not in it
+ // Sets up a caller-configured list and look up something not in it
const uint64_t puLongList[17] = {1,2,1};
const QCBORTagListIn TLLong = {17, puLongList};
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spEncodedLargeTag), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spEncodedLargeTag),
+ QCBOR_DECODE_MODE_NORMAL);
QCBORDecode_SetCallerConfiguredTagList(&DCtx, &TLLong);
if(QCBORDecode_GetNext(&DCtx, &Item)) {
return -11;
@@ -2227,7 +2271,9 @@
// -----------------------
// This tests retrievel of the full tag list
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spLotsOfTags), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spLotsOfTags),
+ QCBOR_DECODE_MODE_NORMAL);
uint64_t puTags[16];
QCBORTagListOut Out = {0, 4, puTags};
if(QCBORDecode_GetNextWithTags(&DCtx, &Item, &Out)) {
@@ -2242,7 +2288,9 @@
// ----------------------
// This text if too small of an out list
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spLotsOfTags), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spLotsOfTags),
+ QCBOR_DECODE_MODE_NORMAL);
QCBORTagListOut OutSmall = {0, 3, puTags};
if(QCBORDecode_GetNextWithTags(&DCtx, &Item, &OutSmall) != QCBOR_ERR_TOO_MANY_TAGS) {
return -14;
@@ -2250,14 +2298,18 @@
// ---------------
// Parse a version of the "CSR" that has had a ton of tags randomly inserted
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCSRWithTags), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCSRWithTags),
+ QCBOR_DECODE_MODE_NORMAL);
int n = CheckCSRMaps(&DCtx);
if(n) {
return n-2000;
}
Out = (QCBORTagListOut){0, 16, puTags};
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCSRWithTags), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCSRWithTags),
+ QCBOR_DECODE_MODE_NORMAL);
const uint64_t puTagList[] = {773, 1, 90599561};
const QCBORTagListIn TagList = {3, puTagList};
@@ -2462,7 +2514,9 @@
QCBORItem Item;
int nCBORError;
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBigNumInput), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBigNumInput),
+ QCBOR_DECODE_MODE_NORMAL);
//
@@ -2534,7 +2588,12 @@
-static int CheckItemWithIntLabel(QCBORDecodeContext *pCtx, uint8_t uDataType, uint8_t uNestingLevel, uint8_t uNextNest, int64_t nLabel, QCBORItem *pItem)
+static int CheckItemWithIntLabel(QCBORDecodeContext *pCtx,
+ uint8_t uDataType,
+ uint8_t uNestingLevel,
+ uint8_t uNextNest,
+ int64_t nLabel,
+ QCBORItem *pItem)
{
QCBORItem Item;
int nCBORError;
@@ -2542,7 +2601,10 @@
if((nCBORError = QCBORDecode_GetNext(pCtx, &Item))) return -1;
if(Item.uDataType != uDataType) return -1;
if(uNestingLevel > 0) {
- if(Item.uLabelType != QCBOR_TYPE_INT64 && Item.uLabelType != QCBOR_TYPE_UINT64) return -1;
+ if(Item.uLabelType != QCBOR_TYPE_INT64 &&
+ Item.uLabelType != QCBOR_TYPE_UINT64) {
+ return -1;
+ }
if(Item.uLabelType == QCBOR_TYPE_INT64) {
if(Item.label.int64 != nLabel) return -1;
} else {
@@ -2629,7 +2691,9 @@
{
QCBORDecodeContext DCtx;
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCSRInput), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCSRInput),
+ QCBOR_DECODE_MODE_NORMAL);
return CheckCSRMaps(&DCtx);
}
@@ -2640,7 +2704,9 @@
{
QCBORDecodeContext DCtx;
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCSRInput), QCBOR_DECODE_MODE_MAP_STRINGS_ONLY);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCSRInput),
+ QCBOR_DECODE_MODE_MAP_STRINGS_ONLY);
QCBORItem Item;
QCBORError nCBORError;
@@ -2678,7 +2744,9 @@
{
QCBORDecodeContext DCtx;
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCSRInputIndefLen), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCSRInputIndefLen),
+ QCBOR_DECODE_MODE_NORMAL);
return CheckCSRMaps(&DCtx);
}
@@ -2751,13 +2819,18 @@
}
-
-static const uint8_t spIndefiniteArray[] = {0x9f, 0x01, 0x82, 0x02, 0x03, 0xff}; // [1, [2, 3]]
-static const uint8_t spIndefiniteArrayBad1[] = {0x9f}; // No closing break
-static const uint8_t spIndefiniteArrayBad2[] = {0x9f, 0x9f, 0x02, 0xff}; // Not enough closing breaks
-static const uint8_t spIndefiniteArrayBad3[] = {0x9f, 0x02, 0xff, 0xff}; // Too many closing breaks
-static const uint8_t spIndefiniteArrayBad4[] = {0x81, 0x9f}; // Unclosed indeflen inside def len
-static const uint8_t spIndefiniteArrayBad5[] = {0x9f, 0xd1, 0xff}; // confused tag
+// [1, [2, 3]]
+static const uint8_t spIndefiniteArray[] = {0x9f, 0x01, 0x82, 0x02, 0x03, 0xff};
+// No closing break
+static const uint8_t spIndefiniteArrayBad1[] = {0x9f};
+// Not enough closing breaks
+static const uint8_t spIndefiniteArrayBad2[] = {0x9f, 0x9f, 0x02, 0xff};
+// Too many closing breaks
+static const uint8_t spIndefiniteArrayBad3[] = {0x9f, 0x02, 0xff, 0xff};
+// Unclosed indeflen inside def len
+static const uint8_t spIndefiniteArrayBad4[] = {0x81, 0x9f};
+// confused tag
+static const uint8_t spIndefiniteArrayBad5[] = {0x9f, 0xd1, 0xff};
int IndefiniteLengthArrayMapTest()
{
@@ -3030,7 +3103,9 @@
}
// ----- types mismatch ---
- QCBORDecode_Init(&DC, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spIndefiniteLenStringBad2), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DC,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spIndefiniteLenStringBad2),
+ QCBOR_DECODE_MODE_NORMAL);
if(QCBORDecode_SetMemPool(&DC, MemPool, false)) {
return -7;
@@ -3048,7 +3123,9 @@
}
// ----- not a string ---
- QCBORDecode_Init(&DC, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spIndefiniteLenStringBad3), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DC,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spIndefiniteLenStringBad3),
+ QCBOR_DECODE_MODE_NORMAL);
if(QCBORDecode_SetMemPool(&DC, MemPool, false)) {
return -11;
@@ -3066,7 +3143,9 @@
}
// ----- no end -----
- QCBORDecode_Init(&DC, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spIndefiniteLenStringBad4), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DC,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spIndefiniteLenStringBad4),
+ QCBOR_DECODE_MODE_NORMAL);
if(QCBORDecode_SetMemPool(&DC, MemPool, false)) {
return -15;
@@ -3107,7 +3186,8 @@
UsefulBuf_MAKE_STACK_UB(BigIndefBStrStorage, 290);
const UsefulBufC BigIndefBStr = MakeIndefiniteBigBstr(BigIndefBStrStorage);
- UsefulBuf_MAKE_STACK_UB(MemPoolSmall, 80); // 80 is big enough for MemPool overhead, but not BigIndefBStr
+ // 80 is big enough for MemPool overhead, but not BigIndefBStr
+ UsefulBuf_MAKE_STACK_UB(MemPoolSmall, 80);
QCBORDecode_Init(&DC, BigIndefBStr, QCBOR_DECODE_MODE_NORMAL);
if(QCBORDecode_SetMemPool(&DC, MemPoolSmall, false)) {
@@ -3164,7 +3244,8 @@
if(QCBORDecode_GetNext(&DC, &Item)){
return -32;
}
- if(Item.uLabelType != QCBOR_TYPE_TEXT_STRING || Item.uDataType != QCBOR_TYPE_INT64 ||
+ if(Item.uLabelType != QCBOR_TYPE_TEXT_STRING ||
+ Item.uDataType != QCBOR_TYPE_INT64 ||
Item.uDataAlloc || !Item.uLabelAlloc ||
UsefulBuf_Compare(Item.label.string, UsefulBuf_FromSZ("struuming"))) {
return -33;
@@ -3185,7 +3266,9 @@
// First test, use the "CSRMap" as easy input and checking
- QCBORDecode_Init(&DC, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCSRInput), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DC,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spCSRInput),
+ QCBOR_DECODE_MODE_NORMAL);
UsefulBuf_MAKE_STACK_UB(Pool, sizeof(spCSRInput) + QCBOR_DECODE_MIN_MEM_POOL_SIZE);
@@ -3257,7 +3340,9 @@
// Next parse with a pool that is too small
UsefulBuf_MAKE_STACK_UB(SmallPool, QCBOR_DECODE_MIN_MEM_POOL_SIZE + 1);
- QCBORDecode_Init(&DC, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapEncoded), QCBOR_DECODE_MODE_NORMAL);
+ QCBORDecode_Init(&DC,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapEncoded),
+ QCBOR_DECODE_MODE_NORMAL);
QCBORDecode_SetMemPool(&DC, SmallPool, 1); // Turn on copying.
if((nCBORError = QCBORDecode_GetNext(&DC, &Item1)))
return -8;
diff --git a/test/qcbor_decode_tests.h b/test/qcbor_decode_tests.h
index f0d1d9a..2c556b8 100644
--- a/test/qcbor_decode_tests.h
+++ b/test/qcbor_decode_tests.h
@@ -1,6 +1,6 @@
/*==============================================================================
Copyright (c) 2016-2018, The Linux Foundation.
- Copyright (c) 2018-2019, Laurence Lundblade.
+ Copyright (c) 2018-2020, Laurence Lundblade.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -28,7 +28,7 @@
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ==============================================================================*/
+ ============================================================================*/
#ifndef __QCBOR__qcbort_decode_tests__
#define __QCBOR__qcbort_decode_tests__
diff --git a/test/qcbor_encode_tests.c b/test/qcbor_encode_tests.c
index ab4fd7a..9a7aecf 100644
--- a/test/qcbor_encode_tests.c
+++ b/test/qcbor_encode_tests.c
@@ -1,6 +1,6 @@
/*==============================================================================
Copyright (c) 2016-2018, The Linux Foundation.
- Copyright (c) 2018-2019, Laurence Lundblade.
+ Copyright (c) 2018-2020, Laurence Lundblade.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -28,7 +28,7 @@
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ==============================================================================*/
+ =============================================================================*/
#include "qcbor.h"
#include "qcbor_encode_tests.h"
@@ -47,11 +47,12 @@
*/
-//#define PRINT_FUNCTIONS_FOR_DEBUGGINGXX
+//#define PRINT_FUNCTIONS_FOR_DEBUGGING
-#ifdef PRINT_FUNCTIONS_FOR_DEBUGGINGXX
+#ifdef PRINT_FUNCTIONS_FOR_DEBUGGING
#include <stdio.h>
+#if 0
// ifdef these out to not have compiler warnings
static void printencoded(const uint8_t *pEncoded, size_t nLen)
{
@@ -64,6 +65,7 @@
fflush(stdout);
}
+#endif
// Do the comparison and print out where it fails
@@ -71,7 +73,10 @@
size_t i;
for(i = 0; i < U1.len; i++) {
if(((uint8_t *)U1.ptr)[i] != ((uint8_t *)U2.ptr)[i]) {
- printf("Position: %d Actual: 0x%x Expected: 0x%x\n", i, ((uint8_t *)U1.ptr)[i], ((uint8_t *)U2.ptr)[i]);
+ printf("Position: %d Actual: 0x%x Expected: 0x%x\n",
+ (uint32_t)i,
+ ((uint8_t *)U1.ptr)[i],
+ ((uint8_t *)U2.ptr)[i]);
return 1;
}
}
@@ -104,7 +109,10 @@
size_t uOffset;
};
-static int32_t UsefulBuf_CompareWithDiagnostic(UsefulBufC Actual, UsefulBufC Expected, struct UBCompareDiagnostic *pDiag) {
+static int32_t
+UsefulBuf_CompareWithDiagnostic(UsefulBufC Actual,
+ UsefulBufC Expected,
+ struct UBCompareDiagnostic *pDiag) {
size_t i;
for(i = 0; i < Actual.len; i++) {
if(((uint8_t *)Actual.ptr)[i] != ((uint8_t *)Expected.ptr)[i]) {
@@ -113,7 +121,9 @@
pDiag->uExpected = ((uint8_t *)Expected.ptr)[i];
pDiag->uOffset = i;
}
- return (int32_t)i + 1000000; // Cast to int is OK as this is only a diagnostic and the sizes here are never over a few KB.
+ // Cast to int is OK as this is only a diagnostic and the sizes
+ // here are never over a few KB.
+ return (int32_t)i + 1000000;
}
}
return 0;
@@ -169,7 +179,8 @@
}
- // Make another encoded message with the CBOR from the previous put into this one
+ // Make another encoded message with the CBOR from the previous
+ // put into this one
UsefulBuf_MAKE_STACK_UB(MemoryForEncoded2, 20);
QCBOREncode_Init(&EC, MemoryForEncoded2);
QCBOREncode_OpenArray(&EC);
@@ -246,7 +257,10 @@
// 2 1:1 2:1 3:1
QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_MAP || Item.val.uCount != 1 || Item.uLabelType != QCBOR_TYPE_INT64 || Item.label.int64 != -70000) {
+ if(Item.uDataType != QCBOR_TYPE_MAP ||
+ Item.val.uCount != 1 ||
+ Item.uLabelType != QCBOR_TYPE_INT64 ||
+ Item.label.int64 != -70000) {
return -11;
}
@@ -499,7 +513,8 @@
int AllAddMethodsTest()
{
- // TODO: this test should be broken down into several so it is more managable. Tags and labels could be more sensible
+ // TODO: this test should be broken down into several so it is more
+ // managable. Tags and labels could be more sensible
QCBOREncodeContext ECtx;
int nReturn = 0;
@@ -507,7 +522,8 @@
QCBOREncode_OpenArray(&ECtx);
- // Some ints that are tagged and have strings preceeding them (not labels becase it is not a map)
+ // Some ints that are tagged and have strings preceeding them
+ // (not labels becase it is not a map)
QCBOREncode_AddSZString(&ECtx, "UINT62");
QCBOREncode_AddTag(&ECtx, 100);
QCBOREncode_AddUInt64(&ECtx, 89989909);
@@ -550,7 +566,9 @@
// text blobs
QCBOREncode_AddText(&ECtx, UsefulBuf_FROM_SZ_LITERAL("bar bar foo bar"));
QCBOREncode_AddSZString(&ECtx, "oof\n");
- QCBOREncode_AddURI(&ECtx, UsefulBuf_FROM_SZ_LITERAL("http://stackoverflow.com/questions/28059697/how-do-i-toggle-between-debug-and-release-builds-in-xcode-6-7-8"));
+ const char *szURL =
+ "http://stackoverflow.com/questions/28059697/how-do-i-toggle-between-debug-and-release-builds-in-xcode-6-7-8";
+ QCBOREncode_AddURI(&ECtx, UsefulBuf_FromSZ(szURL));
QCBOREncode_AddB64Text(&ECtx, UsefulBuf_FROM_SZ_LITERAL("YW55IGNhcm5hbCBwbGVhc3VyZQ=="));
QCBOREncode_AddRegex(&ECtx, UsefulBuf_FROM_SZ_LITERAL("[^abc]+"));
QCBOREncode_AddMIMEData(&ECtx, UsefulBuf_FromSZ(szMIME));
@@ -565,7 +583,9 @@
QCBOREncode_AddTextToMapN(&ECtx,22, UsefulBuf_FROM_SZ_LITERAL("foo foo foo foo"));
QCBOREncode_AddSZStringToMap(&ECtx, "^^", "oooooooof");
QCBOREncode_AddSZStringToMapN(&ECtx, 99, "ffffoooooooof");
- QCBOREncode_AddURIToMap(&ECtx, "RFC", UsefulBuf_FROM_SZ_LITERAL("https://tools.ietf.org/html/rfc7049#section-2.4.5"));
+ QCBOREncode_AddURIToMap(&ECtx,
+ "RFC",
+ UsefulBuf_FROM_SZ_LITERAL("https://tools.ietf.org/html/rfc7049#section-2.4.5"));
QCBOREncode_AddURIToMapN(&ECtx, 0x89, UsefulBuf_FROM_SZ_LITERAL("http://cbor.me/"));
QCBOREncode_AddB64TextToMap(&ECtx, "whenim64", UsefulBuf_FROM_SZ_LITERAL("cGxlYXN1cmUu"));
QCBOREncode_AddB64TextToMapN(&ECtx, 64, UsefulBuf_FROM_SZ_LITERAL("c3VyZS4="));
@@ -639,7 +659,9 @@
QCBOREncode_CloseMap(&ECtx);
// UUIDs
- static const uint8_t ppppUUID[] = {0x53, 0x4D, 0x41, 0x52, 0x54, 0x43, 0x53, 0x4C, 0x54, 0x54, 0x43, 0x46, 0x49, 0x43, 0x41, 0x32};
+ static const uint8_t ppppUUID[] = {0x53, 0x4D, 0x41, 0x52, 0x54, 0x43,
+ 0x53, 0x4C, 0x54, 0x54, 0x43, 0x46,
+ 0x49, 0x43, 0x41, 0x32};
const UsefulBufC XXUUID = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(ppppUUID);
QCBOREncode_AddBinaryUUID(&ECtx, XXUUID);
QCBOREncode_OpenMap(&ECtx);
@@ -1520,11 +1542,13 @@
/*
@brief Encode the RTIC results
- @param[in] nRResult CBOR_SIMPLEV_TRUE, CBOR_SIMPLEV_FALSE or CBOR_SIMPLEV_NULL
- @param[in] time Time stamp in UNIX epoch time or 0 for no time stamp
+ @param[in] nRResult CBOR_SIMPLEV_TRUE, CBOR_SIMPLEV_FALSE or
+ CBOR_SIMPLEV_NULL
+ @param[in] time Time stamp in UNIX epoch time or 0 for none
@param[in] szAlexString Diagnostic code.
@param[in[ pOut Buffer to put the result in
- @param[in/out] pnLen Size of pOut buffer when called; length of data output in buffer on return
+ @param[in/out] pnLen Size of pOut buffer when called; length of data
+ output in buffer on return
@return
One of the CBOR encoder errors. QCBOR_SUCCESS, which is has value 0, if no error.
@@ -1538,11 +1562,17 @@
*/
-static UsefulBufC FormatRTICResults(int nRResult, uint64_t time, const char *szType, const char *szAlexString, UsefulBuf Storage)
+static UsefulBufC
+FormatRTICResults(int nRResult,
+ uint64_t time,
+ const char *szType,
+ const char *szAlexString,
+ UsefulBuf Storage)
{
// Buffer that the result will be written in to
// It is fixed size and small that a stack variable will be fine
- // QCBOREncode will never write off the end of this buffer. If it won't fit QCBOREncode_Finish will return an error.
+ // QCBOREncode will never write off the end of this buffer. If it won't
+ // fit QCBOREncode_Finish will return an error.
// Context for the encoder
QCBOREncodeContext ECtx;
@@ -1554,7 +1584,8 @@
{ // Brace / indention just to show CBOR encoding nesting
- // The result: 0 if scan happened and found nothing; 1 if it happened and found something wrong; 2 if it didn't happen
+ // The result: 0 if scan happened and found nothing; 1 if it happened and
+ // found something wrong; 2 if it didn't happen
QCBOREncode_AddSimpleToMap(&ECtx, "integrity", nRResult);
// Add the diagnostic code
@@ -1721,7 +1752,8 @@
QCBOREncode_CloseArray(&EC);
UsefulBufC BStr;
QCBOREncode_CloseBstrWrap(&EC, &BStr);
- // 3 is one byte for the wrapping bstr, 1 for an array of length 1, and 1 byte for a NULL
+ // 3 is one byte for the wrapping bstr, 1 for an array of length 1,
+ // and 1 byte for a NULL
if(BStr.ptr != NULL || BStr.len != 3) {
return -5;
}
@@ -1747,7 +1779,7 @@
int BstrWrapErrorTest()
{
- // -------------- Test closing a bstrwrap when it is an array that is open -----------
+ // ---- Test closing a bstrwrap when it is an array that is open ---------
QCBOREncodeContext EC;
QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
@@ -1769,7 +1801,7 @@
return -1;
}
- // ----------- test closing a bstrwrap when nothing is open ---------------------
+ // -------- test closing a bstrwrap when nothing is open ----------------
QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
QCBOREncode_CloseBstrWrap(&EC, &Wrapped);
if(QCBOREncode_Finish(&EC, &Encoded2) != QCBOR_ERR_TOO_MANY_CLOSES) {
@@ -2204,7 +2236,8 @@
// ------ Test for QCBOR_ERR_BUFFER_TOO_LARGE ------
- // Do all of these tests with NULL buffers so no actual large allocations are neccesary
+ // Do all of these tests with NULL buffers so no actual
+ // large allocations are neccesary
const UsefulBuf Buffer = (UsefulBuf){NULL, UINT32_MAX};
// First verify no error from a big buffer
diff --git a/test/qcbor_encode_tests.h b/test/qcbor_encode_tests.h
index 1cd8e7b..3d11883 100644
--- a/test/qcbor_encode_tests.h
+++ b/test/qcbor_encode_tests.h
@@ -1,6 +1,6 @@
/*==============================================================================
Copyright (c) 2016-2018, The Linux Foundation.
- Copyright (c) 2018-2019, Laurence Lundblade.
+ Copyright (c) 2018-2020, Laurence Lundblade.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -28,7 +28,7 @@
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ==============================================================================*/
+ =============================================================================*/
#ifndef __QCBOR__qcbor_encode_tests__
#define __QCBOR__qcbor_encode_tests__
@@ -37,7 +37,8 @@
/*
Notes:
- - All the functions in qcbor.h are called once in the aggregation of all the tests below.
+ - All the functions in qcbor.h are called once in the aggregation of all
+ the tests below.
- All the types that are supported are given as input and parsed by these tests
@@ -54,43 +55,45 @@
/*
- Encode lots of integer values, particularly around the boundary and make sure they
- Match the expected binary output. Primarily an encoding test.
+ Encode lots of integer values, particularly around the boundary and
+ make sure they Match the expected binary output. Primarily an
+ encoding test.
*/
int IntegerValuesTest1(void);
/*
- Create nested arrays to the max depth allowed and make sure it succeeds.
- This is an encoding test.
+ Create nested arrays to the max depth allowed and make sure it
+ succeeds. This is an encoding test.
*/
int ArrayNestingTest1(void);
/*
- Create nested arrays to one more than the meax depth and make sure it fails.
- This is an encoding test.
+ Create nested arrays to one more than the meax depth and make sure it
+ fails. This is an encoding test.
*/
int ArrayNestingTest2(void);
/*
- Encoding test.
- Create arrays to max depth and close one extra time and look for correct error code
+ Encoding test. Create arrays to max depth and close one extra time
+ and look for correct error code
*/
int ArrayNestingTest3(void);
/*
- This tests the QCBOREncode_AddRaw() function by adding two chunks or RAWCBOR to an
- array and comparing with expected values. This is an encoding test.
+ This tests the QCBOREncode_AddRaw() function by adding two chunks or
+ RAWCBOR to an array and comparing with expected values. This is an
+ encoding test.
*/
int EncodeRawTest(void);
/*
- This creates a somewhat complicated CBOR MAP and verifies it against expected
- data. This is an encoding test.
+ This creates a somewhat complicated CBOR MAP and verifies it against
+ expected data. This is an encoding test.
*/
int MapEncodeTest(void);
@@ -112,9 +115,10 @@
*/
int SimpleValuesIndefiniteLengthTest1(void);
+
/*
- Indefinite length arrays and maps use the 'magic' number 31, verify that
- everything with length 31 still works properly
+ Indefinite length arrays and maps use the 'magic' number 31, verify
+ that everything with length 31 still works properly
*/
int EncodeLengthThirtyoneTest(void);
diff --git a/test/run_tests.c b/test/run_tests.c
index aba536d..192e319 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -1,14 +1,14 @@
/*==============================================================================
run_tests.c -- test aggregator and results reporting
- Copyright (c) 2018-2019, Laurence Lundblade. All rights reserved.
+ Copyright (c) 2018-2020, Laurence Lundblade. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
See BSD-3-Clause license in README.md
Created on 9/30/18
- ==============================================================================*/
+ =============================================================================*/
#include "run_tests.h"
#include "UsefulBuf.h"
@@ -157,7 +157,10 @@
/*
Public function. See run_test.h.
*/
-int RunTests(const char *szTestNames[], OutputStringCB pfOutput, void *poutCtx, int *pNumTestsRun)
+int RunTests(const char *szTestNames[],
+ OutputStringCB pfOutput,
+ void *poutCtx,
+ int *pNumTestsRun)
{
int nTestsFailed = 0;
int nTestsRun = 0;
@@ -276,7 +279,10 @@
/*
Public function. See run_test.h.
*/
-static void PrintSize(const char *szWhat, uint32_t uSize, OutputStringCB pfOutput, void *pOutCtx)
+static void PrintSize(const char *szWhat,
+ uint32_t uSize,
+ OutputStringCB pfOutput,
+ void *pOutCtx)
{
UsefulBuf_MAKE_STACK_UB(buffer, 20);
@@ -292,13 +298,13 @@
*/
void PrintSizes(OutputStringCB pfOutput, void *pOutCtx)
{
- // Type and size of return from sizeof() varies. These will never be large so cast is safe
- PrintSize("sizeof(QCBORTrackNesting)", (uint32_t)sizeof(QCBORTrackNesting), pfOutput, pOutCtx);
+ // These will never be large so cast is safe
+ PrintSize("sizeof(QCBORTrackNesting)", (uint32_t)sizeof(QCBORTrackNesting), pfOutput, pOutCtx);
PrintSize("sizeof(QCBOREncodeContext)", (uint32_t)sizeof(QCBOREncodeContext), pfOutput, pOutCtx);
PrintSize("sizeof(QCBORDecodeNesting)", (uint32_t)sizeof(QCBORDecodeNesting), pfOutput, pOutCtx);
PrintSize("sizeof(QCBORDecodeContext)", (uint32_t)sizeof(QCBORDecodeContext), pfOutput, pOutCtx);
- PrintSize("sizeof(QCBORItem)", (uint32_t)sizeof(QCBORItem), pfOutput, pOutCtx);
- PrintSize("sizeof(QCBORTagListIn)", (uint32_t)sizeof(QCBORTagListIn), pfOutput, pOutCtx);
- PrintSize("sizeof(QCBORTagListOut)", (uint32_t)sizeof(QCBORTagListOut), pfOutput, pOutCtx);
+ PrintSize("sizeof(QCBORItem)", (uint32_t)sizeof(QCBORItem), pfOutput, pOutCtx);
+ PrintSize("sizeof(QCBORTagListIn)", (uint32_t)sizeof(QCBORTagListIn), pfOutput, pOutCtx);
+ PrintSize("sizeof(QCBORTagListOut)", (uint32_t)sizeof(QCBORTagListOut), pfOutput, pOutCtx);
(*pfOutput)("", pOutCtx, 1);
}
diff --git a/test/run_tests.h b/test/run_tests.h
index 734d4f8..97f2946 100644
--- a/test/run_tests.h
+++ b/test/run_tests.h
@@ -1,14 +1,14 @@
/*==============================================================================
run_tests.h -- test aggregator and results reporting
- Copyright (c) 2018-2019, Laurence Lundblade. All rights reserved.
+ Copyright (c) 2018-2020, Laurence Lundblade. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
See BSD-3-Clause license in README.md
Created 9/30/18
- ==============================================================================*/
+ =============================================================================*/
/**
@file run_tests.h
@@ -53,7 +53,10 @@
@return The number of tests that failed. Zero means overall success.
*/
-int RunTests(const char *szTestNames[], OutputStringCB pfOutput, void *pOutCtx, int *pNumTestsRun);
+int RunTests(const char *szTestNames[],
+ OutputStringCB pfOutput,
+ void *pOutCtx,
+ int *pNumTestsRun);
/**