summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/INDEX3
-rw-r--r--test/Makefile1
-rw-r--r--test/data/oldfminit/INDEX5
-rw-r--r--test/data/oldfminit/Latin1270
-rw-r--r--test/harness-priv.h1
-rw-r--r--test/harness.c5
-rw-r--r--test/harness.h1
-rw-r--r--test/mocks.c14
-rw-r--r--test/oldfminit.c102
9 files changed, 396 insertions, 6 deletions
diff --git a/test/INDEX b/test/INDEX
index 0cbf010..a1b324c 100644
--- a/test/INDEX
+++ b/test/INDEX
@@ -1,6 +1,7 @@
# Index for testcases
#
-# Test Description DataDir
+# 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
+oldfminit Ensure that non-UCS FM initialisation works oldfminit
diff --git a/test/Makefile b/test/Makefile
index 2e773ac..21297e5 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,5 +1,6 @@
# Tests
DIR_TEST_ITEMS := nofonts:nofonts.c;harness.c;mocks.c \
+ oldfminit:oldfminit.c;harness.c;mocks.c \
olducsinit:olducsinit.c;harness.c;mocks.c \
ucsinit:ucsinit.c;harness.c;mocks.c
diff --git a/test/data/oldfminit/INDEX b/test/data/oldfminit/INDEX
new file mode 100644
index 0000000..5ea429d
--- /dev/null
+++ b/test/data/oldfminit/INDEX
@@ -0,0 +1,5 @@
+# Index file for non-UCS FM initialisation tests
+#
+# Test Description
+
+Latin1 Simple Latin1 Encoding
diff --git a/test/data/oldfminit/Latin1 b/test/data/oldfminit/Latin1
new file mode 100644
index 0000000..6821aa8
--- /dev/null
+++ b/test/data/oldfminit/Latin1
@@ -0,0 +1,270 @@
+% Acorn_Latin1Encoding 1.00 0
+
+%%RISCOS_BasedOn 0
+%%RISCOS_Alphabet 101
+
+% These first characters are for use by PostScript printer driver ONLY,
+% they are not accessible using the RISC OS font manager.
+/ring
+/circumflex
+/tilde
+/dotlessi
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+/.notdef
+
+/space
+/exclam
+/quotedbl
+/numbersign
+/dollar
+/percent
+/ampersand
+/quotesingle
+/parenleft
+/parenright
+/asterisk
+/plus
+/comma
+/hyphen
+/period
+/slash
+/zero
+/one
+/two
+/three
+/four
+/five
+/six
+/seven
+/eight
+/nine
+/colon
+/semicolon
+/less
+/equal
+/greater
+/question
+
+/at
+/A
+/B
+/C
+/D
+/E
+/F
+/G
+/H
+/I
+/J
+/K
+/L
+/M
+/N
+/O
+/P
+/Q
+/R
+/S
+/T
+/U
+/V
+/W
+/X
+/Y
+/Z
+/bracketleft
+/backslash
+/bracketright
+/asciicircum
+/underscore
+
+/grave
+/a
+/b
+/c
+/d
+/e
+/f
+/g
+/h
+/i
+/j
+/k
+/l
+/m
+/n
+/o
+/p
+/q
+/r
+/s
+/t
+/u
+/v
+/w
+/x
+/y
+/z
+/braceleft
+/bar
+/braceright
+/asciitilde
+/.notdef
+
+/Euro
+/Wcircumflex
+/wcircumflex
+/.notdef
+/.notdef
+/Ycircumflex
+/ycircumflex
+/special1
+/special2
+/special3
+/special4
+/special5
+/ellipsis
+/trademark
+/perthousand
+/bullet
+/quoteleft
+/quoteright
+/guilsinglleft
+/guilsinglright
+/quotedblleft
+/quotedblright
+/quotedblbase
+/endash
+/emdash
+/minus
+/OE
+/oe
+/dagger
+/daggerdbl
+/fi
+/fl
+
+/space
+/exclamdown
+/cent
+/sterling
+/currency
+/yen
+/brokenbar
+/section
+/dieresis
+/copyright
+/ordfeminine
+/guillemotleft
+/logicalnot
+/hyphen
+/registered
+/macron
+/degree
+/plusminus
+/twosuperior
+/threesuperior
+/acute
+/mu
+/paragraph
+/periodcentered
+/cedilla
+/onesuperior
+/ordmasculine
+/guillemotright
+/onequarter
+/onehalf
+/threequarters
+/questiondown
+
+/Agrave
+/Aacute
+/Acircumflex
+/Atilde
+/Adieresis
+/Aring
+/AE
+/Ccedilla
+/Egrave
+/Eacute
+/Ecircumflex
+/Edieresis
+/Igrave
+/Iacute
+/Icircumflex
+/Idieresis
+/Eth
+/Ntilde
+/Ograve
+/Oacute
+/Ocircumflex
+/Otilde
+/Odieresis
+/multiply
+/Oslash
+/Ugrave
+/Uacute
+/Ucircumflex
+/Udieresis
+/Yacute
+/Thorn
+/germandbls
+
+/agrave
+/aacute
+/acircumflex
+/atilde
+/adieresis
+/aring
+/ae
+/ccedilla
+/egrave
+/eacute
+/ecircumflex
+/edieresis
+/igrave
+/iacute
+/icircumflex
+/idieresis
+/eth
+/ntilde
+/ograve
+/oacute
+/ocircumflex
+/otilde
+/odieresis
+/divide
+/oslash
+/ugrave
+/uacute
+/ucircumflex
+/udieresis
+/yacute
+/thorn
+/ydieresis
diff --git a/test/harness-priv.h b/test/harness-priv.h
index 2bb4bb1..4c0615e 100644
--- a/test/harness-priv.h
+++ b/test/harness-priv.h
@@ -31,6 +31,7 @@ typedef struct {
/* At most 256 active font handles */
rufl_test_harness_sized_font fonts[256];
int current_font;
+ const char *encoding_filename;
char *buffer;
int buffer_flags;
diff --git a/test/harness.c b/test/harness.c
index ff26104..af34cc9 100644
--- a/test/harness.c
+++ b/test/harness.c
@@ -83,3 +83,8 @@ void rufl_test_harness_register_encoding(const char *encoding)
h->encodings[h->n_encodings++] = encoding;
}
+
+void rufl_test_harness_set_font_encoding(const char *path)
+{
+ h->encoding_filename = path;
+}
diff --git a/test/harness.h b/test/harness.h
index f7e19e5..bed4325 100644
--- a/test/harness.h
+++ b/test/harness.h
@@ -4,5 +4,6 @@
void rufl_test_harness_init(int fm_version, bool fm_ucs, bool preload);
void rufl_test_harness_register_font(const char *name);
void rufl_test_harness_register_encoding(const char *encoding);
+void rufl_test_harness_set_font_encoding(const char *path);
#endif
diff --git a/test/mocks.c b/test/mocks.c
index 5edf0da..ce13a8c 100644
--- a/test/mocks.c
+++ b/test/mocks.c
@@ -219,13 +219,17 @@ os_error *xfont_read_encoding_filename (font_f font, char *buffer, int size,
return &font_bad_font_number;
if (h->fonts[font].refcnt == 0)
return &font_no_font;
+ if (h->encoding_filename == NULL)
+ return &font_encoding_not_found;
+ if (buffer == NULL || (size_t) size < strlen(h->encoding_filename) + 1)
+ return &bad_parameters;
- //XXX:
- (void) buffer;
- (void) size;
- (void) end;
+ strcpy(buffer, h->encoding_filename);
- return &unimplemented;
+ if (end != NULL)
+ *end = buffer + strlen(h->encoding_filename) + 1;
+
+ return NULL;
}
os_error *xfont_list_fonts (byte *buffer1, font_list_context context,
diff --git a/test/oldfminit.c b/test/oldfminit.c
new file mode 100644
index 0000000..1df8880
--- /dev/null
+++ b/test/oldfminit.c
@@ -0,0 +1,102 @@
+#include <ftw.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "rufl.h"
+
+#include "harness.h"
+#include "testutils.h"
+
+static char template[] = "/tmp/oldfminitXXXXXX";
+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;
+
+ assert(2 == argc);
+
+ ptmp = mkdtemp(template);
+ assert(NULL != ptmp);
+ atexit(cleanup);
+ chdir(ptmp);
+
+ rufl_test_harness_init(339, false, true);
+ rufl_test_harness_set_font_encoding(argv[1]);
+
+ 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, 160,
+ (const uint8_t *) "!\xc2\xa0", 3, &width));
+ assert(50 == width);
+
+ /* Place caret after first character */
+ assert(rufl_OK == rufl_x_to_offset("Homerton", rufl_WEIGHT_500, 160,
+ (const uint8_t *) "!\xc2\xa0", 3, 25,
+ &offset, &x));
+ assert(1 == offset);
+ assert(25 == x);
+
+ /* Attempt to split after first character. As the split point is
+ * coincident with the start of the second character, however,
+ * the split point is placed after it. */
+ assert(rufl_OK == rufl_split("Trinity", rufl_WEIGHT_500, 160,
+ (const uint8_t *) "!\xc2\xa0", 3, 25,
+ &offset, &x));
+ assert(3 == offset);
+ assert(50 == x);
+
+ rufl_dump_state(true);
+
+ rufl_quit();
+
+ printf("PASS\n");
+
+ return 0;
+}