summaryrefslogtreecommitdiff
path: root/tests/libc/test_sprintf.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-07-23 15:28:13 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-07-23 15:28:13 +0200
commitec9ed8deb79a9fd508a11b122453bb39d3b587a9 (patch)
tree6e35f78af8922083ff5b77dac04e4330e4ac0bb3 /tests/libc/test_sprintf.c
parentab8803f7cfdc7c7b258fb3e59fb2d55bacf7522a (diff)
downloadabaos-ec9ed8deb79a9fd508a11b122453bb39d3b587a9.tar.gz
abaos-ec9ed8deb79a9fd508a11b122453bb39d3b587a9.tar.bz2
added snprintf and a test for it
Diffstat (limited to 'tests/libc/test_sprintf.c')
-rw-r--r--tests/libc/test_sprintf.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/libc/test_sprintf.c b/tests/libc/test_sprintf.c
new file mode 100644
index 0000000..b1f25c7
--- /dev/null
+++ b/tests/libc/test_sprintf.c
@@ -0,0 +1,19 @@
+#include "string.h"
+#include "stdlib.h"
+#include "stdio.h"
+#include "string.h"
+
+int main( void )
+{
+ char *s = "test_string";
+ int i = 47;
+ char c = 'X';
+ char buf[100];
+ const char *must = "string 'test_string', decimal 47, hex 0x2F, character 'X'\n";
+
+ snprintf( buf, 100, "string '%s', decimal %d, hex 0x%X, character '%c'\n",
+ s, i, i, c );
+ if( strncmp( buf, must, strlen( must ) ) != 0 ) exit( 1 );
+
+ exit( 0 );
+}