-
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
7 changed files
with
70 additions
and
28 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
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,9 @@ | ||
#include "ProjectIntegrationTestSuite.hpp" | ||
|
||
void ProjectIntegrationTestSuite::SetUp() { | ||
std::filesystem::create_directories(dirname); | ||
} | ||
|
||
void ProjectIntegrationTestSuite::TearDown() { | ||
std::filesystem::remove_all(dirname); | ||
} |
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,17 @@ | ||
#ifndef TEMPORARYDIRECTORYTESTSUITE_HPP_ | ||
#define TEMPORARYDIRECTORYTESTSUITE_HPP_ | ||
|
||
#include <filesystem> | ||
#include <string> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
struct ProjectIntegrationTestSuite : public testing::Test { // special test structure | ||
const std::string dirname = "./gtest_tmp"; | ||
|
||
void SetUp() override; // method that is called at the beginning of every test | ||
|
||
void TearDown() override; // method that is called at the end of every test | ||
}; | ||
|
||
#endif //TEMPORARYDIRECTORYTESTSUITE_HPP_ |
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,34 +1,10 @@ | ||
#include <sstream> | ||
#include <filesystem> | ||
|
||
#include <gtest/gtest.h> // include your library here | ||
#include <gtest/gtest.h> | ||
#include "ProjectIntegrationTestSuite.hpp" | ||
#include "test_functions.hpp" // include your library here | ||
#include "lib/mylib/MyClass.h" | ||
|
||
struct TemporaryDirectoryTestSuite : public testing::Test { // special test structure | ||
const std::string dirname = "./gtest_tmp"; | ||
|
||
void SetUp() override { // method that is called at the beginning of every test | ||
std::filesystem::create_directories(dirname); | ||
} | ||
|
||
void TearDown() override { // method that is called at the end of every test | ||
std::filesystem::remove_all(dirname); | ||
} | ||
}; | ||
|
||
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_F(TemporaryDirectoryTestSuite, InitTest) { | ||
TEST_F(ProjectIntegrationTestSuite, InitTest) { | ||
ASSERT_TRUE(std::filesystem::is_directory(dirname)); | ||
} | ||
|
||
TEST(MyLibUnitTestSuite, BasicTest1) { | ||
std::ostringstream out; | ||
MyClass printer(out); | ||
printer.Print("Hello, World!"); | ||
ASSERT_EQ(out.str(), "Hello, World!"); | ||
} |
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,10 @@ | ||
#include <iterator> | ||
#include <sstream> | ||
|
||
#include "test_functions.hpp" | ||
|
||
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>()}; | ||
} |
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,10 @@ | ||
#ifndef TESTFUNCTIONS_HPP_ | ||
#define TESTFUNCTIONS_HPP_ | ||
|
||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
|
||
std::vector<std::string> SplitString(const std::string& str); | ||
|
||
#endif //TESTFUNCTIONS_HPP_ |
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,15 @@ | ||
#include <sstream> | ||
|
||
#include <gtest/gtest.h> | ||
#include "test_functions.hpp" // include your library here | ||
#include "lib/mylib/MyClass.h" | ||
|
||
TEST(MyLibUnitTestSuite, BasicTest1) { | ||
std::ostringstream out; | ||
MyClass printer(out); | ||
printer.Print("Hello, World!"); | ||
std::vector<std::string> out_by_words = SplitString(out.str()); | ||
ASSERT_EQ(out_by_words.size(), 2); | ||
ASSERT_EQ(out_by_words[0], "Hello,"); | ||
ASSERT_EQ(out_by_words[1], "World!"); | ||
} |