Imported Upstream version 2.6.7
[platform/upstream/harfbuzz.git] / test / api / test-ot-glyphname.c
1 /*
2  * Copyright © 2019  Adobe, 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  * Adobe Author(s): Michiharu Ariza
25  */
26
27 #include "hb-test.h"
28 #include "hb-ot.h"
29
30 static void
31 test_one_glyph (hb_font_t *font,  hb_codepoint_t gid, const char *name)
32 {
33   char                  buf[64];
34   hb_codepoint_t        glyph;
35
36   g_assert(hb_font_get_glyph_name (font, gid, buf, sizeof (buf)));
37   g_assert_cmpstr(buf, ==, name);
38   g_assert(hb_font_get_glyph_from_name (font, name, -1, &glyph));
39   g_assert_cmpint(glyph, ==, gid);
40 }
41
42 /* Unit tests for CFF glyph names  */
43
44 static void
45 test_standard_names (void)
46 {
47   hb_face_t *face = hb_test_open_font_file ("fonts/MathTestFontFull.otf");
48   hb_font_t *font = hb_font_create (face);
49
50   test_one_glyph (font, 0,   ".notdef");
51   test_one_glyph (font, 27,  "Z");
52
53   hb_font_destroy (font);
54   hb_face_destroy (face);
55 }
56
57 static void
58 test_non_standard_names (void)
59 {
60   hb_face_t *face = hb_test_open_font_file ("fonts/MathTestFontFull.otf");
61   hb_font_t *font = hb_font_create (face);
62
63   test_one_glyph (font, 46,  "arrowdblright");
64   test_one_glyph (font, 138, "uni21E7_size5");
65
66   hb_font_destroy (font);
67   hb_face_destroy (face);
68 }
69
70 static void
71 test_predef_charset_names (void)
72 {
73   hb_face_t *face = hb_test_open_font_file ("fonts/cff1_expert.otf");
74   hb_font_t *font = hb_font_create (face);
75
76   test_one_glyph (font, 0,   ".notdef");
77   test_one_glyph (font, 29,  "centsuperior");
78   test_one_glyph (font, 86,  "commainferior");
79
80   hb_font_destroy (font);
81   hb_face_destroy (face);
82 }
83
84 int
85 main (int argc, char **argv)
86 {
87   hb_test_init (&argc, &argv);
88
89   hb_test_add (test_standard_names);
90   hb_test_add (test_non_standard_names);
91   hb_test_add (test_predef_charset_names);
92
93   return hb_test_run();
94 }