1 /* $NetBSD: atoint.c,v 1.2 2020/05/25 20:47:36 christos Exp $ */ 2 3 #include "config.h" 4 5 #include "ntp_stdlib.h" 6 #include "ntp_calendar.h" 7 #include "unity.h" 8 9 void test_RegularPositive(void); 10 void test_RegularNegative(void); 11 void test_PositiveOverflowBoundary(void); 12 void test_NegativeOverflowBoundary(void); 13 void test_PositiveOverflowBig(void); 14 void test_IllegalCharacter(void); 15 16 17 test_RegularPositive(void)18void test_RegularPositive(void) { 19 const char *str = "17"; 20 long val; 21 22 TEST_ASSERT_TRUE(atoint(str, &val)); 23 TEST_ASSERT_EQUAL(17, val); 24 } 25 test_RegularNegative(void)26void test_RegularNegative(void) { 27 const char *str = "-20"; 28 long val; 29 30 TEST_ASSERT_TRUE(atoint(str, &val)); 31 TEST_ASSERT_EQUAL(-20, val); 32 } 33 test_PositiveOverflowBoundary(void)34void test_PositiveOverflowBoundary(void) { 35 const char *str = "2147483648"; 36 long val; 37 38 TEST_ASSERT_FALSE(atoint(str, &val)); 39 } 40 test_NegativeOverflowBoundary(void)41void test_NegativeOverflowBoundary(void) { 42 const char *str = "-2147483649"; 43 long val; 44 45 TEST_ASSERT_FALSE(atoint(str, &val)); 46 } 47 test_PositiveOverflowBig(void)48void test_PositiveOverflowBig(void) { 49 const char *str = "2300000000"; 50 long val; 51 52 TEST_ASSERT_FALSE(atoint(str, &val)); 53 } 54 test_IllegalCharacter(void)55void test_IllegalCharacter(void) { 56 const char *str = "4500l"; 57 long val; 58 59 TEST_ASSERT_FALSE(atoint(str, &val)); 60 } 61 62 63