Skip to content

Commit

Permalink
Updated project structure^ added UI library
Browse files Browse the repository at this point in the history
  • Loading branch information
bialger committed Jan 22, 2024
1 parent 1b8637b commit 3ef4435
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 13 deletions.
4 changes: 3 additions & 1 deletion bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ endif()

message(STATUS "Main executable build type: ${CMAKE_BUILD_TYPE}")

target_link_libraries(${PROJECT_NAME} PUBLIC mylib)
target_link_libraries(${PROJECT_NAME} PUBLIC
ui
)

target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR})
9 changes: 4 additions & 5 deletions bin/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include <iostream>

#include "lib/mylib/MyClass.h"
#include "lib/ui/ui_functions.hpp"

int main() {
MyClass printer(std::cout);
printer.Print("Hello, World!\n");
return 0;
int main(int32_t argc, char** argv) {
std::vector<std::string> args = std::vector<std::string>(argv, argv + argc);
return StartConsoleUI(args, std::cout);
}
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ endif()
message(STATUS "Libraries build type: ${CMAKE_BUILD_TYPE}")

add_subdirectory(mylib)
add_subdirectory(ui)
5 changes: 4 additions & 1 deletion lib/mylib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
add_library(mylib STATIC MyClass.cpp MyClass.h)
add_library(mylib STATIC
MyClass.cpp
MyClass.hpp
)
2 changes: 1 addition & 1 deletion lib/mylib/MyClass.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "MyClass.h"
#include "MyClass.hpp"

MyClass::MyClass(std::ostream& out) : out_(out) {}

Expand Down
6 changes: 3 additions & 3 deletions lib/mylib/MyClass.h → lib/mylib/MyClass.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MYCLASS_H_
#define MYCLASS_H_
#ifndef MYCLASS_HPP_
#define MYCLASS_HPP_

#include <iostream>

Expand All @@ -13,4 +13,4 @@ class MyClass {
std::ostream& out_;
};

#endif //MYCLASS_H_
#endif //MYCLASS_HPP_
10 changes: 10 additions & 0 deletions lib/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_library(ui STATIC
ui_functions.cpp
ui_functions.hpp
)

target_link_libraries(ui PUBLIC
mylib
)

target_include_directories(ui PUBLIC ${PROJECT_SOURCE_DIR})
13 changes: 13 additions & 0 deletions lib/ui/ui_functions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "ui_functions.hpp"
#include "lib/mylib/MyClass.hpp"

int32_t StartConsoleUI(const std::vector<std::string>& args, std::ostream& out) {
if (args.size() < 2) {
out << "Insufficient arguments\n";
return 1;
}

MyClass printer(out);
printer.Print("Hello, World!\n");
return 0;
}
9 changes: 9 additions & 0 deletions lib/ui/ui_functions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef UI_FUNCTIONS_HPP_
#define UI_FUNCTIONS_HPP_

#include <vector>
#include <string>

int32_t StartConsoleUI(const std::vector<std::string>& args, std::ostream& out);

#endif //UI_FUNCTIONS_HPP_
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ add_executable(

target_link_libraries(
${PROJECT_NAME}_tests # link used libraries from lib directory
ui
mylib
GTest::gtest_main
)
Expand Down
24 changes: 23 additions & 1 deletion tests/main_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,30 @@
#include <gtest/gtest.h>
#include "ProjectIntegrationTestSuite.hpp"
#include "test_functions.hpp" // include your library here
#include "lib/mylib/MyClass.h"
#include "lib/ui/ui_functions.hpp"

TEST_F(ProjectIntegrationTestSuite, InitTest) {
ASSERT_TRUE(std::filesystem::is_directory(kTemporaryDirectoryName));
}

TEST_F(ProjectIntegrationTestSuite, PositiveTest1) {
std::ostringstream out;
ASSERT_EQ(StartConsoleUI(SplitString("test -h"), out), 0);
}

TEST_F(ProjectIntegrationTestSuite, PositiveOutputTest1) {
std::ostringstream out;
StartConsoleUI(SplitString("test -h"), out);
ASSERT_EQ(out.str(), "Hello, World!\n");
}

TEST_F(ProjectIntegrationTestSuite, NegativeTest1) {
std::ostringstream out;
ASSERT_EQ(StartConsoleUI(SplitString("test"), out), 1);
}

TEST_F(ProjectIntegrationTestSuite, NegitiveOutputTest1) {
std::ostringstream out;
StartConsoleUI(SplitString("test"), out);
ASSERT_EQ(out.str(), "Insufficient arguments\n");
}
2 changes: 1 addition & 1 deletion tests/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <gtest/gtest.h>
#include "test_functions.hpp" // include your library here
#include "lib/mylib/MyClass.h"
#include "lib/mylib/MyClass.hpp"

TEST(MyLibUnitTestSuite, BasicTest1) {
std::ostringstream out;
Expand Down

0 comments on commit 3ef4435

Please sign in to comment.