soc/intel/pantherlake: Enable CPU feature programming in coreboot
[coreboot.git] / tests / lib / b64_decode-test.c
blob8560eb2cccce61426b95091f3322380777792b2d
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <stddef.h>
4 #include <stdint.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <b64_decode.h>
8 #include <tests/test.h>
10 struct messages_t {
11 const char *enc;
12 const char *dec;
13 } messages[] = {
14 {"QQ==", "A"},
15 {"Q\r\nUI=", "AB"},
16 {"QUJD", "ABC"},
17 {"\nQUJDRA==", "ABCD"},
18 {"SGVsbG8\r=", "Hello"},
19 {"SGVsbG8h", "Hello!"}
22 const char *invalid[] = {
23 "QQ=-=",
24 "SGVsbG-8="
27 static void test_b64_decode(void **state)
29 uint8_t *decoded;
30 size_t res;
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)));
39 decoded[res] = 0x00;
41 assert_string_equal((const char *)decoded, messages[i].dec);
43 free(decoded);
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);
53 free(decoded);
57 int main(void)
59 const struct CMUnitTest tests[] = {
60 cmocka_unit_test(test_b64_decode),
63 return cb_run_group_tests(tests, NULL, NULL);