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