diff --git a/slsSupportLib/include/CmdLineParser.h b/slsSupportLib/include/CmdLineParser.h index 245f8ad26..af11254d3 100755 --- a/slsSupportLib/include/CmdLineParser.h +++ b/slsSupportLib/include/CmdLineParser.h @@ -6,7 +6,7 @@ class CmdLineParser { public: - void Parse(int argc, char *argv[]); + void Parse(int argc, const char * const argv[]); void Parse(const std::string &s); void Print(); diff --git a/slsSupportLib/src/CmdLineParser.cpp b/slsSupportLib/src/CmdLineParser.cpp index 23a6a8950..cc502978d 100755 --- a/slsSupportLib/src/CmdLineParser.cpp +++ b/slsSupportLib/src/CmdLineParser.cpp @@ -20,7 +20,7 @@ void CmdLineParser::Print() { std::cout << "\n\n"; }; -void CmdLineParser::Parse(int argc, char *argv[]) { +void CmdLineParser::Parse(int argc, const char * const argv[]) { executable_ = argv[0]; //first arg is calling binary if (argc > 1) { DecodeIdAndPosition(argv[1]); diff --git a/slsSupportLib/tests/test-CmdLineParser.cpp b/slsSupportLib/tests/test-CmdLineParser.cpp index 5cb4aaa9c..5a34e7bd5 100755 --- a/slsSupportLib/tests/test-CmdLineParser.cpp +++ b/slsSupportLib/tests/test-CmdLineParser.cpp @@ -92,10 +92,10 @@ SCENARIO("Parsing a string with the command line parser", "[support]") { } } - WHEN("Parsing string with cmd and multiple arguments"){ + WHEN("Parsing string with cmd and multiple arguments") { std::string s = "trimen 5000 6000 7000"; p.Parse(s); - THEN("cmd and args are correct"){ + THEN("cmd and args are correct") { REQUIRE(p.command() == "trimen"); REQUIRE(p.arguments().size() == 3); REQUIRE(p.arguments()[0] == "5000"); @@ -121,10 +121,7 @@ TEST_CASE("Parse with no arguments results in no command and default id", // build up argc and argv // first argument is the command used to call the binary int argc = 1; - char *argv[argc]; - char a0[] = "call"; - argv[0] = static_cast(a0); - + const char* const argv[]{"call"}; CmdLineParser p; p.Parse(argc, argv); @@ -138,12 +135,7 @@ TEST_CASE( "Parse a command without client id and detector id results in default", "[support]") { int argc = 2; - char *argv[argc]; - char a0[] = "call"; - char a1[] = "vrf"; - argv[0] = static_cast(a0); - argv[1] = static_cast(a1); - + const char*const argv[]{"caller", "vrf"}; CmdLineParser p; p.Parse(argc, argv); @@ -156,14 +148,7 @@ TEST_CASE( TEST_CASE("Parse a command with value but without client or detector id", "[support]") { int argc = 3; - char *argv[argc]; - char a0[] = "call"; - char a1[] = "vrf"; - char a2[] = "3000"; - argv[0] = static_cast(a0); - argv[1] = static_cast(a1); - argv[2] = static_cast(a2); - + const char* const argv[]{"caller", "vrf", "3000"}; CmdLineParser p; p.Parse(argc, argv); @@ -176,11 +161,7 @@ TEST_CASE("Parse a command with value but without client or detector id", TEST_CASE("Decodes position") { int argc = 2; - char *argv[argc]; - char a0[] = "call"; - char a1[] = "7:vrf"; - argv[0] = static_cast(a0); - argv[1] = static_cast(a1); + const char*const argv[]{"caller", "7:vrf"}; CmdLineParser p; p.Parse(argc, argv); @@ -193,12 +174,7 @@ TEST_CASE("Decodes position") { TEST_CASE("Decodes double digit position", "[support]") { int argc = 2; - char *argv[argc]; - char a0[] = "call"; - char a1[] = "73:vcmp"; - argv[0] = static_cast(a0); - argv[1] = static_cast(a1); - + const char* const argv[]{"caller", "73:vcmp"}; CmdLineParser p; p.Parse(argc, argv); @@ -210,12 +186,7 @@ TEST_CASE("Decodes double digit position", "[support]") { TEST_CASE("Decodes position and id", "[support]") { int argc = 2; - char *argv[argc]; - char a0[] = "call"; - char a1[] = "5-8:vrf"; - argv[0] = static_cast(a0); - argv[1] = static_cast(a1); - + const char* const argv[]{"caller", "5-8:vrf"}; CmdLineParser p; p.Parse(argc, argv); @@ -227,15 +198,9 @@ TEST_CASE("Decodes position and id", "[support]") { TEST_CASE("Double digit id", "[support]") { int argc = 2; - char *argv[argc]; - char a0[] = "call"; - char a1[] = "56-8:vrf"; - argv[0] = static_cast(a0); - argv[1] = static_cast(a1); - + const char *const argv[]{"caller", "56-8:vrf"}; CmdLineParser p; p.Parse(argc, argv); - REQUIRE(p.detector_id() == 8); REQUIRE(p.multi_id() == 56); REQUIRE(p.command() == "vrf"); @@ -243,26 +208,15 @@ TEST_CASE("Double digit id", "[support]") { } TEST_CASE("Calling with wrong id throws invalid_argument", "[support]") { - int argc = 2; - char *argv[argc]; - char a0[] = "call"; - char a1[] = "asvldkn:vrf"; - argv[0] = static_cast(a0); - argv[1] = static_cast(a1); - + const char *const argv[]{"caller", "asvldkn:vrf"}; CmdLineParser p; CHECK_THROWS(p.Parse(argc, argv)); } TEST_CASE("Calling with wrong client throws invalid_argument", "[support]") { int argc = 2; - char *argv[argc]; - char a0[] = "call"; - char a1[] = "lki-3:vrf"; - argv[0] = static_cast(a0); - argv[1] = static_cast(a1); - + const char *const argv[]{"caller", "lki-3:vrf"}; CmdLineParser p; CHECK_THROWS(p.Parse(argc, argv)); }