Eliminate 'CORD_*printf is never used' cppcheck style warnings (cordtest)
authorIvan Maidanski <ivmai@mail.ru>
Thu, 27 Oct 2016 08:24:26 +0000 (11:24 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 27 Oct 2016 08:24:26 +0000 (11:24 +0300)
Minimal testing of CORD_[v][f]printf is added to cordtest.

* cord/tests/cordtest.c: Include stdarg.h.
* cord/tests/cordtest.c: Reformat the comment describing cordtest.
* cord/tests/cordtest.c (wrap_vprintf, wrap_vfprintf): New function
(calling CORD_v[f]printf).
* cord/tests/cordtest.c (test_printf): Call CORD_printf, wrap_vfprintf,
wrap_vprintf for CORD_EMPTY (with the output to stdout); add TODO item.

cord/tests/cordtest.c

index 3e2092a..35ea9ae 100644 (file)
 
 # include "gc.h"    /* For GC_INIT() only */
 # include "cord.h"
+
+# include <stdarg.h>
 # include <string.h>
 # include <stdio.h>
 # include <stdlib.h>
+
 /* This is a very incomplete test of the cord package.  It knows about  */
 /* a few internals of the package (e.g. when C strings are returned)    */
-/* that real clients shouldn't rely on.                 */
+/* that real clients shouldn't rely on.                                 */
 
 # define ABORT(string) \
     { fprintf(stderr, "FAILED: %s\n", string); abort(); }
@@ -207,6 +210,28 @@ void test_extras(void)
     }
 }
 
+int wrap_vprintf(CORD format, ...)
+{
+    va_list args;
+    int result;
+
+    va_start(args, format);
+    result = CORD_vprintf(format, args);
+    va_end(args);
+    return result;
+}
+
+int wrap_vfprintf(FILE * f, CORD format, ...)
+{
+    va_list args;
+    int result;
+
+    va_start(args, format);
+    result = CORD_vfprintf(f, format, args);
+    va_end(args);
+    return result;
+}
+
 #if defined(__DJGPP__) || defined(__STRICT_ANSI__)
   /* snprintf is missing in DJGPP (v2.0.3) */
 #else
@@ -252,6 +277,10 @@ void test_printf(void)
 #   endif
     result2[sizeof(result2) - 1] = '\0';
     if (CORD_cmp(result, result2) != 0)ABORT("CORD_sprintf goofed 5");
+    /* TODO: Better test CORD_[v][f]printf.     */
+    (void)CORD_printf(CORD_EMPTY);
+    (void)wrap_vfprintf(stdout, CORD_EMPTY);
+    (void)wrap_vprintf(CORD_EMPTY);
 }
 
 int main(void)