This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
-
-
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.
test: Add tests for ArgParser::splitInputOptions
* Integrate Google testing framework into the project. * Add simple unit tests for ArgParser::splitInputOptions. Signed-off-by: Alexander Kurbatov <Alexander.Kurbatov@acronis.com>
- Loading branch information
Alexander Kurbatov
authored and
Alexander Kurbatov
committed
Oct 10, 2020
1 parent
9146010
commit ab0a890
Showing
4 changed files
with
183 additions
and
2 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
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,163 @@ | ||
#include "src/ArgParser.h" | ||
|
||
#include <gmock/gmock.h> | ||
#include <gtest/gtest.h> | ||
|
||
#include <vector> | ||
|
||
TEST(splitInputOptions, ProperlySplitsObserverAndSC2Args) { | ||
std::vector<char*> observer_options; | ||
std::vector<char*> sc2_options; | ||
|
||
const char* argv [] = { | ||
"./bin/Observer", | ||
"--Path", | ||
"/Users/alkurbatov/Downloads/358809_TyrZ_DoogieHowitzer_IceandChromeLE.SC2Replay", | ||
"--", | ||
"-d", | ||
"B89B5D6FA7CBF6452E721311BFBC6CB2", | ||
"-e", | ||
"/Applications/StarCraft II/Versions/Base75689/SC2.app/Contents/MacOS/SC2" | ||
}; | ||
int argc = sizeof argv / sizeof argv[0]; | ||
|
||
splitInputOptions(argc, const_cast<char**>(argv), &observer_options, &sc2_options); | ||
|
||
ASSERT_THAT( | ||
observer_options, | ||
testing::ElementsAre( | ||
"./bin/Observer", | ||
"--Path", | ||
"/Users/alkurbatov/Downloads/358809_TyrZ_DoogieHowitzer_IceandChromeLE.SC2Replay" | ||
) | ||
); | ||
|
||
ASSERT_THAT( | ||
sc2_options, | ||
testing::ElementsAre( | ||
"./bin/Observer", | ||
"-d", | ||
"B89B5D6FA7CBF6452E721311BFBC6CB2", | ||
"-e", | ||
"/Applications/StarCraft II/Versions/Base75689/SC2.app/Contents/MacOS/SC2" | ||
) | ||
); | ||
} | ||
|
||
TEST(splitInputOptions, DoesntSplitAnythingIfDelimiterNotProvided) { | ||
std::vector<char*> observer_options; | ||
std::vector<char*> sc2_options; | ||
|
||
const char* argv [] = { | ||
"./bin/Observer", | ||
"--Path", | ||
"/Users/alkurbatov/Downloads/358809_TyrZ_DoogieHowitzer_IceandChromeLE.SC2Replay" | ||
}; | ||
int argc = sizeof argv / sizeof argv[0]; | ||
|
||
splitInputOptions(argc, const_cast<char**>(argv), &observer_options, &sc2_options); | ||
|
||
ASSERT_THAT( | ||
observer_options, | ||
testing::ElementsAre( | ||
"./bin/Observer", | ||
"--Path", | ||
"/Users/alkurbatov/Downloads/358809_TyrZ_DoogieHowitzer_IceandChromeLE.SC2Replay" | ||
) | ||
); | ||
|
||
ASSERT_THAT( | ||
sc2_options, | ||
testing::ElementsAre( | ||
"./bin/Observer" | ||
) | ||
); | ||
} | ||
|
||
TEST(splitInputOptions, ReturnsObserverArgsIfDelimiterPassedWithoutSC2Options) { | ||
std::vector<char*> observer_options; | ||
std::vector<char*> sc2_options; | ||
|
||
const char* argv [] = { | ||
"./bin/Observer", | ||
"--Path", | ||
"/Users/alkurbatov/Downloads/358809_TyrZ_DoogieHowitzer_IceandChromeLE.SC2Replay", | ||
"--" | ||
}; | ||
int argc = sizeof argv / sizeof argv[0]; | ||
|
||
splitInputOptions(argc, const_cast<char**>(argv), &observer_options, &sc2_options); | ||
|
||
ASSERT_THAT( | ||
observer_options, | ||
testing::ElementsAre( | ||
"./bin/Observer", | ||
"--Path", | ||
"/Users/alkurbatov/Downloads/358809_TyrZ_DoogieHowitzer_IceandChromeLE.SC2Replay" | ||
) | ||
); | ||
|
||
ASSERT_THAT( | ||
sc2_options, | ||
testing::ElementsAre( | ||
"./bin/Observer" | ||
) | ||
); | ||
} | ||
|
||
TEST(splitInputOptions, ReturnsSC2ArgsIfDelimiterPassedWithoutObserverOptions) { | ||
std::vector<char*> observer_options; | ||
std::vector<char*> sc2_options; | ||
|
||
const char* argv [] = { | ||
"./bin/Observer", | ||
"--", | ||
"-d", | ||
"B89B5D6FA7CBF6452E721311BFBC6CB2" | ||
}; | ||
int argc = sizeof argv / sizeof argv[0]; | ||
|
||
splitInputOptions(argc, const_cast<char**>(argv), &observer_options, &sc2_options); | ||
|
||
ASSERT_THAT( | ||
observer_options, | ||
testing::ElementsAre( | ||
"./bin/Observer" | ||
) | ||
); | ||
|
||
ASSERT_THAT( | ||
sc2_options, | ||
testing::ElementsAre( | ||
"./bin/Observer", | ||
"-d", | ||
"B89B5D6FA7CBF6452E721311BFBC6CB2" | ||
) | ||
); | ||
} | ||
|
||
TEST(splitInputOptions, DoesntFailIfNoOptionsSpecified) { | ||
std::vector<char*> observer_options; | ||
std::vector<char*> sc2_options; | ||
|
||
const char* argv [] = { | ||
"./bin/Observer" | ||
}; | ||
int argc = sizeof argv / sizeof argv[0]; | ||
|
||
splitInputOptions(argc, const_cast<char**>(argv), &observer_options, &sc2_options); | ||
|
||
ASSERT_THAT( | ||
observer_options, | ||
testing::ElementsAre( | ||
"./bin/Observer" | ||
) | ||
); | ||
|
||
ASSERT_THAT( | ||
sc2_options, | ||
testing::ElementsAre( | ||
"./bin/Observer" | ||
) | ||
); | ||
} |
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,11 @@ | ||
include(GoogleTest) | ||
|
||
include_directories(${PROJECT_SOURCE_DIR}) | ||
|
||
add_executable( | ||
TestArgParser | ||
${PROJECT_SOURCE_DIR}/src/ArgParser.h | ||
${PROJECT_SOURCE_DIR}/src/ArgParser.cpp | ||
ArgParser.test.cpp) | ||
target_link_libraries(TestArgParser GTest::Main) | ||
gtest_discover_tests(TestArgParser) |