changeset 304:3fcf42cce43d

Fix some tests and use stdout for output.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 22 Feb 2016 19:52:18 +0200
parents 54ea7a73e5fa
children 5afd918cbd79
files tests.c
diffstat 1 files changed, 41 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/tests.c	Mon Feb 22 19:39:14 2016 +0200
+++ b/tests.c	Mon Feb 22 19:52:18 2016 +0200
@@ -33,6 +33,22 @@
 static const int arg_nopts = sizeof(arg_opts) / sizeof(arg_opts[0]);
 
 
+void tprintv(const int level, const char *fmt, va_list ap)
+{
+    if (level >= th_verbosityLevel)
+        vfprintf(stdout, fmt, ap);
+}
+
+
+void tprint(const int level, const char *fmt, ...)
+{
+    va_list ap;
+    va_start(ap, fmt);
+    tprintv(level, fmt, ap);
+    va_end(ap);
+}
+
+
 void arg_show_help(void)
 {
     th_print_banner(stdout, th_prog_name, "[options]");
@@ -126,20 +142,20 @@
 {
     if (check)
     {
-        THPRINT(2, "%s: OK\n", ctx->header);
+        tprint(2, "%s: OK\n", ctx->header);
         tests_passed++;
     }
     else
     {
-        THPRINT(0, "%s: FAIL\n", ctx->header);
+        tprint(0, "%s: FAIL\n", ctx->header);
         if (fmt != NULL)
         {
-            THPRINT(0, "  - ");
-            THPRINT_V(0, fmt, ap);
-            THPRINT(0, "\n");
+            tprint(0, "  - ");
+            tprintv(0, fmt, ap);
+            tprint(0, "\n");
         }
         if (ctx->res != NULL)
-            THPRINT(0, "%s\n", ctx->res);
+            tprint(0, "%s\n", ctx->res);
         tests_failed++;
     }
 }
@@ -203,7 +219,7 @@
     va_copy(tmp, ap); test_snprintf_do(16, fmt, tmp, "16");
     va_copy(tmp, ap); test_snprintf_do(SET_BUF_SIZE, fmt, tmp, "SET_BUF_SIZE");
     va_end(ap); 
-    THPRINT(2,
+    tprint(2,
         "-----------------------------------------------------\n");
 }
 
@@ -213,7 +229,7 @@
     if (tests_enabled[tests_sets++])
     {
         tests_nenabled++;
-        THPRINT(1,
+        tprint(1,
             "======================================================\n"
             " Set #%d : %s tests\n"
             "======================================================\n",
@@ -283,8 +299,11 @@
         char *i_fmts[] = { "%d", "%x", "%05d", "%5d", "%-5d", "%05x", "%5x", "", "% 3d", "% 3o", "%+3o", "%+3d", };
 
         for (i1 = 0; i1 < sizeof(i_vals) / sizeof(i_vals[0]); i1++)
-        for (i2 = 0; i2 < sizeof(i_fmts) / sizeof(i_fmts[0]); i2++)
-            test_snprintf(i_fmts[i2], i_vals);
+        {
+            tprint(1, "Value %d\n", i_vals[i1]);
+            for (i2 = 0; i2 < sizeof(i_fmts) / sizeof(i_fmts[0]); i2++)
+                test_snprintf(i_fmts[i2], i_vals[i1]);
+        }
     }
 
     if (test_set_start("printf() float"))
@@ -293,8 +312,11 @@
         char *f_fmts[] = { "%f", "%1.1f", "%5.5f", "%5f", "%-5f", "", };
 
         for (i1 = 0; i1 < sizeof(f_vals) / sizeof(f_vals[0]); i1++)
-        for (i2 = 0; i2 < sizeof(f_fmts) / sizeof(f_fmts[0]); i2++)
-            test_snprintf(f_fmts[i2], f_vals);
+        {
+            tprint(1, "Value %f\n", f_vals[i1]);
+            for (i2 = 0; i2 < sizeof(f_fmts) / sizeof(f_fmts[0]); i2++)
+                test_snprintf(f_fmts[i2], f_vals[i1]);
+        }
     }
 
     if (test_set_start("printf() string"))
@@ -303,9 +325,11 @@
         char *s_fmts[] = { "%s", "%2s", "%-2s", "%5s", "%-5s", "%16s", "%-16s", "%1s", "%-1s", "% 2s", "%03s", "% -12s", "% 03s", "%-.15s", "%.8s" };
 
         for (i1 = 0; i1 < sizeof(s_vals) / sizeof(s_vals[0]); i1++)
-        for (i2 = 0; i2 < sizeof(s_fmts) / sizeof(s_fmts[0]); i2++)
-            test_snprintf(s_fmts[i2], s_vals);
-
+        {
+            tprint(1, "Value '%s'\n", s_vals[i1]);
+            for (i2 = 0; i2 < sizeof(s_fmts) / sizeof(s_fmts[0]); i2++)
+                test_snprintf(s_fmts[i2], s_vals[i1]);
+        }
     }
 
     if (test_set_start("printf() char"))
@@ -374,10 +398,10 @@
     //
     // Print summary and exit
     //
-    THPRINT(1,
+    tprint(1,
         "======================================================\n");
 
-    THPRINT(0,
+    tprint(0,
         "%d tests failed, %d passed (%d main tests), %d test sets of %d sets total.\n",
         tests_failed, tests_passed, tests_total, tests_nenabled, tests_sets);