Skip to content

Commit

Permalink
using cpputest unit testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
omdxp committed Apr 7, 2024
1 parent 8c89201 commit 6caf3a2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 36 deletions.
9 changes: 5 additions & 4 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,31 @@ 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)
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)
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.")
1 change: 1 addition & 0 deletions c/conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[requires]
jsmn/1.1.0
libunistring/1.1
cpputest/4.0

[generators]
CMakeDeps
Expand Down
32 changes: 0 additions & 32 deletions c/test/test.c

This file was deleted.

28 changes: 28 additions & 0 deletions c/test/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <CppUTest/TestHarness_c.h>
#include <CppUTest/CommandLineTestRunner.h>

#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);
}

0 comments on commit 6caf3a2

Please sign in to comment.