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.
Merge pull request #1 from alkurbatov/dev
Fix recently found bugs
- Loading branch information
Showing
9 changed files
with
231 additions
and
7 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
Submodule cpp-sc2
updated
from ccbb74 to 86f182
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,21 @@ | ||
#include "ArgParser.h" | ||
|
||
#include <cstring> | ||
|
||
void splitInputOptions(int argc, char* argv[], std::vector<char*>* observer_options, std::vector<char*>* sc2_options) { | ||
const char* delimiter = "--"; | ||
|
||
observer_options->push_back(argv[0]); | ||
sc2_options->push_back(argv[0]); | ||
|
||
std::vector<char*>* marker = observer_options; | ||
|
||
for (int i = 1; i < argc; ++i) { | ||
if (strcmp(argv[i], delimiter) == 0) { | ||
marker = sc2_options; | ||
continue; | ||
} | ||
|
||
marker->push_back(argv[i]); | ||
} | ||
} |
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,5 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
void splitInputOptions(int argc, char* argv[], std::vector<char*>* observer_options, std::vector<char*>* sc2_options); |
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) |