--------------------- PatchSet 6033 Date: 2007/10/29 11:56:22 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Fix ICMP tests and remove one found ICMP bug. Members: src/icmp.cc:1.8.8.18->1.8.8.19 src/tests/testICMP.cc:1.1.2.2->1.1.2.3 Index: squid3/src/icmp.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/icmp.cc,v retrieving revision 1.8.8.18 retrieving revision 1.8.8.19 diff -u -r1.8.8.18 -r1.8.8.19 --- squid3/src/icmp.cc 29 Oct 2007 08:36:30 -0000 1.8.8.18 +++ squid3/src/icmp.cc 29 Oct 2007 11:56:22 -0000 1.8.8.19 @@ -1,5 +1,5 @@ /* - * $Id: icmp.cc,v 1.8.8.18 2007/10/29 08:36:30 amosjeffries Exp $ + * $Id: icmp.cc,v 1.8.8.19 2007/10/29 11:56:22 amosjeffries Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels, Amos Jeffries @@ -63,6 +63,9 @@ long sum; unsigned short oddbyte; unsigned short answer; + + if(!ptr) return 65535; // bad input. + sum = 0; while (size > 1) { Index: squid3/src/tests/testICMP.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/tests/Attic/testICMP.cc,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid3/src/tests/testICMP.cc 29 Oct 2007 11:15:38 -0000 1.1.2.2 +++ squid3/src/tests/testICMP.cc 29 Oct 2007 11:56:23 -0000 1.1.2.3 @@ -16,28 +16,26 @@ stubICMP icmp; short unsigned int buf[10] = {1,2,3,4,5,6,7,8,9}; -// TODO calculate the actual checksum expected for each test case. - // NULL data - CPPUNIT_ASSERT_EQUAL(icmp.testChecksum(NULL,0), 0); + CPPUNIT_ASSERT_EQUAL(65535, icmp.testChecksum(NULL,0)); // NULL data with length!! - CPPUNIT_ASSERT_EQUAL(icmp.testChecksum(buf,0), 0); + CPPUNIT_ASSERT_EQUAL(65535, icmp.testChecksum(NULL,1)); // data with 0 length - CPPUNIT_ASSERT_EQUAL(icmp.testChecksum(buf,0), 0); + CPPUNIT_ASSERT_EQUAL(65535, icmp.testChecksum(buf,0)); // data with invalid length (low) - CPPUNIT_ASSERT_EQUAL(icmp.testChecksum(buf,1), 0); + CPPUNIT_ASSERT_EQUAL(65534, icmp.testChecksum(buf,1)); // data with invalid length (max-low) - CPPUNIT_ASSERT_EQUAL(icmp.testChecksum(buf,9), 0); + CPPUNIT_ASSERT_EQUAL(65520, icmp.testChecksum(buf,9)); // data with accurate length - CPPUNIT_ASSERT_EQUAL(icmp.testChecksum(buf,10), 0); + CPPUNIT_ASSERT_EQUAL(65520, icmp.testChecksum(buf,10)); // data with invalid length (overrun) - CPPUNIT_ASSERT_EQUAL(icmp.testChecksum(buf,11), 0); + CPPUNIT_ASSERT_EQUAL(65514, icmp.testChecksum(buf,11)); } void @@ -47,36 +45,40 @@ /* test invalid -(under values) */ // negative : n > 33 - CPPUNIT_ASSERT_EQUAL(icmp.testHops(-1),34); + CPPUNIT_ASSERT_EQUAL(34, icmp.testHops(-1)); // zero - CPPUNIT_ASSERT_EQUAL(icmp.testHops(0), 33); + CPPUNIT_ASSERT_EQUAL(33, icmp.testHops(0)); /* test each valid case boundary */ // n(1...32) : 32 >= n >= 1 - CPPUNIT_ASSERT_EQUAL(icmp.testHops(1), 32); - CPPUNIT_ASSERT_EQUAL(icmp.testHops(32), 1); + CPPUNIT_ASSERT_EQUAL(32, icmp.testHops(1)); + CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(32)); - // n(33...62) : 32 >= n >= 1 - CPPUNIT_ASSERT_EQUAL(icmp.testHops(33), 32); - CPPUNIT_ASSERT_EQUAL(icmp.testHops(62), 1); - - // n(63...128) : 64 >= n >= 1 - CPPUNIT_ASSERT_EQUAL(icmp.testHops(63), 64); - CPPUNIT_ASSERT_EQUAL(icmp.testHops(128), 1); + // n(33...62) : 30 >= n >= 1 + CPPUNIT_ASSERT_EQUAL(30, icmp.testHops(33)); + CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(62)); + + // n(63...64) : 2 >= n >= 1 + CPPUNIT_ASSERT_EQUAL(2, icmp.testHops(63)); + CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(64)); + + // n(65...128) : 64 >= n >= 1 + CPPUNIT_ASSERT_EQUAL(64, icmp.testHops(65)); + CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(128)); // n(129...192) : 64 >= n >= 1 - CPPUNIT_ASSERT_EQUAL(icmp.testHops(129), 64); - CPPUNIT_ASSERT_EQUAL(icmp.testHops(192), 1); + CPPUNIT_ASSERT_EQUAL(64, icmp.testHops(129)); + CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(192)); - // n(193...) : n < 255 - CPPUNIT_ASSERT_EQUAL(icmp.testHops(193), 64); - CPPUNIT_ASSERT_EQUAL(icmp.testHops(255), 1); + // n(193...) : n < 63 + CPPUNIT_ASSERT_EQUAL(63, icmp.testHops(193)); + CPPUNIT_ASSERT_EQUAL(1, icmp.testHops(255)); /* test invalid (over values) */ // 256 - produces zero - CPPUNIT_ASSERT_EQUAL(icmp.testHops(256), 0); + CPPUNIT_ASSERT_EQUAL(0, icmp.testHops(256)); // 257 - produces negative hops - CPPUNIT_ASSERT_EQUAL(icmp.testHops(257), -1); + CPPUNIT_ASSERT_EQUAL(-1, icmp.testHops(257)); } #endif /* USE_ICMP */