1 /* SPDX-License-Identifier: GPL-2.0-only */
7 #include <b64_decode.h>
8 #include <tests/test.h>
17 {"\nQUJDRA==", "ABCD"},
18 {"SGVsbG8\r=", "Hello"},
19 {"SGVsbG8h", "Hello!"}
22 const char *invalid
[] = {
27 static void test_b64_decode(void **state
)
32 for (int i
= 0; i
< ARRAY_SIZE(messages
); i
++) {
33 decoded
= malloc(strlen(messages
[i
].enc
) * sizeof(char));
35 res
= b64_decode((uint8_t *)messages
[i
].enc
, strlen(messages
[i
].enc
), decoded
);
37 assert_int_equal(res
, (strlen(messages
[i
].dec
)));
41 assert_string_equal((const char *)decoded
, messages
[i
].dec
);
46 for (int i
= 0; i
< ARRAY_SIZE(invalid
); i
++) {
47 decoded
= malloc(strlen(invalid
[i
]) * sizeof(char));
49 res
= b64_decode((uint8_t *)invalid
[i
], strlen(invalid
[i
]), decoded
);
51 assert_int_equal(res
, 0);
59 const struct CMUnitTest tests
[] = {
60 cmocka_unit_test(test_b64_decode
),
63 return cb_run_group_tests(tests
, NULL
, NULL
);