Imported Upstream version 2.6.7
[platform/upstream/harfbuzz.git] / test / api / test-ot-ligature-carets.c
1 /*
2  * Copyright © 2018  Ebrahim Byagowi
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
26 #include "hb-test.h"
27
28 #include <hb-ot.h>
29
30 static void
31 test_ot_layout_get_ligature_carets_aat_lcar (void)
32 {
33   hb_face_t *face = hb_test_open_font_file ("fonts/lcar.ttf");
34   hb_font_t *font = hb_font_create (face);
35   hb_font_set_scale (font, hb_face_get_upem (face) * 2, hb_face_get_upem (face) * 4);
36
37   hb_position_t caret_array[16];
38
39   /* a normal call */
40   {
41     unsigned caret_count = 16;
42     g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
43                                                                98, 0, &caret_count,
44                                                                caret_array));
45
46     g_assert_cmpuint (2, ==, caret_count);
47     g_assert_cmpuint (1130, ==, caret_array[0]);
48     g_assert_cmpuint (2344, ==, caret_array[1]);
49   }
50
51   /* RTL, maybe needs to be tweaked however */
52   {
53     unsigned caret_count = 16;
54     g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_RTL,
55                                                                98, 0, &caret_count,
56                                                                caret_array));
57
58     g_assert_cmpuint (2, ==, caret_count);
59     g_assert_cmpuint (1130, ==, caret_array[0]);
60     g_assert_cmpuint (2344, ==, caret_array[1]);
61   }
62
63   /* bottom to top call, bigger caret positions as the specified scaling */
64   {
65     unsigned caret_count = 16;
66     g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_BTT,
67                                                                98, 0, &caret_count,
68                                                                caret_array));
69
70     g_assert_cmpuint (2, ==, caret_count);
71     g_assert_cmpuint (2260, ==, caret_array[0]);
72     g_assert_cmpuint (4688, ==, caret_array[1]);
73   }
74
75   /* the same glyph as above but with offset */
76   {
77     caret_array[1] = 123;
78
79     unsigned caret_count = 16;
80     g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_BTT,
81                                                                98, 1, &caret_count,
82                                                                caret_array));
83
84     g_assert_cmpuint (1, ==, caret_count);
85     g_assert_cmpuint (4688, ==, caret_array[0]);
86
87     g_assert_cmpuint (123, ==, caret_array[1]);
88   }
89
90   /* empty carets */
91   {
92     unsigned caret_count = 16;
93     g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
94                                                                97, 0, &caret_count,
95                                                                caret_array));
96
97     g_assert_cmpuint (0, ==, caret_count);
98   }
99
100   hb_font_destroy (font);
101   hb_face_destroy (face);
102 }
103
104 static void
105 test_ot_layout_get_ligature_carets_ot_gsub (void)
106 {
107   hb_face_t *face = hb_test_open_font_file ("fonts/NotoNastaliqUrdu-Regular.ttf");
108   hb_font_t *font = hb_font_create (face);
109   hb_font_set_scale (font, hb_face_get_upem (face) * 2, hb_face_get_upem (face) * 4);
110
111   hb_position_t caret_array[16];
112
113   /* call with no result */
114   {
115     unsigned caret_count = 16;
116     g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
117                                                                188, 0, &caret_count,
118                                                                caret_array));
119
120     g_assert_cmpuint (0, ==, caret_count);
121   }
122
123   /* call with no result and some offset */
124   {
125     unsigned caret_count = 16;
126     g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
127                                                                188, 10, &caret_count,
128                                                                caret_array));
129
130     g_assert_cmpuint (0, ==, caret_count);
131   }
132
133   /* a glyph with 3 ligature carets */
134   {
135     unsigned caret_count = 16;
136     g_assert_cmpuint (3, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
137                                                                1020, 0, &caret_count,
138                                                                caret_array));
139
140     g_assert_cmpuint (3, ==, caret_count);
141     g_assert_cmpuint (2718, ==, caret_array[0]);
142     g_assert_cmpuint (5438, ==, caret_array[1]);
143     g_assert_cmpuint (8156, ==, caret_array[2]);
144   }
145
146   /* the same glyph as above but with offset */
147   {
148     caret_array[2] = 123;
149
150     unsigned caret_count = 16;
151     g_assert_cmpuint (3, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
152                                                                1020, 1, &caret_count,
153                                                                caret_array));
154
155     g_assert_cmpuint (2, ==, caret_count);
156     g_assert_cmpuint (5438, ==, caret_array[0]);
157     g_assert_cmpuint (8156, ==, caret_array[1]);
158
159     g_assert_cmpuint (123, ==, caret_array[2]);
160   }
161
162   /* the same glyph as above but with another offset */
163   {
164     unsigned caret_count = 16;
165     g_assert_cmpuint (3, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
166                                                                1020, 2, &caret_count,
167                                                                caret_array));
168
169     g_assert_cmpuint (1, ==, caret_count);
170     g_assert_cmpuint (8156, ==, caret_array[0]);
171   }
172
173   /* call with no result */
174   {
175     unsigned caret_count = 16;
176     g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
177                                                                1021, 0, &caret_count,
178                                                                caret_array));
179
180     g_assert_cmpuint (0, ==, caret_count);
181   }
182
183   /* a glyph with 1 ligature caret */
184   {
185     unsigned caret_count = 16;
186     g_assert_cmpuint (1, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
187                                                                1022, 0, &caret_count,
188                                                                caret_array));
189
190     g_assert_cmpuint (1, ==, caret_count);
191     g_assert_cmpuint (3530, ==, caret_array[0]);
192   }
193
194   /* the same glyph as above but with offset */
195   {
196     unsigned caret_count = 16;
197     g_assert_cmpuint (1, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
198                                                                1022, 1, &caret_count,
199                                                                caret_array));
200
201     g_assert_cmpuint (0, ==, caret_count);
202   }
203
204   /* a glyph with 2 ligature carets */
205   {
206     unsigned caret_count = 16;
207     g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
208                                                                1023, 0, &caret_count,
209                                                                caret_array));
210
211     g_assert_cmpuint (2, ==, caret_count);
212     g_assert_cmpuint (2352, ==, caret_array[0]);
213     g_assert_cmpuint (4706, ==, caret_array[1]);
214   }
215
216   hb_font_destroy (font);
217   hb_face_destroy (face);
218 }
219
220 static void
221 test_ot_layout_get_ligature_carets_empty (void)
222 {
223   hb_face_t *face = hb_face_get_empty ();
224   hb_font_t *font = hb_font_create (face);
225   hb_font_set_scale (font, hb_face_get_upem (face) * 2, hb_face_get_upem (face) * 4);
226
227   hb_position_t caret_array[3];
228   unsigned int caret_count = 3;
229   g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_RTL,
230                                                              1024, 0, &caret_count,
231                                                              caret_array));
232
233   g_assert_cmpuint (0, ==, caret_count);
234
235   hb_font_destroy (font);
236   hb_face_destroy (face);
237 }
238
239 int
240 main (int argc, char **argv)
241 {
242   g_test_init (&argc, &argv, NULL);
243
244   hb_test_add (test_ot_layout_get_ligature_carets_aat_lcar);
245   hb_test_add (test_ot_layout_get_ligature_carets_ot_gsub);
246   hb_test_add (test_ot_layout_get_ligature_carets_empty);
247
248   return hb_test_run ();
249 }