mirror of
https://github.com/pumpitupdev/pumptools.git
synced 2025-02-20 04:01:00 +01:00
util/base64: Add tests
This commit is contained in:
parent
8c66e6b763
commit
628a5d040e
@ -1,2 +1,3 @@
|
||||
add_subdirectory(base64)
|
||||
add_subdirectory(mem)
|
||||
add_subdirectory(str)
|
11
cmake/src/test/util/base64/CMakeLists.txt
Normal file
11
cmake/src/test/util/base64/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
project(test-util-base64)
|
||||
message(STATUS "Project " ${PROJECT_NAME})
|
||||
|
||||
set(SRC ${PT_ROOT_TEST}/util/base64)
|
||||
|
||||
set(SOURCE_FILES
|
||||
${SRC}/main.c)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} cmocka test-util util)
|
58
src/test/util/base64/main.c
Normal file
58
src/test/util/base64/main.c
Normal file
@ -0,0 +1,58 @@
|
||||
#include <cmocka/cmocka.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "test-util/mem.h"
|
||||
|
||||
#include "util/base64.h"
|
||||
#include "util/mem.h"
|
||||
|
||||
static int setup(void** state)
|
||||
{
|
||||
test_util_mem_install_mem_interface();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_base64_encode(void** state)
|
||||
{
|
||||
const char* exp_str = "dGhpcyBpcyBhIHRlc3Qgc3RyaW5nIHdpdGggc3R1ZmYgKiYjJDEyMzIxOiJ9e3wrXygp";
|
||||
|
||||
const char* str = "this is a test string with stuff *&#$12321:\"}{|+_()";
|
||||
size_t len = strlen(str);
|
||||
|
||||
size_t out_len = 0;
|
||||
|
||||
uint8_t* out_data = util_base64_encode((const uint8_t*) str, len, &out_len);
|
||||
|
||||
assert_int_equal(out_len, strlen(exp_str));
|
||||
assert_string_equal(out_data, exp_str);
|
||||
|
||||
util_xfree((void**) &out_data);
|
||||
}
|
||||
|
||||
static void test_base64_decode(void** state)
|
||||
{
|
||||
const char* exp_str = "this is a test string with stuff *&#$12321:\"}{|+_()";
|
||||
|
||||
const char* str = "dGhpcyBpcyBhIHRlc3Qgc3RyaW5nIHdpdGggc3R1ZmYgKiYjJDEyMzIxOiJ9e3wrXygp";
|
||||
size_t len = strlen(str);
|
||||
|
||||
size_t out_len = 0;
|
||||
|
||||
uint8_t* out_data = util_base64_decode((const uint8_t*) str, len, &out_len);
|
||||
|
||||
assert_int_equal(out_len, strlen(exp_str));
|
||||
assert_string_equal(out_data, exp_str);
|
||||
|
||||
util_xfree((void**) &out_data);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
const struct CMUnitTest tests[] ={
|
||||
cmocka_unit_test_setup(test_base64_encode, setup),
|
||||
cmocka_unit_test_setup(test_base64_decode, setup),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user