Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
test: Add tests for ArgParser::splitInputOptions
Browse files Browse the repository at this point in the history
* 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
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.10)

project(Observer)

Expand All @@ -15,5 +15,10 @@ set(BUILD_API_EXAMPLES OFF CACHE INTERNAL "" FORCE)
# Disable building of tests in the cpp-sc2 submodule.
set(BUILD_API_TESTS OFF CACHE INTERNAL "" FORCE)

# Search for Google test suite.
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

add_subdirectory("cpp-sc2")
add_subdirectory("src")
add_subdirectory("test")
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ Starcraft 2 replays auto observer inspired by the [SSCAIT-ObserverModule](https:
* Windows: C:\Program Files\StarCraft II\Maps
* OS X: /Applications/StarCraft II/Maps

3. Download and install [CMake](https://cmake.org/download/).
3. Download and install [CMake >= 3.10](https://cmake.org/download/).

4. A compiler with C++17 support.

5. Install [Google test >= 1.10.0](https://github.com/google/googletest)

5. Windows: Download and install [Visual Studio](https://www.visualstudio.com/downloads/)

6. OS X: Install XCode.
Expand Down
163 changes: 163 additions & 0 deletions test/ArgParser.test.cpp
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"
)
);
}
11 changes: 11 additions & 0 deletions test/CMakeLists.txt
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)

0 comments on commit ab0a890

Please sign in to comment.