1 #include "config_ast.h"  // IWYU pragma: keep
2 
3 #include <string.h>
4 #include <sys/types.h>
5 
6 #include "ast.h"
7 #include "terror.h"
8 
9 struct base64_tests {
10     const char *string;
11     const char *base64_string;
12 };
13 
14 struct base64_tests tests[] = {{"VIJZoMLCe1dwwqMiPKC1", "VklKWm9NTENlMWR3d3FNaVBLQzE="},
15                                {"CHCqOznM5peGMaIoccsL", "Q0hDcU96bk01cGVHTWFJb2Njc0w="},
16                                {"RbaVtZYLF9FmuOemXKzi", "UmJhVnRaWUxGOUZtdU9lbVhLemk="},
17                                {"2qKoXd2yH3dcoywNQfDL", "MnFLb1hkMnlIM2Rjb3l3TlFmREw="},
18                                {"iVFjwRZTPrXzQoEbnisP", "aVZGandSWlRQclh6UW9FYm5pc1A="},
19                                {"JDkAUes8uamPqIPwQKGV", "SkRrQVVlczh1YW1QcUlQd1FLR1Y="},
20                                {"bf0bCcTT1LySrR9eHi53", "YmYwYkNjVFQxTHlTclI5ZUhpNTM="},
21                                {"wwsbeqm8xYinra82fDlx", "d3dzYmVxbTh4WWlucmE4MmZEbHg="},
22                                {"pFkDWTcwbGATCiPJpkhy", "cEZrRFdUY3diR0FUQ2lQSnBraHk="},
23                                {"ENwnLtgW5VLvNicthw0N", "RU53bkx0Z1c1Vkx2TmljdGh3ME4="},
24                                {NULL, NULL}};
25 
26 // TODO: What shall we do with the test in 'src/lib/libast/tests/misc/base64.c' ?
tmain()27 tmain() {
28     UNUSED(argc);
29     UNUSED(argv);
30 
31     char encoded_result[1024];
32     char decoded_result[1024];
33     ssize_t result_size;
34 
35     for (int i = 0; tests[i].string; ++i) {
36         result_size = base64encode(tests[i].string, strlen(tests[i].string), encoded_result,
37                                    sizeof(encoded_result));
38 
39         if (result_size != strlen(encoded_result)) {
40             terror("base64encode() :: Invalid return value :: Expected: %d, Actual: %d",
41                    strlen(encoded_result), result_size);
42         }
43 
44         if (strcmp(tests[i].base64_string, encoded_result)) {
45             terror("base64encode() :: Invalid result :: Expected: %s, Actual: %s",
46                    tests[i].base64_string, encoded_result);
47         }
48 
49         result_size = base64decode(encoded_result, strlen(encoded_result), decoded_result,
50                                    sizeof(decoded_result));
51 
52         if (result_size != strlen(decoded_result)) {
53             terror("base64encode() :: Invalid return value :: Expected: %d, Actual: %d",
54                    strlen(decoded_result), result_size);
55         }
56 
57         if (strcmp(decoded_result, tests[i].string)) {
58             terror("base64decode() :: Invalid result :: Expected: %s, Actual: %s", tests[i].string,
59                    decoded_result);
60         }
61     }
62 
63     texit(0);
64 }
65