]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testICMP.cc
Merged from trunk.
[thirdparty/squid.git] / src / tests / testICMP.cc
1 #define SQUID_UNIT_TEST 1
2 #define SQUID_HELPER 1
3
4 #include "squid.h"
5
6 #include <cppunit/TestAssert.h>
7
8 #include "testICMP.h"
9
10 CPPUNIT_TEST_SUITE_REGISTRATION( testICMP );
11
12 #if USE_ICMP
13
14 void
15 testICMP::testChecksum()
16 {
17 stubICMP icmp;
18 short unsigned int buf[10] = {1,2,3,4,5,6,7,8,9};
19
20 // NULL data
21 CPPUNIT_ASSERT_EQUAL(65535, icmp.testChecksum(NULL,0));
22
23 // NULL data with length!!
24 CPPUNIT_ASSERT_EQUAL(65535, icmp.testChecksum(NULL,1));
25
26 // data with 0 length
27 CPPUNIT_ASSERT_EQUAL(65535, icmp.testChecksum(buf,0));
28
29 // data with invalid length (low)
30 CPPUNIT_ASSERT_EQUAL(65534, icmp.testChecksum(buf,1));
31
32 // data with invalid length (max-low)
33 CPPUNIT_ASSERT_EQUAL(65520, icmp.testChecksum(buf,9));
34
35 // data with accurate length
36 CPPUNIT_ASSERT_EQUAL(65520, icmp.testChecksum(buf,10));
37
38 // data with invalid length (overrun)
39 CPPUNIT_ASSERT_EQUAL(65514, icmp.testChecksum(buf,11));
40 }
41
42 void
43 testICMP::testHops()
44 {
45 stubICMP icmp;
46
47 /* test invalid -(under values) */
48 // negative : n > 33
49 CPPUNIT_ASSERT_EQUAL(34, icmp.testHops(-1));
50 // zero
51 CPPUNIT_ASSERT_EQUAL(33, icmp.testHops(0));
52
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));
57
58 // n(33...62) : 30 >= n >= 1
59 CPPUNIT_ASSERT_EQUAL(30, icmp.testHops(33));
60 CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(62));
61
62 // n(63...64) : 2 >= n >= 1
63 CPPUNIT_ASSERT_EQUAL(2, icmp.testHops(63));
64 CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(64));
65
66 // n(65...128) : 64 >= n >= 1
67 CPPUNIT_ASSERT_EQUAL(64, icmp.testHops(65));
68 CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(128));
69
70 // n(129...192) : 64 >= n >= 1
71 CPPUNIT_ASSERT_EQUAL(64, icmp.testHops(129));
72 CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(192));
73
74 // n(193...) : n < 63
75 CPPUNIT_ASSERT_EQUAL(63, icmp.testHops(193));
76 CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(255));
77
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));
83 }
84
85 #endif /* USE_ICMP */