@@ -50,6 +50,46 @@ void test_cb_cbor_encode_false() {
5050 assert (memcmp (expect_t2_s2 , ev_t2_s2 , 2 ) == 0 );
5151}
5252
53+ void test_cb_cbor_encode_true () {
54+ // TEST 1
55+ // test with size == 0 (no change)
56+ uint8_t ev_t1_s0 [2 ] = {0x00 , 0x00 }; // encoded value
57+ uint8_t expect_t1_s0 [2 ] = {0x00 , 0x00 }; // [ 0x00, 0x00 ]
58+ assert (cb_cbor_encode_true (ev_t1_s0 , 0 ) == 0 );
59+ assert (memcmp (expect_t1_s0 , ev_t1_s0 , 2 ) == 0 );
60+
61+ // test with size == 1
62+ uint8_t ev_t1_s1 [2 ] = {0x00 , 0x00 }; // encoded value
63+ uint8_t expect_t1_s1 [2 ] = {0xF5 , 0x00 }; // [ true, 0x00 ]
64+ assert (cb_cbor_encode_true (ev_t1_s1 , 1 ) == 1 );
65+ assert (memcmp (expect_t1_s1 , ev_t1_s1 , 2 ) == 0 );
66+
67+ // test with size == 2
68+ uint8_t ev_t1_s2 [2 ] = {0x00 , 0x00 }; // encoded value
69+ uint8_t expect_t1_s2 [2 ] = {0xF5 , 0x00 }; // [ true, 0x00 ]
70+ assert (cb_cbor_encode_true (ev_t1_s2 , 2 ) == 1 );
71+ assert (memcmp (expect_t1_s2 , ev_t1_s2 , 2 ) == 0 );
72+
73+ // TEST 2 (same test with another end byte)
74+ // test with size == 0 (no change)
75+ uint8_t ev_t2_s0 [2 ] = {0x00 , 0xAB }; // encoded value
76+ uint8_t expect_t2_s0 [2 ] = {0x00 , 0xAB }; // [ 0x00, 0xAB ]
77+ assert (cb_cbor_encode_true (ev_t2_s0 , 0 ) == 0 );
78+ assert (memcmp (expect_t2_s0 , ev_t2_s0 , 2 ) == 0 );
79+
80+ // test with size == 1
81+ uint8_t ev_t2_s1 [2 ] = {0xFF , 0xAB }; // encoded value
82+ uint8_t expect_t2_s1 [2 ] = {0xF5 , 0xAB }; // [ true, 0xAB ]
83+ assert (cb_cbor_encode_true (ev_t2_s1 , 1 ) == 1 );
84+ assert (memcmp (expect_t2_s1 , ev_t2_s1 , 2 ) == 0 );
85+
86+ // test with size == 2
87+ uint8_t ev_t2_s2 [2 ] = {0xFF , 0xAB }; // encoded value
88+ uint8_t expect_t2_s2 [2 ] = {0xF5 , 0xAB }; // [ true, 0xAB ]
89+ assert (cb_cbor_encode_true (ev_t2_s2 , 2 ) == 1 );
90+ assert (memcmp (expect_t2_s2 , ev_t2_s2 , 2 ) == 0 );
91+ }
92+
5393void test_cb_cbor_encode_null () {
5494 // TEST 1
5595 // test with size == 0 (no change)
@@ -133,6 +173,7 @@ void test_cb_cbor_encode_break() {
133173// TODO: criterion or cmocka
134174int main () {
135175 test_cb_cbor_encode_false ();
176+ test_cb_cbor_encode_true ();
136177 test_cb_cbor_encode_null ();
137178 test_cb_cbor_encode_break ();
138179
0 commit comments