diff --git a/.gitignore b/.gitignore index c4f0d1e..3394524 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/* +Testing/* diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f62281..3c3321f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.23) project(maiden) @@ -8,18 +8,40 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}) +# gtest +include(FetchContent) +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.17.x # Use a specific version tag or commit hash +) +FetchContent_MakeAvailable(googletest) + # add_subdirectory() to nest CMakeLists add_executable(maiden + src/App.cpp src/main.cpp # include extra source files here ) +add_executable(maiden_test + src/App.cpp + test/TestApp.cpp +) + target_include_directories(maiden PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src" # add additional include directories here ) -target_link_libraries(maiden PRIVATE - # add libraries here +target_include_directories(maiden_test PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/src" ) + +target_link_libraries(maiden_test PRIVATE + GTest::gmock_main +) + +include(GoogleTest) +gtest_discover_tests(maiden_test) diff --git a/src/App.cpp b/src/App.cpp new file mode 100644 index 0000000..0026493 --- /dev/null +++ b/src/App.cpp @@ -0,0 +1,18 @@ + +#include "App.hpp" + +void App::run() { + + std::cout << "im an app and im running !!" << std::endl; + + (void)foo(); + + return; + +} + +int32_t App::foo() { + + return 12; + +} diff --git a/src/App.hpp b/src/App.hpp new file mode 100644 index 0000000..500db8c --- /dev/null +++ b/src/App.hpp @@ -0,0 +1,19 @@ + +#pragma once + +#include +#include + +class App { + + public: + App() = default; + ~App() = default; + + void run(); + + private: + + int32_t foo(); + +}; diff --git a/src/main.cpp b/src/main.cpp index 6e7b57f..80dab38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,14 @@ #include +#include "App.hpp" + int main(int argc, char** argv) { std::cout << "hi mom !" << std::endl; + App app; + app.run(); + return 0; } diff --git a/test/TestApp.cpp b/test/TestApp.cpp new file mode 100644 index 0000000..65159fa --- /dev/null +++ b/test/TestApp.cpp @@ -0,0 +1,36 @@ + +#include +#include + +#define private public +#include +#undef private + +class TestApp : public testing::Test { + + protected: + + void createUut() { + uut_ = std::make_unique(); + } + + std::unique_ptr uut_; + +}; + +TEST_F(TestApp, TestApp_run_nominal) { + + createUut(); + uut_->run(); + + // no expect here + +} + +TEST_F(TestApp, TestApp_foo_nominal) { + + createUut(); + + EXPECT_EQ(uut_->foo(), 12); + +}