diff --git a/native-schema-registry/c/CMakeLists.txt b/native-schema-registry/c/CMakeLists.txt index e373f38f..b504bf88 100644 --- a/native-schema-registry/c/CMakeLists.txt +++ b/native-schema-registry/c/CMakeLists.txt @@ -26,8 +26,10 @@ set(AWS_COMMON_MEMALLOC aws_common_memalloc) set(NATIVE_SCHEMA_REGISTRY_MODULE_NAME libnativeschemaregistry) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +include_directories("include") +include_directories(${LIB_NATIVE_SCHEMA_REGISTRY_PATH}) + add_subdirectory("src") include (CTest) enable_testing() -add_subdirectory("test") -include_directories("include") \ No newline at end of file +add_subdirectory("test") \ No newline at end of file diff --git a/native-schema-registry/c/include/mutable_byte_array.h b/native-schema-registry/c/include/mutable_byte_array.h index a4d13e8d..0c92184c 100644 --- a/native-schema-registry/c/include/mutable_byte_array.h +++ b/native-schema-registry/c/include/mutable_byte_array.h @@ -1,7 +1,7 @@ #ifndef MUTABLE_BYTE_ARRAY_H #define MUTABLE_BYTE_ARRAY_H #include -#include "../include/glue_schema_registry_error.h" +#include "glue_schema_registry_error.h" //Integer.MAX_VALUE in Java //This gives ~2.1Gb limit on a record. diff --git a/native-schema-registry/c/include/read_only_byte_array.h b/native-schema-registry/c/include/read_only_byte_array.h index 3483b245..8f890576 100644 --- a/native-schema-registry/c/include/read_only_byte_array.h +++ b/native-schema-registry/c/include/read_only_byte_array.h @@ -1,7 +1,7 @@ #ifndef READ_ONLY_BYTE_ARRAY_H #define READ_ONLY_BYTE_ARRAY_H #include -#include "../include/glue_schema_registry_error.h" +#include "glue_schema_registry_error.h" typedef struct read_only_byte_array { unsigned char * data; diff --git a/native-schema-registry/c/src/CMakeLists.txt b/native-schema-registry/c/src/CMakeLists.txt index 1e8056d6..8689f8e5 100644 --- a/native-schema-registry/c/src/CMakeLists.txt +++ b/native-schema-registry/c/src/CMakeLists.txt @@ -1,10 +1,15 @@ #Fix the include path in GraalVM generated header file. execute_process(COMMAND sed -ie "s//\"graal_isolate.h\"/" ${LIB_NATIVE_SCHEMA_REGISTRY_PATH}/libnativeschemaregistry.h) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs -ggdb3 -O2 -Wall") -include(cmake/FetchAwsCommon.cmake) +if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin)$") + list(APPEND TEST_COVERAGE "-fsanitize=address,undefined -fsanitize-recover=address") +else() + #TODO: Figure out equivalent options for Windows + list(APPEND TEST_COVERAGE "") +endif() +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEST_COVERAGE} -O2 -Wall") -include_directories("include") +include(cmake/FetchAwsCommon.cmake) add_library(${AWS_COMMON_MEMALLOC} SHARED memory_allocator.c) target_link_libraries(${AWS_COMMON_MEMALLOC} ${AWS_C_COMMON}) @@ -88,6 +93,7 @@ swig_link_libraries( PUBLIC ${DATA_TYPES_MODULE_NAME} ${SERDE_MODULE_NAME} + ${AWS_COMMON_MEMALLOC} ${NATIVE_SCHEMA_REGISTRY_MODULE_NAME} ) ##TODO: Fix this during release. We should segregate Debug and Release @@ -98,6 +104,7 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E copy $ ${CSHARP_GEN_LIB_PATH}/ COMMAND ${CMAKE_COMMAND} -E copy $ ${CSHARP_GEN_LIB_PATH}/ COMMAND ${CMAKE_COMMAND} -E copy $ ${CSHARP_GEN_LIB_PATH}/ + COMMAND ${CMAKE_COMMAND} -E copy $ ${CSHARP_GEN_LIB_PATH}/ COMMAND ${CMAKE_COMMAND} -E copy $ ${CSHARP_GEN_LIB_PATH}/ ) diff --git a/native-schema-registry/c/src/glue_schema_registry_deserializer.c b/native-schema-registry/c/src/glue_schema_registry_deserializer.c index 06ea34fc..7441cf1d 100644 --- a/native-schema-registry/c/src/glue_schema_registry_deserializer.c +++ b/native-schema-registry/c/src/glue_schema_registry_deserializer.c @@ -1,6 +1,6 @@ -#include "../include/glue_schema_registry_deserializer.h" -#include "../include/memory_allocator.h" -#include "../../target/libnativeschemaregistry.h" +#include "glue_schema_registry_deserializer.h" +#include "memory_allocator.h" +#include "libnativeschemaregistry.h" #include glue_schema_registry_deserializer * new_glue_schema_registry_deserializer(glue_schema_registry_error **p_err) { @@ -35,16 +35,26 @@ void delete_glue_schema_registry_deserializer(glue_schema_registry_deserializer aws_common_free(deserializer); } -mutable_byte_array *glue_schema_registry_deserializer_decode(glue_schema_registry_deserializer * deserializer, - read_only_byte_array *array, - glue_schema_registry_error **p_err) { +static bool validate( + glue_schema_registry_deserializer *deserializer, + read_only_byte_array *array, + glue_schema_registry_error **p_err) { if (deserializer == NULL || deserializer->instance_context == NULL) { throw_error(p_err, "Deserializer instance or instance context is null.", ERR_CODE_INVALID_STATE); - return NULL; + return false; } if (array == NULL || array->len == 0) { throw_error(p_err, "Byte array cannot be null", ERR_CODE_NULL_PARAMETERS); + return false; + } + return true; +} + +mutable_byte_array *glue_schema_registry_deserializer_decode(glue_schema_registry_deserializer * deserializer, + read_only_byte_array *array, + glue_schema_registry_error **p_err) { + if (!validate(deserializer, array, p_err)) { return NULL; } @@ -54,13 +64,7 @@ mutable_byte_array *glue_schema_registry_deserializer_decode(glue_schema_registr glue_schema_registry_schema *glue_schema_registry_deserializer_decode_schema(glue_schema_registry_deserializer * deserializer, read_only_byte_array *array, glue_schema_registry_error **p_err) { - if (deserializer == NULL || deserializer->instance_context == NULL) { - throw_error(p_err, "Deserializer instance or instance context is null.", ERR_CODE_INVALID_STATE); - return NULL; - } - - if (array == NULL || array->len == 0) { - throw_error(p_err, "Byte array cannot be null", ERR_CODE_NULL_PARAMETERS); + if (!validate(deserializer, array, p_err)) { return NULL; } @@ -71,13 +75,7 @@ glue_schema_registry_schema *glue_schema_registry_deserializer_decode_schema(glu bool glue_schema_registry_deserializer_can_decode(glue_schema_registry_deserializer * deserializer, read_only_byte_array *array, glue_schema_registry_error **p_err) { - if (deserializer == NULL || deserializer->instance_context == NULL) { - throw_error(p_err, "Deserializer instance or instance context is null.", ERR_CODE_INVALID_STATE); - return NULL; - } - - if (array == NULL || array->len == 0) { - throw_error(p_err, "Byte array cannot be null", ERR_CODE_NULL_PARAMETERS); + if (!validate(deserializer, array, p_err)) { return NULL; } diff --git a/native-schema-registry/c/src/glue_schema_registry_error.c b/native-schema-registry/c/src/glue_schema_registry_error.c index 8615a2b2..8e07dc50 100644 --- a/native-schema-registry/c/src/glue_schema_registry_error.c +++ b/native-schema-registry/c/src/glue_schema_registry_error.c @@ -1,20 +1,21 @@ #include #include -#include "../include/memory_allocator.h" -#include "../include/glue_schema_registry_error.h" +#include +#include "memory_allocator.h" +#include "glue_schema_registry_error.h" -static int validate(const char *err_msg) { +static bool validate(const char *err_msg) { if (err_msg == NULL) { - return 1; + return false; } - return 0; + return true; } glue_schema_registry_error *new_glue_schema_registry_error( const char *err_msg, int err_code) { - if (validate(err_msg) != 0) { + if (!validate(err_msg)) { log_warn("Error message cannot be null", ERR_CODE_NULL_PARAMETERS); return NULL; } @@ -28,12 +29,11 @@ glue_schema_registry_error *new_glue_schema_registry_error( void delete_glue_schema_registry_error(glue_schema_registry_error *error) { if (error == NULL) { - log_warn("Error pointer passed is NULL", ERR_CODE_NULL_PARAMETERS); return; } if (error->msg != NULL) { - aws_common_free(error->msg); + free(error->msg); error->msg = NULL; } error->code = 0; diff --git a/native-schema-registry/c/src/glue_schema_registry_schema.c b/native-schema-registry/c/src/glue_schema_registry_schema.c index 2862d192..c1f5be22 100644 --- a/native-schema-registry/c/src/glue_schema_registry_schema.c +++ b/native-schema-registry/c/src/glue_schema_registry_schema.c @@ -1,6 +1,6 @@ -#include "../include/glue_schema_registry_schema.h" -#include "../include/glue_schema_registry_error.h" -#include "../include/memory_allocator.h" +#include "glue_schema_registry_schema.h" +#include "glue_schema_registry_error.h" +#include "memory_allocator.h" #include static int validate(const char *schema_name, const char *schema_def, const char *data_format) { @@ -41,13 +41,13 @@ void delete_glue_schema_registry_schema(glue_schema_registry_schema * glueSchema } if (glueSchemaRegistrySchema->schema_name != NULL) { - aws_common_free(glueSchemaRegistrySchema->schema_name); + free(glueSchemaRegistrySchema->schema_name); } if (glueSchemaRegistrySchema->schema_def != NULL) { - aws_common_free(glueSchemaRegistrySchema->schema_def); + free(glueSchemaRegistrySchema->schema_def); } if (glueSchemaRegistrySchema->data_format != NULL) { - aws_common_free(glueSchemaRegistrySchema->data_format); + free(glueSchemaRegistrySchema->data_format); } aws_common_free(glueSchemaRegistrySchema); } diff --git a/native-schema-registry/c/src/glue_schema_registry_serializer.c b/native-schema-registry/c/src/glue_schema_registry_serializer.c index 589ac5b8..b995ba78 100644 --- a/native-schema-registry/c/src/glue_schema_registry_serializer.c +++ b/native-schema-registry/c/src/glue_schema_registry_serializer.c @@ -1,6 +1,6 @@ -#include "../include/glue_schema_registry_serializer.h" -#include "../include/memory_allocator.h" -#include "../../target/libnativeschemaregistry.h" +#include "glue_schema_registry_serializer.h" +#include "memory_allocator.h" +#include "libnativeschemaregistry.h" #include glue_schema_registry_serializer *new_glue_schema_registry_serializer(glue_schema_registry_error **p_err) { diff --git a/native-schema-registry/c/src/memory_allocator.c b/native-schema-registry/c/src/memory_allocator.c index 2e129707..543245b5 100644 --- a/native-schema-registry/c/src/memory_allocator.c +++ b/native-schema-registry/c/src/memory_allocator.c @@ -1,4 +1,4 @@ -#include "../include/memory_allocator.h" +#include "memory_allocator.h" #include "aws/common/allocator.h" /* diff --git a/native-schema-registry/c/src/mutable_byte_array.c b/native-schema-registry/c/src/mutable_byte_array.c index af171d72..f423920a 100644 --- a/native-schema-registry/c/src/mutable_byte_array.c +++ b/native-schema-registry/c/src/mutable_byte_array.c @@ -1,6 +1,6 @@ -#include "../include/mutable_byte_array.h" -#include "../include/glue_schema_registry_error.h" -#include "../include/memory_allocator.h" +#include "mutable_byte_array.h" +#include "glue_schema_registry_error.h" +#include "memory_allocator.h" #include /** diff --git a/native-schema-registry/c/src/read_only_byte_array.c b/native-schema-registry/c/src/read_only_byte_array.c index a0550516..98e9ed07 100644 --- a/native-schema-registry/c/src/read_only_byte_array.c +++ b/native-schema-registry/c/src/read_only_byte_array.c @@ -1,5 +1,5 @@ -#include "../include/read_only_byte_array.h" -#include "../include/memory_allocator.h" +#include "read_only_byte_array.h" +#include "memory_allocator.h" #include diff --git a/native-schema-registry/c/test/CMakeLists.txt b/native-schema-registry/c/test/CMakeLists.txt index 265ba75c..a0cde910 100644 --- a/native-schema-registry/c/test/CMakeLists.txt +++ b/native-schema-registry/c/test/CMakeLists.txt @@ -1,7 +1,20 @@ -list(APPEND sanitizer_checks "-fsanitize=address,undefined -fsanitize-recover=address -fno-stack-protector") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${sanitizer_checks} -fprofile-arcs -ftest-coverage -ggdb3 -O2 -Wall") +if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin)$") + list(APPEND SANITIZER_CHECKS "-fsanitize=address,undefined -fsanitize-recover=address -fno-stack-protector") +else() + #TODO: Figure out equivalent options for Windows + list(APPEND SANITIZER_CHECKS "") +endif() +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_CHECKS} -Wall") include(cmake/FetchCMocka.cmake) +set(TEST_HELPERS test_helpers) +add_library(${TEST_HELPERS} glue_schema_registry_test_helper.c) +target_link_libraries(${TEST_HELPERS} cmocka) + +##GraalVM Mock +add_library(${NATIVE_SCHEMA_REGISTRY_MODULE_NAME} libnativeschemaregistry_mock.c) +target_link_libraries(${NATIVE_SCHEMA_REGISTRY_MODULE_NAME} cmocka) + list( APPEND tests @@ -12,15 +25,28 @@ list( glue_schema_registry_error_test ) -foreach (test ${tests}) +#TODO: These tests don't work on Windows and OSX due to CMake not linking the mock library. +#We have to investigate and fix these. +if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + list(APPEND + tests + glue_schema_registry_serializer_test + glue_schema_registry_deserializer_test + ) +ENDIF () + +foreach (test ${tests}) add_executable( "${test}" "${test}.c" - ) + ) target_link_libraries( "${test}" "${DATA_TYPES_MODULE_NAME}" + "${SERDE_MODULE_NAME}" + "${NATIVE_SCHEMA_REGISTRY_MODULE_NAME}" "${AWS_COMMON_MEMALLOC}" + "${TEST_HELPERS}" "cmocka" ) @@ -28,6 +54,8 @@ foreach (test ${tests}) endforeach () add_custom_target(copy-libs-for-tests ALL - COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR}/ - COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR}/ + COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR}/ + COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR}/ + COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR}/ + COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR}/ ) \ No newline at end of file diff --git a/native-schema-registry/c/test/glue_schema_registry_deserializer_test.c b/native-schema-registry/c/test/glue_schema_registry_deserializer_test.c new file mode 100644 index 00000000..e6548b68 --- /dev/null +++ b/native-schema-registry/c/test/glue_schema_registry_deserializer_test.c @@ -0,0 +1,325 @@ +#include +#include "cmocka.h" +#include "libnativeschemaregistry_mock.h" +#include "glue_schema_registry_test_helper.h" +#include "glue_schema_registry_deserializer.h" + +static void test_new_glue_schema_registry_deserializer_created_successfully(void **state) { + set_mock_state(GRAAL_VM_INIT_SUCCESS); + glue_schema_registry_deserializer *gsr_deserializer = new_glue_schema_registry_deserializer(NULL); + + assert_non_null(gsr_deserializer); + assert_non_null(gsr_deserializer->instance_context); + assert_int_equal(sizeof(graal_isolatethread_t *), sizeof(gsr_deserializer->instance_context)); + delete_glue_schema_registry_deserializer(gsr_deserializer); + + clear_mock_state(); +} + +static void test_new_glue_schema_registry_deserializer_init_fails_throws_exception(void **state) { + set_mock_state(GRAAL_VM_INIT_FAIL); + + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + glue_schema_registry_deserializer *gsr_deserializer = new_glue_schema_registry_deserializer(p_err); + + assert_null(gsr_deserializer); + assert_error_and_clear(p_err, "Failed to initialize GraalVM isolate.", ERR_CODE_GRAALVM_INIT_EXCEPTION); + + delete_glue_schema_registry_deserializer(gsr_deserializer); + + clear_mock_state(); +} + +static void test_new_glue_schema_registry_deserializer_deletes_instance(void **state) { + set_mock_state(GRAAL_VM_INIT_SUCCESS); + + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + glue_schema_registry_deserializer *gsr_deserializer = new_glue_schema_registry_deserializer(p_err); + + assert_non_null(gsr_deserializer); + delete_glue_schema_registry_deserializer(gsr_deserializer); + delete_glue_schema_registry_error_holder(p_err); + + clear_mock_state(); +} + +static void test_new_glue_schema_registry_deserializer_delete_ignores_NULL_deserializer(void **state) { + delete_glue_schema_registry_deserializer(NULL); + assert_true(1); +} + +static void test_new_glue_schema_registry_deserializer_delete_ignores_tear_down_failure(void **state) { + set_mock_state(TEAR_DOWN_FAIL); + + glue_schema_registry_deserializer *deserializer = new_glue_schema_registry_deserializer(NULL); + delete_glue_schema_registry_deserializer(deserializer); + + clear_mock_state(); +} + +static void test_new_glue_schema_registry_deserializer_decodes_successfully(void **state) { + set_mock_state(GRAAL_VM_INIT_SUCCESS); + + read_only_byte_array *arr = get_read_only_byte_array_fixture(); + + glue_schema_registry_deserializer *deserializer = new_glue_schema_registry_deserializer(NULL); + + mutable_byte_array *mut_byte_array = glue_schema_registry_deserializer_decode( + deserializer, + arr, + NULL + ); + + mutable_byte_array *expected = get_mut_byte_array_fixture(); + + assert_non_null(mut_byte_array); + assert_int_equal(expected->max_len, mut_byte_array->max_len); + assert_mutable_byte_array_eq(*expected, *mut_byte_array); + + delete_glue_schema_registry_deserializer(deserializer); + delete_read_only_byte_array(arr); + delete_mutable_byte_array(mut_byte_array); + delete_mutable_byte_array(expected); + clear_mock_state(); +} + +static void test_new_glue_schema_registry_deserializer_decode_throws_exception(void **state) { + set_mock_state(DECODE_FAILURE); + + read_only_byte_array *arr = get_read_only_byte_array_fixture(); + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + + glue_schema_registry_deserializer *deserializer = new_glue_schema_registry_deserializer(NULL); + + mutable_byte_array *mut_byte_array = glue_schema_registry_deserializer_decode( + deserializer, + arr, + p_err + ); + + assert_null(mut_byte_array); + assert_error_and_clear(p_err, "Decoding failed", ERR_CODE_RUNTIME_ERROR); + + delete_glue_schema_registry_deserializer(deserializer); + delete_read_only_byte_array(arr); + clear_mock_state(); +} + +static void test_new_glue_schema_registry_deserializer_decode_deserializer_null_throws_exception(void **state) { + read_only_byte_array *arr = get_read_only_byte_array_fixture(); + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + + mutable_byte_array *mutableByteArray = glue_schema_registry_deserializer_decode( + NULL, + arr, + p_err + ); + + assert_null(mutableByteArray); + assert_error_and_clear(p_err, "Deserializer instance or instance context is null.", ERR_CODE_INVALID_STATE); + + delete_read_only_byte_array(arr); +} + +static void test_new_glue_schema_registry_deserializer_decode_arr_null_throws_exception(void **state) { + set_mock_state(GRAAL_VM_INIT_SUCCESS); + + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + glue_schema_registry_deserializer *deserializer = new_glue_schema_registry_deserializer(NULL); + + mutable_byte_array *mutableByteArray = glue_schema_registry_deserializer_decode( + deserializer, + NULL, + p_err + ); + + assert_null(mutableByteArray); + assert_error_and_clear(p_err, "Byte array cannot be null", ERR_CODE_NULL_PARAMETERS); + + delete_glue_schema_registry_deserializer(deserializer); + + clear_mock_state(); +} + +static void test_new_glue_schema_registry_deserializer_decodes_schema_successfully(void **state) { + set_mock_state(GRAAL_VM_INIT_SUCCESS); + + read_only_byte_array *arr = get_read_only_byte_array_fixture(); + + glue_schema_registry_deserializer *deserializer = new_glue_schema_registry_deserializer(NULL); + + glue_schema_registry_schema *schema = glue_schema_registry_deserializer_decode_schema( + deserializer, + arr, + NULL + ); + + glue_schema_registry_schema *expected = get_gsr_schema_fixture(); + + assert_non_null(schema); + assert_gsr_schema(*expected, *schema); + + delete_glue_schema_registry_deserializer(deserializer); + delete_glue_schema_registry_schema(schema); + delete_glue_schema_registry_schema(expected); + delete_read_only_byte_array(arr); + + clear_mock_state(); +} + +static void test_new_glue_schema_registry_deserializer_decode_schema_throws_exception(void **state) { + set_mock_state(DECODE_SCHEMA_FAILURE); + + read_only_byte_array *arr = get_read_only_byte_array_fixture(); + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + + glue_schema_registry_deserializer *deserializer = new_glue_schema_registry_deserializer(NULL); + + glue_schema_registry_schema *schema = glue_schema_registry_deserializer_decode_schema( + deserializer, + arr, + p_err + ); + + assert_null(schema); + assert_error_and_clear(p_err, "Decoding schema failed", ERR_CODE_RUNTIME_ERROR); + + delete_glue_schema_registry_deserializer(deserializer); + delete_read_only_byte_array(arr); + clear_mock_state(); +} + +static void test_new_glue_schema_registry_deserializer_decode_schema_deserializer_null_throws_exception(void **state) { + read_only_byte_array *arr = get_read_only_byte_array_fixture(); + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + + glue_schema_registry_schema *schema = glue_schema_registry_deserializer_decode_schema( + NULL, + arr, + p_err + ); + + assert_null(schema); + assert_error_and_clear(p_err, "Deserializer instance or instance context is null.", ERR_CODE_INVALID_STATE); + + delete_read_only_byte_array(arr); +} + +static void test_new_glue_schema_registry_deserializer_decode_schema_arr_null_throws_exception(void **state) { + set_mock_state(GRAAL_VM_INIT_SUCCESS); + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + glue_schema_registry_deserializer *deserializer = new_glue_schema_registry_deserializer(NULL); + + glue_schema_registry_schema *schema = glue_schema_registry_deserializer_decode_schema( + deserializer, + NULL, + p_err + ); + + assert_null(schema); + assert_error_and_clear(p_err, "Byte array cannot be null", ERR_CODE_NULL_PARAMETERS); + + delete_glue_schema_registry_deserializer(deserializer); + + clear_mock_state(); +} + +static void test_new_glue_schema_registry_deserializer_can_decode_successfully(void **state) { + set_mock_state(GRAAL_VM_INIT_SUCCESS); + read_only_byte_array *arr = get_read_only_byte_array_fixture(); + + glue_schema_registry_deserializer *deserializer = new_glue_schema_registry_deserializer(NULL); + + bool can_decode = glue_schema_registry_deserializer_can_decode( + deserializer, + arr, + NULL + ); + + assert_true(can_decode); + delete_glue_schema_registry_deserializer(deserializer); + delete_read_only_byte_array(arr); + + clear_mock_state(); +} + +static void test_new_glue_schema_registry_deserializer_can_decode_throws_exception(void **state) { + set_mock_state(CAN_DECODE_FAILURE); + + read_only_byte_array *arr = get_read_only_byte_array_fixture(); + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + + glue_schema_registry_deserializer *deserializer = new_glue_schema_registry_deserializer(NULL); + + bool can_decode = glue_schema_registry_deserializer_can_decode( + deserializer, + arr, + p_err + ); + + assert_false(can_decode); + assert_error_and_clear(p_err, "Can decode failed", ERR_CODE_RUNTIME_ERROR); + + delete_glue_schema_registry_deserializer(deserializer); + delete_read_only_byte_array(arr); + clear_mock_state(); +} + +static void test_new_glue_schema_registry_deserializer_can_decode_deserializer_null_throws_exception(void **state) { + read_only_byte_array *arr = get_read_only_byte_array_fixture(); + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + + bool can_decode = glue_schema_registry_deserializer_can_decode( + NULL, + arr, + p_err + ); + + assert_false(can_decode); + assert_error_and_clear(p_err, "Deserializer instance or instance context is null.", ERR_CODE_INVALID_STATE); + + delete_read_only_byte_array(arr); +} + +static void test_new_glue_schema_registry_deserializer_can_decode_arr_null_throws_exception(void **state) { + set_mock_state(GRAAL_VM_INIT_SUCCESS); + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + glue_schema_registry_deserializer *deserializer = new_glue_schema_registry_deserializer(NULL); + + bool can_decode = glue_schema_registry_deserializer_can_decode( + deserializer, + NULL, + p_err + ); + + assert_false(can_decode); + assert_error_and_clear(p_err, "Byte array cannot be null", ERR_CODE_NULL_PARAMETERS); + + delete_glue_schema_registry_deserializer(deserializer); + + clear_mock_state(); +} + +int main(void) { + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_new_glue_schema_registry_deserializer_created_successfully), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_init_fails_throws_exception), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_deletes_instance), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_delete_ignores_NULL_deserializer), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_delete_ignores_tear_down_failure), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_decodes_successfully), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_decode_throws_exception), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_decode_deserializer_null_throws_exception), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_decode_arr_null_throws_exception), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_decodes_schema_successfully), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_decode_schema_deserializer_null_throws_exception), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_decode_schema_arr_null_throws_exception), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_decode_schema_throws_exception), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_can_decode_successfully), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_can_decode_deserializer_null_throws_exception), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_can_decode_arr_null_throws_exception), + cmocka_unit_test(test_new_glue_schema_registry_deserializer_can_decode_throws_exception) + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/native-schema-registry/c/test/glue_schema_registry_error_test.c b/native-schema-registry/c/test/glue_schema_registry_error_test.c index a0dac7b9..58aa3716 100644 --- a/native-schema-registry/c/test/glue_schema_registry_error_test.c +++ b/native-schema-registry/c/test/glue_schema_registry_error_test.c @@ -1,4 +1,4 @@ -#include "../include/glue_schema_registry_error.h" +#include "glue_schema_registry_error.h" #include #include "cmocka.h" @@ -90,7 +90,7 @@ static void glue_schema_registry_error_holder_creates_deletes_instance(void **st delete_glue_schema_registry_error_holder(p_err); } -int main() { +int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(glue_schema_registry_error_deletes_the_instance), diff --git a/native-schema-registry/c/test/glue_schema_registry_schema_test.c b/native-schema-registry/c/test/glue_schema_registry_schema_test.c index f1df2ab5..c72fa2ab 100644 --- a/native-schema-registry/c/test/glue_schema_registry_schema_test.c +++ b/native-schema-registry/c/test/glue_schema_registry_schema_test.c @@ -1,17 +1,12 @@ -#include "../include/glue_schema_registry_schema.h" +#include "glue_schema_registry_schema.h" #include #include "cmocka.h" +#include "glue_schema_registry_test_helper.h" #define TEST_SCHEMA_NAME "Employee.proto" #define TEST_DATA_FORMAT "PROTOBUF" #define TEST_SCHEMA_DEF "message Employee { string name = 1; int32 rank = 2;}" -static void assert_gsr_schema(glue_schema_registry_schema expected, glue_schema_registry_schema actual) { - assert_string_equal(expected.schema_name, actual.schema_name); - assert_string_equal(expected.schema_def, actual.schema_def); - assert_string_equal(expected.data_format, actual.data_format); -} - static void schema_cleanup(glue_schema_registry_schema * obj) { delete_glue_schema_registry_schema(obj); } @@ -113,7 +108,7 @@ static void glue_schema_registry_schema_not_fail_when_error_pointer_is_null(void schema_cleanup(gsr_schema); } -int main() { +int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(glue_schema_registry_schema_deletes_the_instance), cmocka_unit_test(glue_schema_registry_schema_when_NULLs_are_passed_does_not_initialize), diff --git a/native-schema-registry/c/test/glue_schema_registry_serializer_test.c b/native-schema-registry/c/test/glue_schema_registry_serializer_test.c new file mode 100644 index 00000000..a47b597c --- /dev/null +++ b/native-schema-registry/c/test/glue_schema_registry_serializer_test.c @@ -0,0 +1,202 @@ +#include +#include "glue_schema_registry_serializer.h" +#include "graal_isolate.h" +#include "cmocka.h" +#include "libnativeschemaregistry_mock.h" +#include "glue_schema_registry_test_helper.h" + +static void test_new_glue_schema_registry_serializer_created_successfully(void **state) { + set_mock_state(GRAAL_VM_INIT_SUCCESS); + glue_schema_registry_serializer *gsr_serializer = new_glue_schema_registry_serializer(NULL); + + assert_non_null(gsr_serializer); + assert_non_null(gsr_serializer->instance_context); + assert_int_equal(sizeof(graal_isolatethread_t *), sizeof(gsr_serializer->instance_context)); + delete_glue_schema_registry_serializer(gsr_serializer); + + clear_mock_state(); +} + +static void test_new_glue_schema_registry_serializer_init_fails_throws_exception(void **state) { + set_mock_state(GRAAL_VM_INIT_FAIL); + + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + glue_schema_registry_serializer *gsr_serializer = new_glue_schema_registry_serializer(p_err); + + assert_null(gsr_serializer); + assert_error_and_clear(p_err, "Failed to initialize GraalVM isolate.", ERR_CODE_GRAALVM_INIT_EXCEPTION); + + delete_glue_schema_registry_serializer(gsr_serializer); + + clear_mock_state(); +} + +static void test_new_glue_schema_registry_serializer_deletes_instance(void **state) { + set_mock_state(GRAAL_VM_INIT_SUCCESS); + + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + glue_schema_registry_serializer *gsr_serializer = new_glue_schema_registry_serializer(p_err); + + assert_non_null(gsr_serializer); + delete_glue_schema_registry_serializer(gsr_serializer); + delete_glue_schema_registry_error_holder(p_err); + + clear_mock_state(); +} + +static void test_new_glue_schema_registry_serializer_delete_ignores_NULL_serializer(void **state) { + delete_glue_schema_registry_serializer(NULL); + assert_true(1); +} + +static void test_new_glue_schema_registry_serializer_delete_ignores_tear_down_failure(void **state) { + set_mock_state(TEAR_DOWN_FAIL); + glue_schema_registry_serializer *serializer = new_glue_schema_registry_serializer(NULL); + delete_glue_schema_registry_serializer(serializer); + + clear_mock_state(); +} + + +static void test_new_glue_schema_registry_serializer_encodes_successfully(void **state) { + set_mock_state(GRAAL_VM_INIT_SUCCESS); + const char *transport_name = get_transport_name_fixture(); + glue_schema_registry_schema *schema = get_gsr_schema_fixture(); + read_only_byte_array *arr = get_read_only_byte_array_fixture(); + + glue_schema_registry_serializer *serializer = new_glue_schema_registry_serializer(NULL); + + mutable_byte_array *mut_byte_array = glue_schema_registry_serializer_encode( + serializer, + arr, + transport_name, + schema, + NULL + ); + + mutable_byte_array *expected = get_mut_byte_array_fixture(); + + assert_non_null(mut_byte_array); + assert_int_equal(expected->max_len, mut_byte_array->max_len); + assert_mutable_byte_array_eq(*expected, *mut_byte_array); + + delete_glue_schema_registry_serializer(serializer); + delete_glue_schema_registry_schema(schema); + delete_read_only_byte_array(arr); + delete_mutable_byte_array(mut_byte_array); + delete_mutable_byte_array(expected); + clear_mock_state(); +} + +static void test_new_glue_schema_registry_serializer_encode_throws_exception(void **state) { + set_mock_state(ENCODE_FAILURE); + const char *transport_name = get_transport_name_fixture(); + glue_schema_registry_schema *schema = get_gsr_schema_fixture(); + read_only_byte_array *arr = get_read_only_byte_array_fixture(); + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + + glue_schema_registry_serializer *serializer = new_glue_schema_registry_serializer(NULL); + + mutable_byte_array *mut_byte_array = glue_schema_registry_serializer_encode( + serializer, + arr, + transport_name, + schema, + p_err + ); + + assert_null(mut_byte_array); + assert_error_and_clear(p_err, "Encoding failed", ERR_CODE_RUNTIME_ERROR); + + delete_glue_schema_registry_serializer(serializer); + delete_glue_schema_registry_schema(schema); + delete_read_only_byte_array(arr); + clear_mock_state(); +} + +static void test_new_glue_schema_registry_serializer_encode_serializer_null_throws_exception(void **state) { + const char *transport_name = get_transport_name_fixture(); + glue_schema_registry_schema *schema = get_gsr_schema_fixture(); + read_only_byte_array *arr = get_read_only_byte_array_fixture(); + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + + mutable_byte_array *mutableByteArray = glue_schema_registry_serializer_encode( + NULL, + arr, + transport_name, + schema, + p_err + ); + + assert_null(mutableByteArray); + assert_error_and_clear(p_err, "Serializer instance or instance context is null.", ERR_CODE_INVALID_STATE); + + delete_glue_schema_registry_schema(schema); + delete_read_only_byte_array(arr); +} + +static void test_new_glue_schema_registry_serializer_encode_schema_null_throws_exception(void **state) { + set_mock_state(GRAAL_VM_INIT_SUCCESS); + const char *transport_name = get_transport_name_fixture(); + read_only_byte_array *arr = get_read_only_byte_array_fixture(); + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + glue_schema_registry_serializer *serializer = new_glue_schema_registry_serializer(NULL); + + mutable_byte_array *mutableByteArray = glue_schema_registry_serializer_encode( + serializer, + arr, + transport_name, + NULL, + p_err + ); + + assert_null(mutableByteArray); + assert_error_and_clear(p_err, "Schema passed cannot be null", ERR_CODE_NULL_PARAMETERS); + + delete_glue_schema_registry_serializer(serializer); + delete_read_only_byte_array(arr); + + clear_mock_state(); +} + +static void test_new_glue_schema_registry_serializer_encode_arr_null_throws_exception(void **state) { + set_mock_state(GRAAL_VM_INIT_SUCCESS); + const char *transport_name = get_transport_name_fixture(); + glue_schema_registry_schema *schema = get_gsr_schema_fixture(); + glue_schema_registry_error **p_err = new_glue_schema_registry_error_holder(); + glue_schema_registry_serializer *serializer = new_glue_schema_registry_serializer(NULL); + + mutable_byte_array *mutableByteArray = glue_schema_registry_serializer_encode( + serializer, + NULL, + transport_name, + schema, + p_err + ); + + assert_null(mutableByteArray); + assert_error_and_clear(p_err, "Byte array cannot be null", ERR_CODE_NULL_PARAMETERS); + + delete_glue_schema_registry_serializer(serializer); + delete_glue_schema_registry_schema(schema); + + clear_mock_state(); +} + + +int main(void) { + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_new_glue_schema_registry_serializer_created_successfully), + cmocka_unit_test(test_new_glue_schema_registry_serializer_init_fails_throws_exception), + cmocka_unit_test(test_new_glue_schema_registry_serializer_deletes_instance), + cmocka_unit_test(test_new_glue_schema_registry_serializer_delete_ignores_NULL_serializer), + cmocka_unit_test(test_new_glue_schema_registry_serializer_delete_ignores_tear_down_failure), + cmocka_unit_test(test_new_glue_schema_registry_serializer_encodes_successfully), + cmocka_unit_test(test_new_glue_schema_registry_serializer_encode_throws_exception), + cmocka_unit_test(test_new_glue_schema_registry_serializer_encode_serializer_null_throws_exception), + cmocka_unit_test(test_new_glue_schema_registry_serializer_encode_schema_null_throws_exception), + cmocka_unit_test(test_new_glue_schema_registry_serializer_encode_arr_null_throws_exception) + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/native-schema-registry/c/test/glue_schema_registry_test_helper.c b/native-schema-registry/c/test/glue_schema_registry_test_helper.c new file mode 100644 index 00000000..da23c105 --- /dev/null +++ b/native-schema-registry/c/test/glue_schema_registry_test_helper.c @@ -0,0 +1,51 @@ +#include +#include +#include "glue_schema_registry_test_helper.h" +#include "cmocka.h" + +glue_schema_registry_schema * get_gsr_schema_fixture(void) { + return new_glue_schema_registry_schema("SomeNameOfSchema", "Some Def {}", "PROTOBUF", NULL); +} + +read_only_byte_array * get_read_only_byte_array_fixture(void) { + unsigned char payload[24]; + return new_read_only_byte_array(payload, sizeof(payload), NULL); +} + +mutable_byte_array * get_mut_byte_array_fixture(void) { + const char * test_data = "Test data to write 🦷👑"; + size_t len = strlen(test_data) + 1; + return new_mutable_byte_array(len, NULL); +} + +void assert_mutable_byte_array_eq(mutable_byte_array expected, mutable_byte_array actual) { + assert_int_equal(expected.max_len, actual.max_len); + + //Ensure the pointers are not pointing to same memory address + assert_ptr_not_equal(expected.data, actual.data); + + for (size_t index = 0; index < expected.max_len; index++) { + assert_int_equal(expected.data[index], actual.data[index]); + } +} + +const char * get_transport_name_fixture(void) { + return "Some transport name 123✅"; +} + +void assert_error_and_clear(glue_schema_registry_error **p_err, const char *msg, int code) { + assert_non_null(p_err); + glue_schema_registry_error *err = *p_err; + + assert_non_null(err); + assert_int_equal(code, err->code); + assert_string_equal(msg, err->msg); + + delete_glue_schema_registry_error_holder(p_err); +} + +void assert_gsr_schema(glue_schema_registry_schema expected, glue_schema_registry_schema actual) { + assert_string_equal(expected.schema_name, actual.schema_name); + assert_string_equal(expected.schema_def, actual.schema_def); + assert_string_equal(expected.data_format, actual.data_format); +} diff --git a/native-schema-registry/c/test/glue_schema_registry_test_helper.h b/native-schema-registry/c/test/glue_schema_registry_test_helper.h new file mode 100644 index 00000000..158bfc85 --- /dev/null +++ b/native-schema-registry/c/test/glue_schema_registry_test_helper.h @@ -0,0 +1,21 @@ +#ifndef NATIVE_SCHEMA_REGISTRY_TEST_FIXTURES_H +#define NATIVE_SCHEMA_REGISTRY_TEST_FIXTURES_H +#include "read_only_byte_array.h" +#include "mutable_byte_array.h" +#include "glue_schema_registry_schema.h" + +glue_schema_registry_schema * get_gsr_schema_fixture(void); + +read_only_byte_array * get_read_only_byte_array_fixture(void); + +mutable_byte_array * get_mut_byte_array_fixture(void); + +void assert_mutable_byte_array_eq(mutable_byte_array expected, mutable_byte_array actual); + +void assert_error_and_clear(glue_schema_registry_error **p_err, const char *msg, int code); + +void assert_gsr_schema(glue_schema_registry_schema, glue_schema_registry_schema); + +const char * get_transport_name_fixture(void); + +#endif //NATIVE_SCHEMA_REGISTRY_TEST_FIXTURES_H diff --git a/native-schema-registry/c/test/libnativeschemaregistry_mock.c b/native-schema-registry/c/test/libnativeschemaregistry_mock.c new file mode 100644 index 00000000..3651e3ba --- /dev/null +++ b/native-schema-registry/c/test/libnativeschemaregistry_mock.c @@ -0,0 +1,136 @@ +#include +#include +#include "cmocka.h" +#include "glue_schema_registry_serializer.h" +#include "glue_schema_registry_test_helper.h" +#include "libnativeschemaregistry.h" +#include "libnativeschemaregistry_mock.h" + +//Mocks the functions provided by GraalVM image. + +static int MOCK_STATE = UNINITIALIZED; + +void set_mock_state(int state) { + MOCK_STATE = state; +} + +void clear_mock_state(void) { + MOCK_STATE = UNINITIALIZED; +} + +static void validate_mock_state() { + if (MOCK_STATE == UNINITIALIZED) { + fprintf(stderr, "TEST ERROR: Mock not initialized. Invalid state\n"); + assert_true(0); + } +} + +int graal_create_isolate(graal_create_isolate_params_t* params, graal_isolate_t** isolate, graal_isolatethread_t** thread) { + validate_mock_state(); + + assert_null(params); + assert_null(isolate); + assert_non_null(thread); + + *thread = (graal_isolatethread_t*) malloc(sizeof(graal_isolatethread_t*)); + if (MOCK_STATE == GRAAL_VM_INIT_FAIL) { + return -1; + } + return 0; +} + +int graal_tear_down_isolate(graal_isolatethread_t* isolateThread) { + validate_mock_state(); + + free(isolateThread); + if (MOCK_STATE == TEAR_DOWN_FAIL) { + return -1; + } + return 0; +} + +void initialize_serializer(graal_isolatethread_t* thread) { + validate_mock_state(); + + assert_non_null(thread); + //do nothing +} + +void initialize_deserializer(graal_isolatethread_t* thread) { + validate_mock_state(); + + assert_non_null(thread); + //do nothing +} + +mutable_byte_array* encode_with_schema( + graal_isolatethread_t* isolatethread, + read_only_byte_array* byte_array, + const char* transport_name, + glue_schema_registry_schema* schema, + glue_schema_registry_error** p_err) { + validate_mock_state(); + + assert_non_null(isolatethread); + assert_non_null(byte_array); + assert_non_null(transport_name); + assert_non_null(schema); + + if (MOCK_STATE == ENCODE_FAILURE) { + *p_err = new_glue_schema_registry_error("Encoding failed", ERR_CODE_RUNTIME_ERROR); + return NULL; + } + + return get_mut_byte_array_fixture(); +} + +mutable_byte_array* decode( + graal_isolatethread_t* isolatethread, + read_only_byte_array* byte_array, + glue_schema_registry_error** p_err) { + validate_mock_state(); + + assert_non_null(isolatethread); + assert_non_null(byte_array); + + if (MOCK_STATE == DECODE_FAILURE) { + *p_err = new_glue_schema_registry_error("Decoding failed", ERR_CODE_RUNTIME_ERROR); + return NULL; + } + + return get_mut_byte_array_fixture(); +} + +glue_schema_registry_schema *decode_schema( + graal_isolatethread_t* isolatethread, + read_only_byte_array* byte_array, + glue_schema_registry_error** p_err) { + validate_mock_state(); + + assert_non_null(isolatethread); + assert_non_null(byte_array); + + if (MOCK_STATE == DECODE_SCHEMA_FAILURE) { + *p_err = new_glue_schema_registry_error("Decoding schema failed", ERR_CODE_RUNTIME_ERROR); + return NULL; + } + + return get_gsr_schema_fixture(); +} + +char can_decode( + graal_isolatethread_t* isolatethread, + read_only_byte_array* byte_array, + glue_schema_registry_error** p_err) { + validate_mock_state(); + + assert_non_null(isolatethread); + assert_non_null(byte_array); + + if (MOCK_STATE == CAN_DECODE_FAILURE) { + *p_err = new_glue_schema_registry_error("Can decode failed", ERR_CODE_RUNTIME_ERROR); + return 0; + } + + return 1; +} diff --git a/native-schema-registry/c/test/libnativeschemaregistry_mock.h b/native-schema-registry/c/test/libnativeschemaregistry_mock.h new file mode 100644 index 00000000..cd1aa674 --- /dev/null +++ b/native-schema-registry/c/test/libnativeschemaregistry_mock.h @@ -0,0 +1,19 @@ +#ifndef NATIVE_SCHEMA_REGISTRY_LIBNATIVESCHEMAREGISTRY_MOCK_H +#define NATIVE_SCHEMA_REGISTRY_LIBNATIVESCHEMAREGISTRY_MOCK_H + +#include "graal_isolate.h" + +enum MOCK_STATES { + UNINITIALIZED = 8999, + GRAAL_VM_INIT_SUCCESS = 9000, + GRAAL_VM_INIT_FAIL = 9001, + TEAR_DOWN_FAIL = 9003, + ENCODE_FAILURE = 9004, + DECODE_FAILURE = 9005, + DECODE_SCHEMA_FAILURE = 9006, + CAN_DECODE_FAILURE = 9007 +}; +void set_mock_state(int state); +void clear_mock_state(void); + +#endif //NATIVE_SCHEMA_REGISTRY_LIBNATIVESCHEMAREGISTRY_MOCK_H diff --git a/native-schema-registry/c/test/mutable_byte_array_test.c b/native-schema-registry/c/test/mutable_byte_array_test.c index b019f7b8..0d30b87d 100644 --- a/native-schema-registry/c/test/mutable_byte_array_test.c +++ b/native-schema-registry/c/test/mutable_byte_array_test.c @@ -1,6 +1,7 @@ #include #include "cmocka.h" -#include "../include/mutable_byte_array.h" +#include "glue_schema_registry_test_helper.h" +#include "mutable_byte_array.h" const char * test_mutable_array_payload = "Foobar 01-23 1231!!!!!🍎aosmd🦷"; @@ -13,17 +14,6 @@ static unsigned char * create_mutable_test_payload() { return data; } -static void assert_mutable_byte_array_eq(mutable_byte_array expected, mutable_byte_array actual) { - assert_int_equal(expected.max_len, actual.max_len); - - //Ensure the pointers are not pointing to same memory address - assert_ptr_not_equal(expected.data, actual.data); - - for (size_t index = 0; index < expected.max_len; index++) { - assert_int_equal(expected.data[index], actual.data[index]); - } -} - static void assert_mutable_byte_array_data_zero(mutable_byte_array *byte_array) { for (size_t index = 0; index < byte_array->max_len; index++) { assert_int_equal(byte_array->data[index], 0); @@ -228,7 +218,7 @@ static void mutable_byte_array_test_ignores_null_err_pointer(void **state) { delete_mutable_byte_array(byte_array); } -int main() { +int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(mutable_byte_array_test_creates_byte_array), cmocka_unit_test(mutable_byte_array_test_returns_NULL_when_initialized_empty), diff --git a/native-schema-registry/c/test/read_only_byte_array_test.c b/native-schema-registry/c/test/read_only_byte_array_test.c index f94180f8..fb22ea06 100644 --- a/native-schema-registry/c/test/read_only_byte_array_test.c +++ b/native-schema-registry/c/test/read_only_byte_array_test.c @@ -1,6 +1,6 @@ #include #include "cmocka.h" -#include "../include/read_only_byte_array.h" +#include "read_only_byte_array.h" const char * test_array_payload = "🦀HelloWorld!!!!!🥶"; @@ -107,7 +107,7 @@ static void read_only_byte_array_test_does_not_fail_when_error_pointer_is_null(v byte_array_cleanup(byte_array, expected); } -int main() { +int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(read_only_byte_array_test_creates_byte_array), cmocka_unit_test(read_only_byte_array_test_deletes_byte_array), diff --git a/native-schema-registry/csharp/AWSGsrSerDe/Libs/Libs.projitems b/native-schema-registry/csharp/AWSGsrSerDe/Libs/Libs.projitems index dcec6f1c..7f76a2fa 100644 --- a/native-schema-registry/csharp/AWSGsrSerDe/Libs/Libs.projitems +++ b/native-schema-registry/csharp/AWSGsrSerDe/Libs/Libs.projitems @@ -21,5 +21,8 @@ Always + + Always +