Minor clean up of test code headers
diff --git a/test/qcbor_decode_tests.h b/test/qcbor_decode_tests.h
index dfac338..6423ccf 100644
--- a/test/qcbor_decode_tests.h
+++ b/test/qcbor_decode_tests.h
@@ -33,8 +33,6 @@
#ifndef __QCBOR__qcbort_decode_tests__
#define __QCBOR__qcbort_decode_tests__
-#include "qcbor.h"
-
/*
Notes:
@@ -49,8 +47,6 @@
*/
-
-
/*
Parse a well-known set of integers including those around the boundaries and
make sure the expected values come out
@@ -58,15 +54,13 @@
int IntegerValuesParseTest(void);
-
-
-
/*
Decode a simple CBOR encoded array and make sure it returns all the correct values.
This is a decode test.
*/
int SimpleArrayTest(void);
+
/*
Tests with empty maps and arrays
*/
@@ -117,21 +111,15 @@
int ParseMapTest(void);
-
-int FloatValuesTest1(void);
-
-
-
-int SimpleValuesTest1(void);
-
-
/*
-
+Test the decoder mode where maps are treated as arrays.
*/
int ParseMapAsArrayTest(void);
-
+/*
+ Test parsing of some simple values like true, false, null...
+ */
int ParseSimpleTest(void);
@@ -188,6 +176,9 @@
int BignumParseTest(void);
+/*
+ Test of mode where only string labels are allowed
+ */
int StringDecoderModeFailTest(void);
@@ -244,6 +235,4 @@
int SetUpAllocatorTest(void);
-
-
#endif /* defined(__QCBOR__qcbort_decode_tests__) */
diff --git a/test/qcbor_encode_tests.h b/test/qcbor_encode_tests.h
index 6f921c2..7909288 100644
--- a/test/qcbor_encode_tests.h
+++ b/test/qcbor_encode_tests.h
@@ -33,8 +33,6 @@
#ifndef __QCBOR__qcbor_encode_tests__
#define __QCBOR__qcbor_encode_tests__
-#include "qcbor.h"
-
/*
Notes:
@@ -62,7 +60,6 @@
int IntegerValuesTest1(void);
-
/*
Create nested arrays to the max depth allowed and make sure it succeeds.
This is an encoding test.
@@ -98,7 +95,6 @@
int MapEncodeTest(void);
-
/*
Encodes a goodly number of floats and doubles and checks encoding is right
*/
@@ -144,14 +140,32 @@
*/
int BstrWrapTest(void);
+
+/*
+ Test error cases for bstr wrapping encoding such as closing an open
+ array with CloseBstrWrap
+ */
int BstrWrapErrorTest(void);
+
+/*
+ Test complicated nested bstr wrapping
+ */
int BstrWrapNestTest(void);
+
+/*
+ Test encoding a COSE_Sign1 with bstr wrapping
+ */
int CoseSign1TBSTest(void);
-int EncodeErrorTests(void);
+/*
+ Test the error cases when encoding CBOR such as buffer too large,
+ buffer too small, array nesting too deep. Aims to cover the error
+ codes returned when encoding CBOR
+ */
+int EncodeErrorTests(void);
#endif /* defined(__QCBOR__qcbor_encode_tests__) */
diff --git a/test/run_tests.c b/test/run_tests.c
index becd545..ce4d52b 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -20,54 +20,9 @@
#include "UsefulBuf_Tests.h"
-
-// Used to test RunTests
-int fail_test()
-{
- return -44;
-}
-
-
-
-
/*
- Convert a number up to 999999999 to a string. This is so sprintf doesn't
- have to be linked in so as to minimized dependencies even in test code.
- */
-const char *NumToString(int32_t nNum, UsefulBuf StringMem)
-{
- const int32_t nMax = 1000000000;
-
- UsefulOutBuf OutBuf;
- UsefulOutBuf_Init(&OutBuf, StringMem);
-
- if(nNum < 0) {
- UsefulOutBuf_AppendByte(&OutBuf, '-');
- nNum = -nNum;
- }
- if(nNum > nMax-1) {
- return "XXX";
- }
-
- bool bDidSomeOutput = false;
- for(int n = nMax; n > 0; n/=10) {
- int x = nNum/n;
- if(x || bDidSomeOutput){
- bDidSomeOutput = true;
- UsefulOutBuf_AppendByte(&OutBuf, '0' + x);
- nNum -= x * n;
- }
- }
- if(!bDidSomeOutput){
- UsefulOutBuf_AppendByte(&OutBuf, '0');
- }
- UsefulOutBuf_AppendByte(&OutBuf, '\0');
-
- return UsefulOutBuf_GetError(&OutBuf) ? "" : StringMem.ptr;
-}
-
-
-
+ Test configuration
+ */
typedef int (test_fun_t)(void);
typedef const char * (test_fun2_t)(void);
@@ -88,7 +43,8 @@
bool bEnabled;
} test_entry2;
-test_entry2 s_tests2[] = {
+
+static test_entry2 s_tests2[] = {
TEST_ENTRY(UBUTest_CopyUtil),
TEST_ENTRY(UOBTest_NonAdversarial),
TEST_ENTRY(TestBasicSanity),
@@ -99,7 +55,7 @@
};
-test_entry s_tests[] = {
+static test_entry s_tests[] = {
TEST_ENTRY(EmptyMapsAndArraysTest),
TEST_ENTRY(NotWellFormedTests),
TEST_ENTRY(ParseMapAsArrayTest),
@@ -147,10 +103,51 @@
TEST_ENTRY(SetUpAllocatorTest),
TEST_ENTRY(SimpleValuesIndefiniteLengthTest1),
TEST_ENTRY(EncodeLengthThirtyoneTest),
- //TEST_ENTRY(fail_test),
};
+
+
+/*
+ Convert a number up to 999999999 to a string. This is so sprintf doesn't
+ have to be linked in so as to minimized dependencies even in test code.
+ */
+static const char *NumToString(int32_t nNum, UsefulBuf StringMem)
+{
+ const int32_t nMax = 1000000000;
+
+ UsefulOutBuf OutBuf;
+ UsefulOutBuf_Init(&OutBuf, StringMem);
+
+ if(nNum < 0) {
+ UsefulOutBuf_AppendByte(&OutBuf, '-');
+ nNum = -nNum;
+ }
+ if(nNum > nMax-1) {
+ return "XXX";
+ }
+
+ bool bDidSomeOutput = false;
+ for(int n = nMax; n > 0; n/=10) {
+ int x = nNum/n;
+ if(x || bDidSomeOutput){
+ bDidSomeOutput = true;
+ UsefulOutBuf_AppendByte(&OutBuf, '0' + x);
+ nNum -= x * n;
+ }
+ }
+ if(!bDidSomeOutput){
+ UsefulOutBuf_AppendByte(&OutBuf, '0');
+ }
+ UsefulOutBuf_AppendByte(&OutBuf, '\0');
+
+ return UsefulOutBuf_GetError(&OutBuf) ? "" : StringMem.ptr;
+}
+
+
+/*
+ Public function. See run_test.h.
+ */
int RunTests(const char *szTestNames[], OutputStringCB pfOutput, void *poutCtx, int *pNumTestsRun)
{
int nTestsFailed = 0;
@@ -264,8 +261,11 @@
}
+#include "qcbor.h" // For size printing
-
+/*
+ Public function. See run_test.h.
+ */
static void PrintSize(const char *szWhat, uint32_t uSize, OutputStringCB pfOutput, void *pOutCtx)
{
UsefulBuf_MAKE_STACK_UB(buffer, 20);
@@ -276,6 +276,10 @@
(*pfOutput)("", pOutCtx, 1);
}
+
+/*
+ Public function. See run_test.h.
+ */
void PrintSizes(OutputStringCB pfOutput, void *pOutCtx)
{
// Type and size of return from sizeof() varies. These will never be large so cast is safe