summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn-Mark Bell <jmb@netsurf-browser.org>2022-05-21 22:37:51 +0100
committerJohn-Mark Bell <jmb@netsurf-browser.org>2022-05-21 22:37:51 +0100
commitcea91f55027126013633c7ff932e6eef8ca181a5 (patch)
treeb8dbcc80fd51802c58e3bd7511cd19bbe3f0b834
parent37885aaa2300acb12f57e1dfa7824de32ccd6a17 (diff)
downloadlibrufl-cea91f55027126013633c7ff932e6eef8ca181a5.tar.gz
librufl-cea91f55027126013633c7ff932e6eef8ca181a5.tar.bz2
Add test for initialisation on pre-3.64 UCS FM
This exercises the broken Font_EnumerateCharacters workaround. Ensure tests don't trample on each other by having them run in a temporary directory.
-rw-r--r--Makefile1
-rw-r--r--test/INDEX1
-rw-r--r--test/Makefile1
-rw-r--r--test/olducsinit.c98
-rw-r--r--test/ucsinit.c30
5 files changed, 131 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index bfaf61e..7bc8c9d 100644
--- a/Makefile
+++ b/Makefile
@@ -31,6 +31,7 @@ else
# __inline__ is a GCCism
CFLAGS := $(CFLAGS) -Dinline="__inline__"
endif
+CFLAGS := $(CFLAGS) -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=500
# OSLib
ifneq ($(findstring clean,$(MAKECMDGOALS)),clean)
diff --git a/test/INDEX b/test/INDEX
index 65b87ab..0cbf010 100644
--- a/test/INDEX
+++ b/test/INDEX
@@ -3,3 +3,4 @@
# Test Description DataDir
nofonts Ensure a lack of fonts "works"
ucsinit Ensure that UCS FM initialisation works
+olducsinit Ensure that UCS FM (pre 3.64) initialisation works
diff --git a/test/Makefile b/test/Makefile
index 433a567..2e773ac 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,5 +1,6 @@
# Tests
DIR_TEST_ITEMS := nofonts:nofonts.c;harness.c;mocks.c \
+ olducsinit:olducsinit.c;harness.c;mocks.c \
ucsinit:ucsinit.c;harness.c;mocks.c
ifeq ($(HOST),arm-unknown-riscos)
diff --git a/test/olducsinit.c b/test/olducsinit.c
new file mode 100644
index 0000000..ea1109d
--- /dev/null
+++ b/test/olducsinit.c
@@ -0,0 +1,98 @@
+#include <ftw.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "rufl.h"
+
+#include "harness.h"
+#include "testutils.h"
+
+static char template[] = "/tmp/olducsinitXXXXXX";
+static const char *ptmp = NULL;
+
+static int ftw_cb(const char *path, const struct stat *sb,
+ int typeflag, struct FTW *ftwbuf)
+{
+ (void) sb;
+ (void) typeflag;
+ (void) ftwbuf;
+
+ remove(path);
+
+ return 0;
+}
+
+static void cleanup(void)
+{
+ if (ptmp == NULL)
+ return;
+
+ nftw(ptmp, ftw_cb, FOPEN_MAX, FTW_DEPTH | FTW_MOUNT | FTW_PHYS);
+}
+
+int main(int argc, const char **argv)
+{
+ int width, x;
+ size_t offset;
+ int32_t xkern, ykern, italic, ascent, descent, xheight, cap_height;
+ int8_t uline_position;
+ uint8_t uline_thickness;
+ os_box bbox;
+
+ UNUSED(argc);
+ UNUSED(argv);
+
+ ptmp = mkdtemp(template);
+ assert(NULL != ptmp);
+ atexit(cleanup);
+ chdir(ptmp);
+
+ rufl_test_harness_init(361, true, true);
+
+ assert(rufl_OK == rufl_init());
+ assert(NULL == rufl_fm_error);
+ assert(3 == rufl_family_list_entries);
+ assert(NULL != rufl_family_menu);
+
+ assert(rufl_OK == rufl_font_metrics("Corpus", rufl_WEIGHT_500,
+ &bbox, &xkern, &ykern, &italic,
+ &ascent, &descent, &xheight, &cap_height,
+ &uline_position, &uline_thickness));
+ assert(0 == bbox.x0);
+ assert(2 == bbox.x1);
+ assert(0 == bbox.y0);
+ assert(2 == bbox.y1);
+ assert(0 == xkern);
+ assert(0 == ykern);
+ assert(0 == italic);
+ assert(0 == ascent);
+ assert(0 == descent);
+ assert((bbox.y1 - bbox.y0) == cap_height);
+ assert((cap_height / 2) == xheight);
+ assert(0 == uline_position);
+ assert(0 == uline_thickness);
+
+ assert(rufl_OK == rufl_width("Corpus", rufl_WEIGHT_500, 10,
+ (const uint8_t *) "!\xc2\xa0", 3, &width));
+ assert(2 == width);
+
+ assert(rufl_OK == rufl_x_to_offset("Homerton", rufl_WEIGHT_500, 10,
+ (const uint8_t *) "!\xc2\xa0", 3, 1,
+ &offset, &x));
+ assert(1 == offset);
+ assert(1 == x);
+
+ assert(rufl_OK == rufl_split("Trinity", rufl_WEIGHT_500, 10,
+ (const uint8_t *) "!\xc2\xa0", 3, 1,
+ &offset, &x));
+ assert(1 == offset);
+ assert(1 == x);
+
+ rufl_dump_state(true);
+
+ rufl_quit();
+
+ printf("PASS\n");
+
+ return 0;
+}
diff --git a/test/ucsinit.c b/test/ucsinit.c
index b3d8f53..7439030 100644
--- a/test/ucsinit.c
+++ b/test/ucsinit.c
@@ -1,10 +1,35 @@
+#include <ftw.h>
#include <stdio.h>
+#include <unistd.h>
#include "rufl.h"
#include "harness.h"
#include "testutils.h"
+static char template[] = "/tmp/ucsinitXXXXXX";
+static const char *ptmp = NULL;
+
+static int ftw_cb(const char *path, const struct stat *sb,
+ int typeflag, struct FTW *ftwbuf)
+{
+ (void) sb;
+ (void) typeflag;
+ (void) ftwbuf;
+
+ remove(path);
+
+ return 0;
+}
+
+static void cleanup(void)
+{
+ if (ptmp == NULL)
+ return;
+
+ nftw(ptmp, ftw_cb, FOPEN_MAX, FTW_DEPTH | FTW_MOUNT | FTW_PHYS);
+}
+
int main(int argc, const char **argv)
{
int width, x;
@@ -17,6 +42,11 @@ int main(int argc, const char **argv)
UNUSED(argc);
UNUSED(argv);
+ ptmp = mkdtemp(template);
+ assert(NULL != ptmp);
+ atexit(cleanup);
+ chdir(ptmp);
+
rufl_test_harness_init(380, true, true);
assert(rufl_OK == rufl_init());