]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2524] Add ClientId::toText() functionality
authorStephen Morris <stephen@isc.org>
Fri, 14 Dec 2012 22:17:19 +0000 (22:17 +0000)
committerStephen Morris <stephen@isc.org>
Fri, 14 Dec 2012 22:17:19 +0000 (22:17 +0000)
src/lib/dhcp/duid.cc
src/lib/dhcp/duid.h
src/lib/dhcp/tests/duid_unittest.cc

index 91efe94ad395d1c10199a1ad1381828e78cbcfe4..f1c8866c1c86dcb1d4265ca5e445dedaf03f72ce 100644 (file)
@@ -95,6 +95,16 @@ const std::vector<uint8_t> ClientId::getClientId() const {
     return (duid_);
 }
 
+// Returns the Client ID in text form
+std::string ClientId::toText() const {
+
+    // As DUID is a private base class of ClientId, we can't access
+    // its public toText() method through inheritance: instead we
+    // need the interface of a ClientId::toText() that calls the
+    // equivalent method in the base class.
+    return (DUID::toText());
+}
+
 // Compares two client-ids
 bool ClientId::operator==(const ClientId& other) const {
     return (this->duid_ == other.duid_);
index 60b9706df66e537ce7c6b4a29aaea77abb9b313a..a4e32b3b058f9a2aaa862b847afb0354dfbcc68e 100644 (file)
@@ -107,6 +107,9 @@ public:
     /// @brief Returns reference to the client-id data
     const std::vector<uint8_t> getClientId() const;
 
+    /// @brief Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
+    std::string toText() const;
+
     /// @brief Compares two client-ids for equality
     bool operator==(const ClientId& other) const;
 
index 9db4c352b38db2f9aadd92b38dc4052f242522ed..de20e510604d1d01b9e9165bea144afb1adda733 100644 (file)
@@ -108,6 +108,14 @@ TEST(DuidTest, getType) {
     EXPECT_EQ(DUID::DUID_UNKNOWN, duid_invalid->getType());
 }
 
+// Test checks if the toText() returns valid texual representation
+TEST(DuidTest, toText) {
+    uint8_t data1[] = {0, 1, 2, 3, 4, 0xff, 0xfe};
+
+    DUID duid(data1, sizeof(data1));
+    EXPECT_EQ("00:01:02:03:04:ff:fe", duid.toText());
+}
+
 // This test checks if the comparison operators are sane.
 TEST(DuidTest, operators) {
     uint8_t data1[] = {0, 1, 2, 3, 4, 5, 6};
@@ -174,8 +182,8 @@ TEST(ClientIdTest, operators) {
 TEST(ClientIdTest, toText) {
     uint8_t data1[] = {0, 1, 2, 3, 4, 0xff, 0xfe};
 
-    DUID duid(data1, sizeof(data1));
-    EXPECT_EQ("00:01:02:03:04:ff:fe", duid.toText());
+    ClientId clientid(data1, sizeof(data1));
+    EXPECT_EQ("00:01:02:03:04:ff:fe", clientid.toText());
 }
 
 } // end of anonymous namespace