]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix format specifiers in test cases on Win32
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 29 Mar 2012 09:41:37 +0000 (10:41 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 4 Apr 2012 13:33:27 +0000 (14:33 +0100)
Some of the test suites use fprintf with format specifiers
that are not supported on Win32 and are not fixed by gnulib.

The mingw32 compiler also has trouble detecting ssize_t
correctly, complaining that 'ssize_t' does not match
'signed size_t' (which it expects for %zd). Force the
cast to size_t to avoid this problem

* tests/testutils.c, tests/testutils.h: Fix printf
  annotation on virTestResult. Use virVasprintf
  instead of vfprintf
* tests/virhashtest.c: Use VIR_WARN instead of fprintf(stderr).
  Cast to size_t to avoid mingw32 compiler bug

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
tests/testutils.c
tests/testutils.h
tests/virhashtest.c

index 4b224ee07a5d1acabc1bc3ee88f3b1308917c2ec..4e8484fb68c853e95eecf146d56d81789cc72007 100644 (file)
@@ -72,7 +72,7 @@ virtTestCountAverage(double *items, int nitems)
     return (double) (sum / nitems);
 }
 
-ATTRIBUTE_FMT_PRINTF(3,4)
+
 void virtTestResult(const char *name, int ret, const char *msg, ...)
 {
     va_list vargs;
@@ -89,7 +89,11 @@ void virtTestResult(const char *name, int ret, const char *msg, ...)
         else {
             fprintf(stderr, "FAILED\n");
             if (msg) {
-                vfprintf(stderr, msg, vargs);
+                char *str;
+                if (virVasprintf(&str, msg, vargs) == 0) {
+                    fprintf(stderr, "%s", str);
+                    VIR_FREE(str);
+                }
             }
         }
     } else {
index 2fde1b575047794f2e6cb7332e2aef560ea57356..f8c7567e65f01eb2ca9eb2d7a9e2522c538e7e20 100644 (file)
@@ -23,7 +23,8 @@ extern char *abs_srcdir;
 double virtTestCountAverage(double *items,
                             int nitems);
 
-void virtTestResult(const char *name, int ret, const char *msg, ...);
+void virtTestResult(const char *name, int ret, const char *msg, ...)
+    ATTRIBUTE_FMT_PRINTF(3,4);
 int virtTestRun(const char *title,
                 int nloops,
                 int (*body)(const void *data),
index ba0cf02ff52d6efe7980973bba690cb111f81e3d..be82281c741a73ae787c55ae588a10e657e44b34 100644 (file)
 #include "virhashdata.h"
 #include "testutils.h"
 #include "memory.h"
+#include "util.h"
+#include "logging.h"
 
 
 #define testError(...)                                          \
     do {                                                        \
-        fprintf(stderr, __VA_ARGS__);                           \
+        char *str;                                              \
+        if (virAsprintf(&str, __VA_ARGS__) == 0) {              \
+            fprintf(stderr, "%s", str);                         \
+            VIR_FREE(str);                                      \
+        }                                                       \
         /* Pad to line up with test name ... in virTestRun */   \
         fprintf(stderr, "%74s", "... ");                        \
     } while (0)
@@ -40,16 +46,16 @@ testHashInit(int size)
         }
 
         if (virHashTableSize(hash) != oldsize && virTestGetDebug()) {
-            fprintf(stderr, "\nhash grown from %zd to %zd",
-                    oldsize, virHashTableSize(hash));
+            VIR_WARN("hash grown from %zd to %zd",
+                     (size_t)oldsize, (size_t)virHashTableSize(hash));
         }
     }
 
     for (i = 0; i < ARRAY_CARDINALITY(uuids); i++) {
         if (!virHashLookup(hash, uuids[i])) {
             if (virTestGetVerbose()) {
-                fprintf(stderr, "\nentry \"%s\" could not be found\n",
-                        uuids[i]);
+                VIR_WARN("\nentry \"%s\" could not be found\n",
+                         uuids[i]);
             }
             virHashFree(hash);
             return NULL;
@@ -75,15 +81,15 @@ testHashCheckCount(virHashTablePtr hash, size_t count)
     ssize_t iter_count = 0;
 
     if (virHashSize(hash) != count) {
-        testError("\nhash contains %zd instead of %zu elements\n",
-                  virHashSize(hash), count);
+        testError("\nhash contains %zu instead of %zu elements\n",
+                  (size_t)virHashSize(hash), count);
         return -1;
     }
 
     iter_count = virHashForEach(hash, testHashCheckForEachCount, NULL);
     if (count != iter_count) {
-        testError("\nhash claims to have %zu elements but iteration finds %zd\n",
-                  count, iter_count);
+        testError("\nhash claims to have %zu elements but iteration finds %zu\n",
+                  count, (size_t)iter_count);
         return -1;
     }