aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorStewart Smith <stewart@linux.vnet.ibm.com>2016-10-12 16:26:18 +1100
committerStewart Smith <stewart@linux.vnet.ibm.com>2016-10-17 10:33:52 +1100
commit5f9db1d7689c6e63d910343835d3cdcada5a475e (patch)
tree0f1120ba9e17bab729719e459b1399ff280b6285 /libc
parent53a786a7b4dfbd2f4a567c82e903ccf6745f3b74 (diff)
downloadskiboot-5f9db1d7689c6e63d910343835d3cdcada5a475e.zip
skiboot-5f9db1d7689c6e63d910343835d3cdcada5a475e.tar.gz
skiboot-5f9db1d7689c6e63d910343835d3cdcada5a475e.tar.bz2
snprintf: increase testing, %u and 0 padding
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'libc')
-rw-r--r--libc/test/run-snprintf.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/libc/test/run-snprintf.c b/libc/test/run-snprintf.c
index e1de983..80993e8 100644
--- a/libc/test/run-snprintf.c
+++ b/libc/test/run-snprintf.c
@@ -24,6 +24,57 @@
int test1(void);
int skiboot_snprintf(char *buf, size_t bufsz, size_t l, const char* format, ...);
+static void test_printf_0u(int n)
+{
+ char *buf, *buf2;
+ int blen;
+ unsigned int i;
+
+ for(i=1; i<10; i++)
+ {
+ blen = i+1;
+ if (n<0)
+ blen++;
+
+ buf = (char*)malloc(blen);
+ buf2 = (char*)malloc(blen);
+ skiboot_snprintf(buf, blen, blen, "%08u", n);
+ snprintf(buf2, blen, "%08u", n);
+ n = n * 10;
+ assert(0 == strncmp(buf, buf2, blen));
+ free(buf);
+ free(buf2);
+ }
+}
+
+static void test_printf_u(int n)
+{
+ char *buf, *buf2;
+ int blen;
+ unsigned int r;
+ unsigned int i;
+
+ for(i=1; i<10; i++)
+ {
+ blen = i+1;
+ if (n<0)
+ blen++;
+
+ buf = (char*)malloc(blen);
+ buf2 = (char*)malloc(blen);
+ r = skiboot_snprintf(buf, blen, blen, "%u", n);
+ snprintf(buf2, blen, "%u", n);
+ n = n * 10;
+ if (n<0)
+ assert(i+1 == r);
+ else
+ assert(i == r);
+ assert(0 == strncmp(buf, buf2, blen));
+ free(buf);
+ free(buf2);
+ }
+}
+
static void test_printf_d(int n)
{
char *buf, *buf2;
@@ -180,6 +231,8 @@ int main(void)
assert(buf[9] == 0);
free(buf);
+ test_printf_u(1);
+ test_printf_0u(1);
test_printf_d(1);
test_printf_d(-1);
test_printf_x("%x");