7c6081e02b
When running multiple tests, e.g. by using unit-tests target, it is hard to differentiate, which output comes from which file and/or configuration. This patch makes the output easier to analyze and understand by using new wrapper macro cb_run_group_tests(). This macro uses __TEST_NAME__ value (containing test path and Makefile test name) as a group name when calling cmocka group runner. Example: Test path: tests/lib/ Makefile test name: cbmem_stage_cache-test Test group array name: tests Result: tests/lib/cbmem_stage_cache-test(tests) Signed-off-by: Jakub Czapiga <jacz@semihalf.com> Change-Id: I4fd936d00d77cbe2637b857ba03b4a208428ea0d Reviewed-on: https://review.coreboot.org/c/coreboot/+/57144 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
61 lines
1.2 KiB
C
61 lines
1.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <b64_decode.h>
|
|
#include <tests/test.h>
|
|
|
|
struct messages_t {
|
|
const char *enc;
|
|
const char *dec;
|
|
} messages[] = {
|
|
{"QQ==", "A"},
|
|
{"Q\r\nUI=", "AB"},
|
|
{"QUJD", "ABC"},
|
|
{"\nQUJDRA==", "ABCD"},
|
|
{"SGVsbG8\r=", "Hello"},
|
|
{"SGVsbG8h", "Hello!"}
|
|
};
|
|
|
|
const char *invalid[] = {
|
|
"QQ=-=",
|
|
"SGVsbG-8="
|
|
};
|
|
|
|
static void test_b64_decode(void **state)
|
|
{
|
|
uint8_t *decoded;
|
|
size_t res;
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(messages); i++) {
|
|
decoded = malloc(strlen(messages[i].enc) * sizeof(char));
|
|
|
|
res = b64_decode((uint8_t *)messages[i].enc, strlen(messages[i].enc), decoded);
|
|
|
|
assert_int_equal(res, (strlen(messages[i].dec)));
|
|
assert_string_equal(decoded, messages[i].dec);
|
|
|
|
free(decoded);
|
|
}
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(invalid); i++) {
|
|
decoded = malloc(strlen(invalid[i]) * sizeof(char));
|
|
|
|
res = b64_decode((uint8_t *)invalid[i], strlen(invalid[i]), decoded);
|
|
|
|
assert_int_equal(res, 0);
|
|
|
|
free(decoded);
|
|
}
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
const struct CMUnitTest tests[] = {
|
|
cmocka_unit_test(test_b64_decode),
|
|
};
|
|
|
|
return cb_run_group_tests(tests, NULL, NULL);
|
|
}
|