Free empty output of base64 decoder
[libisds.git] / test / b64encode.c
blobfa677fb520fd670dbec9285eb475aab939c89985
1 #include "test.h"
2 #include "utils.h"
3 #include <string.h>
5 static int test_b64encode(const char *correct, const void *input,
6 size_t length) {
7 char *output = NULL;
9 output = _isds_b64encode(input, length);
11 if (correct == NULL && output == NULL) {
12 PASS_TEST;
15 if (correct != NULL && output == NULL) {
16 FAIL_TEST("Excpected non-NULL, got NULL");
19 if (correct == NULL && output != NULL) {
20 free(output);
21 FAIL_TEST("Excpected NULL, got non-NULL");
24 if (strcmp(correct, output)) {
25 test_asprintf(&reason, "Wrong return value: expected=`%s', got=`%s'",
26 correct, output);
27 free(output);
28 return 1;
31 free(output);
32 PASS_TEST;
36 int main(int argc, char **argv) {
37 INIT_TEST("b64encode");
39 TEST("generic", test_b64encode, "NDIA\n", "42", 3);
40 TEST("empty string", test_b64encode, "AA==\n", "", 1);
41 TEST("NULL input, 0 length", test_b64encode, "\n", NULL, 0);
42 TEST("non-NULL input, 0 length", test_b64encode, "\n", "", 0);
43 TEST("NULL input, non-zero length", test_b64encode, NULL, NULL, 1);
45 SUM_TEST();