changeset 326:75b22d6f8a71

Simplify and improve integer sprintf() tests.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 23 Feb 2016 12:25:05 +0200
parents 40ce4106f4ad
children b0f9f806c8c9
files tests.c
diffstat 1 files changed, 10 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/tests.c	Tue Feb 23 12:16:12 2016 +0200
+++ b/tests.c	Tue Feb 23 12:25:05 2016 +0200
@@ -266,8 +266,8 @@
 
 int main(int argc, char *argv[])
 {
-    size_t i1, i2;
-    char buf[64];
+    size_t i1, i2, i3;
+    char buf[64], buf2[64];
 
     //
     // Initialization
@@ -299,26 +299,19 @@
     if (test_set_start("printf() integer"))
     {
         int i_vals[] = { 0, -0, -1, 2, -2, 612342, -612342, 0x1fff, 0x8000000, };
-        char *i_fmts[] = { "%d", "%x", "%05d", "%5d", "%-5d", "%.5d", "%05x", "%5x", "", "% 3d", "%+3d", "%05.5d", "%-8x", "%.x", };
+        char *i_fmts[] = { "%", "%05", "%5", "%-5", "%.5", "%5.5", "%05.5", "% ", "% 3", "% 3.2", "%+3", };
+        char *i_types[] = { "d", "x", "X", "o", };
 
         for (i1 = 0; i1 < sizeof(i_vals) / sizeof(i_vals[0]); i1++)
         {
             snprintf(buf, sizeof(buf), "%d", i_vals[i1]);
+
+            for (i3 = 0; i3 < sizeof(i_types) / sizeof(i_types[0]); i3++)
             for (i2 = 0; i2 < sizeof(i_fmts) / sizeof(i_fmts[0]); i2++)
-                test_snprintf(buf, i_fmts[i2], i_vals[i1]);
-        }
-    }
-
-    if (test_set_start("printf() integer 2"))
-    {
-        int i_vals[] = { 0, -0, -1, 2, -2, 612342, -612342, 0x1fff, 0x8000000, };
-        char *i_fmts[] = { "% 3o", "%+3o", "%3o", "%.3o", "%3.3o", "%-4.2o", "%-4o", "%.o" };
-
-        for (i1 = 0; i1 < sizeof(i_vals) / sizeof(i_vals[0]); i1++)
-        {
-            snprintf(buf, sizeof(buf), "%d", i_vals[i1]);
-            for (i2 = 0; i2 < sizeof(i_fmts) / sizeof(i_fmts[0]); i2++)
-                test_snprintf(buf, i_fmts[i2], i_vals[i1]);
+            {
+                snprintf(buf2, sizeof(buf2), "%s%s", i_fmts[i2], i_types[i3]);
+                test_snprintf(buf, buf2, i_vals[i1]);
+            }
         }
     }