This commit is contained in:
Erik Frojdh
2021-09-14 15:14:08 +02:00
parent abf56ad643
commit adaf56ca2e
7 changed files with 188 additions and 121 deletions

View File

@ -105,16 +105,6 @@ SCENARIO("Parsing a string with the command line parser", "[support]") {
REQUIRE(p.arguments()[2] == "7000");
}
}
// WHEN("Cliend id and or detector id cannot be decoded") {
// vs arg{"o:cmd", "-5:cmd", "aedpva:cmd",
// "5-svc:vrf", "asv-5:cmd", "savc-asa:cmd"};
// THEN("Parsing Throws") {
// for (size_t i = 0; i != arg.size(); ++i) {
// REQUIRE_THROWS(p.Parse(arg[i]));
// }
// }
// }
}
}
@ -157,6 +147,20 @@ SCENARIO("Parsing strings with -h or --help", "[support]") {
}
}
TEST_CASE("Parse string with --help"){
CmdParser p;
p.Parse("list --help");
REQUIRE(p.isHelp()==true);
REQUIRE(p.command()=="list");
}
TEST_CASE("Parse string with -h"){
CmdParser p;
p.Parse("list -h");
REQUIRE(p.isHelp()==true);
REQUIRE(p.command()=="list");
}
TEST_CASE("Parsing consecutive strings resets not found det id") {
CmdParser p;
p.Parse("1:exptime 0.5");
@ -266,19 +270,6 @@ TEST_CASE("Double digit id", "[support]") {
REQUIRE(p.arguments().empty());
}
// TEST_CASE("Calling with wrong id throws invalid_argument", "[support]") {
// int argc = 2;
// const char *const argv[]{"caller", "asvldkn:vrf"};
// CmdParser p;
// CHECK_THROWS(p.Parse(argc, argv));
// }
// TEST_CASE("Calling with wrong client throws invalid_argument", "[support]") {
// int argc = 2;
// const char *const argv[]{"caller", "lki-3:vrf"};
// CmdParser p;
// CHECK_THROWS(p.Parse(argc, argv));
// }
TEST_CASE("Build up argv", "[support]") {
CmdParser p;
@ -293,8 +284,8 @@ TEST_CASE("Build up argv", "[support]") {
TEST_CASE("Allows space between mod id and command"){
CmdParser p;
p.Parse("1: exptime 0.5");
REQUIRE(p.detector_id() == 8);
p.Parse("7: exptime 0.5");
REQUIRE(p.detector_id() == 7);
REQUIRE(p.command() == "exptime");
REQUIRE(p.arguments().size() == 1);
REQUIRE(p.arguments()[0] == "0.5");
@ -327,4 +318,79 @@ TEST_CASE("Allows space between mod id and command with detector id and :"){
REQUIRE(p.command() == "exptime");
REQUIRE(p.arguments().size() == 1);
REQUIRE(p.arguments()[0] == "0.5");
}
TEST_CASE("Parse receiver ID"){
CmdParser p;
p.Parse("2-5:3 flowcontrol10g 1");
REQUIRE(p.detector_id() == 5);
REQUIRE(p.multi_id() == 2);
REQUIRE(p.command() == "flowcontrol10g");
REQUIRE(p.arguments().size() == 1);
REQUIRE(p.arguments()[0] == "1");
REQUIRE(p.receiver_id()==3);
}
TEST_CASE("Parse receiver ID no det id"){
CmdParser p;
p.Parse("5:95 flowcontrol10g");
REQUIRE(p.detector_id() == 5);
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command() == "flowcontrol10g");
REQUIRE(p.arguments().size() == 0);
REQUIRE(p.receiver_id()==95);
}
TEST_CASE("Det id but no mod id"){
CmdParser p;
p.Parse("1-exptime");
REQUIRE(p.detector_id() == -1); //not there
REQUIRE(p.multi_id() == 1);
REQUIRE(p.command() == "exptime");
}
TEST_CASE("Det id but no mod id but with space after -"){
CmdParser p;
p.Parse("1- exptime");
REQUIRE(p.detector_id() == -1); //not there
REQUIRE(p.multi_id() == 1);
REQUIRE(p.command() == "exptime");
}
TEST_CASE("Parse receiver ID no det id no mod"){
CmdParser p;
p.Parse(":95 flowcontrol10g");
REQUIRE(p.detector_id() == -1); //not there
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command() == "flowcontrol10g");
REQUIRE(p.arguments().size() == 0);
REQUIRE(p.receiver_id()==95);
}
TEST_CASE("Parse mod and receiver id"){
CmdParser p;
p.Parse("1:3 exptime");
REQUIRE(p.detector_id() == 1);
REQUIRE(p.receiver_id()==3);
REQUIRE(p.command() == "exptime");
}
TEST_CASE("Det id but no no mod"){
CmdParser p;
p.Parse("2-:35 exptime");
REQUIRE(p.detector_id() == -1);
REQUIRE(p.receiver_id()==35);
REQUIRE(p.multi_id() == 2);
REQUIRE(p.command() == "exptime");
}
TEST_CASE("All stuff"){
CmdParser p;
p.Parse("3-4:2 exptime");
REQUIRE(p.detector_id() == 4);
REQUIRE(p.receiver_id()==2);
REQUIRE(p.multi_id() == 3);
REQUIRE(p.command() == "exptime");
}