]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testICMP.cc
1 #define SQUID_UNIT_TEST 1
6 #include <cppunit/TestAssert.h>
10 CPPUNIT_TEST_SUITE_REGISTRATION( testICMP
);
15 testICMP::testChecksum()
18 short unsigned int buf
[10] = {1,2,3,4,5,6,7,8,9};
21 CPPUNIT_ASSERT_EQUAL(65535, icmp
.testChecksum(NULL
,0));
23 // NULL data with length!!
24 CPPUNIT_ASSERT_EQUAL(65535, icmp
.testChecksum(NULL
,1));
27 CPPUNIT_ASSERT_EQUAL(65535, icmp
.testChecksum(buf
,0));
29 // data with invalid length (low)
30 CPPUNIT_ASSERT_EQUAL(65534, icmp
.testChecksum(buf
,1));
32 // data with invalid length (max-low)
33 CPPUNIT_ASSERT_EQUAL(65520, icmp
.testChecksum(buf
,9));
35 // data with accurate length
36 CPPUNIT_ASSERT_EQUAL(65520, icmp
.testChecksum(buf
,10));
38 // data with invalid length (overrun)
39 CPPUNIT_ASSERT_EQUAL(65514, icmp
.testChecksum(buf
,11));
47 /* test invalid -(under values) */
49 CPPUNIT_ASSERT_EQUAL(34, icmp
.testHops(-1));
51 CPPUNIT_ASSERT_EQUAL(33, icmp
.testHops(0));
53 /* test each valid case boundary */
54 // n(1...32) : 32 >= n >= 1
55 CPPUNIT_ASSERT_EQUAL(32, icmp
.testHops(1));
56 CPPUNIT_ASSERT_EQUAL(1, icmp
.testHops(32));
58 // n(33...62) : 30 >= n >= 1
59 CPPUNIT_ASSERT_EQUAL(30, icmp
.testHops(33));
60 CPPUNIT_ASSERT_EQUAL(1, icmp
.testHops(62));
62 // n(63...64) : 2 >= n >= 1
63 CPPUNIT_ASSERT_EQUAL(2, icmp
.testHops(63));
64 CPPUNIT_ASSERT_EQUAL(1, icmp
.testHops(64));
66 // n(65...128) : 64 >= n >= 1
67 CPPUNIT_ASSERT_EQUAL(64, icmp
.testHops(65));
68 CPPUNIT_ASSERT_EQUAL(1, icmp
.testHops(128));
70 // n(129...192) : 64 >= n >= 1
71 CPPUNIT_ASSERT_EQUAL(64, icmp
.testHops(129));
72 CPPUNIT_ASSERT_EQUAL(1, icmp
.testHops(192));
75 CPPUNIT_ASSERT_EQUAL(63, icmp
.testHops(193));
76 CPPUNIT_ASSERT_EQUAL(1, icmp
.testHops(255));
78 /* test invalid (over values) */
79 // 256 - produces zero
80 CPPUNIT_ASSERT_EQUAL(0, icmp
.testHops(256));
81 // 257 - produces negative hops
82 CPPUNIT_ASSERT_EQUAL(-1, icmp
.testHops(257));