2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-29 04:57:52 +00:00

[2524] Add ClientId::toText() functionality

This commit is contained in:
Stephen Morris 2012-12-14 22:17:19 +00:00
parent e632c67d9f
commit be90b92cbe
3 changed files with 23 additions and 2 deletions

View 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_);

View 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;

View 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