1 #include "config.h" 2 3 #include "ntp_stdlib.h" 4 #include "ntp_calendar.h" 5 #include "ntp_fp.h" 6 7 #include "unity.h" 8 9 void test_SingleDigit(void); 10 void test_MultipleDigits(void); 11 void test_MaxUnsigned(void); 12 void test_Overflow(void); 13 void test_IllegalChar(void); 14 15 16 void test_SingleDigit(void) { 17 const char *str = "a"; // 10 decimal 18 u_long actual; 19 20 TEST_ASSERT_TRUE(hextoint(str, &actual)); 21 TEST_ASSERT_EQUAL(10, actual); 22 } 23 24 void test_MultipleDigits(void) { 25 const char *str = "8F3"; // 2291 decimal 26 u_long actual; 27 28 TEST_ASSERT_TRUE(hextoint(str, &actual)); 29 TEST_ASSERT_EQUAL(2291, actual); 30 } 31 32 void test_MaxUnsigned(void) { 33 const char *str = "ffffffff"; // 4294967295 decimal 34 u_long actual; 35 36 TEST_ASSERT_TRUE(hextoint(str, &actual)); 37 TEST_ASSERT_EQUAL(4294967295UL, actual); 38 } 39 40 void test_Overflow(void) { 41 const char *str = "100000000"; // Overflow by 1 42 u_long actual; 43 44 TEST_ASSERT_FALSE(hextoint(str, &actual)); 45 } 46 47 void test_IllegalChar(void) { 48 const char *str = "5gb"; // Illegal character g 49 u_long actual; 50 51 TEST_ASSERT_FALSE(hextoint(str, &actual)); 52 } 53 54