|
@@ -25,96 +25,57 @@ using namespace isc;
|
|
|
using namespace isc::badpacket;
|
|
|
|
|
|
|
|
|
-// Test fixture class
|
|
|
+/// \brief Test Fixture Class
|
|
|
|
|
|
class CommandOptionsTest : public virtual ::testing::Test,
|
|
|
public virtual CommandOptions
|
|
|
{
|
|
|
public:
|
|
|
- CommandOptionsTest() {}
|
|
|
-};
|
|
|
-
|
|
|
-// Check that the getRange() method works
|
|
|
-
|
|
|
-TEST_F(CommandOptionsTest, processOptionValue) {
|
|
|
-
|
|
|
- uint32_t result[2];
|
|
|
-
|
|
|
- // Check valid data
|
|
|
- processOptionValue("dummy", "1", result, 0, 1);
|
|
|
- EXPECT_EQ(1, result[0]);
|
|
|
- EXPECT_EQ(1, result[1]);
|
|
|
-
|
|
|
- processOptionValue("dummy", "0-2", result, 0, 5);
|
|
|
- EXPECT_EQ(0, result[0]);
|
|
|
- EXPECT_EQ(2, result[1]);
|
|
|
-
|
|
|
- processOptionValue("dummy", "4-8", result, 0, 10);
|
|
|
- EXPECT_EQ(4, result[0]);
|
|
|
- EXPECT_EQ(8, result[1]);
|
|
|
-
|
|
|
- processOptionValue("dummy", "172-103", result, 0, 200);
|
|
|
- EXPECT_EQ(103, result[0]);
|
|
|
- EXPECT_EQ(172, result[1]);
|
|
|
-
|
|
|
- // Check out of range values cause a BadValue exception
|
|
|
- EXPECT_THROW(processOptionValue("dummy", "1", result, 3, 4),
|
|
|
- isc::BadValue); // Single value below range
|
|
|
- EXPECT_THROW(processOptionValue("dummy", "7", result, 3, 6),
|
|
|
- isc::BadValue); // Single value above range
|
|
|
- EXPECT_THROW(processOptionValue("dummy", "2-6", result, 5, 10),
|
|
|
- isc::BadValue); // Range overlaps valid range on low side
|
|
|
- EXPECT_THROW(processOptionValue("dummy", "4-7", result, 5, 9),
|
|
|
- isc::BadValue); // Range overlaps valid range on high side
|
|
|
- EXPECT_THROW(processOptionValue("dummy", "9-1", result, 4, 8),
|
|
|
- isc::BadValue); // Range overlaps valid range
|
|
|
|
|
|
- // ... and that any invalid string does the same
|
|
|
- EXPECT_THROW(processOptionValue("dummy", "", result, 0, 1),
|
|
|
- isc::BadValue);
|
|
|
- EXPECT_THROW(processOptionValue("dummy", " ", result, 0, 1),
|
|
|
- isc::BadValue);
|
|
|
- EXPECT_THROW(processOptionValue("dummy", "abc", result, 0, 1),
|
|
|
- isc::BadValue);
|
|
|
- EXPECT_THROW(processOptionValue("dummy", "xyz-def", result, 0, 1),
|
|
|
- isc::BadValue);
|
|
|
- EXPECT_THROW(processOptionValue("dummy", "0.7", result, 0, 1),
|
|
|
- isc::BadValue);
|
|
|
- EXPECT_THROW(processOptionValue("dummy", "0.7-2.3", result, 0, 1),
|
|
|
- isc::BadValue);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-// Checks the minimum and maximum values specified for a flag
|
|
|
-void
|
|
|
-checkValuePair(const uint32_t value[2], uint32_t minval = 0,
|
|
|
- uint32_t maxval = 0)
|
|
|
-{
|
|
|
- EXPECT_EQ(minval, value[0]);
|
|
|
- EXPECT_EQ(maxval, value[1]);
|
|
|
-}
|
|
|
-
|
|
|
-// Checks that all flag values in the command values are zero
|
|
|
-void
|
|
|
-checkDefaultFlagValues(const CommandOptions::FlagValues& values) {
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc);
|
|
|
-}
|
|
|
+ /// \brief Default Constructor
|
|
|
+ CommandOptionsTest() {}
|
|
|
|
|
|
-// Checks non-flag options are set to defaults.
|
|
|
-void
|
|
|
-checkDefaultOtherValues(CommandOptions& options) {
|
|
|
- EXPECT_EQ("127.0.0.1", options.getAddress());
|
|
|
- EXPECT_EQ(53, options.getPort());
|
|
|
- EXPECT_EQ(500, options.getTimeout());
|
|
|
- EXPECT_EQ("www.example.com", options.getQname());
|
|
|
-}
|
|
|
+ /// \brief Checks the minimum and maximum () specified for an option
|
|
|
+ ///
|
|
|
+ /// Checks the () for one of the options whose values are stored in the
|
|
|
+ /// class's limits) array.
|
|
|
+ ///
|
|
|
+ /// \param index Index of the option in the limits_ array
|
|
|
+ /// \param minval Expected minimum value
|
|
|
+ /// \param maxval Expected maximum value
|
|
|
+ void checkValuePair(int index, uint32_t minval = 0, uint32_t maxval = 0)
|
|
|
+ {
|
|
|
+ EXPECT_EQ(minimum(index), minval);
|
|
|
+ EXPECT_EQ(maximum(index), maxval);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// \brief Checks that all options giving flags () are zero.
|
|
|
+ ///
|
|
|
+ /// Checks that all options whose () are stored in the class's limits_
|
|
|
+ /// array have both their maximum and minimum () set to zero.
|
|
|
+ void checkDefaultLimitsValues() {
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// \brief Check Non-Limit Options
|
|
|
+ ///
|
|
|
+ /// Checks that the options whose () are NOT stored in the limits_
|
|
|
+ /// array are set to their default ().
|
|
|
+ void
|
|
|
+ checkDefaultOtherValues() {
|
|
|
+ EXPECT_EQ("127.0.0.1", getAddress());
|
|
|
+ EXPECT_EQ(53, getPort());
|
|
|
+ EXPECT_EQ(500, getTimeout());
|
|
|
+ EXPECT_EQ("www.example.com", getQname());
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
// Check that each of the options will be recognised
|
|
|
|
|
@@ -131,7 +92,7 @@ TEST_F(CommandOptionsTest, address) {
|
|
|
EXPECT_EQ(53, getPort());
|
|
|
EXPECT_EQ(500, getTimeout());
|
|
|
EXPECT_EQ("www.example.com", getQname());
|
|
|
- checkDefaultFlagValues(getFlagValues());
|
|
|
+ checkDefaultLimitsValues();
|
|
|
}
|
|
|
|
|
|
TEST_F(CommandOptionsTest, port) {
|
|
@@ -143,7 +104,7 @@ TEST_F(CommandOptionsTest, port) {
|
|
|
EXPECT_EQ(153, getPort());
|
|
|
EXPECT_EQ(500, getTimeout());
|
|
|
EXPECT_EQ("www.example.com", getQname());
|
|
|
- checkDefaultFlagValues(getFlagValues());
|
|
|
+ checkDefaultLimitsValues();
|
|
|
}
|
|
|
|
|
|
TEST_F(CommandOptionsTest, timeout) {
|
|
@@ -155,7 +116,7 @@ TEST_F(CommandOptionsTest, timeout) {
|
|
|
EXPECT_EQ(53, getPort());
|
|
|
EXPECT_EQ(250, getTimeout());
|
|
|
EXPECT_EQ("www.example.com", getQname());
|
|
|
- checkDefaultFlagValues(getFlagValues());
|
|
|
+ checkDefaultLimitsValues();
|
|
|
}
|
|
|
|
|
|
TEST_F(CommandOptionsTest, parameter) {
|
|
@@ -167,348 +128,325 @@ TEST_F(CommandOptionsTest, parameter) {
|
|
|
EXPECT_EQ(53, getPort());
|
|
|
EXPECT_EQ(500, getTimeout());
|
|
|
EXPECT_EQ("ftp.example.net", getQname());
|
|
|
- checkDefaultFlagValues(getFlagValues());
|
|
|
+ checkDefaultLimitsValues();
|
|
|
}
|
|
|
|
|
|
// The various tests of the different flags
|
|
|
TEST_F(CommandOptionsTest, qr) {
|
|
|
|
|
|
- // Specifying a value of zero, we expect all flag values to be zero
|
|
|
+ // Specifying a value of zero, we expect all flag () to be zero
|
|
|
const char* argv1[] = {"badpacket", "--qr", "0"};
|
|
|
int argc1 = sizeof(argv1) / sizeof(const char*);
|
|
|
|
|
|
parse(argc1, const_cast<char**>(argv1));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- FlagValues values = getFlagValues();
|
|
|
- checkDefaultFlagValues(values);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkDefaultLimitsValues();
|
|
|
|
|
|
// Check that a value of 1 is accepted
|
|
|
const char* argv2[] = {"badpacket", "--qr", "1"};
|
|
|
int argc2 = sizeof(argv2) / sizeof(const char*);
|
|
|
|
|
|
parse(argc2, const_cast<char**>(argv2));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr, 1, 1);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR, 1, 1);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
|
|
|
// Check that a range is accepted (in this case, specified backwards)
|
|
|
const char* argv3[] = {"badpacket", "--qr", "1-0"};
|
|
|
int argc3 = sizeof(argv3) / sizeof(const char*);
|
|
|
|
|
|
parse(argc3, const_cast<char**>(argv3));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr, 0, 1);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR, 0, 1);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
}
|
|
|
|
|
|
// The following are cut-and-pasted from the "qr" test. (It is awkward to put
|
|
|
-// the test into a general function because of differing string values and
|
|
|
+// the test into a general function because of differing string () and
|
|
|
// variables.)
|
|
|
|
|
|
TEST_F(CommandOptionsTest, op) {
|
|
|
|
|
|
- // Specifying a value of zero, we expect all flag values to be zero
|
|
|
+ // Specifying a value of zero, we expect all flag () to be zero
|
|
|
const char* argv1[] = {"badpacket", "--op", "0"};
|
|
|
int argc1 = sizeof(argv1) / sizeof(const char*);
|
|
|
|
|
|
parse(argc1, const_cast<char**>(argv1));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- FlagValues values = getFlagValues();
|
|
|
- checkDefaultFlagValues(values);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkDefaultLimitsValues();
|
|
|
|
|
|
// Check that a value of 1 is accepted
|
|
|
const char* argv2[] = {"badpacket", "--op", "8"};
|
|
|
int argc2 = sizeof(argv2) / sizeof(const char*);
|
|
|
|
|
|
parse(argc2, const_cast<char**>(argv2));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op, 8, 8);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP, 8, 8);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
|
|
|
// Check that a range is accepted (in this case, specified backwards)
|
|
|
const char* argv3[] = {"badpacket", "--op", "14-2"};
|
|
|
int argc3 = sizeof(argv3) / sizeof(const char*);
|
|
|
|
|
|
parse(argc3, const_cast<char**>(argv3));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op, 2, 14);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP, 2, 14);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
}
|
|
|
|
|
|
TEST_F(CommandOptionsTest, aa) {
|
|
|
|
|
|
- // Specifying a value of zero, we expect all flag values to be zero
|
|
|
+ // Specifying a value of zero, we expect all flag () to be zero
|
|
|
const char* argv1[] = {"badpacket", "--aa", "0"};
|
|
|
int argc1 = sizeof(argv1) / sizeof(const char*);
|
|
|
|
|
|
parse(argc1, const_cast<char**>(argv1));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- FlagValues values = getFlagValues();
|
|
|
- checkDefaultFlagValues(values);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkDefaultLimitsValues();
|
|
|
|
|
|
// Check that a value of 1 is accepted
|
|
|
const char* argv2[] = {"badpacket", "--aa", "1"};
|
|
|
int argc2 = sizeof(argv2) / sizeof(const char*);
|
|
|
|
|
|
parse(argc2, const_cast<char**>(argv2));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa, 1, 1);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA, 1, 1);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
|
|
|
// Check that a range is accepted.
|
|
|
const char* argv3[] = {"badpacket", "--aa", "1-0"};
|
|
|
int argc3 = sizeof(argv3) / sizeof(const char*);
|
|
|
|
|
|
parse(argc3, const_cast<char**>(argv3));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa, 0, 1);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA, 0, 1);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
}
|
|
|
|
|
|
TEST_F(CommandOptionsTest, tc) {
|
|
|
|
|
|
- // Specifying a value of zero, we expect all flag values to be zero
|
|
|
+ // Specifying a value of zero, we expect all flag () to be zero
|
|
|
const char* argv1[] = {"badpacket", "--tc", "0"};
|
|
|
int argc1 = sizeof(argv1) / sizeof(const char*);
|
|
|
|
|
|
parse(argc1, const_cast<char**>(argv1));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- FlagValues values = getFlagValues();
|
|
|
- checkDefaultFlagValues(values);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkDefaultLimitsValues();
|
|
|
|
|
|
// Check that a value of 1 is accepted
|
|
|
const char* argv2[] = {"badpacket", "--tc", "1"};
|
|
|
int argc2 = sizeof(argv2) / sizeof(const char*);
|
|
|
|
|
|
parse(argc2, const_cast<char**>(argv2));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc, 1, 1);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC, 1, 1);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
|
|
|
// Check that a range is accepted.
|
|
|
const char* argv3[] = {"badpacket", "--tc", "1-0"};
|
|
|
int argc3 = sizeof(argv3) / sizeof(const char*);
|
|
|
|
|
|
parse(argc3, const_cast<char**>(argv3));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc, 0, 1);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC, 0, 1);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
}
|
|
|
|
|
|
TEST_F(CommandOptionsTest, z) {
|
|
|
|
|
|
- // Specifying a value of zero, we expect all flag values to be zero
|
|
|
+ // Specifying a value of zero, we expect all flag () to be zero
|
|
|
const char* argv1[] = {"badpacket", "--z", "0"};
|
|
|
int argc1 = sizeof(argv1) / sizeof(const char*);
|
|
|
|
|
|
parse(argc1, const_cast<char**>(argv1));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- FlagValues values = getFlagValues();
|
|
|
- checkDefaultFlagValues(values);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkDefaultLimitsValues();
|
|
|
|
|
|
// Check that a value of 1 is accepted
|
|
|
const char* argv2[] = {"badpacket", "--z", "1"};
|
|
|
int argc2 = sizeof(argv2) / sizeof(const char*);
|
|
|
|
|
|
parse(argc2, const_cast<char**>(argv2));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z, 1, 1);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z, 1, 1);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
|
|
|
// Check that a range is accepted.
|
|
|
const char* argv3[] = {"badpacket", "--z", "1-0"};
|
|
|
int argc3 = sizeof(argv3) / sizeof(const char*);
|
|
|
|
|
|
parse(argc3, const_cast<char**>(argv3));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z, 0, 1);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z, 0, 1);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
}
|
|
|
|
|
|
TEST_F(CommandOptionsTest, ad) {
|
|
|
|
|
|
- // Specifying a value of zero, we expect all flag values to be zero
|
|
|
+ // Specifying a value of zero, we expect all flag () to be zero
|
|
|
const char* argv1[] = {"badpacket", "--ad", "0"};
|
|
|
int argc1 = sizeof(argv1) / sizeof(const char*);
|
|
|
|
|
|
parse(argc1, const_cast<char**>(argv1));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- FlagValues values = getFlagValues();
|
|
|
- checkDefaultFlagValues(values);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkDefaultLimitsValues();
|
|
|
|
|
|
// Check that a value of 1 is accepted
|
|
|
const char* argv2[] = {"badpacket", "--ad", "1"};
|
|
|
int argc2 = sizeof(argv2) / sizeof(const char*);
|
|
|
|
|
|
parse(argc2, const_cast<char**>(argv2));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad, 1, 1);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD, 1, 1);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
|
|
|
// Check that a range is accepted.
|
|
|
const char* argv3[] = {"badpacket", "--ad", "0-1"};
|
|
|
int argc3 = sizeof(argv3) / sizeof(const char*);
|
|
|
|
|
|
parse(argc3, const_cast<char**>(argv3));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad, 0, 1);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD, 0, 1);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
}
|
|
|
|
|
|
TEST_F(CommandOptionsTest, cd) {
|
|
|
|
|
|
- // Specifying a value of zero, we expect all flag values to be zero
|
|
|
+ // Specifying a value of zero, we expect all flag () to be zero
|
|
|
const char* argv1[] = {"badpacket", "--cd", "0"};
|
|
|
int argc1 = sizeof(argv1) / sizeof(const char*);
|
|
|
|
|
|
parse(argc1, const_cast<char**>(argv1));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- FlagValues values = getFlagValues();
|
|
|
- checkDefaultFlagValues(values);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkDefaultLimitsValues();
|
|
|
|
|
|
// Check that a value of 1 is accepted
|
|
|
const char* argv2[] = {"badpacket", "--cd", "1"};
|
|
|
int argc2 = sizeof(argv2) / sizeof(const char*);
|
|
|
|
|
|
parse(argc2, const_cast<char**>(argv2));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd, 1, 1);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD, 1, 1);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
|
|
|
// Check that a range is accepted.
|
|
|
const char* argv3[] = {"badpacket", "--cd", "1-0"};
|
|
|
int argc3 = sizeof(argv3) / sizeof(const char*);
|
|
|
|
|
|
parse(argc3, const_cast<char**>(argv3));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd, 0, 1);
|
|
|
- checkValuePair(values.rc);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD, 0, 1);
|
|
|
+ checkValuePair(OptionInfo::RC);
|
|
|
}
|
|
|
|
|
|
TEST_F(CommandOptionsTest, rc) {
|
|
|
|
|
|
- // Specifying a value of zero, we expect all flag values to be zero
|
|
|
+ // Specifying a value of zero, we expect all flag () to be zero
|
|
|
const char* argv1[] = {"badpacket", "--rc", "0"};
|
|
|
int argc1 = sizeof(argv1) / sizeof(const char*);
|
|
|
|
|
|
parse(argc1, const_cast<char**>(argv1));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- FlagValues values = getFlagValues();
|
|
|
- checkDefaultFlagValues(values);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkDefaultLimitsValues();
|
|
|
|
|
|
// Check that a valid value is accepted.
|
|
|
const char* argv2[] = {"badpacket", "--rc", "15"};
|
|
|
int argc2 = sizeof(argv2) / sizeof(const char*);
|
|
|
|
|
|
parse(argc2, const_cast<char**>(argv2));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc, 15, 15);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC, 15, 15);
|
|
|
|
|
|
// Check that a range is accepted (in this case, specified backwards and
|
|
|
// outside the range - so it should be truncated).
|
|
@@ -516,14 +454,30 @@ TEST_F(CommandOptionsTest, rc) {
|
|
|
int argc3 = sizeof(argv3) / sizeof(const char*);
|
|
|
|
|
|
parse(argc3, const_cast<char**>(argv3));
|
|
|
- checkDefaultOtherValues(*this);
|
|
|
- values = getFlagValues();
|
|
|
- checkValuePair(values.qr);
|
|
|
- checkValuePair(values.op);
|
|
|
- checkValuePair(values.aa);
|
|
|
- checkValuePair(values.tc);
|
|
|
- checkValuePair(values.z);
|
|
|
- checkValuePair(values.ad);
|
|
|
- checkValuePair(values.cd);
|
|
|
- checkValuePair(values.rc, 4, 8);
|
|
|
+ checkDefaultOtherValues();
|
|
|
+ checkValuePair(OptionInfo::QR);
|
|
|
+ checkValuePair(OptionInfo::OP);
|
|
|
+ checkValuePair(OptionInfo::AA);
|
|
|
+ checkValuePair(OptionInfo::TC);
|
|
|
+ checkValuePair(OptionInfo::Z);
|
|
|
+ checkValuePair(OptionInfo::AD);
|
|
|
+ checkValuePair(OptionInfo::CD);
|
|
|
+ checkValuePair(OptionInfo::RC, 4, 8);
|
|
|
+}
|
|
|
+
|
|
|
+// Check that invalid () are caught.
|
|
|
+TEST_F(CommandOptionsTest, processOptionValue) {
|
|
|
+
|
|
|
+ // Check out of range () cause a BadValue exception
|
|
|
+ EXPECT_THROW(processOptionValue('Q', "2"), isc::BadValue); // Single value above range
|
|
|
+ EXPECT_THROW(processOptionValue('O', "0-17"), isc::BadValue); // Range overlapping valid range
|
|
|
+
|
|
|
+ // ... and that any invalid string does the same
|
|
|
+ EXPECT_THROW(processOptionValue('O', ""), isc::BadValue);
|
|
|
+ EXPECT_THROW(processOptionValue('O', " "), isc::BadValue);
|
|
|
+ EXPECT_THROW(processOptionValue('O', "1-2-3"), isc::BadValue);
|
|
|
+ EXPECT_THROW(processOptionValue('O', "abc"), isc::BadValue);
|
|
|
+ EXPECT_THROW(processOptionValue('O', "abc-xyz"), isc::BadValue);
|
|
|
+ EXPECT_THROW(processOptionValue('O', "0.7"), isc::BadValue);
|
|
|
+ EXPECT_THROW(processOptionValue('O', "0.7-2.3"), isc::BadValue);
|
|
|
}
|