]>
Commit | Line | Data |
---|---|---|
86db5dfb DH |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | /*** | |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright (C) 2014 David Herrmann <dh.herrmann@gmail.com> | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
21 | /* | |
22 | * Test Unifont Helper | |
23 | * This tries opening the binary unifont glyph-array and renders some glyphs. | |
24 | * The glyphs are then compared to hard-coded glyphs. | |
25 | */ | |
26 | ||
27 | #include <errno.h> | |
28 | #include <stdio.h> | |
29 | #include <stdlib.h> | |
30 | #include <string.h> | |
31 | #include "macro.h" | |
32 | #include "unifont-def.h" | |
c2977e5c | 33 | #include "unifont.h" |
86db5dfb DH |
34 | #include "util.h" |
35 | ||
36 | static void render(char *w, const unifont_glyph *g) { | |
37 | unsigned int i, j; | |
38 | const uint8_t *d = g->data; | |
39 | ||
40 | for (j = 0; j < 16; ++j) { | |
41 | for (i = 0; i < 8 * g->cwidth; ++i) { | |
42 | if (d[i / 8] & (1 << (7 - i % 8))) | |
43 | *w++ = '#'; | |
44 | else | |
45 | *w++ = ' '; | |
46 | } | |
47 | *w++ = '\n'; | |
48 | d += g->stride; | |
49 | } | |
50 | ||
51 | *w++ = 0; | |
52 | } | |
53 | ||
54 | static void test_unifont(void) { | |
55 | char buf[4096]; | |
56 | unifont_glyph g; | |
57 | unifont *u; | |
58 | ||
59 | assert_se(unifont_new(&u) >= 0); | |
60 | ||
61 | /* lookup invalid font */ | |
62 | assert_se(unifont_lookup(u, &g, 0xffffffffU) < 0); | |
63 | ||
64 | /* lookup and render 'A' */ | |
65 | assert_se(unifont_lookup(u, &g, 'A') >= 0); | |
66 | assert_se(g.width == 8); | |
67 | assert_se(g.height == 16); | |
68 | assert_se(g.stride >= 1); | |
69 | assert_se(g.cwidth == 1); | |
70 | assert_se(g.data != NULL); | |
71 | render(buf, &g); | |
72 | assert_se(!strcmp(buf, | |
73 | " \n" | |
74 | " \n" | |
75 | " \n" | |
76 | " \n" | |
77 | " ## \n" | |
78 | " # # \n" | |
79 | " # # \n" | |
80 | " # # \n" | |
81 | " # # \n" | |
82 | " ###### \n" | |
83 | " # # \n" | |
84 | " # # \n" | |
85 | " # # \n" | |
86 | " # # \n" | |
87 | " \n" | |
88 | " \n" | |
89 | )); | |
90 | ||
91 | /* lookup and render '什' */ | |
92 | assert_se(unifont_lookup(u, &g, 0x4ec0) >= 0); | |
93 | assert_se(g.width == 16); | |
94 | assert_se(g.height == 16); | |
95 | assert_se(g.stride >= 2); | |
96 | assert_se(g.cwidth == 2); | |
97 | assert_se(g.data != NULL); | |
98 | render(buf, &g); | |
99 | assert_se(!strcmp(buf, | |
100 | " # # \n" | |
101 | " # # \n" | |
102 | " # # \n" | |
103 | " # # \n" | |
104 | " # # \n" | |
105 | " ## # \n" | |
106 | " ## ########## \n" | |
107 | " # # # \n" | |
108 | "# # # \n" | |
109 | " # # \n" | |
110 | " # # \n" | |
111 | " # # \n" | |
112 | " # # \n" | |
113 | " # # \n" | |
114 | " # # \n" | |
115 | " # # \n" | |
116 | )); | |
117 | ||
118 | unifont_unref(u); | |
119 | } | |
120 | ||
121 | int main(int argc, char **argv) { | |
122 | if (access(UNIFONT_PATH, F_OK)) | |
123 | return 77; | |
124 | ||
125 | test_unifont(); | |
126 | ||
127 | return 0; | |
128 | } |