From: Harlan Stenn Date: Sat, 27 Aug 2011 07:38:01 +0000 (-0400) Subject: Use pre-calculated values for the sntp synch distance checks X-Git-Tag: NTP_4_2_7P209~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8c07ebf4e82174dceb357cc8e842e015e9b55f6;p=thirdparty%2Fntp.git Use pre-calculated values for the sntp synch distance checks bk: 4e589ed9pL6yskSu7OuKrkSKHp8F7g --- diff --git a/sntp/tests/packetHandling.cpp b/sntp/tests/packetHandling.cpp index 87d9eee1e..5c39b6ed4 100644 --- a/sntp/tests/packetHandling.cpp +++ b/sntp/tests/packetHandling.cpp @@ -7,8 +7,6 @@ extern "C" { #include "ntp.h" }; -#define CALC_SYNCH_DISTANCE(a, b) ((a + b)/2.0) - class mainTest : public sntptest { protected: ::testing::AssertionResult LfpEquality(const l_fp &expected, const l_fp &actual) { @@ -91,8 +89,8 @@ TEST_F(mainTest, OffsetCalculationPositiveOffset) { rpkt.precision = -16; // 0,000015259 rpkt.rootdelay = HTONS_FP(DTOUFP(0.125)); - rpkt.rootdisp = HTONS_FP(DTOUFP(0.25)); // - double x_synchDist = CALC_SYNCH_DISTANCE(0.125, 0.25); + rpkt.rootdisp = HTONS_FP(DTOUFP(0.25)); + // Synch Distance: (0.125+0.25)/2.0 == 0.1875 l_fp reftime; get_systime(&reftime); HTONL_FP(&reftime, &rpkt.reftime); @@ -126,7 +124,7 @@ TEST_F(mainTest, OffsetCalculationPositiveOffset) { EXPECT_DOUBLE_EQ(1.25, offset); EXPECT_DOUBLE_EQ(1. / ULOGTOD(16), precision); - EXPECT_DOUBLE_EQ(CALC_SYNCH_DISTANCE(0.125, 0.25), synch_distance); + EXPECT_DOUBLE_EQ(0.1875, synch_distance); } TEST_F(mainTest, OffsetCalculationNegativeOffset) { @@ -135,7 +133,7 @@ TEST_F(mainTest, OffsetCalculationNegativeOffset) { rpkt.precision = -1; rpkt.rootdelay = HTONS_FP(DTOUFP(0.5)); rpkt.rootdisp = HTONS_FP(DTOUFP(0.5)); - double x_synchDist = CALC_SYNCH_DISTANCE(0.5, 0.5); + // Synch Distance is (0.5+0.5)/2.0, or 0.5 l_fp reftime; get_systime(&reftime); HTONL_FP(&reftime, &rpkt.reftime); @@ -169,7 +167,7 @@ TEST_F(mainTest, OffsetCalculationNegativeOffset) { EXPECT_DOUBLE_EQ(-1, offset); EXPECT_DOUBLE_EQ(1. / ULOGTOD(1), precision); - EXPECT_DOUBLE_EQ(CALC_SYNCH_DISTANCE(0.5, 0.5), synch_distance); + EXPECT_DOUBLE_EQ(0.5, synch_distance); } TEST_F(mainTest, HandleUnusableServer) {