Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame^] | 1 | #include <libcper/base64.h> |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <assert.h> |
| 6 | #include <string.h> |
| 7 | |
| 8 | void test_base64_encode_good() |
| 9 | { |
| 10 | int32_t encoded_len = 0; |
| 11 | const char *data = "f"; |
| 12 | char *encoded = base64_encode((unsigned char *)data, strlen(data), |
| 13 | &encoded_len); |
| 14 | assert(encoded_len == 4); |
| 15 | assert(memcmp(encoded, "Zg==", encoded_len) == 0); |
| 16 | free(encoded); |
| 17 | } |
| 18 | |
| 19 | void test_base64_decode_good() |
| 20 | { |
| 21 | int32_t decoded_len = 0; |
| 22 | const char *data = "Zg=="; |
| 23 | UINT8 *decoded = base64_decode(data, strlen(data), &decoded_len); |
| 24 | assert(decoded_len == 1); |
| 25 | assert(decoded[0] == 'f'); |
| 26 | free(decoded); |
| 27 | } |