3 #include "ntp_stdlib.h"
4 #include "ntp_calendar.h"
9 void test_PositiveInteger(void);
10 void test_NegativeInteger(void);
11 void test_PositiveFraction(void);
12 void test_NegativeFraction(void);
13 void test_IllegalNumberOfInteger(void);
14 void test_IllegalChar(void);
18 test_PositiveInteger(void) {
19 const char *str = "00001000.00000000";
22 l_fp expected = {{4096}, 0}; /* 16^3, no fraction part. */
24 TEST_ASSERT_TRUE(hextolfp(str, &actual));
25 TEST_ASSERT_TRUE(IsEqual(expected, actual));
29 test_NegativeInteger(void) {
30 const char *str = "ffffffff.00000000"; /* -1 decimal */
33 l_fp expected = {{-1}, 0};
35 TEST_ASSERT_TRUE(hextolfp(str, &actual));
36 TEST_ASSERT_TRUE(IsEqual(expected, actual));
40 test_PositiveFraction(void) {
41 const char *str = "00002000.80000000"; /* 8196.5 decimal */
44 l_fp expected = {{8192}, HALF};
46 TEST_ASSERT_TRUE(hextolfp(str, &actual));
47 TEST_ASSERT_TRUE(IsEqual(expected, actual));
51 test_NegativeFraction(void) {
52 const char *str = "ffffffff.40000000"; /* -1 + 0.25 decimal */
55 l_fp expected = {{-1}, QUARTER}; /* -1 + 0.25 */
57 TEST_ASSERT_TRUE(hextolfp(str, &actual));
58 TEST_ASSERT_TRUE(IsEqual(expected, actual));
62 test_IllegalNumberOfInteger(void) {
63 const char *str = "1000000.00000000"; /* Missing one digit in integral part. */
66 TEST_ASSERT_FALSE(hextolfp(str, &actual));
70 test_IllegalChar(void) {
71 const char *str = "10000000.0000h000"; /* Illegal character h. */
74 TEST_ASSERT_FALSE(hextolfp(str, &actual));