Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,36 @@ set(PROJECT_NAME "to-dos-api")
project(${PROJECT_NAME} CXX)

file(GLOB_RECURSE sources CONFIGURE_DEPENDS
${CMAKE_SOURCE_DIR}/src/*.cpp
${CMAKE_SOURCE_DIR}/src/*/*.cpp
${CMAKE_SOURCE_DIR}/src/data/models/odb-gen/*.cxx
)

add_executable(${PROJECT_NAME} ${sources})
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/src
/usr/include
src/data/models/
)
set(PROJECT_OBJECTS ${PROJECT_NAME}_lib)

add_library(${PROJECT_OBJECTS} OBJECT ${sources})

target_link_libraries(${PROJECT_NAME} PRIVATE odb odb-pgsql)
target_include_directories(${PROJECT_OBJECTS} PUBLIC
${CMAKE_SOURCE_DIR}/src
/usr/include
src/data/models/
)

find_package(Drogon REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon)
find_package(jsoncpp REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE JsonCpp::JsonCpp)

target_link_libraries(${PROJECT_OBJECTS} PUBLIC
Drogon::Drogon
JsonCpp::JsonCpp
odb odb-pgsql
)

add_executable(${PROJECT_NAME}
${CMAKE_SOURCE_DIR}/src/main.cpp
$<TARGET_OBJECTS:${PROJECT_OBJECTS}>
)

target_link_libraries(${PROJECT_NAME} PUBLIC
${PROJECT_OBJECTS}
)

add_subdirectory(test)
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ To run clang-tidy, run the following command:
find ./src -name "*.cpp" -not -path "*/build/*" -exec echo "Checking {}..." \; -exec clang-tidy --config-file=.clang-tidy {} -- -I./include -std=c++20 \;
```

## Tests run

The project presents an example of test implementation using GTest tools. Test files are located in the `test` directory at the root of the project. Inside the `test` directory there is a `CMakeLists.txt` file created specifically for building a separate executable file for tests.

### How to run tests

To run tests, go to the `build/Debug` directory, and then run the `ctest` command in the terminal (`Ctrl + Shift + ~`).

Alternatively, use the CMake Tools Extension in VS Code. To do this, open the CMake Tools Extension and click `Test`, after configuring and building the project.
<p style="text-align: center;"><img src="docs/images/cmakeTests.png" alt="cmakeTests" width="400"/></p>

## Working with ORM+Migration.

### ORM:
Expand Down
1 change: 1 addition & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ def package(self):

def requirements(self):
self.requires("drogon/1.9.10")
self.requires("gtest/1.14.0")
Binary file added docs/images/cmakeTests.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions docs/technologies.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ At the time of research, the following versions were used:
| Availability of a suitable ORM | - | (not studied due to exclusion) | - |
| Presence of migrations | - | (not studied due to exclusion) | - |


#### Why Drogon - Chosen solution

**Advantages:**
Expand Down Expand Up @@ -190,5 +189,4 @@ Final decision: manage migrations with SQLAlchemy/Alembic and use ODB for C++ da
- Implement and maintain C++ data access with ODB on PostgreSQL.
- Coordination workflow: apply Alembic migrations first, then synchronize ODB mappings/models and the C++ data access code to reflect schema updates.


## E2E Tests
22 changes: 22 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
enable_testing()

include(GoogleTest)

set(TEST_PROJECT ${PROJECT_NAME}_unit_tests)

file(GLOB_RECURSE test_sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)

add_executable(${TEST_PROJECT} ${test_sources})

find_package(GTest REQUIRED)

target_link_libraries(${TEST_PROJECT} PRIVATE
${PROJECT_OBJECTS}
GTest::gtest
)

target_include_directories(${TEST_PROJECT} PRIVATE
${CMAKE_SOURCE_DIR}/src
)

gtest_discover_tests(${TEST_PROJECT})
6 changes: 6 additions & 0 deletions test/addition-operation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "addition-operation.h"

int AdditionOperation(int a, int b)
{
return a + b;
}
3 changes: 3 additions & 0 deletions test/addition-operation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

int AdditionOperation(int a, int b);
19 changes: 19 additions & 0 deletions test/test_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "addition-operation.h"
#include "gtest/gtest.h"

// Testing reference section in GTest documentation
// https://google.github.io/googletest/reference/testing.html
TEST(MathTest, AdditionOperation)
{
// Assertions section in GTest documentation
// https://google.github.io/googletest/reference/assertions.html#EXPECT_EQ
EXPECT_EQ(AdditionOperation(2, 3), 5);
EXPECT_EQ(AdditionOperation(-1, 1), 0);
}

int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS();
}