Move common test functions to separate module
authorPeter Colberg <peter@colberg.org>
Fri, 30 Oct 2015 19:13:48 +0000 (15:13 -0400)
committerPeter Colberg <peter@colberg.org>
Fri, 30 Oct 2015 19:13:48 +0000 (15:13 -0400)
This resolves warnings for missing function prototypes.

Makefile
test/tests.c [new file with mode: 0644]
test/tests.h

index 1d41ba995049c650c981f040c5dd4789f351e1fb..710dad1b0e6a8371621d00e72a45351fc82b8005 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -43,10 +43,11 @@ includedir=$(prefix)/include
 all: libutf8proc.a libutf8proc.$(SHLIB_EXT)
 
 clean:
-       rm -f utf8proc.o libutf8proc.a libutf8proc.$(SHLIB_VERS_EXT) libutf8proc.$(SHLIB_EXT) test/normtest test/graphemetest test/printproperty test/charwidth test/valid test/iterate
+       rm -f utf8proc.o libutf8proc.a libutf8proc.$(SHLIB_VERS_EXT) libutf8proc.$(SHLIB_EXT)
 ifneq ($(OS),Darwin)
        rm -f libutf8proc.so.$(MAJOR)
 endif
+       rm -f test/tests.o test/normtest test/graphemetest test/printproperty test/charwidth test/valid test/iterate test/case
        $(MAKE) -C bench clean
        $(MAKE) -C data clean
 
@@ -100,26 +101,29 @@ data/NormalizationTest.txt:
 data/GraphemeBreakTest.txt:
        $(MAKE) -C data GraphemeBreakTest.txt
 
-test/normtest: test/normtest.c utf8proc.o utf8proc.h test/tests.h
-       $(CC) $(UCFLAGS) test/normtest.c utf8proc.o -o $@
+test/tests.o: test/tests.c test/tests.h utf8proc.h
+       $(CC) $(UCFLAGS) -c -o test/tests.o test/tests.c
 
-test/graphemetest: test/graphemetest.c utf8proc.o utf8proc.h test/tests.h
-       $(CC) $(UCFLAGS) test/graphemetest.c utf8proc.o -o $@
+test/normtest: test/normtest.c test/tests.o utf8proc.o utf8proc.h test/tests.h
+       $(CC) $(UCFLAGS) test/normtest.c test/tests.o utf8proc.o -o $@
 
-test/printproperty: test/printproperty.c utf8proc.o utf8proc.h test/tests.h
-       $(CC) $(UCFLAGS) test/printproperty.c utf8proc.o -o $@
+test/graphemetest: test/graphemetest.c test/tests.o utf8proc.o utf8proc.h test/tests.h
+       $(CC) $(UCFLAGS) test/graphemetest.c test/tests.o utf8proc.o -o $@
 
-test/charwidth: test/charwidth.c utf8proc.o utf8proc.h test/tests.h
-       $(CC) $(UCFLAGS) test/charwidth.c utf8proc.o -o $@
+test/printproperty: test/printproperty.c test/tests.o utf8proc.o utf8proc.h test/tests.h
+       $(CC) $(UCFLAGS) test/printproperty.c test/tests.o utf8proc.o -o $@
 
-test/valid: test/valid.c utf8proc.o utf8proc.h test/tests.h
-       $(CC) $(UCFLAGS) test/valid.c utf8proc.o -o $@
+test/charwidth: test/charwidth.c test/tests.o utf8proc.o utf8proc.h test/tests.h
+       $(CC) $(UCFLAGS) test/charwidth.c test/tests.o utf8proc.o -o $@
 
-test/iterate: test/iterate.c utf8proc.o utf8proc.h test/tests.h
-       $(CC) $(UCFLAGS) test/iterate.c utf8proc.o -o $@
+test/valid: test/valid.c test/tests.o utf8proc.o utf8proc.h test/tests.h
+       $(CC) $(UCFLAGS) test/valid.c test/tests.o utf8proc.o -o $@
 
