diff options
| author | rimio <vasi.vilvoiu@gmail.com> | 2018-03-01 20:11:43 +0200 |
|---|---|---|
| committer | rimio <vasi.vilvoiu@gmail.com> | 2018-03-01 20:11:43 +0200 |
| commit | df8d9c31e2191aeedd967560f222971d978a9a1c (patch) | |
| tree | 8f1290e32f9e794fbff32eed47407f427aa8cd07 | |
| parent | 657b61d3a96c68c7f1882ceb0632ecfd6461fb51 (diff) | |
Added tests; small fixes to library
88 files changed, 257 insertions, 27 deletions
diff --git a/include/ecbor.h b/include/ecbor.h index c3befb8..039264f 100644 --- a/include/ecbor.h +++ b/include/ecbor.h @@ -236,6 +236,9 @@ ecbor_get_tag_item (ecbor_item_t *tag, ecbor_item_t *arr_item); #define ECBOR_GET_TYPE(i) \ ((i).major_type) +#define ECBOR_IS_INDEFINITE(i) \ + ((i).is_indefinite) + #define ECBOR_IS_NINT(i) \ ((i).major_type == ECBOR_MT_NINT) #define ECBOR_IS_UINT(i) \ diff --git a/src/ecbor.c b/src/ecbor.c index cb489f8..9e8404f 100644 --- a/src/ecbor.c +++ b/src/ecbor.c @@ -112,7 +112,7 @@ ecbor_get_array_item (ecbor_item_t *array, uint64_t index, return rc; } - for (i = 0; i < index+1; i ++) { + for (i = 0; i <= index; i ++) { rc = ecbor_decode (&context, item); if (rc != ECBOR_OK) { if (rc == ECBOR_END_OF_BUFFER) { @@ -137,7 +137,7 @@ ecbor_get_map_item (ecbor_item_t *map, uint64_t index, ecbor_item_t *key, if (!map) { return ECBOR_ERR_NULL_MAP; } - if (map->major_type != ECBOR_MT_ARRAY) { + if (map->major_type != ECBOR_MT_MAP) { return ECBOR_ERR_INVALID_TYPE; } if (map->length <= (index * 2)) { @@ -152,7 +152,7 @@ ecbor_get_map_item (ecbor_item_t *map, uint64_t index, ecbor_item_t *key, return rc; } - for (i = 0; i < index; i ++) { + for (i = 0; i <= index; i ++) { rc = ecbor_decode (&context, key); if (rc != ECBOR_OK) { if (rc == ECBOR_END_OF_BUFFER) { diff --git a/src/ecbor_describe.c b/src/ecbor_describe.c index 301505e..1f5dd5a 100644 --- a/src/ecbor_describe.c +++ b/src/ecbor_describe.c @@ -20,9 +20,12 @@ static struct option long_options[] = { { 0, 0, 0, 0 } }; -void print_help (void); -void print_ecbor_error (ecbor_error_t err); -ecbor_error_t print_ecbor_item (ecbor_item_t *item, int level); +void +print_help (void); +void +print_ecbor_error (ecbor_error_t err); +ecbor_error_t +print_ecbor_item (ecbor_item_t *item, unsigned int level, char *prefix); /* * Print help @@ -42,13 +45,16 @@ print_ecbor_error (ecbor_error_t err) } ecbor_error_t -print_ecbor_item (ecbor_item_t *item, int level) +print_ecbor_item (ecbor_item_t *item, unsigned int level, char *prefix) { + static const unsigned int max_str_print_len = 64; + static const char *msg_too_large = "<too_large>"; ecbor_major_type_t mt; ecbor_error_t rc; - int i; + unsigned int i; for(i = 0; i < level * 2; i ++) putchar(' '); + printf (prefix); mt = ecbor_get_type (item); switch (mt) { @@ -58,7 +64,6 @@ print_ecbor_item (ecbor_item_t *item, int level) rc = ecbor_get_value (item, (void *) &val); if (rc != ECBOR_OK) { - print_ecbor_error (rc); return rc; } @@ -72,7 +77,6 @@ print_ecbor_item (ecbor_item_t *item, int level) rc = ecbor_get_value (item, (void *) &val); if (rc != ECBOR_OK) { - print_ecbor_error (rc); return rc; } @@ -80,27 +84,112 @@ print_ecbor_item (ecbor_item_t *item, int level) } break; + case ECBOR_MT_STR: + { + uint64_t len; + char *val; + + rc = ecbor_get_length (item, &len); + if (rc != ECBOR_OK) { + return rc; + } + + rc = ecbor_get_value (item, (char *) &val); + if (rc != ECBOR_OK) { + return rc; + } + + printf ("[STR] len %u %s value '%.*s'\n", (unsigned int) len, + (ECBOR_IS_INDEFINITE (*item) ? "(indefinite)" : ""), + (int)(len <= max_str_print_len ? len : strlen(msg_too_large)), + (len <= max_str_print_len ? val : msg_too_large)); + } + break; + + case ECBOR_MT_BSTR: + { + uint64_t len; + char *val; + + rc = ecbor_get_length (item, &len); + if (rc != ECBOR_OK) { + return rc; + } + + rc = ecbor_get_value (item, (char *) &val); + if (rc != ECBOR_OK) { + return rc; + } + + printf ("[BSTR] len %u %s value ", (unsigned int) len, + (ECBOR_IS_INDEFINITE (*item) ? "(indefinite)" : "")); + if (len > max_str_print_len) { + printf ("'%s'\n", msg_too_large); + } else { + printf ("'"); + for (i = 0; i < len; i ++) { + printf("%2x", val[i]); + } + printf ("'\n"); + } + } + break; + case ECBOR_MT_ARRAY: { uint64_t len, i; rc = ecbor_get_length (item, &len); if (rc != ECBOR_OK) { - print_ecbor_error (rc); return rc; } - printf ("[ARRAY] len %u\n", (unsigned int) len); + printf ("[ARRAY] len %u %s\n", (unsigned int) len, + (ECBOR_IS_INDEFINITE (*item) ? "(indefinite)" : "")); for (i = 0; i < len; i ++) { ecbor_item_t child; rc = ecbor_get_array_item (item, i, &child); if (rc != ECBOR_OK) { - print_ecbor_error (rc); + return rc; + } + + print_ecbor_item (&child, level+1, ""); + } + } + break; + + case ECBOR_MT_MAP: + { + uint64_t len, i; + char kv_msg[100] = { 0 }; + + rc = ecbor_get_length (item, &len); + if (rc != ECBOR_OK) { + return rc; + } + + printf ("[MAP] len %u %s\n", (unsigned int) len, + (ECBOR_IS_INDEFINITE (*item) ? "(indefinite)" : "")); + for (i = 0; i < len; i ++) { + ecbor_item_t k, v; + + rc = ecbor_get_map_item (item, i, &k, &v); + if (rc != ECBOR_OK) { + return rc; + } + + sprintf (kv_msg, "key[%u]: ", (unsigned int) i); + rc = print_ecbor_item (&k, level+2, kv_msg); + if (rc != ECBOR_OK) { return rc; } - print_ecbor_item (&child, level+1); + sprintf (kv_msg, "val[%u]: ", (unsigned int) i); + rc = print_ecbor_item (&v, level+2, kv_msg); + if (rc != ECBOR_OK) { + return rc; + } } } break; @@ -140,7 +229,7 @@ main(int argc, char **argv) } if (optind != (argc-1)) { - printf ("Expecting exactly one file name!\n"); + fprintf (stderr, "Expecting exactly one file name!\n"); print_help (); return -1; } else { @@ -151,39 +240,39 @@ main(int argc, char **argv) { FILE *fp; - printf ("Reading CBOR from file '%s'\n", filename); + fprintf (stderr, "Reading CBOR from file '%s'\n", filename); fp = fopen (filename, "rb"); if (!fp) { - printf ("Error opening file!\n"); + fprintf (stderr, "Error opening file!\n"); return -1; } if (fseek (fp, 0L, SEEK_END)) { - printf ("Error seeking end of file!\n"); + fprintf (stderr, "Error seeking end of file!\n"); fclose (fp); return -1; } cbor_length = ftell(fp); if (cbor_length < 0) { - printf ("Error determining input size!\n"); + fprintf (stderr, "Error determining input size!\n"); fclose (fp); return -1; } if (fseek (fp, 0L, SEEK_SET)) { - printf ("Error seeking beginning of file!\n"); + fprintf (stderr, "Error seeking beginning of file!\n"); fclose (fp); return -1; } cbor = (unsigned char *) malloc (cbor_length); if (!cbor) { - printf ("Error allocating %d bytes!\n", (int) cbor_length); + fprintf (stderr, "Error allocating %d bytes!\n", (int) cbor_length); fclose (fp); return -1; } if (fread (cbor, 1, cbor_length, fp) != (size_t) cbor_length) { - printf ("Error reading %d bytes!\n", (int) cbor_length); + fprintf (stderr, "Error reading %d bytes!\n", (int) cbor_length); fclose (fp); return -1; } @@ -204,7 +293,7 @@ main(int argc, char **argv) return -1; } - printf ("CBOR objects:\n"); + fprintf (stderr, "CBOR objects:\n"); while (1) { rc = ecbor_decode (&context, &item); @@ -215,8 +304,12 @@ main(int argc, char **argv) print_ecbor_error (rc); return -1; } - - print_ecbor_item (&item, 0); + + rc = print_ecbor_item (&item, 0, ""); + if (rc != ECBOR_OK) { + print_ecbor_error (rc); + return -1; + } } } diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..a3dea27 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,2 @@ +*.bin +*.result
\ No newline at end of file diff --git a/test/files/appendix_a/0000.hex b/test/files/appendix_a/0000.hex new file mode 100644 index 0000000..857f065 --- /dev/null +++ b/test/files/appendix_a/0000.hex @@ -0,0 +1 @@ +00
\ No newline at end of file diff --git a/test/files/appendix_a/0001.hex b/test/files/appendix_a/0001.hex new file mode 100644 index 0000000..a616ad4 --- /dev/null +++ b/test/files/appendix_a/0001.hex @@ -0,0 +1 @@ +01
\ No newline at end of file diff --git a/test/files/appendix_a/0002.hex b/test/files/appendix_a/0002.hex new file mode 100644 index 0000000..47d26df --- /dev/null +++ b/test/files/appendix_a/0002.hex @@ -0,0 +1 @@ +0a
\ No newline at end of file diff --git a/test/files/appendix_a/0003.hex b/test/files/appendix_a/0003.hex new file mode 100644 index 0000000..8e2afd3 --- /dev/null +++ b/test/files/appendix_a/0003.hex @@ -0,0 +1 @@ +17
\ No newline at end of file diff --git a/test/files/appendix_a/0004.hex b/test/files/appendix_a/0004.hex new file mode 100644 index 0000000..34f7d67 --- /dev/null +++ b/test/files/appendix_a/0004.hex @@ -0,0 +1 @@ +1818
\ No newline at end of file diff --git a/test/files/appendix_a/0005.hex b/test/files/appendix_a/0005.hex new file mode 100644 index 0000000..0068294 --- /dev/null +++ b/test/files/appendix_a/0005.hex @@ -0,0 +1 @@ +1819
\ No newline at end of file diff --git a/test/files/appendix_a/0006.hex b/test/files/appendix_a/0006.hex new file mode 100644 index 0000000..30e6e7d --- /dev/null +++ b/test/files/appendix_a/0006.hex @@ -0,0 +1 @@ +1864
\ No newline at end of file diff --git a/test/files/appendix_a/0007.hex b/test/files/appendix_a/0007.hex new file mode 100644 index 0000000..c9ebbdc --- /dev/null +++ b/test/files/appendix_a/0007.hex @@ -0,0 +1 @@ +1903e8
\ No newline at end of file diff --git a/test/files/appendix_a/0008.hex b/test/files/appendix_a/0008.hex new file mode 100644 index 0000000..d42a41c --- /dev/null +++ b/test/files/appendix_a/0008.hex @@ -0,0 +1 @@ +1a000f4240
\ No newline at end of file diff --git a/test/files/appendix_a/0009.hex b/test/files/appendix_a/0009.hex new file mode 100644 index 0000000..0d6dd2a --- /dev/null +++ b/test/files/appendix_a/0009.hex @@ -0,0 +1 @@ +1b000000e8d4a51000
\ No newline at end of file diff --git a/test/files/appendix_a/0010.hex b/test/files/appendix_a/0010.hex new file mode 100644 index 0000000..f925e5a --- /dev/null +++ b/test/files/appendix_a/0010.hex @@ -0,0 +1 @@ +1bfffffffffffffffc249010000000000000000f
\ No newline at end of file diff --git a/test/files/appendix_a/0011.hex b/test/files/appendix_a/0011.hex new file mode 100644 index 0000000..d8965b2 --- /dev/null +++ b/test/files/appendix_a/0011.hex @@ -0,0 +1 @@ +c249010000000000000000
\ No newline at end of file diff --git a/test/files/appendix_a/0012.hex b/test/files/appendix_a/0012.hex new file mode 100644 index 0000000..60755d5 --- /dev/null +++ b/test/files/appendix_a/0012.hex @@ -0,0 +1 @@ +3bffffffffffffffff
\ No newline at end of file diff --git a/test/files/appendix_a/0013.hex b/test/files/appendix_a/0013.hex new file mode 100644 index 0000000..7588986 --- /dev/null +++ b/test/files/appendix_a/0013.hex @@ -0,0 +1 @@ +c349010000000000000000
\ No newline at end of file diff --git a/test/files/appendix_a/0014.hex b/test/files/appendix_a/0014.hex new file mode 100644 index 0000000..2edeafb --- /dev/null +++ b/test/files/appendix_a/0014.hex @@ -0,0 +1 @@ +20
\ No newline at end of file diff --git a/test/files/appendix_a/0015.hex b/test/files/appendix_a/0015.hex new file mode 100644 index 0000000..d99e90e --- /dev/null +++ b/test/files/appendix_a/0015.hex @@ -0,0 +1 @@ +29
\ No newline at end of file diff --git a/test/files/appendix_a/0016.hex b/test/files/appendix_a/0016.hex new file mode 100644 index 0000000..d42e2ba --- /dev/null +++ b/test/files/appendix_a/0016.hex @@ -0,0 +1 @@ +3863
\ No newline at end of file diff --git a/test/files/appendix_a/0017.hex b/test/files/appendix_a/0017.hex new file mode 100644 index 0000000..3c57fe7 --- /dev/null +++ b/test/files/appendix_a/0017.hex @@ -0,0 +1 @@ +3903e7
\ No newline at end of file diff --git a/test/files/appendix_a/0018.hex b/test/files/appendix_a/0018.hex new file mode 100644 index 0000000..bbae380 --- /dev/null +++ b/test/files/appendix_a/0018.hex @@ -0,0 +1 @@ +f90000
\ No newline at end of file diff --git a/test/files/appendix_a/0019.hex b/test/files/appendix_a/0019.hex new file mode 100644 index 0000000..da78709 --- /dev/null +++ b/test/files/appendix_a/0019.hex @@ -0,0 +1 @@ +f98000
\ No newline at end of file diff --git a/test/files/appendix_a/0020.hex b/test/files/appendix_a/0020.hex new file mode 100644 index 0000000..8ee3207 --- /dev/null +++ b/test/files/appendix_a/0020.hex @@ -0,0 +1 @@ +f93c00
\ No newline at end of file diff --git a/test/files/appendix_a/0021.hex b/test/files/appendix_a/0021.hex new file mode 100644 index 0000000..13b99a6 --- /dev/null +++ b/test/files/appendix_a/0021.hex @@ -0,0 +1 @@ +fb3ff199999999999a
\ No newline at end of file diff --git a/test/files/appendix_a/0022.hex b/test/files/appendix_a/0022.hex new file mode 100644 index 0000000..c2b5a77 --- /dev/null +++ b/test/files/appendix_a/0022.hex @@ -0,0 +1 @@ +f93e00
\ No newline at end of file diff --git a/test/files/appendix_a/0023.hex b/test/files/appendix_a/0023.hex new file mode 100644 index 0000000..4c18df2 --- /dev/null +++ b/test/files/appendix_a/0023.hex @@ -0,0 +1 @@ +f97bff
\ No newline at end of file diff --git a/test/files/appendix_a/0024.hex b/test/files/appendix_a/0024.hex new file mode 100644 index 0000000..1fba09b --- /dev/null +++ b/test/files/appendix_a/0024.hex @@ -0,0 +1 @@ +fa47c35000
\ No newline at end of file diff --git a/test/files/appendix_a/0025.hex b/test/files/appendix_a/0025.hex new file mode 100644 index 0000000..0aecfb2 --- /dev/null +++ b/test/files/appendix_a/0025.hex @@ -0,0 +1 @@ +fa7f7fffff
\ No newline at end of file diff --git a/test/files/appendix_a/0026.hex b/test/files/appendix_a/0026.hex new file mode 100644 index 0000000..3517c0c --- /dev/null +++ b/test/files/appendix_a/0026.hex @@ -0,0 +1 @@ +fb7e37e43c8800759c
\ No newline at end of file diff --git a/test/files/appendix_a/0027.hex b/test/files/appendix_a/0027.hex new file mode 100644 index 0000000..ed2e150 --- /dev/null +++ b/test/files/appendix_a/0027.hex @@ -0,0 +1 @@ +f90001
\ No newline at end of file diff --git a/test/files/appendix_a/0028.hex b/test/files/appendix_a/0028.hex new file mode 100644 index 0000000..a5225ba --- /dev/null +++ b/test/files/appendix_a/0028.hex @@ -0,0 +1 @@ +f90400
\ No newline at end of file diff --git a/test/files/appendix_a/0029.hex b/test/files/appendix_a/0029.hex new file mode 100644 index 0000000..979e7f1 --- /dev/null +++ b/test/files/appendix_a/0029.hex @@ -0,0 +1 @@ +f9c400
\ No newline at end of file diff --git a/test/files/appendix_a/0030.hex b/test/files/appendix_a/0030.hex new file mode 100644 index 0000000..2e809fd --- /dev/null +++ b/test/files/appendix_a/0030.hex @@ -0,0 +1 @@ +fbc010666666666666
\ No newline at end of file diff --git a/test/files/appendix_a/0031.hex b/test/files/appendix_a/0031.hex new file mode 100644 index 0000000..cae7292 --- /dev/null +++ b/test/files/appendix_a/0031.hex @@ -0,0 +1 @@ +f97c00
\ No newline at end of file diff --git a/test/files/appendix_a/0032.hex b/test/files/appendix_a/0032.hex new file mode 100644 index 0000000..809f04c --- /dev/null +++ b/test/files/appendix_a/0032.hex @@ -0,0 +1 @@ +f97e00
\ No newline at end of file diff --git a/test/files/appendix_a/0033.hex b/test/files/appendix_a/0033.hex new file mode 100644 index 0000000..6e7342b --- /dev/null +++ b/test/files/appendix_a/0033.hex @@ -0,0 +1 @@ +f9fc00
\ No newline at end of file diff --git a/test/files/appendix_a/0034.hex b/test/files/appendix_a/0034.hex new file mode 100644 index 0000000..0cd43af --- /dev/null +++ b/test/files/appendix_a/0034.hex @@ -0,0 +1 @@ +fa7f800000
\ No newline at end of file diff --git a/test/files/appendix_a/0035.hex b/test/files/appendix_a/0035.hex new file mode 100644 index 0000000..89af808 --- /dev/null +++ b/test/files/appendix_a/0035.hex @@ -0,0 +1 @@ +fa7fc00000
\ No newline at end of file diff --git a/test/files/appendix_a/0036.hex b/test/files/appendix_a/0036.hex new file mode 100644 index 0000000..c651442 --- /dev/null +++ b/test/files/appendix_a/0036.hex @@ -0,0 +1 @@ +faff800000
\ No newline at end of file diff --git a/test/files/appendix_a/0037.hex b/test/files/appendix_a/0037.hex new file mode 100644 index 0000000..114d6d0 --- /dev/null +++ b/test/files/appendix_a/0037.hex @@ -0,0 +1 @@ +fb7ff0000000000000
\ No newline at end of file diff --git a/test/files/appendix_a/0038.hex b/test/files/appendix_a/0038.hex new file mode 100644 index 0000000..444b7b3 --- /dev/null +++ b/test/files/appendix_a/0038.hex @@ -0,0 +1 @@ +fb7ff8000000000000
\ No newline at end of file diff --git a/test/files/appendix_a/0039.hex b/test/files/appendix_a/0039.hex new file mode 100644 index 0000000..5f5b774 --- /dev/null +++ b/test/files/appendix_a/0039.hex @@ -0,0 +1 @@ +fbfff0000000000000
\ No newline at end of file diff --git a/test/files/appendix_a/0040.hex b/test/files/appendix_a/0040.hex new file mode 100644 index 0000000..00cc282 --- /dev/null +++ b/test/files/appendix_a/0040.hex @@ -0,0 +1 @@ +f4
\ No newline at end of file diff --git a/test/files/appendix_a/0041.hex b/test/files/appendix_a/0041.hex new file mode 100644 index 0000000..968c356 --- /dev/null +++ b/test/files/appendix_a/0041.hex @@ -0,0 +1 @@ +f5
\ No newline at end of file diff --git a/test/files/appendix_a/0042.hex b/test/files/appendix_a/0042.hex new file mode 100644 index 0000000..e5bef7d --- /dev/null +++ b/test/files/appendix_a/0042.hex @@ -0,0 +1 @@ +f6
\ No newline at end of file diff --git a/test/files/appendix_a/0043.hex b/test/files/appendix_a/0043.hex new file mode 100644 index 0000000..5cc5e92 --- /dev/null +++ b/test/files/appendix_a/0043.hex @@ -0,0 +1 @@ +f7
\ No newline at end of file diff --git a/test/files/appendix_a/0044.hex b/test/files/appendix_a/0044.hex new file mode 100644 index 0000000..78177fa --- /dev/null +++ b/test/files/appendix_a/0044.hex @@ -0,0 +1 @@ +f0
\ No newline at end of file diff --git a/test/files/appendix_a/0045.hex b/test/files/appendix_a/0045.hex new file mode 100644 index 0000000..5ad81ce --- /dev/null +++ b/test/files/appendix_a/0045.hex @@ -0,0 +1 @@ +f818
\ No newline at end of file diff --git a/test/files/appendix_a/0046.hex b/test/files/appendix_a/0046.hex new file mode 100644 index 0000000..feab44e --- /dev/null +++ b/test/files/appendix_a/0046.hex @@ -0,0 +1 @@ +f8ff
\ No newline at end of file diff --git a/test/files/appendix_a/0047.hex b/test/files/appendix_a/0047.hex new file mode 100644 index 0000000..cf5065b --- /dev/null +++ b/test/files/appendix_a/0047.hex @@ -0,0 +1 @@ +c074323031332d30332d32315432303a30343a30305a
\ No newline at end of file diff --git a/test/files/appendix_a/0048.hex b/test/files/appendix_a/0048.hex new file mode 100644 index 0000000..d0b4e4a --- /dev/null +++ b/test/files/appendix_a/0048.hex @@ -0,0 +1 @@ +c11a514b67b0
\ No newline at end of file diff --git a/test/files/appendix_a/0049.hex b/test/files/appendix_a/0049.hex new file mode 100644 index 0000000..597c77c --- /dev/null +++ b/test/files/appendix_a/0049.hex @@ -0,0 +1 @@ +c1fb41d452d9ec200000
\ No newline at end of file diff --git a/test/files/appendix_a/0050.hex b/test/files/appendix_a/0050.hex new file mode 100644 index 0000000..5d59c22 --- /dev/null +++ b/test/files/appendix_a/0050.hex @@ -0,0 +1 @@ +d74401020304
\ No newline at end of file diff --git a/test/files/appendix_a/0051.hex b/test/files/appendix_a/0051.hex new file mode 100644 index 0000000..1076d6c --- /dev/null +++ b/test/files/appendix_a/0051.hex @@ -0,0 +1 @@ +d818456449455446
\ No newline at end of file diff --git a/test/files/appendix_a/0052.hex b/test/files/appendix_a/0052.hex new file mode 100644 index 0000000..39b46f7 --- /dev/null +++ b/test/files/appendix_a/0052.hex @@ -0,0 +1 @@ +d82076687474703a2f2f7777772e6578616d706c652e636f6d
\ No newline at end of file diff --git a/test/files/appendix_a/0053.hex b/test/files/appendix_a/0053.hex new file mode 100644 index 0000000..86ee83a --- /dev/null +++ b/test/files/appendix_a/0053.hex @@ -0,0 +1 @@ +40
\ No newline at end of file diff --git a/test/files/appendix_a/0054.hex b/test/files/appendix_a/0054.hex new file mode 100644 index 0000000..1d872dd --- /dev/null +++ b/test/files/appendix_a/0054.hex @@ -0,0 +1 @@ +4401020304
\ No newline at end of file diff --git a/test/files/appendix_a/0055.hex b/test/files/appendix_a/0055.hex new file mode 100644 index 0000000..2b82dfe --- /dev/null +++ b/test/files/appendix_a/0055.hex @@ -0,0 +1 @@ +60
\ No newline at end of file diff --git a/test/files/appendix_a/0056.hex b/test/files/appendix_a/0056.hex new file mode 100644 index 0000000..9e72f44 --- /dev/null +++ b/test/files/appendix_a/0056.hex @@ -0,0 +1 @@ +6161
\ No newline at end of file diff --git a/test/files/appendix_a/0057.hex b/test/files/appendix_a/0057.hex new file mode 100644 index 0000000..dd4878c --- /dev/null +++ b/test/files/appendix_a/0057.hex @@ -0,0 +1 @@ +6449455446
\ No newline at end of file diff --git a/test/files/appendix_a/0058.hex b/test/files/appendix_a/0058.hex new file mode 100644 index 0000000..1ed12cb --- /dev/null +++ b/test/files/appendix_a/0058.hex @@ -0,0 +1 @@ +62225c
\ No newline at end of file diff --git a/test/files/appendix_a/0059.hex b/test/files/appendix_a/0059.hex new file mode 100644 index 0000000..30af0d8 --- /dev/null +++ b/test/files/appendix_a/0059.hex @@ -0,0 +1 @@ +62c3bc
\ No newline at end of file diff --git a/test/files/appendix_a/0060.hex b/test/files/appendix_a/0060.hex new file mode 100644 index 0000000..1007ed1 --- /dev/null +++ b/test/files/appendix_a/0060.hex @@ -0,0 +1 @@ +63e6b0b4
\ No newline at end of file diff --git a/test/files/appendix_a/0061.hex b/test/files/appendix_a/0061.hex new file mode 100644 index 0000000..fd5eb57 --- /dev/null +++ b/test/files/appendix_a/0061.hex @@ -0,0 +1 @@ +64f0908591
\ No newline at end of file diff --git a/test/files/appendix_a/0062.hex b/test/files/appendix_a/0062.hex new file mode 100644 index 0000000..e3f1e9b --- /dev/null +++ b/test/files/appendix_a/0062.hex @@ -0,0 +1 @@ +80
\ No newline at end of file diff --git a/test/files/appendix_a/0063.hex b/test/files/appendix_a/0063.hex new file mode 100644 index 0000000..a40de5e --- /dev/null +++ b/test/files/appendix_a/0063.hex @@ -0,0 +1 @@ +83010203
\ No newline at end of file diff --git a/test/files/appendix_a/0064.hex b/test/files/appendix_a/0064.hex new file mode 100644 index 0000000..12f64c7 --- /dev/null +++ b/test/files/appendix_a/0064.hex @@ -0,0 +1 @@ +8301820203820405
\ No newline at end of file diff --git a/test/files/appendix_a/0065.hex b/test/files/appendix_a/0065.hex new file mode 100644 index 0000000..2f2468d --- /dev/null +++ b/test/files/appendix_a/0065.hex @@ -0,0 +1 @@ +98190102030405060708090a0b0c0d0e0f101112131415161718181819
\ No newline at end of file diff --git a/test/files/appendix_a/0066.hex b/test/files/appendix_a/0066.hex new file mode 100644 index 0000000..c545f2f --- /dev/null +++ b/test/files/appendix_a/0066.hex @@ -0,0 +1 @@ +a0
\ No newline at end of file diff --git a/test/files/appendix_a/0067.hex b/test/files/appendix_a/0067.hex new file mode 100644 index 0000000..38f9a6f --- /dev/null +++ b/test/files/appendix_a/0067.hex @@ -0,0 +1 @@ +a201020304
\ No newline at end of file diff --git a/test/files/appendix_a/0068.hex b/test/files/appendix_a/0068.hex new file mode 100644 index 0000000..15799ae --- /dev/null +++ b/test/files/appendix_a/0068.hex @@ -0,0 +1 @@ +a26161016162820203
\ No newline at end of file diff --git a/test/files/appendix_a/0069.hex b/test/files/appendix_a/0069.hex new file mode 100644 index 0000000..f5f7aed --- /dev/null +++ b/test/files/appendix_a/0069.hex @@ -0,0 +1 @@ +826161a161626163
\ No newline at end of file diff --git a/test/files/appendix_a/0070.hex b/test/files/appendix_a/0070.hex new file mode 100644 index 0000000..8df1df6 --- /dev/null +++ b/test/files/appendix_a/0070.hex @@ -0,0 +1 @@ +a56161614161626142616361436164614461656145
\ No newline at end of file diff --git a/test/files/appendix_a/0071.hex b/test/files/appendix_a/0071.hex new file mode 100644 index 0000000..8c97dce --- /dev/null +++ b/test/files/appendix_a/0071.hex @@ -0,0 +1 @@ +5f42010243030405ff
\ No newline at end of file diff --git a/test/files/appendix_a/0072.hex b/test/files/appendix_a/0072.hex new file mode 100644 index 0000000..0352afd --- /dev/null +++ b/test/files/appendix_a/0072.hex @@ -0,0 +1 @@ +7f657374726561646d696e67ff
\ No newline at end of file diff --git a/test/files/appendix_a/0073.hex b/test/files/appendix_a/0073.hex new file mode 100644 index 0000000..4415c34 --- /dev/null +++ b/test/files/appendix_a/0073.hex @@ -0,0 +1 @@ +9fff
\ No newline at end of file diff --git a/test/files/appendix_a/0074.hex b/test/files/appendix_a/0074.hex new file mode 100644 index 0000000..228b510 --- /dev/null +++ b/test/files/appendix_a/0074.hex @@ -0,0 +1 @@ +9f018202039f0405ffff
\ No newline at end of file diff --git a/test/files/appendix_a/0075.hex b/test/files/appendix_a/0075.hex new file mode 100644 index 0000000..a0f0579 --- /dev/null +++ b/test/files/appendix_a/0075.hex @@ -0,0 +1 @@ +9f01820203820405ff
\ No newline at end of file diff --git a/test/files/appendix_a/0076.hex b/test/files/appendix_a/0076.hex new file mode 100644 index 0000000..b887762 --- /dev/null +++ b/test/files/appendix_a/0076.hex @@ -0,0 +1 @@ +83018202039f0405ff
\ No newline at end of file diff --git a/test/files/appendix_a/0077.hex b/test/files/appendix_a/0077.hex new file mode 100644 index 0000000..300f25e --- /dev/null +++ b/test/files/appendix_a/0077.hex @@ -0,0 +1 @@ +83019f0203ff820405
\ No newline at end of file diff --git a/test/files/appendix_a/0078.hex b/test/files/appendix_a/0078.hex new file mode 100644 index 0000000..076177d --- /dev/null +++ b/test/files/appendix_a/0078.hex @@ -0,0 +1 @@ +9f0102030405060708090a0b0c0d0e0f101112131415161718181819ff
\ No newline at end of file diff --git a/test/files/appendix_a/0079.hex b/test/files/appendix_a/0079.hex new file mode 100644 index 0000000..f57e157 --- /dev/null +++ b/test/files/appendix_a/0079.hex @@ -0,0 +1 @@ +bf61610161629f0203ffff
\ No newline at end of file diff --git a/test/files/appendix_a/0080.hex b/test/files/appendix_a/0080.hex new file mode 100644 index 0000000..c1df54e --- /dev/null +++ b/test/files/appendix_a/0080.hex @@ -0,0 +1 @@ +826161bf61626163ff
\ No newline at end of file diff --git a/test/files/appendix_a/0081.hex b/test/files/appendix_a/0081.hex new file mode 100644 index 0000000..b3025b5 --- /dev/null +++ b/test/files/appendix_a/0081.hex @@ -0,0 +1 @@ +bf6346756ef563416d7421ff
\ No newline at end of file diff --git a/test/files/array000 b/test/files/array000 deleted file mode 100644 index 81c9910..0000000 --- a/test/files/array000 +++ /dev/null @@ -1,2 +0,0 @@ -Ÿ -
ÿ
\ No newline at end of file diff --git a/test/runtests.sh b/test/runtests.sh new file mode 100755 index 0000000..ba49058 --- /dev/null +++ b/test/runtests.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Convert all hex files to binary +find files/ -iname "*.hex" | while read f; do xxd -r -p $f > ${f%.hex}.bin; done + +# Messages +PASS_MSG=$(echo -e "\033[0;32mPASS\033[0m") +FAIL_MSG=$(echo -e "\033[0;31mFAIL\033[0m") + +# Keep totals +total_pass=0 +total_fail=0 + +# Run Appendix A tests +pass=0 +fail=0 + +echo "" +echo "============================== APPENDIX A ==============================" +for f in files/appendix_a/*.bin; do + answer_file=${f%.bin}.answer + result_file=${f%.bin}.result + + ../bin/ecbor-describe $f > $result_file 2>/dev/null + rc=$? + + if [ ! -f $result_file ] || [ ! -f $answer_file ] || [ ! $rc -eq 0 ] || [ "$(diff $answer_file $result_file 2>/dev/null)" != "" ]; then + fail=$(($fail + 1)) + status=$FAIL_MSG + else + pass=$(($pass + 1)) + status=$PASS_MSG + fi + + machine_indented=$(printf '%-67s' "$f") + machine_indented=${machine_indented// /.} + printf "%s %s\n" "$machine_indented" "$status" +done +echo "========================================================================" +echo "Passed / Failed: ${pass}/${fail}" + +total_pass=$(($total_pass + $pass)) +total_fail=$(($total_fail + $fail)) + + +# Final report +echo "" +echo "" +echo "============================== FINAL REPORT ============================" +echo "Total tests passed: $total_pass" +echo "Total tests failed: $total_fail" +echo "========================================================================"
\ No newline at end of file |
