-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
add_executable(${PROJECT_NAME} main.cpp) | ||
|
||
target_link_libraries(${PROJECT_NAME} PUBLIC mylib) | ||
|
||
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
#include <iostream> | ||
|
||
#include "lib/mylib/MyClass.h" | ||
|
||
int main() { | ||
std::cout << "Hello, World!" << std::endl; | ||
MyClass printer(std::cout); | ||
printer.Print("Hello, World!"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ else () | |
endif() | ||
|
||
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") | ||
|
||
add_subdirectory(mylib) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_library(mylib STATIC MyClass.cpp MyClass.h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "MyClass.h" | ||
|
||
MyClass::MyClass(std::ostream& out) : out_(out) {} | ||
|
||
void MyClass::Print(const std::string& str) { | ||
out_ << str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef MYCLASS_H_ | ||
#define MYCLASS_H_ | ||
|
||
#include <iostream> | ||
|
||
class MyClass { | ||
public: | ||
explicit MyClass(std::ostream& out); | ||
|
||
void Print(const std::string& str); | ||
|
||
private: | ||
std::ostream& out_; | ||
}; | ||
|
||
#endif //MYCLASS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
#include <sstream> | ||
|
||
#include <gtest/gtest.h> // include your library here | ||
#include "lib/mylib/MyClass.h" | ||
|
||
std::vector<std::string> SplitString(const std::string& str) { | ||
std::istringstream iss(str); | ||
|
||
return {std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>()}; | ||
} | ||
|
||
TEST(BasicTestSuite, BasicTest1) { | ||
TEST(MyLibUnitTestSuite, BasicTest1) { | ||
std::ostringstream out; | ||
out << "Hello, World!"; | ||
MyClass printer(out); | ||
printer.Print("Hello, World!"); | ||
ASSERT_EQ(out.str(), "Hello, World!"); | ||
} |