1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#include "../catch.hpp"
#include "rkcommon/utility/ArgumentList.h"
using rkcommon::utility::ArgumentList;
static const char *test_arguments[5] = {
"testApp", "arg1", "arg2", "arg3", "arg4"};
SCENARIO("ArgumentList correctness", "[ArgumentList]")
{
GIVEN("A constructed ArgumentList from a given const char *[]")
{
ArgumentList args(5, test_arguments);
THEN("The list is initially not empty")
{
REQUIRE(!args.empty());
}
THEN("The list contains only the arguments, and not the application")
{
REQUIRE(args.size() == 4);
REQUIRE(args[0] != "testApp");
}
THEN("Removal of arguments from given indices mutates the list")
{
args.remove(0);
REQUIRE(args[0] == "arg2");
REQUIRE(args[1] == "arg3");
REQUIRE(args[2] == "arg4");
args.remove(0, 2);
REQUIRE(args[0] == "arg4");
args.remove(0);
REQUIRE(args.empty());
}
}
}
struct TestParser final : public rkcommon::utility::ArgumentsParser
{
int tryConsume(ArgumentList &argList, int argID) override
{
const auto arg = argList[argID];
if (arg == "arg1")
return 1;
else if (arg == "arg3")
return 2;
return 0;
}
};
TEST_CASE("ArgumentsParser correctness", "[ArgumentList]")
{
ArgumentList args(5, test_arguments);
TestParser parser;
parser.parseAndRemove(args);
REQUIRE(args.size() == 1);
REQUIRE(args[0] == "arg2");
}
|