diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:19:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:20:02 +0000 |
commit | 58daab21cd043e1dc37024a7f99b396788372918 (patch) | |
tree | 96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /fluent-bit/tests/internal/base64.c | |
parent | Releasing debian version 1.43.2-1. (diff) | |
download | netdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz netdata-58daab21cd043e1dc37024a7f99b396788372918.zip |
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fluent-bit/tests/internal/base64.c')
-rw-r--r-- | fluent-bit/tests/internal/base64.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/fluent-bit/tests/internal/base64.c b/fluent-bit/tests/internal/base64.c new file mode 100644 index 000000000..4375870fc --- /dev/null +++ b/fluent-bit/tests/internal/base64.c @@ -0,0 +1,50 @@ +#include <fluent-bit/flb_sds.h> +#include <fluent-bit/flb_mem.h> +#include <fluent-bit/flb_base64.h> +#include <fluent-bit/flb_time.h> + +#include "flb_tests_internal.h" + +static void b64_basic_test_encode() +{ + char* data = "Hello world"; + char out[100]; + char* expect = "SGVsbG8gd29ybGQ="; + size_t olen; + out[16] = 'X'; + + flb_base64_encode((unsigned char *) out, 100, &olen, (unsigned char *)data, 11); + + TEST_CHECK(strlen(out) == 16 && olen == 16); + TEST_MSG("Base64 encode failed to output result of expected length"); + + TEST_CHECK(strcmp(out, expect) == 0); + TEST_MSG("Base64 encode failed to output result of expected value"); + + TEST_CHECK(out[16] == 0); + TEST_MSG("Base64 not null terminated"); + return; +} + +static void b64_basic_test_decode() +{ + char* data = "SGVsbG8gd29ybGQ="; + char out[100] = { 0 }; + char* expect = "Hello world"; + size_t olen; + + flb_base64_decode((unsigned char *) out, 100, &olen, (unsigned char *)data, 16); + + TEST_CHECK(strlen(out) == 11 && olen == 11); + TEST_MSG("Base64 decode failed to output result of expected length"); + + TEST_CHECK(strcmp(out, expect) == 0); + TEST_MSG("Base64 decode failed to output result of expected value"); + return; +} + +TEST_LIST = { + { "b64_basic_test_encode" , b64_basic_test_encode }, + { "b64_basic_test_decode", b64_basic_test_decode }, + { 0 } +}; |