hextolfp.c revision 1.1.1.2
1/* $NetBSD: hextolfp.c,v 1.1.1.2 2015/07/10 13:11:14 christos Exp $ */ 2 3#include "config.h" 4 5#include "ntp_stdlib.h" 6#include "ntp_calendar.h" 7 8#include "unity.h" 9#include "lfptest.h" 10 11 12void test_PositiveInteger(void) { 13 const char *str = "00001000.00000000"; 14 l_fp actual; 15 16 l_fp expected = {4096, 0}; // 16^3, no fraction part. 17 18 TEST_ASSERT_TRUE(hextolfp(str, &actual)); 19 TEST_ASSERT_TRUE(IsEqual(expected, actual)); 20} 21 22void test_NegativeInteger(void) { 23 const char *str = "ffffffff.00000000"; // -1 decimal 24 l_fp actual; 25 26 l_fp expected = {-1, 0}; 27 28 TEST_ASSERT_TRUE(hextolfp(str, &actual)); 29 TEST_ASSERT_TRUE(IsEqual(expected, actual)); 30} 31 32void test_PositiveFraction(void) { 33 const char *str = "00002000.80000000"; // 8196.5 decimal 34 l_fp actual; 35 36 l_fp expected = {8192, HALF}; 37 38 TEST_ASSERT_TRUE(hextolfp(str, &actual)); 39 TEST_ASSERT_TRUE(IsEqual(expected, actual)); 40} 41 42void test_NegativeFraction(void) { 43 const char *str = "ffffffff.40000000"; // -1 + 0.25 decimal 44 l_fp actual; 45 46 l_fp expected = {-1, QUARTER}; //-1 + 0.25 47 48 TEST_ASSERT_TRUE(hextolfp(str, &actual)); 49 TEST_ASSERT_TRUE(IsEqual(expected, actual)); 50} 51 52void test_IllegalNumberOfInteger(void) { 53 const char *str = "1000000.00000000"; // Missing one digit in integral part. 54 l_fp actual; 55 56 TEST_ASSERT_FALSE(hextolfp(str, &actual)); 57} 58 59void test_IllegalChar(void) { 60 const char *str = "10000000.0000h000"; // Illegal character h. 61 l_fp actual; 62 63 TEST_ASSERT_FALSE(hextolfp(str, &actual)); 64} 65 66