]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
bde978a6 | 2 | * Copyright (C) 1996-2015 The Squid Software Foundation and contributors |
bbc27441 AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
cc192b50 | 9 | #define SQUID_HELPER 1 |
ec94e362 | 10 | |
582c2af2 | 11 | #include "squid.h" |
cc192b50 | 12 | |
13 | #include <cppunit/TestAssert.h> | |
14 | ||
b826ffb5 | 15 | #include "testIcmp.h" |
7f861c77 AJ |
16 | #include "unitTestMain.h" |
17 | ||
b826ffb5 | 18 | CPPUNIT_TEST_SUITE_REGISTRATION( testIcmp ); |
cc192b50 | 19 | |
20 | #if USE_ICMP | |
21 | ||
22 | void | |
b826ffb5 | 23 | testIcmp::testChecksum() |
cc192b50 | 24 | { |
b826ffb5 | 25 | stubIcmp icmp; |
f77d2de8 FC |
26 | uint16_t buf[10], tmpval; |
27 | for (tmpval=0; tmpval < 10; ++tmpval) | |
b4624c6c | 28 | buf[tmpval]=htons(1+tmpval); |
cc192b50 | 29 | |
30 | // NULL data | |
4d6662d9 | 31 | CPPUNIT_ASSERT_EQUAL((int)htons(0xffff), icmp.testChecksum(NULL,0)); |
cc192b50 | 32 | |
33 | // NULL data with length!! | |
4d6662d9 | 34 | CPPUNIT_ASSERT_EQUAL((int)htons(0xffff), icmp.testChecksum(NULL,1)); |
cc192b50 | 35 | |
36 | // data with 0 length | |
4d6662d9 | 37 | CPPUNIT_ASSERT_EQUAL((int)htons(0xffff), icmp.testChecksum(buf,0)); |
cc192b50 | 38 | |
39 | // data with invalid length (low) | |
4d6662d9 | 40 | CPPUNIT_ASSERT_EQUAL((int)htons(0xffff), icmp.testChecksum(buf,1)); |
cc192b50 | 41 | |
4d6662d9 AJ |
42 | CPPUNIT_ASSERT_EQUAL((int)htons(0xfffe), icmp.testChecksum(buf,2)); // 1 |
43 | CPPUNIT_ASSERT_EQUAL((int)htons(0xfffe), icmp.testChecksum(buf,3)); | |
b0ed693e | 44 | |
4d6662d9 AJ |
45 | CPPUNIT_ASSERT_EQUAL((int)htons(0xfffc), icmp.testChecksum(buf,4)); // 1+2 |
46 | CPPUNIT_ASSERT_EQUAL((int)htons(0xfffc), icmp.testChecksum(buf,5)); | |
cc192b50 | 47 | |
4d6662d9 | 48 | CPPUNIT_ASSERT_EQUAL((int)htons(0xfff9), icmp.testChecksum(buf,6)); // 1+2+3 |
b0ed693e | 49 | CPPUNIT_ASSERT_EQUAL((int)htons(0xfff9), icmp.testChecksum(buf,7)); |
cc192b50 | 50 | |
4d6662d9 | 51 | CPPUNIT_ASSERT_EQUAL((int)htons(0xfff5), icmp.testChecksum(buf,8)); // 1+2+3+4 |
b0ed693e | 52 | CPPUNIT_ASSERT_EQUAL((int)htons(0xfff5), icmp.testChecksum(buf,9)); |
4d6662d9 AJ |
53 | |
54 | CPPUNIT_ASSERT_EQUAL((int)htons(0xfff0), icmp.testChecksum(buf,10)); // 1+2...+5 | |
55 | CPPUNIT_ASSERT_EQUAL((int)htons(0xfff0), icmp.testChecksum(buf,11)); | |
56 | ||
57 | CPPUNIT_ASSERT_EQUAL((int)htons(0xffea), icmp.testChecksum(buf,12)); // 1+2...+6 | |
58 | CPPUNIT_ASSERT_EQUAL((int)htons(0xffea), icmp.testChecksum(buf,13)); | |
59 | ||
60 | CPPUNIT_ASSERT_EQUAL((int)htons(0xffe3), icmp.testChecksum(buf,14)); // 1+2...+7 | |
61 | CPPUNIT_ASSERT_EQUAL((int)htons(0xffe3), icmp.testChecksum(buf,15)); | |
62 | ||
63 | CPPUNIT_ASSERT_EQUAL((int)htons(0xffdb), icmp.testChecksum(buf,16)); // 1+2...+8 | |
64 | CPPUNIT_ASSERT_EQUAL((int)htons(0xffdb), icmp.testChecksum(buf,17)); | |
65 | ||
66 | CPPUNIT_ASSERT_EQUAL((int)htons(0xffd2), icmp.testChecksum(buf,18)); // 1+2...+9 | |
67 | CPPUNIT_ASSERT_EQUAL((int)htons(0xffd2), icmp.testChecksum(buf,19)); | |
68 | ||
b0ed693e | 69 | // data with accurate length |
4d6662d9 AJ |
70 | CPPUNIT_ASSERT_EQUAL((int)htons(0xffc8), icmp.testChecksum(buf,20)); // 1+2...+10 |
71 | ||
72 | // data with invalid length (overrun) ==> Garbage checksum... | |
cc192b50 | 73 | } |
74 | ||
75 | void | |
b826ffb5 | 76 | testIcmp::testHops() |
cc192b50 | 77 | { |
b826ffb5 | 78 | stubIcmp icmp; |
cc192b50 | 79 | |
80 | /* test invalid -(under values) */ | |
81 | // negative : n > 33 | |
82 | CPPUNIT_ASSERT_EQUAL(34, icmp.testHops(-1)); | |
83 | // zero | |
84 | CPPUNIT_ASSERT_EQUAL(33, icmp.testHops(0)); | |
85 | ||
26ac0430 | 86 | /* test each valid case boundary */ |
cc192b50 | 87 | // n(1...32) : 32 >= n >= 1 |
88 | CPPUNIT_ASSERT_EQUAL(32, icmp.testHops(1)); | |
89 | CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(32)); | |
90 | ||
91 | // n(33...62) : 30 >= n >= 1 | |
92 | CPPUNIT_ASSERT_EQUAL(30, icmp.testHops(33)); | |
93 | CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(62)); | |
94 | ||
95 | // n(63...64) : 2 >= n >= 1 | |
96 | CPPUNIT_ASSERT_EQUAL(2, icmp.testHops(63)); | |
97 | CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(64)); | |
98 | ||
99 | // n(65...128) : 64 >= n >= 1 | |
100 | CPPUNIT_ASSERT_EQUAL(64, icmp.testHops(65)); | |
101 | CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(128)); | |
102 | ||
103 | // n(129...192) : 64 >= n >= 1 | |
104 | CPPUNIT_ASSERT_EQUAL(64, icmp.testHops(129)); | |
105 | CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(192)); | |
106 | ||
107 | // n(193...) : n < 63 | |
108 | CPPUNIT_ASSERT_EQUAL(63, icmp.testHops(193)); | |
109 | CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(255)); | |
110 | ||
26ac0430 | 111 | /* test invalid (over values) */ |
cc192b50 | 112 | // 256 - produces zero |
113 | CPPUNIT_ASSERT_EQUAL(0, icmp.testHops(256)); | |
114 | // 257 - produces negative hops | |
115 | CPPUNIT_ASSERT_EQUAL(-1, icmp.testHops(257)); | |
116 | } | |
117 | ||
118 | #endif /* USE_ICMP */ | |
f53969cc | 119 |