3 #include "ntp_stdlib.h"
4 #include "ntp_calendar.h"
10 void test_PositiveInteger(void) {
11 const char *str = "00001000.00000000";
14 l_fp expected = {4096, 0}; // 16^3, no fraction part.
16 TEST_ASSERT_TRUE(hextolfp(str, &actual));
17 TEST_ASSERT_TRUE(IsEqual(expected, actual));
20 void test_NegativeInteger(void) {
21 const char *str = "ffffffff.00000000"; // -1 decimal
24 l_fp expected = {-1, 0};
26 TEST_ASSERT_TRUE(hextolfp(str, &actual));
27 TEST_ASSERT_TRUE(IsEqual(expected, actual));
30 void test_PositiveFraction(void) {
31 const char *str = "00002000.80000000"; // 8196.5 decimal
34 l_fp expected = {8192, HALF};
36 TEST_ASSERT_TRUE(hextolfp(str, &actual));
37 TEST_ASSERT_TRUE(IsEqual(expected, actual));
40 void test_NegativeFraction(void) {
41 const char *str = "ffffffff.40000000"; // -1 + 0.25 decimal
44 l_fp expected = {-1, QUARTER}; //-1 + 0.25
46 TEST_ASSERT_TRUE(hextolfp(str, &actual));
47 TEST_ASSERT_TRUE(IsEqual(expected, actual));
50 void test_IllegalNumberOfInteger(void) {
51 const char *str = "1000000.00000000"; // Missing one digit in integral part.
54 TEST_ASSERT_FALSE(hextolfp(str, &actual));
57 void test_IllegalChar(void) {
58 const char *str = "10000000.0000h000"; // Illegal character h.
61 TEST_ASSERT_FALSE(hextolfp(str, &actual));