|
| 1 | +/** |
| 2 | + * Copyright (c) 2021-present Adil Benhlal <[email protected]> |
| 3 | + * |
| 4 | + */ |
| 5 | + |
| 6 | +#include <assert.h> |
| 7 | +#include <stdio.h> |
| 8 | +#include <stdlib.h> |
| 9 | +#include <string.h> |
| 10 | + |
| 11 | +#include "common/cbor/cb_cbor_array.h" |
| 12 | +#include "common/cbor/cb_cbor_int.h" |
| 13 | + |
| 14 | +void test_cb_cbor_array() { |
| 15 | + uint8_t ev_array[4] = {0xFF, 0xFF, 0xFF, 0xFF}; // encoded value |
| 16 | + uint8_t expect_array[4] = {0x83, 0x0E, 0x00, 0x17}; // [ 0x83, 0x0E, 0x00, 0x17 ] |
| 17 | + assert(cb_cbor_encode_array_start(ev_array, 3, 4) == 1); |
| 18 | + assert(cb_cbor_encode_uint(14, ev_array + 1, 3) == 1); |
| 19 | + assert(cb_cbor_encode_uint(0, ev_array + 2, 2) == 1); |
| 20 | + assert(cb_cbor_encode_uint(23, ev_array + 3, 1) == 1); |
| 21 | + assert(memcmp(expect_array, ev_array, 4) == 0); |
| 22 | +} |
| 23 | + |
| 24 | +void test_cb_cbor_array_indef() { |
| 25 | + uint8_t ev_array_indef[5] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA}; // encoded value |
| 26 | + uint8_t expect_array_indef[5] = {0x9F, 0x0E, 0x00, 0x17, 0xFF}; // [ 0x9F, 0x0E, 0x00, 0x17, 0xFF ] |
| 27 | + assert(cb_cbor_encode_array_start_indef(ev_array_indef, 5) == 1); |
| 28 | + assert(cb_cbor_encode_uint(14, ev_array_indef + 1, 4) == 1); |
| 29 | + assert(cb_cbor_encode_uint(0, ev_array_indef + 2, 3) == 1); |
| 30 | + assert(cb_cbor_encode_uint(23, ev_array_indef + 3, 2) == 1); |
| 31 | + assert(cb_cbor_encode_array_stop_indef(ev_array_indef + 4, 1) == 1); |
| 32 | + assert(memcmp(expect_array_indef, ev_array_indef, 5) == 0); |
| 33 | +} |
| 34 | + |
| 35 | +// TODO: criterion or cmocka |
| 36 | +int main() { |
| 37 | + test_cb_cbor_array(); |
| 38 | + test_cb_cbor_array_indef(); |
| 39 | + |
| 40 | + return EXIT_SUCCESS; |
| 41 | +} |
0 commit comments