From: Marcin Siodelski Date: Tue, 27 Nov 2012 13:21:03 +0000 (+0100) Subject: [2312] Constructor unit test. X-Git-Tag: bind10-1.0.0-beta-release~46^2~18^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=deaf3af3f2b12e34dee77b31ff28748cbaef3778;p=thirdparty%2Fkea.git [2312] Constructor unit test. --- diff --git a/src/lib/dhcp/tests/option_custom_unittest.cc b/src/lib/dhcp/tests/option_custom_unittest.cc index bdb0322ca0..39a46868de 100644 --- a/src/lib/dhcp/tests/option_custom_unittest.cc +++ b/src/lib/dhcp/tests/option_custom_unittest.cc @@ -32,6 +32,10 @@ public: /// @brief Constructor. OptionCustomTest() { } + /// @brief Write IP address into a buffer. + /// + /// @param address address to be written. + /// @param [out] buf output buffer. void writeAddress(const asiolink::IOAddress& address, std::vector& buf) { short family = address.getFamily(); @@ -46,6 +50,11 @@ public: } } + /// @brief Write integer (signed or unsiged) into a buffer. + /// + /// @param value integer value. + /// @param [out] buf output buffer. + /// @tparam integer type. template void writeInt(T value, std::vector& buf) { for (int i = 0; i < sizeof(T); ++i) { @@ -53,6 +62,10 @@ public: } } + /// @brief Write a string into a buffer. + /// + /// @param value string to be written into a buffer. + /// @param buf output buffer. void writeString(const std::string& value, std::vector& buf) { buf.resize(buf.size() + value.size()); @@ -61,9 +74,38 @@ public: } }; +// The purpose of this test is to check that parameters passed to +// a custom option's constructor are used to initialize class +// members. TEST_F(OptionCustomTest, constructor) { - /* OptionDefinition opt_def1("OPTION_FOO", 1000, "string", true); - ASSERT_THROW(opt_def1.validate(), isc::Exception); */ + // Create option definition for a DHCPv6 option. + OptionDefinition opt_def1("OPTION_FOO", 1000, "boolean", true); + + // Initialize some dummy buffer that holds single boolean value. + OptionBuffer buf; + buf.push_back(1); + + // Create DHCPv6 option. + boost::scoped_ptr option; + ASSERT_NO_THROW( + option.reset(new OptionCustom(opt_def1, Option::V6, buf)); + ); + ASSERT_TRUE(option); + + // Check if constructor initialized the universe and type correctly. + EXPECT_EQ(Option::V6, option->getUniverse()); + EXPECT_EQ(1000, option->getType()); + + // Do another round of testing for DHCPv4 option. + OptionDefinition opt_def2("OPTION_FOO", 232, "boolean"); + + ASSERT_NO_THROW( + option.reset(new OptionCustom(opt_def2, Option::V4, buf.begin(), buf.end())); + ); + ASSERT_TRUE(option); + + EXPECT_EQ(Option::V4, option->getUniverse()); + EXPECT_EQ(232, option->getType()); } // The purpose of this test is to verify that 'empty' option definition can