diff options
Diffstat (limited to 'contrib/ntp/sntp/tests/packetHandling.c')
-rw-r--r-- | contrib/ntp/sntp/tests/packetHandling.c | 92 |
1 files changed, 60 insertions, 32 deletions
diff --git a/contrib/ntp/sntp/tests/packetHandling.c b/contrib/ntp/sntp/tests/packetHandling.c index 4cb5a91..1036fc3 100644 --- a/contrib/ntp/sntp/tests/packetHandling.c +++ b/contrib/ntp/sntp/tests/packetHandling.c @@ -12,27 +12,37 @@ #include "unity.h" - -int counter = 0; - - -// old code from google test framework, moved to SetUp() for unity -void setUp(void) -{ +void setUp(void); +int LfpEquality(const l_fp expected, const l_fp actual); +void test_GenerateUnauthenticatedPacket(void); +void test_GenerateAuthenticatedPacket(void); +void test_OffsetCalculationPositiveOffset(void); +void test_OffsetCalculationNegativeOffset(void); +void test_HandleUnusableServer(void); +void test_HandleUnusablePacket(void); +void test_HandleServerAuthenticationFailure(void); +void test_HandleKodDemobilize(void); +void test_HandleKodRate(void); +void test_HandleCorrectPacket(void); + + +void +setUp(void) { init_lib(); } - -int LfpEquality(const l_fp expected, const l_fp actual) { - if (L_ISEQU(&expected, &actual)) { - return TRUE; - } else { - return FALSE; - } +int +LfpEquality(const l_fp expected, const l_fp actual) { + if (L_ISEQU(&expected, &actual)) + return TRUE; + else + return FALSE; } -void test_GenerateUnauthenticatedPacket(void) { + +void +test_GenerateUnauthenticatedPacket(void) { struct pkt testpkt; struct timeval xmt; @@ -55,7 +65,9 @@ void test_GenerateUnauthenticatedPacket(void) { TEST_ASSERT_TRUE(LfpEquality(expected_xmt, actual_xmt)); } -void test_GenerateAuthenticatedPacket(void) { + +void +test_GenerateAuthenticatedPacket(void) { struct key testkey; testkey.next = NULL; testkey.key_id = 30; @@ -91,10 +103,12 @@ void test_GenerateAuthenticatedPacket(void) { char expected_mac[MAX_MD5_LEN]; TEST_ASSERT_EQUAL(MAX_MD5_LEN - 4, // Remove the key_id, only keep the mac. make_mac((char*)&testpkt, LEN_PKT_NOMAC, MAX_MD5_LEN, &testkey, expected_mac)); - TEST_ASSERT_TRUE(memcmp(expected_mac, (char*)&testpkt.exten[1], MAX_MD5_LEN -4) == 0); + TEST_ASSERT_EQUAL_MEMORY(expected_mac, (char*)&testpkt.exten[1], MAX_MD5_LEN -4); } -void test_OffsetCalculationPositiveOffset(void) { + +void +test_OffsetCalculationPositiveOffset(void) { struct pkt rpkt; rpkt.precision = -16; // 0,000015259 @@ -132,13 +146,15 @@ void test_OffsetCalculationPositiveOffset(void) { double offset, precision, synch_distance; offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &synch_distance); - TEST_ASSERT_EQUAL_FLOAT(1.25, offset); - TEST_ASSERT_EQUAL_FLOAT(1. / ULOGTOD(16), precision); + TEST_ASSERT_EQUAL_DOUBLE(1.25, offset); + TEST_ASSERT_EQUAL_DOUBLE(1. / ULOGTOD(16), precision); // 1.1250150000000001 ? - TEST_ASSERT_EQUAL_FLOAT(1.125015, synch_distance); + TEST_ASSERT_EQUAL_DOUBLE(1.125015, synch_distance); } -void test_OffsetCalculationNegativeOffset(void) { + +void +test_OffsetCalculationNegativeOffset(void) { struct pkt rpkt; rpkt.precision = -1; @@ -176,12 +192,14 @@ void test_OffsetCalculationNegativeOffset(void) { double offset, precision, synch_distance; offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &synch_distance); - TEST_ASSERT_EQUAL_FLOAT(-1, offset); - TEST_ASSERT_EQUAL_FLOAT(1. / ULOGTOD(1), precision); - TEST_ASSERT_EQUAL_FLOAT(1.3333483333333334, synch_distance); + TEST_ASSERT_EQUAL_DOUBLE(-1, offset); + TEST_ASSERT_EQUAL_DOUBLE(1. / ULOGTOD(1), precision); + TEST_ASSERT_EQUAL_DOUBLE(1.3333483333333334, synch_distance); } -void test_HandleUnusableServer(void) { + +void +test_HandleUnusableServer(void) { struct pkt rpkt; sockaddr_u host; int rpktl; @@ -192,7 +210,9 @@ void test_HandleUnusableServer(void) { TEST_ASSERT_EQUAL(-1, handle_pkt(rpktl, &rpkt, &host, "")); } -void test_HandleUnusablePacket(void) { + +void +test_HandleUnusablePacket(void) { struct pkt rpkt; sockaddr_u host; int rpktl; @@ -203,7 +223,9 @@ void test_HandleUnusablePacket(void) { TEST_ASSERT_EQUAL(1, handle_pkt(rpktl, &rpkt, &host, "")); } -void test_HandleServerAuthenticationFailure(void) { + +void +test_HandleServerAuthenticationFailure(void) { struct pkt rpkt; sockaddr_u host; int rpktl; @@ -214,7 +236,9 @@ void test_HandleServerAuthenticationFailure(void) { TEST_ASSERT_EQUAL(1, handle_pkt(rpktl, &rpkt, &host, "")); } -void test_HandleKodDemobilize(void) { + +void +test_HandleKodDemobilize(void) { const char * HOSTNAME = "192.0.2.1"; const char * REASON = "DENY"; struct pkt rpkt; @@ -235,10 +259,12 @@ void test_HandleKodDemobilize(void) { TEST_ASSERT_EQUAL(1, handle_pkt(rpktl, &rpkt, &host, HOSTNAME)); TEST_ASSERT_EQUAL(1, search_entry(HOSTNAME, &entry)); - TEST_ASSERT_TRUE(memcmp(REASON, entry->type, 4) == 0); + TEST_ASSERT_EQUAL_MEMORY(REASON, entry->type, 4); } -void test_HandleKodRate(void) { + +void +test_HandleKodRate(void) { struct pkt rpkt; sockaddr_u host; int rpktl; @@ -249,7 +275,9 @@ void test_HandleKodRate(void) { TEST_ASSERT_EQUAL(1, handle_pkt(rpktl, &rpkt, &host, "")); } -void test_HandleCorrectPacket(void) { + +void +test_HandleCorrectPacket(void) { struct pkt rpkt; sockaddr_u host; int rpktl; |