From: Marcin Siodelski Date: Tue, 27 May 2014 13:20:37 +0000 (+0200) Subject: [3336] It is now possible to mark triplet unspecified. X-Git-Tag: trac3434_base~14^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0a48d176a2115716926611bf55f087efd16b2e56;p=thirdparty%2Fkea.git [3336] It is now possible to mark triplet unspecified. --- diff --git a/src/lib/dhcpsrv/tests/triplet_unittest.cc b/src/lib/dhcpsrv/tests/triplet_unittest.cc index 61b08a85ae..160eef174d 100644 --- a/src/lib/dhcpsrv/tests/triplet_unittest.cc +++ b/src/lib/dhcpsrv/tests/triplet_unittest.cc @@ -38,6 +38,7 @@ TEST(TripletTest, constructor) { EXPECT_EQ(min, x.getMin()); EXPECT_EQ(value, x.get()); EXPECT_EQ(max, x.getMax()); + EXPECT_FALSE(x.unspecified()); // requested values below min should return allowed min value EXPECT_EQ(min, x.get(min - 5)); @@ -58,6 +59,7 @@ TEST(TripletTest, constructor) { EXPECT_EQ(42, y.getMin()); // min, default and max are equal to 42 EXPECT_EQ(42, y.get()); // it returns ... EXPECT_EQ(42, y.getMax()); // the exact value... + EXPECT_FALSE(x.unspecified()); // requested values below or above are ignore EXPECT_EQ(42, y.get(5)); // all... @@ -65,6 +67,29 @@ TEST(TripletTest, constructor) { EXPECT_EQ(42, y.get(80)); // time! } +TEST(TripletTest, unspecified) { + Triplet x; + // When using the constructor without parameters, the triplet + // value is unspecified. + EXPECT_EQ(0, x.getMin()); + EXPECT_EQ(0, x.get()); + EXPECT_EQ(0, x.getMax()); + EXPECT_TRUE(x.unspecified()); + + // For the triplet which has unspecified value we can call accessors + // without an exception. + uint32_t exp_unspec = 0; + EXPECT_EQ(exp_unspec, x); + + x = 72; + // Check if the new value has been assigned. + EXPECT_EQ(72, x.getMin()); + EXPECT_EQ(72, x.get()); + EXPECT_EQ(72, x.getMax()); + // Triplet is now specified. + EXPECT_FALSE(x.unspecified()); +} + // Triplets must be easy to use. // Simple to/from int conversions must be done on the fly. TEST(TripletTest, operator) { @@ -79,6 +104,7 @@ TEST(TripletTest, operator) { EXPECT_EQ(4, foo.getMin()); EXPECT_EQ(5, foo.get()); EXPECT_EQ(6, foo.getMax()); + EXPECT_FALSE(foo.unspecified()); // assignment operator: uint32_t => triplet Triplet y(0); diff --git a/src/lib/dhcpsrv/triplet.h b/src/lib/dhcpsrv/triplet.h index 8aa0d3adcb..de72ca48f6 100644 --- a/src/lib/dhcpsrv/triplet.h +++ b/src/lib/dhcpsrv/triplet.h @@ -54,6 +54,8 @@ public: min_ = other; default_ = other; max_ = other; + // The value is now specified because we just assigned one. + unspecified_ = false; return (*this); } @@ -65,6 +67,14 @@ public: return (default_); } + /// @brief Constructor without parameters. + /// + /// Marks value in @c Triplet unspecified. + Triplet() + : min_(0), default_(0), max_(0), + unspecified_(true) { + } + /// @brief Sets a fixed value. /// /// This constructor assigns a fixed (i.e. no range, just a single value) @@ -72,14 +82,16 @@ public: /// /// @param value A number to be assigned as min, max and default value. Triplet(T value) - :min_(value), default_(value), max_(value) { + : min_(value), default_(value), max_(value), + unspecified_(false) { } /// @brief Sets the default value and thresholds /// /// @throw BadValue if min <= def <= max rule is violated Triplet(T min, T def, T max) - :min_(min), default_(def), max_(max) { + : min_(min), default_(def), max_(max), + unspecified_(false) { if ( (min_ > def) || (def > max_) ) { isc_throw(BadValue, "Invalid triplet values."); } @@ -118,6 +130,13 @@ public: /// @brief Returns a maximum allowed value T getMax() const { return (max_); } + /// @brief Check if the value has been specified. + /// + /// @return true if the value hasn't been specified, or false otherwise. + bool unspecified() const { + return (unspecified_); + } + private: /// @brief the minimum value @@ -128,6 +147,9 @@ private: /// @brief the maximum value T max_; + + /// @brief Indicates whether the value is unspecified. + bool unspecified_; };