l10n: Update translation catalogues
[libisds.git] / test / offline / b64decode.c
blob3b41d24509157a26e8196e711a7d324f765754f5
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);
11 TEST_DESTRUCTOR(free, output);
13 if (length == correct_length) {
14 if (length != (size_t)-1) {
15 if (!memcmp(correct, output, length)) {
16 PASS_TEST;
17 } else {
18 FAIL_TEST("Output length matches, but content differs");
20 } else {
21 if (output == NULL) {
22 PASS_TEST;
23 } else {
24 FAIL_TEST("Output length signals error as expected, "
25 "but content has not been deallocated");
28 } else {
29 /* Format as signed to get -1 as error. Big positive numbers should
30 * not occure in these tests */
31 FAIL_TEST("Output length differs: expected=%zd, got=%zd",
32 correct_length, length);
37 static int test_b64decode_null_pointer(const void *input,
38 size_t correct_length) {
39 size_t length;
41 length = _isds_b64decode(input, NULL);
43 if (length == correct_length)
44 PASS_TEST
45 else
46 /* Format as signed to get -1 as error. Big positive numbers should
47 * not occure in these tests */
48 FAIL_TEST("Output length differs: expected=%zd, got=%zd",
49 correct_length, length)
53 int main(void) {
54 INIT_TEST("b64decode");
56 TEST("generic", test_b64decode, "Af+qVQA=\n", "\x1\xff\xaa\x55", 5);
57 TEST("partial cycle", test_b64decode, "MQA=\n", "1", 2);
58 TEST("1 cycle", test_b64decode, "NDIA\n", "42", 3);
59 TEST("2 cycles", test_b64decode, "MTIzNDUA\n", "12345", 6);
60 TEST("generic with new line", test_b64decode, "NDIA\n", "42", 3);
61 TEST("generic without new line", test_b64decode, "NDIA", "42", 3);
62 TEST("new line only", test_b64decode, "\n", NULL, 0);
63 TEST("empty string", test_b64decode, "", NULL, 0);
64 TEST("incomplete input", test_b64decode, "42", "\xe3", 1);
65 TEST("NULL input", test_b64decode, NULL, NULL, (size_t) -1);
66 TEST("NULL output pointer", test_b64decode_null_pointer, "\n",
67 (size_t) -1);
69 SUM_TEST();