summaryrefslogtreecommitdiff
path: root/test/manyfonts.c
blob: bc4b01e00db06a99b2c654232965bd19999d55c5 (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
/*
 * XXX: This test currently needs the following patch to be valid.
 * We need a way of ensuring the library chooses the direct substitution
 * table format (which basically means we need to flood a plane with glyphs)
 *
 * diff --git a/src/rufl_substitution_table.c b/src/rufl_substitution_table.c
 * index f5de7d8..2b58b72 100644
 * --- a/src/rufl_substitution_table.c
 * +++ b/src/rufl_substitution_table.c
 * @@ -1019,7 +1019,7 @@ static rufl_code create_substitution_table_for_plane(unsigned int plane)
 *                         table_entries, blocks_used);
 *         chd_size = rufl_substitution_table_estimate_size_chd(
 *                         table_entries, blocks_used);
 * -       if (direct_size <= chd_size) {
 * +       if (1 || direct_size <= chd_size) {
 *                 result = direct(table, table_entries, blocks_used,
 *                                 block_histogram,
 *                                 &rufl_substitution_table[plane]);
 */

#include <ftw.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "rufl.h"

#include "harness.h"
#include "testutils.h"

static char template[] = "/tmp/manyfontsXXXXXX";
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)
{
	char *names[300];
	int x;

	UNUSED(argc);
	UNUSED(argv);

	ptmp = mkdtemp(template);
	assert(NULL != ptmp);
	atexit(cleanup);
	chdir(ptmp);

	rufl_test_harness_init(380, true, true);

	for (x = 0; x < 300; x++) {
		char buf[64];
		sprintf(buf, "Font%03d", x);
		names[x] = strdup(buf);
		rufl_test_harness_register_font(names[x]);
	}

	assert(rufl_OK == rufl_init());
	assert(NULL == rufl_fm_error);
	assert(303 == rufl_family_list_entries);
	assert(NULL != rufl_family_menu);

	rufl_dump_state(true);

	rufl_quit();

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

	for (x = 0; x < 300; x++) {
		free(names[x]);
	}

	printf("PASS\n");

	return 0;
}