diff --git a/prj/vs2022/Test.vcxproj b/prj/vs2022/Test.vcxproj index 175dfdb..0b8941e 100644 --- a/prj/vs2022/Test.vcxproj +++ b/prj/vs2022/Test.vcxproj @@ -22,6 +22,7 @@ + diff --git a/prj/vs2022/Test.vcxproj.filters b/prj/vs2022/Test.vcxproj.filters index 80125ef..7bfbc79 100644 --- a/prj/vs2022/Test.vcxproj.filters +++ b/prj/vs2022/Test.vcxproj.filters @@ -36,6 +36,9 @@ Test + + + Test diff --git a/src/Cpl/Args.h b/src/Cpl/Args.h index e64e9da..2629bae 100644 --- a/src/Cpl/Args.h +++ b/src/Cpl/Args.h @@ -144,7 +144,7 @@ namespace Cpl bool HasArg(const String& name) const { - return HasArg({ name }); + return HasArg(Strings{ name }); } bool HasArg(const String& name0, const String& name1) const diff --git a/src/Test/Test.cpp b/src/Test/Test.cpp index 847d85f..8047f0e 100644 --- a/src/Test/Test.cpp +++ b/src/Test/Test.cpp @@ -53,6 +53,10 @@ namespace Test bool name##AddToList(){ g_groups.push_back(Group(#name, name##Test)); return true; } \ bool name##AtList = name##AddToList(); + TEST_ADD(HasArg); + TEST_ADD(HasArg1); + TEST_ADD(HasArg2); + TEST_ADD(LogCallback); TEST_ADD(LogCallbackRaw); TEST_ADD(LogDateTime); diff --git a/src/Test/TestArgsParser.cpp b/src/Test/TestArgsParser.cpp new file mode 100644 index 0000000..60b81b8 --- /dev/null +++ b/src/Test/TestArgsParser.cpp @@ -0,0 +1,73 @@ +/* +* Tests for Common Purpose Library (http://github.com/ermig1979/Cpl). +* +* Copyright (c) 2021-2022 Yermalayeu Ihar, +* 2021-2022 Andrey Drogolyub. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include "Test/Test.h" + +#include "Cpl/Args.h" + +namespace Test +{ + struct TestArgs : public Cpl::ArgsParser + { + TestArgs(int argc, char* argv[]) + : Cpl::ArgsParser(argc, argv, true) {} + + bool Check(const Cpl::String& name) { return HasArg(name); } + bool Check(const String& name0, const String& name1) { return HasArg(name0, name1); } + }; + + bool HasArgTest() + { + int argc = 2; + std::vector args = {"test", "-h"}; + + TestArgs a(argc, args.data()); + + return a.Check("-h"); + } + + bool HasArg1Test() + { + int argc = 2; + std::vector args = { "test", "-h" }; + + TestArgs a(argc, args.data()); + + return !a.Check("-g"); + } + + bool HasArg2Test() + { + int argc = 2; + std::vector args = { "test", "-h" }; + + TestArgs a(argc, args.data()); + + return a.Check("-h", "-?"); + } +} + + +