test: Add tests for isd_get_commercial_credit()
[libisds.git] / test / offline / b64decode.c
blob43633b223d247392605e11099b810c94cd84d52a
1 #include "../test.h"
2 #include "utils.h"
3 #include <string.h>
5 static int test_b64decode(const void *input, const void *correct,
6 size_t correct_length) {
7 void *output = NULL;
8 size_t length;
10 length = _isds_b64decode(input, &output);
12 if (length == correct_length) {
13 if (length != -1) {
14 if (!memcmp(correct, output, length)) {
15 free(output);
16 PASS_TEST;
17 } else {
18 free(output);
19 FAIL_TEST("Output length matches, but content differs");
21 } else {
22 free(output);
24 if (output == NULL) {
25 PASS_TEST;
26 } else {
27 FAIL_TEST("Output length signals error as expected, "
28 "but content has not been deallocated");
31 } else {
32 free(output);
33 /* Format as signed to get -1 as error. Big positive numbers should
34 * not occure in these tests */
35 FAIL_TEST("Output length differs: expected=%zd, got=%zd",
36 correct_length, length);
39 free(output);
40 FAIL_TEST("Test could not been judged -- Internal test error");
44 static int test_b64decode_null_pointer(const void *input,
45 size_t correct_length) {
46 size_t length;
48 length = _isds_b64decode(input, NULL);
50 if (length == correct_length)
51 PASS_TEST
52 else
53 /* Format as signed to get -1 as error. Big positive numbers should
54 * not occure in these tests */
55 FAIL_TEST("Output length differs: expected=%zd, got=%zd",
56 correct_length, length)
60 int main(int argc, char **argv) {
61 INIT_TEST("b64decode");
63 TEST("generic", test_b64decode, "Af+qVQA=\n", "\x1\xff\xaa\x55", 5);
64 TEST("partial cycle", test_b64decode, "MQA=\n", "1", 2);
65 TEST("1 cycle", test_b64decode, "NDIA\n", "42", 3);
66 TEST("2 cycles", test_b64decode, "MTIzNDUA\n", "12345", 6);
67 TEST("generic with new line", test_b64decode, "NDIA\n", "42", 3);
68 TEST("generic without new line", test_b64decode, "NDIA", "42", 3);
69 TEST("new line only", test_b64decode, "\n", NULL, 0);
70 TEST("empty string", test_b64decode, "", NULL, 0);
71 TEST("incomplete input", test_b64decode, "42", "\xe3", 1);
72 TEST("NULL input", test_b64decode, NULL, NULL, (size_t) -1);
73 TEST("NULL output pointer", test_b64decode_null_pointer, "\n",
74 (size_t) -1);
76 SUM_TEST();