utils/gprintf.c: Return the correct number of output characters.
[mLib] / struct / t / dstr-putf-test.c
index 416b164..044da71 100644 (file)
@@ -18,13 +18,16 @@ static char strbuf[1024];
 
 #define TESTGROUP(name) TVEC_TESTGROUP_TAG(grp, &tvstate, name)
 
-static void PRINTF_LIKE(1, 2) format(const char *fmt, ...)
+static int PRINTF_LIKE(1, 2) format(const char *fmt, ...)
 {
   va_list ap;
+  int n;
+
   va_start(ap, fmt);
   dstr_reset(&d);
-  dstr_vputf(&d, fmt, &ap);
+  n = dstr_vputf(&d, fmt, &ap);
   va_end(ap);
+  return (n);
 }
 
 static void PRINTF_LIKE(1, 2) prepare(const char *fmt, ...)
@@ -42,14 +45,18 @@ static void PRINTF_LIKE(1, 2) prepare(const char *fmt, ...)
 }
 
 #define TEST_KNOWN(fmtargs, want) do {                                 \
-  format fmtargs;                                                      \
+  int n; n = format fmtargs;                                           \
+  tvec_claimeq_int(&tvstate, n, strlen(want),                          \
+                  __FILE__, __LINE__, "format " #fmtargs);             \
   tvec_claimeq_string(&tvstate, d.buf, d.len, want, strlen(want),      \
                      __FILE__, __LINE__, "format " #fmtargs);          \
 } while (0)
 
 #define TEST_REF(fmtargs) do {                                         \
-  format fmtargs;                                                      \
+  int n = format fmtargs;                                              \
   prepare fmtargs;                                                     \
+  tvec_claimeq_int(&tvstate, n, strlen(strbuf),                                \
+                  __FILE__, __LINE__, "format " #fmtargs);             \
   tvec_claimeq_string(&tvstate, d.buf, d.len, strbuf, strlen(strbuf),  \
                      __FILE__, __LINE__, "format " #fmtargs);          \
 } while (0)