From e8885b01e302c5a3978c613c3617701bf376dc11 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Sun, 29 Sep 2024 21:07:07 -0400 Subject: [PATCH] Adding Test dir --- CMakeLists.txt | 38 +++-------------------- src/CMakeLists.txt | 32 +++++++++++++++++++ src/game_logic/fen_strings.h | 2 +- test/CMakeLists.txt | 50 ++++++++++++++++++++++++++++++ test/game_logic/test_game_state.cc | 12 +++++++ test/hello_test.cc | 10 ++++++ 6 files changed, 110 insertions(+), 34 deletions(-) create mode 100644 src/CMakeLists.txt create mode 100644 test/CMakeLists.txt create mode 100644 test/game_logic/test_game_state.cc create mode 100644 test/hello_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index bb27396..bc70db2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,33 +1,5 @@ -cmake_minimum_required(VERSION 3.8) - -project(Chess C CXX) - -find_package(SDL2 REQUIRED) - -file(GLOB_RECURSE cpp_sources - CONFIGURE_DEPENDS - "src/*.cpp") - -file(GLOB_RECURSE c_sources - CONFIGURE_DEPENDS - "src/*.c") - -file (GLOB_RECURSE headers CONFIGURE_DEPENDS "src/*.h") - -set (include_dirs "") -foreach (_headerFile ${headers}) - get_filename_component(_dir ${_headerFile} PATH) - list (APPEND include_dirs ${_dir}) -endforeach() - -add_executable(Chess ${cpp_sources} ${c_sources}) -set_target_properties(Chess PROPERTIES CXX_STANDARD 17) # set standard level -target_include_directories(Chess PRIVATE ${include_dirs}) -target_compile_options(Chess PRIVATE - -Wall -Wextra -Wredundant-decls -Wcast-align - -Wshadow -Wnon-virtual-dtor - -Wunused -Woverloaded-virtual -Wpedantic -Wconversion - -Wsign-conversion -Wmisleading-indentation - -Wnull-dereference -Wformat=2 -) -target_link_libraries(Chess SDL2::SDL2) +cmake_minimum_required(VERSION 3.8) +project(Chess C CXX) + +add_subdirectory(src) +add_subdirectory(test) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..344f2d8 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.8) + + +find_package(SDL2 REQUIRED) + +file(GLOB_RECURSE cpp_sources + CONFIGURE_DEPENDS + "./*.cpp") + +file(GLOB_RECURSE c_sources + CONFIGURE_DEPENDS + "./*.c") + +file (GLOB_RECURSE headers CONFIGURE_DEPENDS "./*.h") + +set (include_dirs "") +foreach (_headerFile ${headers}) + get_filename_component(_dir ${_headerFile} PATH) + list (APPEND include_dirs ${_dir}) +endforeach() + +add_executable(Chess ${cpp_sources} ${c_sources}) +set_target_properties(Chess PROPERTIES CXX_STANDARD 17) # set standard level +target_include_directories(Chess PRIVATE ${include_dirs}) +target_compile_options(Chess PRIVATE + -Wall -Wextra -Wredundant-decls -Wcast-align + -Wshadow -Wnon-virtual-dtor + -Wunused -Woverloaded-virtual -Wpedantic -Wconversion + -Wsign-conversion -Wmisleading-indentation + -Wnull-dereference -Wformat=2 +) +target_link_libraries(Chess SDL2::SDL2) diff --git a/src/game_logic/fen_strings.h b/src/game_logic/fen_strings.h index ba88ebd..16f0cb5 100644 --- a/src/game_logic/fen_strings.h +++ b/src/game_logic/fen_strings.h @@ -3,7 +3,7 @@ extern "C" { #endif char * fen_string_get_state(void); -void fen_string_set_state(void); +void fen_string_set_state(char *); #ifdef __cplusplus } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..2e8c618 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,50 @@ + +find_package(SDL2 REQUIRED) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.15.2.zip +) +FetchContent_MakeAvailable(googletest) + +enable_testing() + +file(GLOB_RECURSE cpp_sources + CONFIGURE_DEPENDS + "../src/*.cpp") + +list(REMOVE_ITEM cpp_sources + "../src/pc_app/main.cpp") + +file(GLOB_RECURSE test_sources + CONFIGURE_DEPENDS + "*.cc") + +file(GLOB_RECURSE c_sources + CONFIGURE_DEPENDS + "../src/*.c") + +file (GLOB_RECURSE headers CONFIGURE_DEPENDS "../src/*.h") +set (include_dirs "") +foreach (_headerFile ${headers}) + get_filename_component(_dir ${_headerFile} PATH) + list (APPEND include_dirs ${_dir}) +endforeach() + +add_executable( + hello_test + # ${cpp_sources} + ${test_sources} + ${c_sources} +) +target_include_directories(hello_test PRIVATE ${include_dirs}) +target_link_libraries( + hello_test + GTest::gtest_main + SDL2::SDL2 +) + +include(GoogleTest) +gtest_discover_tests(hello_test) + diff --git a/test/game_logic/test_game_state.cc b/test/game_logic/test_game_state.cc new file mode 100644 index 0000000..68b7155 --- /dev/null +++ b/test/game_logic/test_game_state.cc @@ -0,0 +1,12 @@ +#include +#include "game_state.h" +#include "fen_strings.h" + +// Demonstrate some basic assertions. +TEST(GameLogic, initialized_state) { + // Expect two strings not to be equal. + game_state_init(); + char * test_data = fen_string_get_state(); + EXPECT_STREQ(test_data, "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -"); +} + diff --git a/test/hello_test.cc b/test/hello_test.cc new file mode 100644 index 0000000..9432d54 --- /dev/null +++ b/test/hello_test.cc @@ -0,0 +1,10 @@ +#include + +// Demonstrate some basic assertions. +TEST(HelloTest, BasicAssertions) { + // Expect two strings not to be equal. + EXPECT_STRNE("hello", "world"); + // Expect equality. + EXPECT_EQ(7 * 6, 42); +} +