aboutsummaryrefslogtreecommitdiffstats
path: root/libfonts_get_default_font_name.c
blob: 66d14cbec92dd4516c3299150b4db38788cf21b7 (plain) (blame)
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
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


int
libfonts_get_default_font_name(enum libfonts_default_font font, size_t index, const char **namep)
{
	const char *alias = NULL;

	if (font == LIBFONTS_DEFAULT_SANS_SERIF) {
		if (index == 0)
			alias = "sans-serif";
		else if (index == 1)
			alias = "sans serif";
		else if (index == 2)
			alias = "sans";

	} else if (font == LIBFONTS_DEFAULT_SERIF) {
		if (index == 0)
			alias = "serif";

	} else if (font == LIBFONTS_DEFAULT_MONOSPACE) {
		if (index == 0)
			alias = "monospace";
		else if (index == 1)
			alias = "monospaced";

	} else {
		errno = EINVAL;
		return -1;
	}

	if (namep)
		*namep = alias;
	return alias != NULL;
}


#else


int
main(void)
{
	const char *r;

#define T(FONT, INDEX, NAME)\
	do {\
		errno = 0;\
		ASSERT(libfonts_get_default_font_name(FONT, INDEX, &r) == 1);\
		ASSERT(r != NULL);\
		ASSERT(!strcmp(r, NAME));\
		ASSERT(!errno);\
		ASSERT(libfonts_get_default_font_name(FONT, INDEX, NULL) == 1);\
		ASSERT(!errno);\
	} while (0)

#define X(FONT, INDEX)\
	do {\
		errno = 0;\
		ASSERT(libfonts_get_default_font_name(FONT, INDEX, &r) == 0);\
		ASSERT(r == NULL);\
		ASSERT(!errno);\
		ASSERT(libfonts_get_default_font_name(FONT, INDEX, NULL) == 0);\
		ASSERT(!errno);\
	} while (0)

	errno = 0;
	ASSERT(libfonts_get_default_font_name(-1, 0, &r) == -1);
	ASSERT(errno == EINVAL);

	errno = 0;
	ASSERT(libfonts_get_default_font_name(99, 0, &r) == -1);
	ASSERT(errno == EINVAL);

	T(LIBFONTS_DEFAULT_SANS_SERIF, 0, "sans-serif");
	T(LIBFONTS_DEFAULT_SANS_SERIF, 1, "sans serif");
	T(LIBFONTS_DEFAULT_SANS_SERIF, 2, "sans");
	X(LIBFONTS_DEFAULT_SANS_SERIF, 3);

	T(LIBFONTS_DEFAULT_SERIF, 0, "serif");
	X(LIBFONTS_DEFAULT_SERIF, 1);

	T(LIBFONTS_DEFAULT_MONOSPACE, 0, "monospace");
	T(LIBFONTS_DEFAULT_MONOSPACE, 1, "monospaced");
	X(LIBFONTS_DEFAULT_MONOSPACE, 2);

	return 0;
}


#endif