Parcourir la source

Add conversion to c-style strings to let Google Test build.

Shane Kerr il y a 13 ans
Parent
commit
54aad8af04

+ 5 - 0
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

+ 3 - 0
src/lib/asiolink/tests/io_address_unittest.cc

@@ -18,11 +18,14 @@
 #include <asiolink/io_error.h>
 #include <asiolink/io_address.h>
 
+#include <cstring>
+
 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());