summaryrefslogtreecommitdiff
path: root/tests/libc/test_itoa.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-06-10 21:29:21 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-06-10 21:29:21 +0200
commit7deaa5e3a148c143b1f9dd0f485b0200890ba87f (patch)
treeb2a7bd22d6e0e2a8c8b8e00a0a9634872db5e315 /tests/libc/test_itoa.c
parentd6d1bdfefafff50b7b6d15d218c0a188570be541 (diff)
downloadabaos-7deaa5e3a148c143b1f9dd0f485b0200890ba87f.tar.gz
abaos-7deaa5e3a148c143b1f9dd0f485b0200890ba87f.tar.bz2
also moved tests into tests/libc
Diffstat (limited to 'tests/libc/test_itoa.c')
-rw-r--r--tests/libc/test_itoa.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/libc/test_itoa.c b/tests/libc/test_itoa.c
new file mode 100644
index 0000000..837b77a
--- /dev/null
+++ b/tests/libc/test_itoa.c
@@ -0,0 +1,34 @@
+#include "stdlib.h"
+#include "string.h"
+#include "limits.h"
+
+int main( void )
+{
+ char *res;
+ 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;
+}