chiark / gitweb /
@@@ tvec doc wip
[mLib] / struct / t / dstr-putf-test.c
index 416b164bd2509c3f4cf58f4d2e0859bc2b69c536..eb67e608b70ae942626cbe545d638cd10927c4fe 100644 (file)
@@ -1,3 +1,32 @@
+/* -*-c-*-
+ *
+ * Test driver for universal hashing
+ *
+ * (c) 2009 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------*
+ *
+ * This file is part of the mLib utilities library.
+ *
+ * mLib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * mLib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with mLib; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
 #include "config.h"
 
 #include <assert.h>
 #include "report.h"
 #include "tvec.h"
 
+/*----- Static variables --------------------------------------------------*/
+
 static struct tvec_state tvstate;
 static dstr d = DSTR_INIT;
 static char strbuf[1024];
 
+/*----- Utilities ---------------------------------------------------------*/
+
 #define TESTGROUP(name) TVEC_TESTGROUP_TAG(grp, &tvstate, name)
 
-static void PRINTF_LIKE(1, 2) format(const char *fmt, ...)
+static PRINTF_LIKE(1, 2) int 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, ...)
+static PRINTF_LIKE(1, 2) void prepare(const char *fmt, ...)
 {
   va_list ap;
   int n;
@@ -42,21 +78,27 @@ static void PRINTF_LIKE(1, 2) prepare(const char *fmt, ...)
 }
 
 #define TEST_KNOWN(fmtargs, want) do {                                 \
-  format fmtargs;                                                      \
-  tvec_claimeq_string(&tvstate, d.buf, d.len, want, strlen(want),      \
-                     __FILE__, __LINE__, "format " #fmtargs);          \
+  int n; n = format fmtargs;                                           \
+  tvec_claimeq_int(&tvstate, n, strlen(want),                          \
+                  __FILE__, __LINE__, "format " #fmtargs);             \
+  tvec_claimeq_text(&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_string(&tvstate, d.buf, d.len, strbuf, strlen(strbuf),  \
-                     __FILE__, __LINE__, "format " #fmtargs);          \
+  tvec_claimeq_int(&tvstate, n, strlen(strbuf),                                \
+                  __FILE__, __LINE__, "format " #fmtargs);             \
+  tvec_claimeq_text(&tvstate, d.buf, d.len, strbuf, strlen(strbuf),    \
+                   __FILE__, __LINE__, "format " #fmtargs);            \
 } while (0)
 
-#define LENGTHY \
+#define LENGTHY                                                                \
   "This is a rather longer string than the code is expecting: will it fit?"
 
+/*----- Main program ------------------------------------------------------*/
+
 int main(int argc, char *argv[])
 {
   struct tvec_test test;
@@ -108,3 +150,5 @@ int main(int argc, char *argv[])
 
   return (tvec_end(&tvstate));
 }
+
+/*----- That's all, folks -------------------------------------------------*/