diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt index 9097c34..23cc869 100644 --- a/c/CMakeLists.txt +++ b/c/CMakeLists.txt @@ -25,7 +25,7 @@ add_library(kuliya SHARED kuliya.h) set_target_properties(kuliya PROPERTIES LINKER_LANGUAGE C) # Create the test executable -add_executable(test test/test.c) +add_executable(test test/test.cpp) # Create the example executable add_executable(example example/main.c) @@ -33,13 +33,11 @@ add_executable(example2 example/main.cpp) # Link the test and example executables with the "kuliya" library -target_link_libraries(test kuliya) target_link_libraries(example kuliya) target_link_libraries(example2 kuliya) # Link the build and test executables with the "helpers" library target_link_libraries(build helpers) -target_link_libraries(test helpers) # Find and link the jsmn library find_package(jsmn REQUIRED) @@ -47,8 +45,11 @@ target_link_libraries(build jsmn::jsmn) # Link the "helpers" shared library with libunistring find_package(libunistring REQUIRED) -target_link_libraries(test libunistring::libunistring) target_link_libraries(build libunistring::libunistring) +# Link test executable with "CppUTest" library +find_package(CppUTest REQUIRED) +target_link_libraries(test PRIVATE kuliya helpers cpputest::cpputest libunistring::libunistring) + # Print a success message message("CMakeLists.txt updated successfully.") diff --git a/c/conanfile.txt b/c/conanfile.txt index 8817c65..ab14d34 100644 --- a/c/conanfile.txt +++ b/c/conanfile.txt @@ -1,6 +1,7 @@ [requires] jsmn/1.1.0 libunistring/1.1 +cpputest/4.0 [generators] CMakeDeps diff --git a/c/test/test.c b/c/test/test.c deleted file mode 100644 index 1b88ded..0000000 --- a/c/test/test.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "test.h" - -int test_get_existing_schema(void) -{ - kuliya_schema *res = get_node_by_path("umkb"); - if (res == NULL) - return 1; - - assert(STR_EQ(res->name.ar, "جامعة محمد خيضر بسكرة") && "arabic names were not equal"); - assert(STR_EQ(res->name.en, "University of Mohamed Khider Biskra") && "english names were not equal"); - assert(STR_EQ(res->name.fr, "Université Mohamed Khider Biskra") && "french names were not equal"); - assert(res->type == UNIVERSITY && "schema types were not equal"); - - return 0; -} - -int test_get_null_for_non_existing_schema(void) -{ - kuliya_schema *res = get_node_by_path("does/not/exist"); - if (res == NULL) - return 0; - - return 1; -} - -int main(void) -{ - test(test_get_existing_schema, "get existing schema"); - test(test_get_null_for_non_existing_schema, "get null for non existing schema"); - printf("\n\tPASSED: %d\tFAILED: %d\n", tests_passed, tests_failed); - return (tests_failed > 0); -} diff --git a/c/test/test.cpp b/c/test/test.cpp new file mode 100644 index 0000000..6e9d9bb --- /dev/null +++ b/c/test/test.cpp @@ -0,0 +1,28 @@ +#include +#include + +#include "test.h" + +TEST_GROUP(KuliyaSchemaTests){ + void setup(){} void teardown(){}}; + +TEST(KuliyaSchemaTests, GetExistingSchema) +{ + kuliya_schema *res = get_node_by_path("umkb"); + CHECK(res != NULL); + CHECK_EQUAL_C_STRING("جامعة محمد خيضر بسكرة", res->name.ar); + CHECK_EQUAL_C_STRING("University of Mohamed Khider Biskra", res->name.en); + CHECK_EQUAL_C_STRING("Université Mohamed Khider Biskra", res->name.fr); + CHECK_EQUAL(UNIVERSITY, res->type); +} + +TEST(KuliyaSchemaTests, GetNullForNonExistingSchema) +{ + kuliya_schema *res = get_node_by_path("does/not/exist"); + CHECK(res == NULL); +} + +int main(int argc, char **argv) +{ + return RUN_ALL_TESTS(argc, argv); +}