summaryrefslogtreecommitdiff
path: root/test/olducsinit.c
blob: 813c541ece4c6831db35bcdde274731a1172d9c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#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, 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);

	/* Compute width of replacement character */
	assert(rufl_OK == rufl_width("Corpus", rufl_WEIGHT_500, 160,
			(const uint8_t *) "\xef\xbf\xbd", 3, &width));
	assert(17 == width);
	assert(rufl_OK == rufl_width("Corpus", rufl_WEIGHT_500, 160,
			(const uint8_t *) "\xf0\xa0\x80\xa5", 4, &width));
	assert(26 == width);

	rufl_dump_state(true);

	rufl_quit();

	/* Reinit -- should load cache */
	assert(rufl_OK == rufl_init());
	assert(NULL == rufl_fm_error);
	assert(3 == rufl_family_list_entries);
	assert(NULL != rufl_family_menu);
	/* Done for real this time */
	rufl_quit();

	printf("PASS\n");

	return 0;
}