Skip to content

Commit f298f73

Browse files
author
Adil Benhlal
committed
test(cbor): cbor_encode_undefined
1 parent b175360 commit f298f73

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/common/cbor/test_cb_cbor_simple.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,46 @@ void test_cb_cbor_encode_null() {
130130
assert(memcmp(expect_t2_s2, ev_t2_s2, 2) == 0);
131131
}
132132

133+
void test_cb_cbor_encode_undefined() {
134+
// TEST 1
135+
// test with size == 0 (no change)
136+
uint8_t ev_t1_s0[2] = {0x00, 0x00}; // encoded value
137+
uint8_t expect_t1_s0[2] = {0x00, 0x00}; // [ 0x00, 0x00 ]
138+
assert(cb_cbor_encode_undefined(ev_t1_s0, 0) == 0);
139+
assert(memcmp(expect_t1_s0, ev_t1_s0, 2) == 0);
140+
141+
// test with size == 1
142+
uint8_t ev_t1_s1[2] = {0x00, 0x00}; // encoded value
143+
uint8_t expect_t1_s1[2] = {0xF7, 0x00}; // [ undefined, 0x00 ]
144+
assert(cb_cbor_encode_undefined(ev_t1_s1, 1) == 1);
145+
assert(memcmp(expect_t1_s1, ev_t1_s1, 2) == 0);
146+
147+
// test with size == 2
148+
uint8_t ev_t1_s2[2] = {0x00, 0x00}; // encoded value
149+
uint8_t expect_t1_s2[2] = {0xF7, 0x00}; // [ undefined, 0x00 ]
150+
assert(cb_cbor_encode_undefined(ev_t1_s2, 2) == 1);
151+
assert(memcmp(expect_t1_s2, ev_t1_s2, 2) == 0);
152+
153+
// TEST 2 (same test with another end byte)
154+
// test with size == 0 (no change)
155+
uint8_t ev_t2_s0[2] = {0x00, 0xAB}; // encoded value
156+
uint8_t expect_t2_s0[2] = {0x00, 0xAB}; // [ 0x00, 0xAB ]
157+
assert(cb_cbor_encode_undefined(ev_t2_s0, 0) == 0);
158+
assert(memcmp(expect_t2_s0, ev_t2_s0, 2) == 0);
159+
160+
// test with size == 1
161+
uint8_t ev_t2_s1[2] = {0xFF, 0xAB}; // encoded value
162+
uint8_t expect_t2_s1[2] = {0xF7, 0xAB}; // [ undefined, 0xAB ]
163+
assert(cb_cbor_encode_undefined(ev_t2_s1, 1) == 1);
164+
assert(memcmp(expect_t2_s1, ev_t2_s1, 2) == 0);
165+
166+
// test with size == 2
167+
uint8_t ev_t2_s2[2] = {0xFF, 0xAB}; // encoded value
168+
uint8_t expect_t2_s2[2] = {0xF7, 0xAB}; // [ undefined, 0xAB ]
169+
assert(cb_cbor_encode_undefined(ev_t2_s2, 2) == 1);
170+
assert(memcmp(expect_t2_s2, ev_t2_s2, 2) == 0);
171+
}
172+
133173
void test_cb_cbor_encode_break() {
134174
// TEST 1
135175
// test with size == 0 (no change)
@@ -175,6 +215,7 @@ int main() {
175215
test_cb_cbor_encode_false();
176216
test_cb_cbor_encode_true();
177217
test_cb_cbor_encode_null();
218+
test_cb_cbor_encode_undefined();
178219
test_cb_cbor_encode_break();
179220

180221
return EXIT_SUCCESS;

0 commit comments

Comments
 (0)