Browse Source

[trac998] Renamed createNetmask to internal::createMask

Stephen Morris 14 years ago
parent
commit
8034dbfe87
2 changed files with 20 additions and 12 deletions
  1. 11 4
      src/lib/acl/ip_check.h
  2. 9 8
      src/lib/acl/tests/ip_check_unittest.cc

+ 11 - 4
src/lib/acl/ip_check.h

@@ -36,7 +36,11 @@
 namespace isc {
 namespace acl {
 
-// Free functions
+// Free functions.  These are not supposed to be used outside this module,
+// but are declared public for testing.  To try to conceal them, they are
+// put in an "internal" namespace.
+
+namespace internal {
 
 /// \brief Convert prefix length to mask
 ///
@@ -56,7 +60,7 @@ namespace acl {
 /// \exception OutOfRange prefixlen is too large for the data type.
 
 template <typename T>
-T createNetmask(size_t prefixlen) {
+T createMask(size_t prefixlen) {
 
     if (prefixlen == 0) {
         return (0);
@@ -155,6 +159,8 @@ splitIPAddress(const std::string& prefix) {
     return (std::make_pair(components[0], prefixlen));
 }
 
+} // namespace internal
+
 
 
 /// \brief IP Check
@@ -277,7 +283,8 @@ public:
             // General address prefix.  Split into address part and prefix
             // length.
 
-            std::pair<std::string, int> result = splitIPAddress(addrprfx);
+            std::pair<std::string, int> result =
+                internal::splitIPAddress(addrprfx);
 
             // Try to convert the address.  If successful, the result is in
             // network-byte order (most significant components at lower
@@ -505,7 +512,7 @@ private:
                     bits_left -= 8;
 
                 } else if (bits_left > 0) {
-                    mask_.byte[++i] = createNetmask<uint8_t>(bits_left);
+                    mask_.byte[++i] = internal::createMask<uint8_t>(bits_left);
                     bits_left = 0;
 
                 }

+ 9 - 8
src/lib/acl/tests/ip_check_unittest.cc

@@ -18,6 +18,7 @@
 #include <boost/scoped_ptr.hpp>
 
 using namespace isc::acl;
+using namespace isc::acl::internal;
 using namespace std;
 
 // Simple struct holding either an IPV4 or IPV6 address.  This is the "Context"
@@ -94,30 +95,30 @@ bool IPCheck<GeneralAddress>::matches(const GeneralAddress& addr) const {
 
 /// *** Free Function Tests ***
 
-// Test the createNetmask() function.
-TEST(IPFunctionCheck, CreateNetmask) {
+// Test the createMask() function.
+TEST(IPFunctionCheck, CreateMask) {
 
     // 8-bit tests: invalid arguments should throw.
-    EXPECT_THROW(createNetmask<uint8_t>(9), isc::OutOfRange);
+    EXPECT_THROW(createMask<uint8_t>(9), isc::OutOfRange);
 
     // Check on all possible 8-bit values.  Use a signed type to generate a
     // variable with the most significant bits set (right-shifting will
     // introduce additional bits).
     int8_t expected8 = 0x80;
     for (size_t i = 1; i <= 8; ++i, expected8 >>= 1) {
-        EXPECT_EQ(static_cast<uint8_t>(expected8), createNetmask<uint8_t>(i));
+        EXPECT_EQ(static_cast<uint8_t>(expected8), createMask<uint8_t>(i));
     }
-    EXPECT_EQ(0, createNetmask<uint8_t>(0));
+    EXPECT_EQ(0, createMask<uint8_t>(0));
 
     // Do the same for 32 bits.
-    EXPECT_THROW(createNetmask<int32_t>(33), isc::OutOfRange);
+    EXPECT_THROW(createMask<int32_t>(33), isc::OutOfRange);
 
     int32_t expected32 = 0x80000000;
     for (size_t i = 1; i <= 32; ++i, expected32 >>= 1) {
         EXPECT_EQ(static_cast<uint32_t>(expected32),
-                  createNetmask<uint32_t>(i));
+                  createMask<uint32_t>(i));
     }
-    EXPECT_EQ(0, createNetmask<uint32_t>(0));
+    EXPECT_EQ(0, createMask<uint32_t>(0));
 }
 
 // Test the splitIPAddress() function.