summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-05-12 21:34:58 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-05-12 21:34:58 +0200
commit178d93bced74198123254bdff9c06b1121f633d6 (patch)
tree5e350c8570e4c1d548c1ee4dbb4dfddcca458781
parent0a1c5c69244b1199cb877aed029a3c9aca68f60a (diff)
downloadabaos-178d93bced74198123254bdff9c06b1121f633d6.tar.gz
abaos-178d93bced74198123254bdff9c06b1121f633d6.tar.bz2
some testing of atoi, added a limits.h
-rw-r--r--src/limits.h7
-rw-r--r--src/port.h2
-rw-r--r--src/stdlib.h2
-rw-r--r--src/string.h2
-rw-r--r--tests/test_itoa.c23
5 files changed, 32 insertions, 4 deletions
diff --git a/src/limits.h b/src/limits.h
new file mode 100644
index 0000000..1fc4e37
--- /dev/null
+++ b/src/limits.h
@@ -0,0 +1,7 @@
+#ifndef LIMITS_H
+#define LIMITS_H
+
+#define INT_MAX 2147483647
+#define INT_MIN -2147483648
+
+#endif // LIMITS_H
diff --git a/src/port.h b/src/port.h
index 98f63fc..a5e8bd8 100644
--- a/src/port.h
+++ b/src/port.h
@@ -11,4 +11,4 @@ void port8_init( port8_t *port, uint16_t number );
void port8_write( port8_t *port, uint8_t data );
uint8_t port8_read( port8_t *port );
-#endif /* PORT_H */
+#endif //
diff --git a/src/stdlib.h b/src/stdlib.h
index fc6e248..331012e 100644
--- a/src/stdlib.h
+++ b/src/stdlib.h
@@ -3,4 +3,4 @@
char *itoa( int v, char *s, int base );
-#endif /* STDLIB_H */
+#endif // STDLIB_H
diff --git a/src/string.h b/src/string.h
index c3e3145..e24df9b 100644
--- a/src/string.h
+++ b/src/string.h
@@ -9,4 +9,4 @@ size_t strlen( const char *s );
int strcmp( const char *s1, const char *s2 );
size_t strlcpy( char *d, const char *s, size_t n );
-#endif /* STRING_H */
+#endif // STRING_H
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;
}