]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1456] Addressed comments
authorFrancis Dupont <fdupont@isc.org>
Fri, 4 Dec 2020 11:00:11 +0000 (12:00 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 9 Dec 2020 14:14:06 +0000 (15:14 +0100)
src/bin/dhcp6/tests/config_parser_unittest.cc
src/lib/dhcpsrv/network.h
src/lib/dhcpsrv/tests/network_unittest.cc

index 026457d517c087d39104ba56f385532eaf8cd0d3..2a1dfe746c3c17596434be1a823e9ca6bd27acff 100644 (file)
@@ -1102,6 +1102,7 @@ TEST_F(Dhcp6ParserTest, outBoundValidLifetime) {
         "    \"subnet\": \"2001:db8::/32\" } ],"
         "\"valid-lifetime\": 1500, \"min-valid-lifetime\": 2000, "
         "\"max-valid-lifetime\": 1000 }";
+
     ASSERT_NO_THROW(json = parseDHCP6(crossed));
     EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json));
     expected = "subnet configuration failed: "
@@ -1113,7 +1114,7 @@ TEST_F(Dhcp6ParserTest, outBoundValidLifetime) {
 /// Check that valid-lifetime must be between min-valid-lifetime and
 /// max-valid-lifetime when a bound is specified. Check on global
 /// parameters only.
-TEST_F(Dhcp6ParserTest, outGlobalBoundValidLifetime) {
+TEST_F(Dhcp6ParserTest, outBoundGlobaValidLifetime) {
 
     string too_small =  "{ " + genIfaceConfig() + "," +
         "\"valid-lifetime\": 1000, \"min-valid-lifetime\": 2000 }";
@@ -1167,6 +1168,7 @@ TEST_F(Dhcp6ParserTest, outGlobalBoundValidLifetime) {
     string crossed =  "{ " + genIfaceConfig() + "," +
         "\"valid-lifetime\": 1500, \"min-valid-lifetime\": 2000, "
         "\"max-valid-lifetime\": 1000 }";
+
     ASSERT_NO_THROW(json = parseDHCP6(crossed));
     EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json));
     expected =
@@ -1247,6 +1249,7 @@ TEST_F(Dhcp6ParserTest, outBoundPreferredLifetime) {
         "    \"subnet\": \"2001:db8::/32\" } ],"
         "\"preferred-lifetime\": 1500, \"min-preferred-lifetime\": 2000, "
         "\"max-preferred-lifetime\": 1000 }";
+
     ASSERT_NO_THROW(json = parseDHCP6(crossed));
     EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json));
     expected = "subnet configuration failed: "
@@ -1312,6 +1315,7 @@ TEST_F(Dhcp6ParserTest, outBoundGlobalPreferredLifetime) {
     string crossed =  "{ " + genIfaceConfig() + "," +
         "\"preferred-lifetime\": 1500, \"min-preferred-lifetime\": 2000, "
         "\"max-preferred-lifetime\": 1000 }";
+
     ASSERT_NO_THROW(json = parseDHCP6(crossed));
     EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json));
     expected =
index dd1ee9a67b6a28e8748ab6c585dd1146b84d70f0..4166eb34fa084fa5ce1a6c4b39ee71e495100609 100644 (file)
@@ -794,7 +794,7 @@ protected:
     /// @note: use overloading vs specialization because full specialization
     /// is not allowed in this scope.
     ///
-    /// @tparam IntType Type of the encapsulated value(s).
+    /// @tparam NumType Type of the encapsulated value(s).
     ///
     /// @param property Value to be returned when it is specified or when
     /// no global value is found.
@@ -805,8 +805,8 @@ protected:
     ///
     /// @return Optional value fetched from the global level or the value
     /// of @c property.
