Imported Upstream version 2.3.1
[platform/upstream/harfbuzz.git] / test / api / test-aat-layout.c
1 /*
2  * Copyright © 2018  Google, 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
25 #include "hb-test.h"
26
27 #include <hb.h>
28 #include <hb-ot.h>
29 #include <hb-aat.h>
30
31 /* Unit tests for hb-aat.h */
32
33 static hb_face_t *face;
34 static hb_face_t *sbix;
35
36 static void
37 test_aat_get_feature_types (void)
38 {
39   hb_aat_layout_feature_type_t features[3];
40   unsigned int count = 3;
41   g_assert_cmpuint (11, ==, hb_aat_layout_get_feature_types (face, 0, &count, features));
42
43   g_assert_cmpuint (1, ==, features[0]);
44   g_assert_cmpuint (3, ==, features[1]);
45   g_assert_cmpuint (6, ==, features[2]);
46
47   g_assert_cmpuint (258, ==, hb_aat_layout_feature_type_get_name_id (face, features[0]));
48   g_assert_cmpuint (261, ==, hb_aat_layout_feature_type_get_name_id (face, features[1]));
49   g_assert_cmpuint (265, ==, hb_aat_layout_feature_type_get_name_id (face, features[2]));
50 }
51
52 static void
53 test_aat_get_feature_selectors (void)
54 {
55   unsigned int default_index;
56   hb_aat_layout_feature_selector_info_t settings[3];
57   unsigned int count = 3;
58
59   g_assert_cmpuint (4, ==, hb_aat_layout_feature_type_get_selector_infos (face,
60                                                                           HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE,
61                                                                           0, &count, settings,
62                                                                           &default_index));
63   g_assert_cmpuint (3, ==, count);
64   g_assert_cmpuint (0, ==, default_index);
65
66   g_assert_cmpuint (0, ==, settings[0].enable);
67   g_assert_cmpuint (294, ==, settings[0].name_id);
68
69   g_assert_cmpuint (1, ==, settings[1].enable);
70   g_assert_cmpuint (295, ==, settings[1].name_id);
71
72   g_assert_cmpuint (2, ==, settings[2].enable);
73   g_assert_cmpuint (296, ==, settings[2].name_id);
74
75   count = 3;
76   g_assert_cmpuint (4, ==, hb_aat_layout_feature_type_get_selector_infos (face,
77                                                                           HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE,
78                                                                           3, &count, settings,
79                                                                           &default_index));
80   g_assert_cmpuint (1, ==, count);
81   g_assert_cmpuint (0, ==, default_index);
82
83   g_assert_cmpuint (3, ==, settings[0].enable);
84   g_assert_cmpuint (297, ==, settings[0].name_id);
85
86   count = 1;
87   g_assert_cmpuint (1, ==, hb_aat_layout_feature_type_get_selector_infos (face,
88                                                                           HB_AAT_LAYOUT_FEATURE_TYPE_TYPOGRAPHIC_EXTRAS,
89                                                                           0, &count, settings,
90                                                                           &default_index));
91   g_assert_cmpuint (1, ==, count);
92   g_assert_cmpuint (HB_AAT_LAYOUT_NO_SELECTOR_INDEX, ==, default_index);
93
94   g_assert_cmpuint (8, ==, settings[0].enable);
95   g_assert_cmpuint (308, ==, settings[0].name_id);
96
97   count = 100;
98   g_assert_cmpuint (0, ==, hb_aat_layout_feature_type_get_selector_infos (face, HB_AAT_LAYOUT_FEATURE_TYPE_INVALID,
99                                                                           0, &count, settings,
100                                                                           NULL));
101   g_assert_cmpuint (0, ==, count);
102 }
103
104 static void
105 test_aat_has (void)
106 {
107   hb_face_t *morx = hb_test_open_font_file ("fonts/aat-morx.ttf");
108   hb_face_t *trak;
109   g_assert (hb_aat_layout_has_substitution (morx));
110   hb_face_destroy (morx);
111
112   trak = hb_test_open_font_file ("fonts/aat-trak.ttf");
113   g_assert (hb_aat_layout_has_tracking (trak));
114   hb_face_destroy (trak);
115 }
116
117 int
118 main (int argc, char **argv)
119 {
120   unsigned int status;
121   hb_test_init (&argc, &argv);
122
123   hb_test_add (test_aat_get_feature_types);
124   hb_test_add (test_aat_get_feature_selectors);
125   hb_test_add (test_aat_has);
126
127   face = hb_test_open_font_file ("fonts/aat-feat.ttf");
128   sbix = hb_test_open_font_file ("fonts/chromacheck-sbix.ttf");
129   status = hb_test_run ();
130   hb_face_destroy (sbix);
131   hb_face_destroy (face);
132   return status;
133 }