1 /*
2 * Copyright © 2023 Red Hat, Inc.
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
11 *
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16 * DAMAGE.
17 *
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 *
24 * Author(s): Matthias Clasen
25 */
26
27 #include "hb-test.h"
28
29 static void
test_glyph_names_post(void)30 test_glyph_names_post (void)
31 {
32 hb_face_t *face;
33 hb_font_t *font;
34 hb_bool_t ret;
35 char name [64];
36
37 face = hb_test_open_font_file ("fonts/adwaita.ttf");
38 font = hb_font_create (face);
39
40 ret = hb_font_get_glyph_name (font, 0, name, 64);
41 g_assert_true (ret);
42 g_assert_cmpstr (name, ==, ".notdef");
43
44 ret = hb_font_get_glyph_name (font, 1, name, 64);
45 g_assert_true (ret);
46 g_assert_cmpstr (name, ==, ".space");
47
48 ret = hb_font_get_glyph_name (font, 2, name, 64);
49 g_assert_true (ret);
50 g_assert_cmpstr (name, ==, "icon0");
51
52 ret = hb_font_get_glyph_name (font, 3, name, 64);
53 g_assert_true (ret);
54 g_assert_cmpstr (name, ==, "icon0.0");
55
56 ret = hb_font_get_glyph_name (font, 4, name, 64);
57 g_assert_true (ret);
58 g_assert_cmpstr (name, ==, "icon0.1");
59
60 ret = hb_font_get_glyph_name (font, 5, name, 64);
61 g_assert_true (ret);
62 g_assert_cmpstr (name, ==, "icon0.2");
63
64 /* beyond last glyph */
65 ret = hb_font_get_glyph_name (font, 100, name, 64);
66 g_assert_false (ret);
67
68 hb_font_destroy (font);
69 hb_face_destroy (face);
70 }
71
72 static void
test_glyph_names_cff(void)73 test_glyph_names_cff (void)
74 {
75 hb_face_t *face;
76 hb_font_t *font;
77 hb_bool_t ret;
78 char name [64];
79
80 face = hb_test_open_font_file ("fonts/SourceSansPro-Regular.otf");
81 font = hb_font_create (face);
82
83 ret = hb_font_get_glyph_name (font, 0, name, 64);
84 g_assert_true (ret);
85 g_assert_cmpstr (name, ==, ".notdef");
86
87 ret = hb_font_get_glyph_name (font, 1, name, 64);
88 g_assert_true (ret);
89 g_assert_cmpstr (name, ==, "space");
90
91 ret = hb_font_get_glyph_name (font, 2, name, 64);
92 g_assert_true (ret);
93 g_assert_cmpstr (name, ==, "A");
94
95 /* beyond last glyph */
96 ret = hb_font_get_glyph_name (font, 2000, name, 64);
97 g_assert_false (ret);
98
99 hb_font_destroy (font);
100 hb_face_destroy (face);
101 }
102
103 int
main(int argc,char ** argv)104 main (int argc, char **argv)
105 {
106 hb_test_init (&argc, &argv);
107
108 hb_test_add (test_glyph_names_post);
109 hb_test_add (test_glyph_names_cff);
110
111 return hb_test_run();
112 }
113