From: Shane Kerr Date: Mon, 12 Sep 2011 12:19:17 +0000 (+0200) Subject: Add conversion to c-style strings to let Google Test build. X-Git-Tag: perftcpdns_before_epoll~37^2~21^2~23 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=54aad8af04350eb3a45a4bd6623681efa2f8d2fb;p=thirdparty%2Fkea.git Add conversion to c-style strings to let Google Test build. --- diff --git a/src/lib/asiolink/io_address.h b/src/lib/asiolink/io_address.h index 1b488fa9c8..1a42da710f 100644 --- a/src/lib/asiolink/io_address.h +++ b/src/lib/asiolink/io_address.h @@ -74,6 +74,11 @@ public: /// \return A string representation of the address. std::string toText() const; + /// \brief Convert the address to a C-style null-terminated string. + /// + /// \return A string representation of the address. + operator const char*() const { return toText().c_str(); } + /// \brief Returns const reference to the underlying address object. /// /// This is useful, when access to interface offerted by diff --git a/src/lib/asiolink/tests/io_address_unittest.cc b/src/lib/asiolink/tests/io_address_unittest.cc index 18b181e8b6..b2a0dccb4e 100644 --- a/src/lib/asiolink/tests/io_address_unittest.cc +++ b/src/lib/asiolink/tests/io_address_unittest.cc @@ -18,11 +18,14 @@ #include #include +#include + using namespace isc::asiolink; TEST(IOAddressTest, fromText) { IOAddress io_address_v4("192.0.2.1"); EXPECT_EQ("192.0.2.1", io_address_v4.toText()); + EXPECT_EQ(0, strcmp("192.0.2.1", (const char *)io_address_v4)); IOAddress io_address_v6("2001:db8::1234"); EXPECT_EQ("2001:db8::1234", io_address_v6.toText());