summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/charwidth.c2
-rw-r--r--test/iterate.c2
-rw-r--r--test/printproperty.c2
-rw-r--r--test/tests.c46
-rw-r--r--test/tests.h54
5 files changed, 61 insertions, 45 deletions
diff --git a/test/charwidth.c b/test/charwidth.c
index 986e7ca..330f18e 100644
--- a/test/charwidth.c
+++ b/test/charwidth.c
@@ -2,7 +2,7 @@
#include <ctype.h>
#include <wchar.h>
-int my_isprint(int c) {
+static int my_isprint(int c) {
int cat = utf8proc_get_property(c)->category;
return (UTF8PROC_CATEGORY_LU <= cat && cat <= UTF8PROC_CATEGORY_ZS) ||
(c == 0x0601 || c == 0x0602 || c == 0x0603 || c == 0x06dd);
diff --git a/test/iterate.c b/test/iterate.c
index cd68a52..30b307d 100644
--- a/test/iterate.c
+++ b/test/iterate.c
@@ -8,7 +8,7 @@ static int error;
#define CHECKVALID(pos, val, len) buf[pos] = val; testbytes(buf,len,len,__LINE__)
#define CHECKINVALID(pos, val, len) buf[pos] = val; testbytes(buf,len,UTF8PROC_ERROR_INVALIDUTF8,__LINE__)
-void testbytes(unsigned char *buf, int len, utf8proc_ssize_t retval, int line)
+static void testbytes(unsigned char *buf, int len, utf8proc_ssize_t retval, int line)
{
utf8proc_int32_t out[16];
utf8proc_ssize_t ret;
diff --git a/test/printproperty.c b/test/printproperty.c
index b876f0c..4c0aae5 100644
--- a/test/printproperty.c
+++ b/test/printproperty.c
@@ -7,7 +7,7 @@ int main(int argc, char **argv)
int i;
for (i = 1; i < argc; ++i) {
- int c;
+ unsigned int c;
if (!strcmp(argv[i], "-V")) {
printf("utf8proc version %s\n", utf8proc_version());
continue;
diff --git a/test/tests.c b/test/tests.c
new file mode 100644
index 0000000..0fb0da3
--- /dev/null
+++ b/test/tests.c
@@ -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));
+ }
+}
diff --git a/test/tests.h b/test/tests.h
index 43df51f..1811a73 100644
--- a/test/tests.h
+++ b/test/tests.h
@@ -1,5 +1,13 @@
/* Common functions and includes for our test programs. */
+/*
+ * Set feature macro to enable getline() and wcwidth().
+ *
+ * Please refer to section 2.2.1 of POSIX.1-2008:
+ * http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02_01_02
+ */
+#define _XOPEN_SOURCE 700
+
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
@@ -8,46 +16,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);