15#include <cppunit/TestAssert.h>
24 uint16_t buf[10], tmpval;
25 for (tmpval=0; tmpval < 10; ++tmpval)
26 buf[tmpval]=htons(1+tmpval);
29 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffff), icmp.
testChecksum(
nullptr,0));
32 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffff), icmp.
testChecksum(
nullptr,1));
35 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffff), icmp.
testChecksum(buf,0));
38 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffff), icmp.
testChecksum(buf,1));
40 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfffe), icmp.
testChecksum(buf,2));
41 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfffe), icmp.
testChecksum(buf,3));
43 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfffc), icmp.
testChecksum(buf,4));
44 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfffc), icmp.
testChecksum(buf,5));
46 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfff9), icmp.
testChecksum(buf,6));
47 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfff9), icmp.
testChecksum(buf,7));
49 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfff5), icmp.
testChecksum(buf,8));
50 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfff5), icmp.
testChecksum(buf,9));
52 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfff0), icmp.
testChecksum(buf,10));
53 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfff0), icmp.
testChecksum(buf,11));
55 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffea), icmp.
testChecksum(buf,12));
56 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffea), icmp.
testChecksum(buf,13));
58 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffe3), icmp.
testChecksum(buf,14));
59 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffe3), icmp.
testChecksum(buf,15));
61 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffdb), icmp.
testChecksum(buf,16));
62 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffdb), icmp.
testChecksum(buf,17));
64 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffd2), icmp.
testChecksum(buf,18));
65 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffd2), icmp.
testChecksum(buf,19));
68 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffc8), icmp.
testChecksum(buf,20));
82 CPPUNIT_ASSERT_EQUAL(34, icmp.
testHops(-1));
84 CPPUNIT_ASSERT_EQUAL(33, icmp.
testHops(0));
88 CPPUNIT_ASSERT_EQUAL(32, icmp.
testHops(1));
89 CPPUNIT_ASSERT_EQUAL(1, icmp.
testHops(32));
92 CPPUNIT_ASSERT_EQUAL(30, icmp.
testHops(33));
93 CPPUNIT_ASSERT_EQUAL(1, icmp.
testHops(62));
96 CPPUNIT_ASSERT_EQUAL(2, icmp.
testHops(63));
97 CPPUNIT_ASSERT_EQUAL(1, icmp.
testHops(64));
100 CPPUNIT_ASSERT_EQUAL(64, icmp.
testHops(65));
101 CPPUNIT_ASSERT_EQUAL(1, icmp.
testHops(128));
104 CPPUNIT_ASSERT_EQUAL(64, icmp.
testHops(129));
105 CPPUNIT_ASSERT_EQUAL(1, icmp.
testHops(192));
108 CPPUNIT_ASSERT_EQUAL(63, icmp.
testHops(193));
109 CPPUNIT_ASSERT_EQUAL(1, icmp.
testHops(255));
113 CPPUNIT_ASSERT_EQUAL(0, icmp.
testHops(256));
115 CPPUNIT_ASSERT_EQUAL(-1, icmp.
testHops(257));
int testChecksum(unsigned short *ptr, int size)
CPPUNIT_TEST_SUITE_REGISTRATION(TestIcmp)