-    template<typename IntType>
-    Triplet<IntType> getGlobalProperty(Triplet<IntType> property,
+    template<typename NumType>
+    Triplet<NumType> getGlobalProperty(Triplet<NumType> property,
                                        const std::string& global_name,
                                        bool triplet) const {
         if (!global_name.empty() && fetch_globals_fn_) {
@@ -814,23 +814,23 @@ protected:
             if (globals && (globals->getType() == data::Element::map)) {
                 data::ConstElementPtr param = globals->get(global_name);
                 if (param) {
-                    IntType def_value = static_cast<IntType>(param->intValue());
+                    NumType def_value = static_cast<NumType>(param->intValue());
                     if (!triplet) {
                         return (def_value);
                     } else {
-                        IntType min_value = def_value;
-                        IntType max_value = def_value;
+                        NumType min_value = def_value;
+                        NumType max_value = def_value;
                         const std::string& min_name = "min-" + global_name;
                         data::ConstElementPtr min_param = globals->get(min_name);
                         if (min_param) {
-                            min_value = static_cast<IntType>(min_param->intValue());
+                            min_value = static_cast<NumType>(min_param->intValue());
                         }
                         const std::string& max_name = "max-" + global_name;
                         data::ConstElementPtr max_param = globals->get(max_name);
-                        if (min_param) {
-                            min_value = static_cast<IntType>(min_param->intValue());
+                        if (max_param) {
+                            max_value = static_cast<NumType>(max_param->intValue());
                         }
-                        return (Triplet<IntType>(min_value, def_value, max_value));
+                        return (Triplet<NumType>(min_value, def_value, max_value));
                     }
                 }
             }
index d97bcd6203f3f110236197d193af61e5264fad1e..c8312fd4770ee33cf33b8c139fdeadc056da7447 100644 (file)
@@ -740,28 +740,44 @@ TEST_F(NetworkReservationTest, move) {
 }
 
 // This test verifies that the inheritance is supported for triplets.
+// Note that triplets have no comparison operator.
 TEST_F(NetworkTest, inheritanceTriplet) {
     NetworkPtr net(new Network());
-    Triplet<uint32_t> empty;
-    EXPECT_EQ(empty, net->getValid());
-    EXPECT_EQ(empty, net->getValid(Network::Inheritance::ALL));
-    EXPECT_EQ(empty, net->getValid(Network::Inheritance::GLOBAL));
+    EXPECT_TRUE(net->getValid().unspecified());
+    EXPECT_TRUE(net->getValid(Network::Inheritance::ALL).unspecified());
+    EXPECT_TRUE(net->getValid(Network::Inheritance::GLOBAL).unspecified());
 
     // Set valid lifetime global parameter.
     globals_->set("valid-lifetime", Element::create(200));
     net->setFetchGlobalsFn(getFetchGlobalsFn());
-    Triplet<uint32_t> one(200);
-    EXPECT_EQ(one, net->getValid());
-    EXPECT_EQ(one, net->getValid(Network::Inheritance::ALL));
-    EXPECT_EQ(one, net->getValid(Network::Inheritance::GLOBAL));
+    EXPECT_FALSE(net->getValid().unspecified());
+    EXPECT_FALSE(net->getValid(Network::Inheritance::ALL).unspecified());
+    EXPECT_FALSE(net->getValid(Network::Inheritance::GLOBAL).unspecified());
+    EXPECT_EQ(200, net->getValid().get());
+    EXPECT_EQ(200, net->getValid(Network::Inheritance::ALL).get());
+    EXPECT_EQ(200, net->getValid(Network::Inheritance::GLOBAL).get());
+    EXPECT_EQ(200, net->getValid().getMin());
+    EXPECT_EQ(200, net->getValid(Network::Inheritance::ALL).getMin());
+    EXPECT_EQ(200, net->getValid(Network::Inheritance::GLOBAL).getMin());
+    EXPECT_EQ(200, net->getValid().getMax());
+    EXPECT_EQ(200, net->getValid(Network::Inheritance::ALL).getMax());
+    EXPECT_EQ(200, net->getValid(Network::Inheritance::GLOBAL).getMax());
 
     // Set all valid lifetime global parameters.
     globals_->set("min-valid-lifetime", Element::create(100));
     globals_->set("max-valid-lifetime", Element::create(300));
-    Triplet<uint32_t> three(100, 200, 300);
-    EXPECT_EQ(three, net->getValid());
-    EXPECT_EQ(three, net->getValid(Network::Inheritance::ALL));
-    EXPECT_EQ(three, net->getValid(Network::Inheritance::GLOBAL));
+    EXPECT_FALSE(net->getValid().unspecified());
+    EXPECT_FALSE(net->getValid(Network::Inheritance::ALL).unspecified());
+    EXPECT_FALSE(net->getValid(Network::Inheritance::GLOBAL).unspecified());
+    EXPECT_EQ(200, net->getValid().get());
+    EXPECT_EQ(200, net->getValid(Network::Inheritance::ALL).get());
+    EXPECT_EQ(200, net->getValid(Network::Inheritance::GLOBAL).get());
+    EXPECT_EQ(100, net->getValid().getMin());
+    EXPECT_EQ(100, net->getValid(Network::Inheritance::ALL).getMin());
+    EXPECT_EQ(100, net->getValid(Network::Inheritance::GLOBAL).getMin());
+    EXPECT_EQ(300, net->getValid().getMax());
+    EXPECT_EQ(300, net->getValid(Network::Inheritance::ALL).getMax());
+    EXPECT_EQ(300, net->getValid(Network::Inheritance::GLOBAL).getMax());
 }
 
 }