-test/case: test/case.c utf8proc.o utf8proc.h test/tests.h
-       $(CC) $(UCFLAGS) test/case.c utf8proc.o -o $@
+test/iterate: test/iterate.c test/tests.o utf8proc.o utf8proc.h test/tests.h
+       $(CC) $(UCFLAGS) test/iterate.c test/tests.o utf8proc.o -o $@
+
+test/case: test/case.c test/tests.o utf8proc.o utf8proc.h test/tests.h
+       $(CC) $(UCFLAGS) test/case.c test/tests.o utf8proc.o -o $@
 
 check: test/normtest data/NormalizationTest.txt test/graphemetest data/GraphemeBreakTest.txt test/printproperty test/case test/charwidth test/valid test/iterate bench/bench.c bench/util.c bench/util.h utf8proc.o
        $(MAKE) -C bench
diff --git a/test/tests.c b/test/tests.c
new file mode 100644 (file)
index 0000000..0fb0da3
--- /dev/null
@@ -0,0 +1,46 @@
+/* Common functions for our test programs. */
+
+#include "tests.h"
+
+size_t lineno = 0;
+
+void check(int cond, const char *format, ...)
+{
+     if (!cond) {
+          va_list args;
+          fprintf(stderr, "line %zd: ", lineno);
+          va_start(args, format);
+          vfprintf(stderr, format, args);
+          va_end(args);
+          fprintf(stderr, "\n");
+          exit(1);
+     }
+}
+
+size_t skipspaces(const char *buf, size_t i)
+{
+    while (isspace(buf[i])) ++i;
+    return i;
+}
+
+/* if buf points to a sequence of codepoints encoded as hexadecimal strings,
+   separated by whitespace, and terminated by any character not in
+   [0-9a-fA-F] or whitespace, then stores the corresponding utf8 string
+   in dest, returning the number of bytes read from buf */
+size_t encode(char *dest, const char *buf)
+{
+     size_t i = 0, j, d = 0;
+     for (;;) {
+          int c;
+          i = skipspaces(buf, i);
+          for (j=i; buf[j] && strchr("0123456789abcdef", tolower(buf[j])); ++j)
+               ; /* find end of hex input */
+          if (j == i) { /* no codepoint found */
+               dest[d] = 0; /* NUL-terminate destination string */
+               return i + 1;
+          }
+          check(sscanf(buf + i, "%x", (unsigned int *)&c) == 1, "invalid hex input %s", buf+i);
+          i = j; /* skip to char after hex input */
+          d += utf8proc_encode_char(c, (utf8proc_uint8_t *) (dest + d));
+     }
+}
index 43df51fdc057f1dc524e4af1e51d04d3f53ce86c..4bc725a3fc1166340afc690960995aee5badd382 100644 (file)
@@ -8,46 +8,8 @@
 
 #include "../utf8proc.h"
 
-size_t lineno = 0;
-
-void check(int cond, const char *format, ...)
-{
-     if (!cond) {
-          va_list args;
-          fprintf(stderr, "line %zd: ", lineno);
-          va_start(args, format);
-          vfprintf(stderr, format, args);
-          va_end(args);
-          fprintf(stderr, "\n");
-          exit(1);
-     }
-}
-
-size_t skipspaces(const char *buf, size_t i)
-{
-    while (isspace(buf[i])) ++i;
-    return i;
-}
-
-/* if buf points to a sequence of codepoints encoded as hexadecimal strings,
-   separated by whitespace, and terminated by any character not in
-   [0-9a-fA-F] or whitespace, then stores the corresponding utf8 string
-   in dest, returning the number of bytes read from buf */
-size_t encode(char *dest, const char *buf)
-{
-     size_t i = 0, j, d = 0;
-     for (;;) {
-          int c;
-          i = skipspaces(buf, i);
-          for (j=i; buf[j] && strchr("0123456789abcdef", tolower(buf[j])); ++j)
-               ; /* find end of hex input */
-          if (j == i) { /* no codepoint found */
-               dest[d] = 0; /* NUL-terminate destination string */
-               return i + 1;
-          }
-          check(sscanf(buf + i, "%x", (unsigned int *)&c) == 1, "invalid hex input %s", buf+i);
-          i = j; /* skip to char after hex input */
-          d += utf8proc_encode_char(c, (utf8proc_uint8_t *) (dest + d));
-     }
-}
+extern size_t lineno;
 
+void check(int cond, const char *format, ...);
+size_t skipspaces(const char *buf, size_t i);
+size_t encode(char *dest, const char *buf);