fold basic and indefinite length tests in with the others; fix up Makefile
diff --git a/Makefile b/Makefile
index 233164b..c739908 100644
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,8 @@
QCBOR_OBJ=src/UsefulBuf.o src/qcbor_encode.o src/qcbor_decode.o src/ieee754.o
-TEST_OBJ=test/basic_test.o test/bstrwrap_tests.o test/run_tests.o test/half_precision_test.o \
- test/half_to_double_from_rfc7049.o
+TEST_OBJ=test/UsefulBuf_Tests.o test/qcbor_encode_tests.o test/qcbor_decode_tests.o test/run_tests.o \
+ test/float_tests.o test/half_to_double_from_rfc7049.o
CMD_LINE_OBJ=$(QCBOR_OBJ) $(TEST_OBJ) cmd_line_main.o
@@ -15,10 +15,12 @@
src/qcbor_encode.o: inc/UsefulBuf.h inc/qcbor.h src/ieee754.h
src/iee754.o: src/ieee754.h
-test/basic_test.o: test/basic_test.h inc/qcbor.h inc/UsefulBuf.h
-test/bstrwrap_tests.o: test/bstrwrap_tests.h inc/qcbor.h inc/UsefulBuf.h
-test/run_tests.o: test/half_precision_test.h test/run_tests.h test/basic_test.h test/bstrwrap_tests.h
-test/half_precision_test.o: inc/qcbor.h test/half_precision_test.h test/half_to_double_from_rfc7049.h
+test/run_tests.o: test/UsefulBuf_Tests.h test/float_tests.h test/run_tests.h test/qcbor_encode_tests.h\
+ test/qcbor_decode_tests.h
+test/UsefulBuf_Tests.o: test/UsefulBuf_Tests.h inc/qcbor.h inc/UsefulBuf.h
+test/qcbor_encode_tests.o: test/qcbor_encode_tests.h inc/qcbor.h inc/UsefulBuf.h
+test/qcbor_decode_tests.o: test/qcbor_decode_tests.h inc/qcbor.h inc/UsefulBuf.h
+test/float_tests.o: inc/qcbor.h inc/UsefulBuf.h test/float_tests.h test/half_to_double_from_rfc7049.h
test/half_to_double_from_rfc7049.o: test/half_to_double_from_rfc7049.h
cmd_line_main.o: test/run_tests.h
diff --git a/QCBOR.xcodeproj/project.pbxproj b/QCBOR.xcodeproj/project.pbxproj
index 36f89be..7dd2403 100644
--- a/QCBOR.xcodeproj/project.pbxproj
+++ b/QCBOR.xcodeproj/project.pbxproj
@@ -19,7 +19,6 @@
E776E090214AE07500E67947 /* UsefulBuf.c in Sources */ = {isa = PBXBuildFile; fileRef = E776E08D214AE07500E67947 /* UsefulBuf.c */; };
E776E091214AE07500E67947 /* qcbor_decode.c in Sources */ = {isa = PBXBuildFile; fileRef = E776E08E214AE07500E67947 /* qcbor_decode.c */; };
E776E097214AE0C700E67947 /* cmd_line_main.c in Sources */ = {isa = PBXBuildFile; fileRef = E776E096214AE0C700E67947 /* cmd_line_main.c */; };
- E776E09D214AEEEA00E67947 /* basic_test.c in Sources */ = {isa = PBXBuildFile; fileRef = E776E09C214AEEEA00E67947 /* basic_test.c */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -57,8 +56,6 @@
E776E093214AE08B00E67947 /* qcbor.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 3; lastKnownFileType = sourcecode.c.h; name = qcbor.h; path = inc/qcbor.h; sourceTree = "<group>"; tabWidth = 3; };
E776E094214AE09700E67947 /* UsefulBuf.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 3; lastKnownFileType = sourcecode.c.h; name = UsefulBuf.h; path = inc/UsefulBuf.h; sourceTree = "<group>"; tabWidth = 3; };
E776E096214AE0C700E67947 /* cmd_line_main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cmd_line_main.c; sourceTree = "<group>"; };
- E776E09B214AEEEA00E67947 /* basic_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = basic_test.h; path = test/basic_test.h; sourceTree = "<group>"; };
- E776E09C214AEEEA00E67947 /* basic_test.c */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 3; lastKnownFileType = sourcecode.c.c; name = basic_test.c; path = test/basic_test.c; sourceTree = "<group>"; tabWidth = 3; };
E776E161214EE19C00E67947 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -78,9 +75,9 @@
children = (
E776E161214EE19C00E67947 /* README.md */,
E776E096214AE0C700E67947 /* cmd_line_main.c */,
- E776E095214AE0B600E67947 /* test */,
E776E092214AE07C00E67947 /* inc */,
E776E08B214AE06600E67947 /* src */,
+ E776E095214AE0B600E67947 /* test */,
E776E07D214ADF7F00E67947 /* Products */,
);
sourceTree = "<group>";
@@ -96,12 +93,12 @@
E776E08B214AE06600E67947 /* src */ = {
isa = PBXGroup;
children = (
+ E776E08C214AE07400E67947 /* qcbor_encode.c */,
+ E776E08E214AE07500E67947 /* qcbor_decode.c */,
0F58EB9B216A388E002FD6D1 /* qcbor_decode_malloc.c */,
+ E776E08D214AE07500E67947 /* UsefulBuf.c */,
E73B57582161CA690080D658 /* ieee754.c */,
E73B57572161CA680080D658 /* ieee754.h */,
- E776E08E214AE07500E67947 /* qcbor_decode.c */,
- E776E08C214AE07400E67947 /* qcbor_encode.c */,
- E776E08D214AE07500E67947 /* UsefulBuf.c */,
);
name = src;
sourceTree = "<group>";
@@ -118,20 +115,18 @@
E776E095214AE0B600E67947 /* test */ = {
isa = PBXGroup;
children = (
+ E73B57632161F8F70080D658 /* run_tests.c */,
+ E73B57642161F8F80080D658 /* run_tests.h */,
0FA9BEBC216DE31700BA646B /* UsefulBuf_Tests.c */,
0FA9BEBB216DE31700BA646B /* UsefulBuf_Tests.h */,
0FA9BEB8216DC7AD00BA646B /* qcbor_encode_tests.c */,
0FA9BEB9216DC7AD00BA646B /* qcbor_encode_tests.h */,
0FA9BEB5216CE6CA00BA646B /* qcbor_decode_tests.c */,
0FA9BEB6216CE6CA00BA646B /* qcbor_decode_tests.h */,
- E73B57632161F8F70080D658 /* run_tests.c */,
- E73B57642161F8F80080D658 /* run_tests.h */,
E73B575A2161CA7C0080D658 /* float_tests.c */,
E73B575C2161CA7C0080D658 /* float_tests.h */,
E73B575D2161CA7C0080D658 /* half_to_double_from_rfc7049.c */,
E73B575B2161CA7C0080D658 /* half_to_double_from_rfc7049.h */,
- E776E09C214AEEEA00E67947 /* basic_test.c */,
- E776E09B214AEEEA00E67947 /* basic_test.h */,
);
name = test;
sourceTree = "<group>";
@@ -203,7 +198,6 @@
E776E090214AE07500E67947 /* UsefulBuf.c in Sources */,
0FA9BEBA216DC7AD00BA646B /* qcbor_encode_tests.c in Sources */,
E776E097214AE0C700E67947 /* cmd_line_main.c in Sources */,
- E776E09D214AEEEA00E67947 /* basic_test.c in Sources */,
0FA9BEBD216DE31700BA646B /* UsefulBuf_Tests.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
diff --git a/test/basic_test.c b/test/basic_test.c
deleted file mode 100644
index 645cce6..0000000
--- a/test/basic_test.c
+++ /dev/null
@@ -1,261 +0,0 @@
-/*==============================================================================
- basic_test.c -- most basic test for QCBOR
-
- Copyright 2018 Laurence Lundblade
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be included
- in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
-
- (This is the MIT license)
- ==============================================================================*/
-// Created by Laurence Lundblade on 9/13/18.
-
-
-#include "basic_test.h"
-#include "qcbor.h"
-
-
-/*
- Some very minimal tests until the full test suite is open sourced and available.
- Return codes here don't mean much (yet).
- */
-int basic_test_one()
-{
- // Very simple CBOR, a map with one boolean that is true in it
- UsefulBuf_MakeStackUB(MemoryForEncoded, 100);
- QCBOREncodeContext EC;
-
- QCBOREncode_Init(&EC, MemoryForEncoded);
-
- QCBOREncode_OpenMap(&EC);
- QCBOREncode_AddBoolToMapN(&EC, 66, true);
- QCBOREncode_CloseMap(&EC);
-
- UsefulBufC Encoded;
- if(QCBOREncode_Finish2(&EC, &Encoded)) {
- return -3;
- }
-
-
- // Decode it and see that is right
- QCBORDecodeContext DC;
- QCBORItem Item;
- QCBORDecode_Init(&DC, Encoded, QCBOR_DECODE_MODE_NORMAL);
-
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_MAP) {
- return -1;
- }
-
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_TRUE) {
- return -1;
- }
-
- if(QCBORDecode_Finish(&DC)) {
- return -2;
- }
-
-
- // Make another encoded message with the CBOR from the previous put into this one
- UsefulBuf_MakeStackUB(MemoryForEncoded2, 100);
- QCBOREncode_Init(&EC, MemoryForEncoded2);
- QCBOREncode_OpenArray(&EC);
- QCBOREncode_AddUInt64(&EC, 451);
- QCBOREncode_AddEncoded(&EC, Encoded);
- QCBOREncode_OpenMap(&EC);
- QCBOREncode_AddEncodedToMapN(&EC, -70000, Encoded);
- QCBOREncode_CloseMap(&EC);
- QCBOREncode_CloseArray(&EC);
-
- UsefulBufC Encoded2;
- if(QCBOREncode_Finish2(&EC, &Encoded2)) {
- return -3;
- }
- /*
- [ // 0 1:3
- 451, // 1 1:2
- { // 1 1:2 2:1
- 66: true // 2 1:1
- },
- { // 1 1:1 2:1
- -70000: { // 2 1:1 2:1 3:1
- 66: true // 3 XXXXXX
- }
- }
- ]
-
-
-
- 83 # array(3)
- 19 01C3 # unsigned(451)
- A1 # map(1)
- 18 42 # unsigned(66)
- F5 # primitive(21)
- A1 # map(1)
- 3A 0001116F # negative(69999)
- A1 # map(1)
- 18 42 # unsigned(66)
- F5 # primitive(21)
- */
-
- // Decode it and see if it is OK
- QCBORDecode_Init(&DC, Encoded2, QCBOR_DECODE_MODE_NORMAL);
-
- // 0 1:3
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_ARRAY || Item.val.uCount != 3) {
- return -1;
- }
-
- // 1 1:2
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_INT64 || Item.val.uint64 != 451) {
- return -1;
- }
-
- // 1 1:2 2:1
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_MAP || Item.val.uCount != 1) {
- return -1;
- }
-
- // 2 1:1
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_TRUE) {
- return -1;
- }
-
- // 1 1:1 2:1
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_MAP || Item.val.uCount != 1) {
- return -1;
- }
-
- // 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) {
- return -1;
- }
-
- // 3 XXXXXX
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_TRUE || Item.uLabelType != QCBOR_TYPE_INT64 || Item.label.int64 != 66) {
- return -1;
- }
-
- if(QCBORDecode_Finish(&DC)) {
- return -2;
- }
-
- return 0;
-}
-
-
-
-static const uint8_t pIndefiniteLenString[] = {
- 0x81, // Array of length one
- 0x7f, // text string marked with indefinite length
- 0x65, 0x73, 0x74, 0x72, 0x65, 0x61, // first segment
- 0x64, 0x6d, 0x69, 0x6e, 0x67, // second segment
- 0xff // ending break
-};
-
-static const uint8_t pIndefiniteArray[] = {0x9f, 0x01, 0x82, 0x02, 0x03, 0xff};
-
-// [1, [2, 3]]
-
-
-//0x9f018202039f0405ffff
-
-int indefinite_length_decode_test()
-{
- UsefulBufC IndefLen = UsefulBuf_FromByteArrayLiteral(pIndefiniteArray);
-
-
- // Decode it and see if it is OK
- UsefulBuf_MakeStackUB(MemPool, 200);
- QCBORDecodeContext DC;
- QCBORItem Item;
- QCBORDecode_Init(&DC, IndefLen, QCBOR_DECODE_MODE_NORMAL);
-
- QCBORDecode_SetMemPool(&DC, MemPool, false);
-
-
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_ARRAY) {
- return -1;
- }
-
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_INT64) {
- return -1;
- }
-
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_ARRAY) {
- return -1;
- }
-
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_INT64) {
- return -1;
- }
-
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_INT64) {
- return -1;
- }
-
- if(QCBORDecode_Finish(&DC)) {
- return -2;
- }
-
- return 0;
-}
-
-int indefinite_length_decode_string_test() {
- UsefulBufC IndefLen = UsefulBuf_FromByteArrayLiteral(pIndefiniteLenString);
-
-
- // Decode it and see if it is OK
- QCBORDecodeContext DC;
- QCBORItem Item;
- UsefulBuf_MakeStackUB(MemPool, 200);
-
- QCBORDecode_Init(&DC, IndefLen, QCBOR_DECODE_MODE_NORMAL);
-
- QCBORDecode_SetMemPool(&DC, MemPool, false);
-
-
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_ARRAY) {
- return -1;
- }
-
- QCBORDecode_GetNext(&DC, &Item);
- if(Item.uDataType != QCBOR_TYPE_TEXT_STRING) {
- return -1;
- }
-
- return 0;
-}
-
-
diff --git a/test/basic_test.h b/test/basic_test.h
deleted file mode 100644
index 6f3dd66..0000000
--- a/test/basic_test.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*==============================================================================
- basic_test.h -- most basic test for QCBOR
-
- Copyright 2018 Laurence Lundblade
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be included
- in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- */
-
-// Created by Laurence Lundblade on 9/13/18.
-
-#ifndef basic_test_h
-#define basic_test_h
-
-int basic_test_one(void);
-
-int indefinite_length_decode_test(void);
-int indefinite_length_decode_string_test(void);
-
-#endif /* basic_test_h */
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 41532b7..778bca9 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -1537,6 +1537,101 @@
}
+
+
+
+
+
+static const uint8_t pIndefiniteLenString[] = {
+ 0x81, // Array of length one
+ 0x7f, // text string marked with indefinite length
+ 0x65, 0x73, 0x74, 0x72, 0x65, 0x61, // first segment
+ 0x64, 0x6d, 0x69, 0x6e, 0x67, // second segment
+ 0xff // ending break
+};
+
+static const uint8_t pIndefiniteArray[] = {0x9f, 0x01, 0x82, 0x02, 0x03, 0xff};
+
+// [1, [2, 3]]
+
+
+//0x9f018202039f0405ffff
+
+int indefinite_length_decode_test()
+{
+ UsefulBufC IndefLen = UsefulBuf_FromByteArrayLiteral(pIndefiniteArray);
+
+
+ // Decode it and see if it is OK
+ UsefulBuf_MakeStackUB(MemPool, 200);
+ QCBORDecodeContext DC;
+ QCBORItem Item;
+ QCBORDecode_Init(&DC, IndefLen, QCBOR_DECODE_MODE_NORMAL);
+
+ QCBORDecode_SetMemPool(&DC, MemPool, false);
+
+
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_ARRAY) {
+ return -1;
+ }
+
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_INT64) {
+ return -1;
+ }
+
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_ARRAY) {
+ return -1;
+ }
+
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_INT64) {
+ return -1;
+ }
+
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_INT64) {
+ return -1;
+ }
+
+ if(QCBORDecode_Finish(&DC)) {
+ return -2;
+ }
+
+ return 0;
+}
+
+int indefinite_length_decode_string_test() {
+ UsefulBufC IndefLen = UsefulBuf_FromByteArrayLiteral(pIndefiniteLenString);
+
+
+ // Decode it and see if it is OK
+ QCBORDecodeContext DC;
+ QCBORItem Item;
+ UsefulBuf_MakeStackUB(MemPool, 200);
+
+ QCBORDecode_Init(&DC, IndefLen, QCBOR_DECODE_MODE_NORMAL);
+
+ QCBORDecode_SetMemPool(&DC, MemPool, false);
+
+
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_ARRAY) {
+ return -1;
+ }
+
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_TEXT_STRING) {
+ return -1;
+ }
+
+ return 0;
+}
+
+
+
int mempool_test(void)
{
QCBORDecodeContext DC;
diff --git a/test/qcbor_decode_tests.h b/test/qcbor_decode_tests.h
index e6f1b68..751da8b 100644
--- a/test/qcbor_decode_tests.h
+++ b/test/qcbor_decode_tests.h
@@ -158,6 +158,10 @@
int NestedMapTest(void);
+int indefinite_length_decode_test(void);
+int indefinite_length_decode_string_test(void);
+
+
int mempool_test(void);
diff --git a/test/qcbor_encode_tests.c b/test/qcbor_encode_tests.c
index 000d416..ae94a7f 100644
--- a/test/qcbor_encode_tests.c
+++ b/test/qcbor_encode_tests.c
@@ -104,6 +104,144 @@
Compare(Enc, (UsefulBufC){Expected, sizeof(Expected)})
+
+/*
+ Some very minimal tests.
+ */
+int basic_encode_test()
+{
+ // Very simple CBOR, a map with one boolean that is true in it
+ UsefulBuf_MakeStackUB(MemoryForEncoded, 100);
+ QCBOREncodeContext EC;
+
+ QCBOREncode_Init(&EC, MemoryForEncoded);
+
+ QCBOREncode_OpenMap(&EC);
+ QCBOREncode_AddBoolToMapN(&EC, 66, true);
+ QCBOREncode_CloseMap(&EC);
+
+ UsefulBufC Encoded;
+ if(QCBOREncode_Finish2(&EC, &Encoded)) {
+ return -3;
+ }
+
+
+ // Decode it and see that is right
+ QCBORDecodeContext DC;
+ QCBORItem Item;
+ QCBORDecode_Init(&DC, Encoded, QCBOR_DECODE_MODE_NORMAL);
+
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_MAP) {
+ return -1;
+ }
+
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_TRUE) {
+ return -1;
+ }
+
+ if(QCBORDecode_Finish(&DC)) {
+ return -2;
+ }
+
+
+ // Make another encoded message with the CBOR from the previous put into this one
+ UsefulBuf_MakeStackUB(MemoryForEncoded2, 100);
+ QCBOREncode_Init(&EC, MemoryForEncoded2);
+ QCBOREncode_OpenArray(&EC);
+ QCBOREncode_AddUInt64(&EC, 451);
+ QCBOREncode_AddEncoded(&EC, Encoded);
+ QCBOREncode_OpenMap(&EC);
+ QCBOREncode_AddEncodedToMapN(&EC, -70000, Encoded);
+ QCBOREncode_CloseMap(&EC);
+ QCBOREncode_CloseArray(&EC);
+
+ UsefulBufC Encoded2;
+ if(QCBOREncode_Finish2(&EC, &Encoded2)) {
+ return -3;
+ }
+ /*
+ [ // 0 1:3
+ 451, // 1 1:2
+ { // 1 1:2 2:1
+ 66: true // 2 1:1
+ },
+ { // 1 1:1 2:1
+ -70000: { // 2 1:1 2:1 3:1
+ 66: true // 3 XXXXXX
+ }
+ }
+ ]
+
+
+
+ 83 # array(3)
+ 19 01C3 # unsigned(451)
+ A1 # map(1)
+ 18 42 # unsigned(66)
+ F5 # primitive(21)
+ A1 # map(1)
+ 3A 0001116F # negative(69999)
+ A1 # map(1)
+ 18 42 # unsigned(66)
+ F5 # primitive(21)
+ */
+
+ // Decode it and see if it is OK
+ QCBORDecode_Init(&DC, Encoded2, QCBOR_DECODE_MODE_NORMAL);
+
+ // 0 1:3
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_ARRAY || Item.val.uCount != 3) {
+ return -1;
+ }
+
+ // 1 1:2
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_INT64 || Item.val.uint64 != 451) {
+ return -1;
+ }
+
+ // 1 1:2 2:1
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_MAP || Item.val.uCount != 1) {
+ return -1;
+ }
+
+ // 2 1:1
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_TRUE) {
+ return -1;
+ }
+
+ // 1 1:1 2:1
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_MAP || Item.val.uCount != 1) {
+ return -1;
+ }
+
+ // 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) {
+ return -1;
+ }
+
+ // 3 XXXXXX
+ QCBORDecode_GetNext(&DC, &Item);
+ if(Item.uDataType != QCBOR_TYPE_TRUE || Item.uLabelType != QCBOR_TYPE_INT64 || Item.label.int64 != 66) {
+ return -1;
+ }
+
+ if(QCBORDecode_Finish(&DC)) {
+ return -2;
+ }
+
+ return 0;
+}
+
+
+
static const uint8_t pExpectedEncodedAll[] = {
0x98, 0x29, 0x66, 0x55, 0x49, 0x4e, 0x54, 0x36, 0x32, 0xd8,
diff --git a/test/qcbor_encode_tests.h b/test/qcbor_encode_tests.h
index fae9f4b..8625fe2 100644
--- a/test/qcbor_encode_tests.h
+++ b/test/qcbor_encode_tests.h
@@ -47,6 +47,12 @@
/*
+ Most basic test.
+ */
+int basic_encode_test(void);
+
+
+/*
Encode lots of integer values, particularly around the boundary and make sure they
Match the expected binary output. Primarily an encoding test.
*/
diff --git a/test/run_tests.c b/test/run_tests.c
index a9317a2..ed58746 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -34,7 +34,6 @@
#include <stdbool.h>
#include "float_tests.h"
-#include "basic_test.h"
#include "qcbor_decode_tests.h"
#include "qcbor_encode_tests.h"
#include "UsefulBuf_Tests.h"
@@ -127,7 +126,7 @@
TEST_ENTRY(ComprehensiveInputTest),
TEST_ENTRY(ParseMapTest),
TEST_ENTRY(indefinite_length_decode_test),
- TEST_ENTRY(basic_test_one),
+ TEST_ENTRY(basic_encode_test),
TEST_ENTRY(NestedMapTest),
TEST_ENTRY(BignumParseTest),
TEST_ENTRY(OptTagParseTest),