mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-02 06:55:16 +00:00
[2524] Add ClientId::toText() functionality
This commit is contained in:
@@ -95,6 +95,16 @@ const std::vector<uint8_t> ClientId::getClientId() const {
|
|||||||
return (duid_);
|
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
|
// Compares two client-ids
|
||||||
bool ClientId::operator==(const ClientId& other) const {
|
bool ClientId::operator==(const ClientId& other) const {
|
||||||
return (this->duid_ == other.duid_);
|
return (this->duid_ == other.duid_);
|
||||||
|
@@ -107,6 +107,9 @@ public:
|
|||||||
/// @brief Returns reference to the client-id data
|
/// @brief Returns reference to the client-id data
|
||||||
const std::vector<uint8_t> getClientId() const;
|
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
|
/// @brief Compares two client-ids for equality
|
||||||
bool operator==(const ClientId& other) const;
|
bool operator==(const ClientId& other) const;
|
||||||
|
|
||||||
|
@@ -108,6 +108,14 @@ TEST(DuidTest, getType) {
|
|||||||
EXPECT_EQ(DUID::DUID_UNKNOWN, duid_invalid->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.
|
// This test checks if the comparison operators are sane.
|
||||||
TEST(DuidTest, operators) {
|
TEST(DuidTest, operators) {
|
||||||
uint8_t data1[] = {0, 1, 2, 3, 4, 5, 6};
|
uint8_t data1[] = {0, 1, 2, 3, 4, 5, 6};
|
||||||
@@ -174,8 +182,8 @@ TEST(ClientIdTest, operators) {
|
|||||||
TEST(ClientIdTest, toText) {
|
TEST(ClientIdTest, toText) {
|
||||||
uint8_t data1[] = {0, 1, 2, 3, 4, 0xff, 0xfe};
|
uint8_t data1[] = {0, 1, 2, 3, 4, 0xff, 0xfe};
|
||||||
|
|
||||||
DUID duid(data1, sizeof(data1));
|
ClientId clientid(data1, sizeof(data1));
|
||||||
EXPECT_EQ("00:01:02:03:04:ff:fe", duid.toText());
|
EXPECT_EQ("00:01:02:03:04:ff:fe", clientid.toText());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end of anonymous namespace
|
} // end of anonymous namespace
|
||||||
|
Reference in New Issue
Block a user