From cea91f55027126013633c7ff932e6eef8ca181a5 Mon Sep 17 00:00:00 2001 From: John-Mark Bell Date: Sat, 21 May 2022 22:37:51 +0100 Subject: 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. --- Makefile | 1 + test/INDEX | 1 + test/Makefile | 1 + test/olducsinit.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/ucsinit.c | 30 +++++++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 test/olducsinit.c 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 +#include +#include + +#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 #include +#include #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()); -- cgit v1.2.3