From: Marcin Siodelski Date: Fri, 21 Dec 2012 12:26:52 +0000 (+0100) Subject: [2545] Added a test that checks whether value in CSV format is accepted. X-Git-Tag: bind10-1.0.0-rc-release~99^2~21^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9065335de2f05d3bc1d874b933ba80b51feb68f6;p=thirdparty%2Fkea.git [2545] Added a test that checks whether value in CSV format is accepted. --- diff --git a/src/bin/dhcp4/tests/config_parser_unittest.cc b/src/bin/dhcp4/tests/config_parser_unittest.cc index 6de7e94332..baf550dd10 100644 --- a/src/bin/dhcp4/tests/config_parser_unittest.cc +++ b/src/bin/dhcp4/tests/config_parser_unittest.cc @@ -17,9 +17,10 @@ #include #include +#include #include #include -#include +#include #include #include #include @@ -737,6 +738,64 @@ TEST_F(Dhcp4ParserTest, optionDataLowerCase) { testOption(*range.first, 56, foo_expected, sizeof(foo_expected)); } +// Verify that specific option object is returned for standard +// option which has dedicated option class derived from Option. +TEST_F(Dhcp4ParserTest, stdOptionData) { + ConstElementPtr x; + std::map params; + params["name"] = "nis-servers"; + // Option code 41 means nis-servers. + params["code"] = "41"; + // Specify option values in a CSV (user friendly) format. + params["data"] = "192.0.2.10, 192.0.2.1, 192.0.2.3"; + params["csv-format"] = "True"; + + std::string config = createConfigWithOption(params); + ElementPtr json = Element::fromJSON(config); + + EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json)); + ASSERT_TRUE(x); + comment_ = parseAnswer(rcode_, x); + ASSERT_EQ(0, rcode_); + + Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5")); + ASSERT_TRUE(subnet); + const Subnet::OptionContainer& options = subnet->getOptions(); + ASSERT_EQ(1, options.size()); + + // Get the search index. Index #1 is to search using option code. + const Subnet::OptionContainerTypeIndex& idx = options.get<1>(); + + // Get the options for specified index. Expecting one option to be + // returned but in theory we may have multiple options with the same + // code so we get the range. + std::pair range = + idx.equal_range(DHO_NIS_SERVERS); + // Expect single option with the code equal to NIS_SERVERS option code. + ASSERT_EQ(1, std::distance(range.first, range.second)); + // The actual pointer to the option is held in the option field + // in the structure returned. + OptionPtr option = range.first->option; + ASSERT_TRUE(option); + // Option object returned for here is expected to be Option6IA + // which is derived from Option. This class is dedicated to + // represent standard option IA_NA. + boost::shared_ptr option_addrs = + boost::dynamic_pointer_cast(option); + // If cast is unsuccessful than option returned was of a + // differnt type than Option6IA. This is wrong. + ASSERT_TRUE(option_addrs); + + // Get addresses from the option. + Option4AddrLst::AddressContainer addrs = option_addrs->getAddresses(); + // Verify that the addresses have been configured correctly. + ASSERT_EQ(3, addrs.size()); + EXPECT_EQ("192.0.2.10", addrs[0].toText()); + EXPECT_EQ("192.0.2.1", addrs[1].toText()); + EXPECT_EQ("192.0.2.3", addrs[2].toText()); +} + /// This test checks if Uint32Parser can really parse the whole range /// and properly err of out of range values. As we can't call Uint32Parser /// directly, we are exploiting the fact that it is used to parse global diff --git a/src/bin/dhcp6/tests/config_parser_unittest.cc b/src/bin/dhcp6/tests/config_parser_unittest.cc index 3aa25f6570..9774270cac 100644 --- a/src/bin/dhcp6/tests/config_parser_unittest.cc +++ b/src/bin/dhcp6/tests/config_parser_unittest.cc @@ -763,7 +763,6 @@ TEST_F(Dhcp6ParserTest, stdOptionData) { EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json)); ASSERT_TRUE(x); comment_ = parseAnswer(rcode_, x); - std::cout << comment_->str() << std::endl; ASSERT_EQ(0, rcode_); Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"));