bool
CommandOptions::initialize(int argc, char** argv, bool print_cmd_line) {
int opt = 0; // Subsequent options returned by getopt()
+ int opt_long_index = 0; // Holds index of long_option inside of long_options[]
std::string drop_arg; // Value of -D<value>argument
size_t percent_loc = 0; // Location of % sign in -D<value>
double drop_percent = 0; // % value (1..100) in -D<value%>
while((opt = getopt_long(argc, argv,
"huv46A:r:t:R:b:n:p:d:D:l:P:a:L:N:M:s:iBc1"
"J:T:X:O:o:E:S:I:x:W:w:e:f:F:g:C:y:Y:",
- long_options, NULL)) != -1) {
- stream << " -" << static_cast<char>(opt);
+ long_options, &opt_long_index)) != -1) {
+ stream << " -";
+ opt <= 'z' ? stream << static_cast<char>(opt) :
+ stream << "-" << long_options[opt_long_index].name;
if (optarg) {
stream << " " << optarg;
}
try {
isc::util::encode::decodeHex(opt_text, bin);
} catch (const BadValue& e) {
- isc_throw(InvalidParameter, "Error during encoding option --o1r:"
+ isc_throw(InvalidParameter, "Error during decoding option --o1r:"
<< e.what());
}
// Create and remember the option.
OptionPtr option(new Option(Option::V6, code, bin));
// For now, only 1 level of encapsulation is allowed for relay options,
- // thus 1 key is hardcoded below. But in future, if needed, level of
+ // thus 1 key is hardcoded below. But in the future, if needed, level of
// encapsulation of relay option could be taken from command option.
auto relay_1_opts = relay_opts_.find(1);
relay_1_opts->second.insert(make_pair(code, option));
EXPECT_EQ(3, opt.getIncreaseElapsedTime());
EXPECT_EQ(10, opt.getWaitForElapsedTime());
}
+
+TEST_F(CommandOptionsTest, UseRelayV6OptionsWithoutRelayEncapsulation) {
+ CommandOptions opt;
+ EXPECT_NO_THROW(process(opt, "perfdhcp -6 -A1 --o1r 32,00000E10 -l ethx all"));
+ EXPECT_TRUE(opt.isUseRelayedV6());
+ EXPECT_EQ(1, opt.getRelayOpts().size());
+
+ // --o1r must be used together with -A
+ EXPECT_THROW(process(opt, "perfdhcp -6 --o1r 32,00000E10 -l ethx all"), isc::InvalidParameter);
+}
+
+TEST_F(CommandOptionsTest, UseRelayV6OptionsNoComma) {
+ CommandOptions opt;
+
+ // --o1r must be followed by option code, a coma and hexstring
+ EXPECT_THROW(process(opt, "perfdhcp -6 --o1r 3200000E10 -l ethx all"), isc::InvalidParameter);
+}
+
+TEST_F(CommandOptionsTest, UseRelayV6OptionsNegativeOptionCode) {
+ CommandOptions opt;
+
+ // --o1r must be followed by positive option code, a coma and hexstring
+ EXPECT_THROW(process(opt, "perfdhcp -6 --o1r -32,00000E10 -l ethx all"), isc::InvalidParameter);
+}
+
+TEST_F(CommandOptionsTest, UseRelayV6OptionsWrongHexstring) {
+ CommandOptions opt;
+
+ // --o1r hexstring containing char Z which is not correct
+ EXPECT_THROW(process(opt, "perfdhcp -6 --o1r -32,Z0000E10 -l ethx all"), isc::InvalidParameter);
+}