Commit 4865dbd4 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[1186] Tests for libdhcp::packOptions6 implemented.

parent c7b87837
......@@ -25,7 +25,7 @@
using namespace std;
using namespace isc::dhcp;
// static array with factory
// static array with factories for options
std::map<unsigned short, Option::Factory*> LibDHCP::v6factories_;
std::string
......
......@@ -75,9 +75,10 @@ public:
///
/// @return true, if registration was successful, false otherwise
///
bool OptionFactoryRegister(Option::Universe u,
unsigned short type,
Option::Factory * factory);
static bool
OptionFactoryRegister(Option::Universe u,
unsigned short type,
Option::Factory * factory);
protected:
// pointers to factories that produce DHCPv6 options
static std::map<unsigned short, Option::Factory*> v6factories_;
......
......@@ -39,4 +39,46 @@ TEST_F(LibDhcpTest, basic) {
EXPECT_EQ(LibDHCP::version(), PACKAGE_VERSION);
}
TEST_F(LibDhcpTest, packOptions6) {
boost::shared_array<char> buf(new char[512]);
isc::dhcp::Option::Option6Lst opts; // list of options
// generate content for options
for (int i=0;i<64;i++) {
buf[i]=i+100;
}
boost::shared_ptr<Option> opt1(new Option(Option::V6, 12, buf, 0, 5));
boost::shared_ptr<Option> opt2(new Option(Option::V6, 13, buf, 5, 3));
boost::shared_ptr<Option> opt3(new Option(Option::V6, 14, buf, 8, 2));
boost::shared_ptr<Option> opt4(new Option(Option::V6,256, buf,10, 4));
boost::shared_ptr<Option> opt5(new Option(Option::V6,257, buf,14, 1));
char expected[] = {
0, 12, 0, 5, 100, 101, 102, 103, 104, // opt1
0, 13, 0, 3, 105, 106, 107, // opt2
0, 14, 0, 2, 108, 109, // opt3
1, 0, 0, 4, 110, 111, 112, 113, // opt4
1, 1, 0, 1, 114
};
opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt1));
opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt2));
opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt3));
opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt4));
opts.insert(pair<int, boost::shared_ptr<Option> >(opt1->getType(), opt5));
unsigned int offset;
EXPECT_NO_THROW (
{
offset = LibDHCP::packOptions6(buf, 512, 100, opts);
});
EXPECT_EQ(135, offset); // options should take 35 bytes
EXPECT_EQ(0, memcmp(&buf[100], expected, 35) );
}
TEST_F(LibDhcpTest, unpackOptions6) {
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment