Add support for day count dates, RFC 8943 (#106)
This addresses #98
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 236f59c..779b094 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -2576,7 +2576,7 @@
0xc0, // tag for string date
0xa0, // Erroneous empty map as content for date
- 0xa9, // Open a map for tests involving labels.
+ 0xad, // Open a map for tests involving labels.
0x00,
0xc0, // tag for string date
@@ -2615,6 +2615,25 @@
// Untagged half-precision float with value -2
0x09,
0xF9, 0xC0, 0x00,
+
+ /* Tagged date-only date string */
+ 0x63, 0x53, 0x44, 0x53,
+ 0xD9, 0x03, 0xEC,
+ 0x6A, 0x31, 0x39, 0x38, 0x35, 0x2D, 0x30, 0x34, 0x2D, 0x31, 0x32, /* "1985-04-12" */
+
+ /* Untagged date-only date string */
+ 0x18, 0x63,
+ 0x6A, 0x31, 0x39, 0x38, 0x35, 0x2D, 0x30, 0x34, 0x2D, 0x31, 0x32, /* "1985-04-12" */
+
+ /* Tagged days-count epoch date */
+ 0x63, 0x53, 0x44, 0x45,
+ 0xD8, 0x64, /* tag(100) */
+ 0x39, 0x29, 0xB3, /* -10676 */
+
+ /* Untagged days-count epoch date */
+ 0x11,
+ 0x19, 0x0F, 0x9A /* 3994 */
+
};
int32_t SpiffyDateDecodeTest()
@@ -2623,8 +2642,8 @@
QCBORError uError;
int64_t nEpochDate2, nEpochDate3, nEpochDate5,
nEpochDate4, nEpochDate6, nEpochDateFail,
- nEpochDate1400000000;
- UsefulBufC StringDate1, StringDate2;
+ nEpochDate1400000000, nEpochDays1, nEpochDays2;
+ UsefulBufC StringDate1, StringDate2, StringDays1, StringDays2;
uint64_t uTag1, uTag2;
QCBORDecode_Init(&DC,
@@ -2804,6 +2823,26 @@
&nEpochDate6);
uTag2 = QCBORDecode_GetNthTagOfLast(&DC, 0);
+ /* The days format is much simpler than the date format
+ * because it can't be a floating point value. The test
+ * of the spiffy decode functions sufficiently covers
+ * the test of the non-spiffy decode days date decoding.
+ * There is no full fan out of the error conditions
+ * and decode options as that is implemented by code
+ * that is tested well by the date testing above.
+ */
+ QCBORDecode_GetDaysStringInMapSZ(&DC, "SDS", QCBOR_TAG_REQUIREMENT_TAG,
+ &StringDays1);
+
+ QCBORDecode_GetDaysStringInMapN(&DC, 99, QCBOR_TAG_REQUIREMENT_NOT_A_TAG,
+ &StringDays2);
+
+ QCBORDecode_GetEpochDaysInMapSZ(&DC, "SDE", QCBOR_TAG_REQUIREMENT_TAG,
+ &nEpochDays1);
+
+ QCBORDecode_GetEpochDaysInMapN(&DC, 17, QCBOR_TAG_REQUIREMENT_NOT_A_TAG,
+ &nEpochDays2);
+
QCBORDecode_ExitMap(&DC);
QCBORDecode_ExitArray(&DC);
uError = QCBORDecode_Finish(&DC);
@@ -2831,6 +2870,14 @@
return 204;
}
+ if(nEpochDays1 != -10676) {
+ return 205;
+ }
+
+ if(nEpochDays2 != 3994) {
+ return 206;
+ }
+
if(UsefulBuf_Compare(StringDate1, UsefulBuf_FromSZ("1985-04-12"))) {
return 205;
}
@@ -2839,6 +2886,14 @@
return 206;
}
+ if(UsefulBuf_Compare(StringDays1, UsefulBuf_FromSZ("1985-04-12"))) {
+ return 207;
+ }
+
+ if(UsefulBuf_Compare(StringDays2, UsefulBuf_FromSZ("1985-04-12"))) {
+ return 208;
+ }
+
return 0;
}