Add preliminary working principle of unit tests

This commit is contained in:
Mario Hüttel 2020-04-18 03:23:15 +02:00
parent f4fa1bd4e5
commit 94851570e9
3 changed files with 70 additions and 13 deletions

View File

@ -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})

View File

@ -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})

View File

@ -0,0 +1,43 @@
#include <catch.hpp>
#include <limits>
extern "C" {
#include <gds-render/geometric/vector-operations.h>
}
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));
}