From: Damir Tomic Date: Thu, 25 Jun 2015 08:10:48 +0000 (+0200) Subject: lfpfunc.c: X-Git-Tag: NTP_4_2_8P3_RC3~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=adb9e35e955d650c0a3ac60c6887bdab6d98bdcd;p=thirdparty%2Fntp.git lfpfunc.c: replaced TEST_ASSERT_EQUAL_MEMORY(&a,&b,sizeof(a)) with TEST_ASSERT_EQUAL_l_fp(a,b). It's safer this way, because structs can be compared even if they aren't initiated with memset (due to padding bytes) bk: 558bb788i_-w6pYbnxoFdzQz7CpiJg --- diff --git a/tests/libntp/lfpfunc.c b/tests/libntp/lfpfunc.c index 72c564026..188478d10 100644 --- a/tests/libntp/lfpfunc.c +++ b/tests/libntp/lfpfunc.c @@ -10,6 +10,12 @@ #include +//replaced TEST_ASSERT_EQUAL_MEMORY(&a,&b,sizeof(a)) with TEST_ASSERT_EQUAL_l_fp(a,b). It's safer this way, because structs can be compared even if they aren't initiated with memset (due to padding bytes) +#define TEST_ASSERT_EQUAL_l_fp(a, b) { \ + TEST_ASSERT_EQUAL_MESSAGE(a.l_i, b.l_i, "Field l_i"); \ + TEST_ASSERT_EQUAL_UINT_MESSAGE(a.l_uf, b.l_uf, "Field l_uf"); \ +} + typedef struct { uint32_t h, l; } lfp_hl; @@ -326,7 +332,8 @@ void test_AdditionLR() { //LFP res(op1 + op2); l_fp res = l_fp_add(op1,op2); - TEST_ASSERT_EQUAL_MEMORY(&exp, &res,sizeof(exp)); + TEST_ASSERT_EQUAL_l_fp(exp,res); + //TEST_ASSERT_EQUAL_MEMORY(&exp, &res,sizeof(exp)); } } @@ -339,7 +346,8 @@ void test_AdditionRL() { l_fp exp = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l); l_fp res = l_fp_add(op1,op2); - TEST_ASSERT_EQUAL_MEMORY(&exp, &res,sizeof(exp)); + TEST_ASSERT_EQUAL_l_fp(exp,res); + //TEST_ASSERT_EQUAL_MEMORY(&exp, &res,sizeof(exp)); } } @@ -357,8 +365,9 @@ void test_SubtractionLR() { l_fp op1 = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l); l_fp res = l_fp_subtract(op1,op2); //LFP res(op1 - op2); - - TEST_ASSERT_EQUAL_MEMORY(&exp, &res,sizeof(exp)); + + TEST_ASSERT_EQUAL_l_fp(exp,res); + //TEST_ASSERT_EQUAL_MEMORY(&exp, &res,sizeof(exp)); } } @@ -371,7 +380,8 @@ void test_SubtractionRL() { l_fp op1 = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l); l_fp res = l_fp_subtract(op1,op2); - TEST_ASSERT_EQUAL_MEMORY(&exp, &res,sizeof(exp)); + TEST_ASSERT_EQUAL_l_fp(exp,res); + //TEST_ASSERT_EQUAL_MEMORY(&exp, &res,sizeof(exp)); } } @@ -388,7 +398,9 @@ void test_Negation() { l_fp sum = l_fp_add(op1, op2); l_fp zero = l_fp_init(0,0); - TEST_ASSERT_EQUAL_MEMORY(&zero, &sum,sizeof(sum)); + + TEST_ASSERT_EQUAL_l_fp(zero,sum); + //TEST_ASSERT_EQUAL_MEMORY(&zero, &sum,sizeof(sum)); } } @@ -413,7 +425,9 @@ void test_Absolute() { op1 = l_fp_add(op1,op2); l_fp zero = l_fp_init(0,0); - TEST_ASSERT_EQUAL_MEMORY(&zero, &op1,sizeof(op1)); + + TEST_ASSERT_EQUAL_l_fp(zero,op1); + //TEST_ASSERT_EQUAL_MEMORY(&zero, &op1,sizeof(op1)); } // There is one special case we have to check: the minimum @@ -422,7 +436,9 @@ void test_Absolute() { l_fp minVal = l_fp_init(0x80000000, 0x00000000); l_fp minAbs = l_fp_abs(minVal); TEST_ASSERT_EQUAL(-1, l_fp_signum(minVal)); - TEST_ASSERT_EQUAL_MEMORY(&minVal, &minAbs,sizeof(minAbs)); + + TEST_ASSERT_EQUAL_l_fp(minVal,minAbs); + //TEST_ASSERT_EQUAL_MEMORY(&minVal, &minAbs,sizeof(minAbs)); } @@ -450,6 +466,7 @@ void test_FDF_RoundTrip() { TEST_ASSERT_DOUBLE_WITHIN(eps(op2),0.0, fabs(d)); //delta,epected,actual //ASSERT_LE(fabs(op1-op3), eps(op2)); //unity has no equivalent of LE!!! + //you could use TEST_ASSERT_TRUE(IsLE(fabs(op1-op3), eps(op2))); } } diff --git a/tests/libntp/run-lfpfunc.c b/tests/libntp/run-lfpfunc.c index 72b616b73..2f0e1c254 100644 --- a/tests/libntp/run-lfpfunc.c +++ b/tests/libntp/run-lfpfunc.c @@ -26,6 +26,7 @@ //=======External Functions This Runner Calls===== extern void setUp(void); extern void tearDown(void); +void resetTest(void); extern void test_AdditionLR(); extern void test_AdditionRL(); extern void test_SubtractionLR(); @@ -53,15 +54,15 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "lfpfunc.c"; UnityBegin("lfpfunc.c"); - RUN_TEST(test_AdditionLR, 315); - RUN_TEST(test_AdditionRL, 333); - RUN_TEST(test_SubtractionLR, 351); - RUN_TEST(test_SubtractionRL, 365); - RUN_TEST(test_Negation, 382); - RUN_TEST(test_Absolute, 401); - RUN_TEST(test_FDF_RoundTrip, 432); - RUN_TEST(test_SignedRelOps, 463); - RUN_TEST(test_UnsignedRelOps, 506); + RUN_TEST(test_AdditionLR, 320); + RUN_TEST(test_AdditionRL, 339); + RUN_TEST(test_SubtractionLR, 358); + RUN_TEST(test_SubtractionRL, 373); + RUN_TEST(test_Negation, 391); + RUN_TEST(test_Absolute, 412); + RUN_TEST(test_FDF_RoundTrip, 447); + RUN_TEST(test_SignedRelOps, 479); + RUN_TEST(test_UnsignedRelOps, 522); return (UnityEnd()); }