diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/getopt/ut/modchooser_ut.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/getopt/ut/modchooser_ut.cpp')
-rw-r--r-- | library/cpp/getopt/ut/modchooser_ut.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/library/cpp/getopt/ut/modchooser_ut.cpp b/library/cpp/getopt/ut/modchooser_ut.cpp new file mode 100644 index 0000000000..a14c8a5853 --- /dev/null +++ b/library/cpp/getopt/ut/modchooser_ut.cpp @@ -0,0 +1,71 @@ +#include <library/cpp/getopt/modchooser.h> + +#include <library/cpp/testing/unittest/registar.h> + +#include <util/stream/str.h> + +void ValidateArgcArgv(int argc, const char** argv) { + UNIT_ASSERT_EQUAL(argc, 1); + UNIT_ASSERT_EQUAL(argv[argc], nullptr); +} + +int One(int argc, const char** argv) { + ValidateArgcArgv(argc, argv); + return 1; +} + +int Two(int argc, const char** argv) { + ValidateArgcArgv(argc, argv); + return 2; +} + +int Three(int argc, const char** argv) { + ValidateArgcArgv(argc, argv); + return 3; +} + +int Four(int argc, const char** argv) { + ValidateArgcArgv(argc, argv); + return 4; +} + +int Five(int argc, const char** argv) { + ValidateArgcArgv(argc, argv); + return 5; +} + +typedef int (*F_PTR)(int, const char**); +static const F_PTR FUNCTIONS[] = {One, Two, Three, Four, Five}; +static const char* NAMES[] = {"one", "two", "three", "four", "five"}; +static_assert(Y_ARRAY_SIZE(FUNCTIONS) == Y_ARRAY_SIZE(NAMES), "Incorrect input tests data"); + +Y_UNIT_TEST_SUITE(TModChooserTest) { + Y_UNIT_TEST(TestModesSimpleRunner) { + TModChooser chooser; + for (size_t idx = 0; idx < Y_ARRAY_SIZE(NAMES); ++idx) { + chooser.AddMode(NAMES[idx], FUNCTIONS[idx], NAMES[idx]); + } + + // test argc, argv + for (size_t idx = 0; idx < Y_ARRAY_SIZE(NAMES); ++idx) { + int argc = 2; + const char* argv[] = {"UNITTEST", NAMES[idx], nullptr}; + UNIT_ASSERT_EQUAL(static_cast<int>(idx) + 1, chooser.Run(argc, argv)); + } + + // test TVector<TString> argv + for (size_t idx = 0; idx < Y_ARRAY_SIZE(NAMES); ++idx) { + const TVector<TString> argv = {"UNITTEST", NAMES[idx]}; + UNIT_ASSERT_EQUAL(static_cast<int>(idx) + 1, chooser.Run(argv)); + } + } + + Y_UNIT_TEST(TestHelpMessage) { + TModChooser chooser; + + int argc = 2; + const char* argv[] = {"UNITTEST", "-?", nullptr}; + + chooser.Run(argc, argv); + } +} |