15#include <cppunit/TestAssert.h>
26 int Open()
override {
return 0; };
33 void Recv(
void)
override {};
63 uint16_t buf[10], tmpval;
64 for (tmpval=0; tmpval < 10; ++tmpval)
65 buf[tmpval]=htons(1+tmpval);
68 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffff), icmp.
testChecksum(
nullptr,0));
71 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffff), icmp.
testChecksum(
nullptr,1));
74 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffff), icmp.
testChecksum(buf,0));
77 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffff), icmp.
testChecksum(buf,1));
79 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfffe), icmp.
testChecksum(buf,2));
80 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfffe), icmp.
testChecksum(buf,3));
82 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfffc), icmp.
testChecksum(buf,4));
83 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfffc), icmp.
testChecksum(buf,5));
85 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfff9), icmp.
testChecksum(buf,6));
86 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfff9), icmp.
testChecksum(buf,7));
88 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfff5), icmp.
testChecksum(buf,8));
89 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfff5), icmp.
testChecksum(buf,9));
91 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfff0), icmp.
testChecksum(buf,10));
92 CPPUNIT_ASSERT_EQUAL((
int)htons(0xfff0), icmp.
testChecksum(buf,11));
94 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffea), icmp.
testChecksum(buf,12));
95 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffea), icmp.
testChecksum(buf,13));
97 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffe3), icmp.
testChecksum(buf,14));
98 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffe3), icmp.
testChecksum(buf,15));
100 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffdb), icmp.
testChecksum(buf,16));
101 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffdb), icmp.
testChecksum(buf,17));
103 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffd2), icmp.
testChecksum(buf,18));
104 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffd2), icmp.
testChecksum(buf,19));
107 CPPUNIT_ASSERT_EQUAL((
int)htons(0xffc8), icmp.
testChecksum(buf,20));
121 CPPUNIT_ASSERT_EQUAL(34, icmp.
testHops(-1));
123 CPPUNIT_ASSERT_EQUAL(33, icmp.
testHops(0));
127 CPPUNIT_ASSERT_EQUAL(32, icmp.
testHops(1));
128 CPPUNIT_ASSERT_EQUAL(1, icmp.
testHops(32));
131 CPPUNIT_ASSERT_EQUAL(30, icmp.
testHops(33));
132 CPPUNIT_ASSERT_EQUAL(1, icmp.
testHops(62));
135 CPPUNIT_ASSERT_EQUAL(2, icmp.
testHops(63));
136 CPPUNIT_ASSERT_EQUAL(1, icmp.
testHops(64));
139 CPPUNIT_ASSERT_EQUAL(64, icmp.
testHops(65));
140 CPPUNIT_ASSERT_EQUAL(1, icmp.
testHops(128));
143 CPPUNIT_ASSERT_EQUAL(64, icmp.
testHops(129));
144 CPPUNIT_ASSERT_EQUAL(1, icmp.
testHops(192));
147 CPPUNIT_ASSERT_EQUAL(63, icmp.
testHops(193));
148 CPPUNIT_ASSERT_EQUAL(1, icmp.
testHops(255));
152 CPPUNIT_ASSERT_EQUAL(0, icmp.
testHops(256));
154 CPPUNIT_ASSERT_EQUAL(-1, icmp.
testHops(257));
void SendEcho(Ip::Address &, int, const char *, int) override
Construct ECHO request.
void Close() override
Shutdown pinger helper and control channel.
int testChecksum(unsigned short *ptr, int size)
void Recv(void) override
Handle ICMP responses.
int Open() override
Start pinger helper and initiate control channel.
int CheckSum(unsigned short *ptr, int size)
Calculate a packet checksum.
CPPUNIT_TEST(testChecksum)
CPPUNIT_TEST_SUITE(TestIcmp)
implements test program's main() function while enabling customization
int run(int argc, char *argv[])
CPPUNIT_TEST_SUITE_REGISTRATION(TestIcmp)
int main(int argc, char *argv[])