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