From 94851570e935c9b3a3a3955438beae1adb754be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sat, 18 Apr 2020 03:23:15 +0200 Subject: [PATCH] Add preliminary working principle of unit tests --- CMakeLists.txt | 27 +++++++++-------- test/CMakeLists.txt | 13 ++++++++- test/geometric/vector-operations.cpp | 43 ++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 test/geometric/vector-operations.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 20c32af..7ed875d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,6 @@ pkg_check_modules(CAIRO REQUIRED cairo) include_directories(${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include) add_subdirectory(plugins) - IF(CMAKE_BUILD_TYPE STREQUAL "Debug") message("${Yellow}Debug mode for translations used!${ColorReset}") add_definitions(-DGETTEXT_PACKAGE=\"gds-render\" -DLOCALEDATADIR=\"${CMAKE_CURRENT_BINARY_DIR}/translations/output\") @@ -43,17 +42,7 @@ else(CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions(-DGETTEXT_PACKAGE=\"gds-render\" -DLOCALEDATADIR=\"/usr/share\") ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") -add_subdirectory(test) -add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) - -add_subdirectory(resources) -add_subdirectory(doxygen) -add_subdirectory(translations) -add_subdirectory(version) - -link_directories(${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS} ${CAIRO_LINK_DIRS}) -add_definitions(${GLIB2_CFLAGS_OTHER}) aux_source_directory("widgets" LAYER_SOURCES) aux_source_directory("cell-selector" CELL_SELECTOR_SOURCES) @@ -77,15 +66,29 @@ set(SOURCE_GENERATED ${CMAKE_CURRENT_BINARY_DIR}/resources/resources.c ) +link_directories(${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS} ${CAIRO_LINK_DIRS}) SET_SOURCE_FILES_PROPERTIES(${SOURCE_GENERATED} PROPERTIES GENERATED 1) +add_subdirectory(test) + +add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) + +add_subdirectory(resources) +add_subdirectory(doxygen) +add_subdirectory(translations) +add_subdirectory(version) + +link_directories(${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS} ${CAIRO_LINK_DIRS}) +add_definitions(${GLIB2_CFLAGS_OTHER}) + add_executable(${PROJECT_NAME} ${SOURCE} ${SOURCE_GENERATED}) add_dependencies(${PROJECT_NAME} glib-resources) add_dependencies(${PROJECT_NAME} version) add_dependencies(${PROJECT_NAME} translations) -target_link_libraries(${PROJECT_NAME} ${GLIB_LDFLAGS} ${GTK3_LDFLAGS} ${CAIRO_LDFLAGS} m version ${CMAKE_DL_LIBS}) install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin ) +target_link_libraries(${PROJECT_NAME} ${GLIB_LDFLAGS} ${GTK3_LDFLAGS} ${CAIRO_LDFLAGS} m version ${CMAKE_DL_LIBS}) + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f2ee0ef..11265c9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -25,6 +25,17 @@ endif() cmake_minimum_required(VERSION 2.8) find_package(PkgConfig REQUIRED) -add_executable(${PROJECT_NAME} EXCLUDE_FROM_ALL "test-main.cpp") +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/catch-framework") + +aux_source_directory("geometric" GEOMETRIC_TEST_SOURCES) +set(TEST_SOURCES + ${GEOMETRIC_TEST_SOURCES} +) + +set(DUT_SOURCES + "../geometric/vector-operations.c" +) + +add_executable(${PROJECT_NAME} EXCLUDE_FROM_ALL "test-main.cpp" ${TEST_SOURCES} ${DUT_SOURCES}) target_link_libraries(${PROJECT_NAME} ${GLIB_LDFLAGS} ${GTK3_LDFLAGS} ${CAIRO_LDFLAGS} m version ${CMAKE_DL_LIBS}) diff --git a/test/geometric/vector-operations.cpp b/test/geometric/vector-operations.cpp new file mode 100644 index 0000000..259df90 --- /dev/null +++ b/test/geometric/vector-operations.cpp @@ -0,0 +1,43 @@ +#include +#include + +extern "C" { +#include +} + +TEST_CASE("geometric/vector-operations/vector_2d_add", "[GEOMETRIC]") +{ + struct vector_2d res; + struct vector_2d a; + struct vector_2d b; + + a.x = 1; + a.y = 2; + + b.x = 2; + b.y = 6; + + vector_2d_add(&res, &a, &b); + + REQUIRE(res.x == Approx(a.x + b.x)); + REQUIRE(res.y == Approx(a.y + b.y)); +} + +TEST_CASE("geometric/vector-operations/vector_2d_calculate_angle_between", "[GEOMETRIC]") +{ + double angle; + struct vector_2d a; + struct vector_2d b; + + a.x = 1; + a.y = 0; + + b.x = 0; + b.y = 1; + + angle = vector_2d_calculate_angle_between(&a, &a); + REQUIRE(angle == Approx(0.0)); + + angle = vector_2d_calculate_angle_between(&a, &b); + REQUIRE(angle == Approx(90.0 / 180.0 * M_PI)); +}