#include <dhcp/addr_utilities.h>
#include <asiolink/io_address.h>
#include <dhcp/subnet.h>
+#include <sstream>
using namespace isc::asiolink;
options_.clear();
}
+std::string Subnet::toText() {
+ std::stringstream tmp;
+ tmp << prefix_.toText() << "/" << static_cast<unsigned int>(prefix_len_);
+ return (tmp.str());
+}
+
Subnet4::Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length,
const Triplet<uint32_t>& t1,
const Triplet<uint32_t>& t2,
/// @return unique ID for that subnet
SubnetID getID() const { return (id_); }
+ std::pair<isc::asiolink::IOAddress, uint8_t> get() {
+ return (std::pair<isc::asiolink::IOAddress, uint8_t>(prefix_, prefix_len_));
+ }
+
+ virtual std::string toText();
+
protected:
/// @brief protected constructor
//
EXPECT_FALSE(subnet->inPool(IOAddress("192.3.0.0")));
}
+// This test checks if the toText() method returns text representation
+TEST(Subnet4Test, toText) {
+ Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"), 24, 1, 2, 3));
+ EXPECT_EQ("192.0.2.0/24", subnet->toText());
+}
+
+// This test checks if the get() method returns proper parameters
+TEST(Subnet4Test, get) {
+ Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"), 28, 1, 2, 3));
+ EXPECT_EQ("192.0.2.0", subnet->get().first.toText());
+ EXPECT_EQ(28, subnet->get().second);
+}
+
// Tests for Subnet6
TEST(Subnet6Test, constructor) {
EXPECT_FALSE(subnet->inPool(IOAddress("2001:db8::21")));
}
+// This test checks if the toText() method returns text representation
+TEST(Subnet6Test, toText) {
+ Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8::"), 32, 1, 2, 3, 4));
+ EXPECT_EQ("2001:db8::/32", subnet->toText());
+}
+
+// This test checks if the get() method returns proper parameters
+TEST(Subnet6Test, get) {
+ Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8::"), 32, 1, 2, 3, 4));
+ EXPECT_EQ("2001:db8::", subnet->get().first.toText());
+ EXPECT_EQ(32, subnet->get().second);
+}
+
};