From 178d93bced74198123254bdff9c06b1121f633d6 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Fri, 12 May 2017 21:34:58 +0200 Subject: some testing of atoi, added a limits.h --- tests/test_itoa.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_itoa.c b/tests/test_itoa.c index 76df145..837b77a 100644 --- a/tests/test_itoa.c +++ b/tests/test_itoa.c @@ -1,13 +1,34 @@ #include "stdlib.h" #include "string.h" +#include "limits.h" int main( void ) { char *res; - char buf[11]; + char buf[12]; + // simple conversion without sign res = itoa( 568876, buf, 10 ); + if( strcmp( buf, "568876" ) ) return 1; + + // test if the returned pointer points to the buffer if( strcmp( res, buf ) ) return 1; + + // conversion with sign + res = itoa( -568876, buf, 10 ); + if( strcmp( buf, "-568876" ) ) return 1; + + // convert upper limit + res = itoa( INT_MAX, buf, 10 ); + if( strcmp( buf, "2147483647" ) ) return 1; + + // convert lower limit + res = itoa( INT_MIN+1, buf, 10 ); + if( strcmp( buf, "-2147483647" ) ) return 1; + + // convert to hex + res = itoa( 568876, buf, 16 ); + if( strcmp( buf, "8AE2C" ) ) return 1; return 0; } -- cgit v1.2.3-54-g00ecf