123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #include <config.h>
- #include <iostream>
- #include <sstream>
- #include <arpa/inet.h>
- #include <gtest/gtest.h>
- #include "dhcp/libdhcp.h"
- #include "config.h"
- using namespace std;
- using namespace isc;
- using namespace isc::dhcp;
- namespace {
- class LibDhcpTest : public ::testing::Test {
- public:
- LibDhcpTest() {
- }
- };
- static const uint8_t packed[] = {
- 0, 12, 0, 5, 100, 101, 102, 103, 104,
- 0, 13, 0, 3, 105, 106, 107,
- 0, 14, 0, 2, 108, 109,
- 1, 0, 0, 4, 110, 111, 112, 113,
- 1, 1, 0, 1, 114
- };
- TEST_F(LibDhcpTest, packOptions6) {
- boost::shared_array<uint8_t> buf(new uint8_t[512]);
- isc::dhcp::Option::Option6Collection opts;
-
- 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));
- 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);
- EXPECT_EQ(0, memcmp(&buf[100], packed, 35) );
- }
- TEST_F(LibDhcpTest, unpackOptions6) {
-
-
-
-
- isc::dhcp::Option::Option6Collection options;
-
-
- boost::shared_array<uint8_t> buf(new uint8_t[512]);
- memcpy(&buf[0], packed, 35);
- unsigned int offset;
- EXPECT_NO_THROW ({
- offset = LibDHCP::unpackOptions6(buf, 512, 0, 35, options);
- });
- EXPECT_EQ(35, offset);
- EXPECT_EQ(options.size(), 5);
- isc::dhcp::Option::Option6Collection::const_iterator x = options.find(12);
- ASSERT_FALSE(x == options.end());
- EXPECT_EQ(12, x->second->getType());
- ASSERT_EQ(9, x->second->len());
- EXPECT_EQ(0, memcmp(x->second->getData(), packed+4, 5));
- x = options.find(13);
- ASSERT_FALSE(x == options.end());
- EXPECT_EQ(13, x->second->getType());
- ASSERT_EQ(7, x->second->len());
- EXPECT_EQ(0, memcmp(x->second->getData(), packed+13, 3));
- x = options.find(14);
- ASSERT_FALSE(x == options.end());
- EXPECT_EQ(14, x->second->getType());
- ASSERT_EQ(6, x->second->len());
- EXPECT_EQ(0, memcmp(x->second->getData(), packed+20, 2));
- x = options.find(256);
- ASSERT_FALSE(x == options.end());
- EXPECT_EQ(256, x->second->getType());
- ASSERT_EQ(8, x->second->len());
- EXPECT_EQ(0, memcmp(x->second->getData(), packed+26, 4));
- x = options.find(257);
- ASSERT_FALSE(x == options.end());
- EXPECT_EQ(257, x->second->getType());
- ASSERT_EQ(5, x->second->len());
- EXPECT_EQ(0, memcmp(x->second->getData(), packed+34, 1));
- x = options.find(0);
- EXPECT_TRUE(x == options.end());
- x = options.find(1);
- EXPECT_TRUE(x == options.end());
- x = options.find(2);
- EXPECT_TRUE(x == options.end());
- x = options.find(32000);
- EXPECT_TRUE(x == options.end());
- }
- }
|