1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-24 19:21:35 +01:00

Done minor modifications.

This commit is contained in:
Matias Fontanini
2012-03-06 08:31:10 -03:00
parent d2f6862b7b
commit 53dfad8bf2
5 changed files with 120 additions and 40 deletions

View File

@@ -12,9 +12,14 @@ class IPTest : public testing::Test {
public:
static const uint8_t expected_packet[];
void test_equals(const IP &tcp1, const IP &tcp2);
void test_equals(const IP &ip1, const IP &ip2);
};
const uint8_t IPTest::expected_packet[] = { '(', '\x7f', '\x00', ' ',
'\x00', 'z', '\x00', 'C', '\x15', '\x01', '\xfb', 'g', 'T', '4', '\xfe',
'\x05', '\xc0', '\xa8', '\t', '+', '\x82', '\x0b', 't', 'j', 'g', '\xab',
'w', '\xab', 'h', 'e', 'l', '\x00' };
TEST_F(IPTest, DefaultConstructor) {
IP ip;
@@ -128,6 +133,42 @@ TEST_F(IPTest, SecOption) {
ip.set_sec_option(data, sizeof(data));
const IP::IPOption *option;
ASSERT_TRUE((option = ip.search_option(IP::CONTROL, IP::SEC)));
ASSERT_EQ(option->optional_data_size, sizeof(data));
EXPECT_TRUE(memcmp(option->optional_data, data, sizeof(data)) == 0);
ASSERT_EQ(option->data_size(), sizeof(data));
EXPECT_TRUE(memcmp(option->data_ptr(), data, sizeof(data)) == 0);
}
void IPTest::test_equals(const IP &ip1, const IP &ip2) {
EXPECT_EQ(ip1.dst_addr(), ip2.dst_addr());
EXPECT_EQ(ip1.src_addr(), ip2.src_addr());
EXPECT_EQ(ip1.id(), ip2.id());
EXPECT_EQ(ip1.frag_off(), ip2.frag_off());
EXPECT_EQ(ip1.tos(), ip2.tos());
EXPECT_EQ(ip1.ttl(), ip2.ttl());
EXPECT_EQ(ip1.version(), ip2.version());
}
TEST_F(IPTest, ConstructorFromBuffer) {
IP ip1(expected_packet, sizeof(expected_packet));
const uint8_t opt_sec[] = { 't', 'j', 'g', '\xab', 'w', '\xab', 'h', 'e', 'l' };
EXPECT_EQ(ip1.dst_addr(), Utils::ip_to_int("192.168.9.43"));
EXPECT_EQ(ip1.src_addr(), Utils::ip_to_int("84.52.254.5"));
EXPECT_EQ(ip1.id(), 0x7a);
EXPECT_EQ(ip1.tos(), 0x7f);
EXPECT_EQ(ip1.frag_off(), 0x43);
EXPECT_EQ(ip1.protocol(), 1);
EXPECT_EQ(ip1.ttl(), 0x15);
EXPECT_EQ(ip1.version(), 2);
const IP::IPOption *option;
ASSERT_TRUE((option = ip1.search_option(IP::CONTROL, IP::SEC)));
EXPECT_EQ(option->type.number, IP::SEC);
EXPECT_EQ(option->type.op_class, IP::CONTROL);
ASSERT_EQ(option->data_size(), sizeof(opt_sec));
EXPECT_TRUE(memcmp(option->data_ptr(), opt_sec, sizeof(opt_sec)) == 0);
uint32_t size;
uint8_t *buffer = ip1.serialize(size);
ASSERT_TRUE(buffer);
IP ip2(buffer, size);
}