nb/intel/sandybridge: Use SA devid to identify PC type
[coreboot2.git] / tests / lib / b64_decode-test.c
blob189ce9623779e35a644879c7edb78bc567415cfe
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)));
38 assert_string_equal((const char *)decoded, messages[i].dec);
40 free(decoded);
43 for (int i = 0; i < ARRAY_SIZE(invalid); i++) {
44 decoded = malloc(strlen(invalid[i]) * sizeof(char));
46 res = b64_decode((uint8_t *)invalid[i], strlen(invalid[i]), decoded);
48 assert_int_equal(res, 0);
50 free(decoded);
54 int main(void)
56 const struct CMUnitTest tests[] = {
57 cmocka_unit_test(test_b64_decode),
60 return cb_run_group_tests(tests, NULL, NULL);