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 9void test_RegularPositive(void); 10void test_RegularNegative(void); 11void test_PositiveOverflowBoundary(void); 12void test_NegativeOverflowBoundary(void); 13void test_PositiveOverflowBig(void); 14void test_IllegalCharacter(void); 15 16 17 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 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 34void test_PositiveOverflowBoundary(void) { 35 const char *str = "2147483648"; 36 long val; 37 38 TEST_ASSERT_FALSE(atoint(str, &val)); 39} 40 41void test_NegativeOverflowBoundary(void) { 42 const char *str = "-2147483649"; 43 long val; 44 45 TEST_ASSERT_FALSE(atoint(str, &val)); 46} 47 48void test_PositiveOverflowBig(void) { 49 const char *str = "2300000000"; 50 long val; 51 52 TEST_ASSERT_FALSE(atoint(str, &val)); 53} 54 55void test_IllegalCharacter(void) { 56 const char *str = "4500l"; 57 long val; 58 59 TEST_ASSERT_FALSE(atoint(str, &val)); 60} 61 62 63