xref: /aosp_15_r20/external/harfbuzz_ng/test/api/test-subset-repacker.c (revision 2d1272b857b1f7575e6e246373e1cb218663db8a)
1 /*
2  * Copyright © 2022  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 
26 #include "hb-test.h"
27 #include "hb-subset-test.h"
28 
29 #ifdef HB_EXPERIMENTAL_API
30 #include "hb-subset-repacker.h"
31 
32 char test_gsub_data[106] = "\x0\x1\x0\x0\x0\xa\x0\x1e\x0\x2c\x0\x1\x6c\x61\x74\x6e\x0\x8\x0\x4\x0\x0\x0\x0\xff\xff\x0\x1\x0\x0\x0\x1\x74\x65\x73\x74\x0\x8\x0\x0\x0\x1\x0\x1\x0\x2\x0\x2a\x0\x6\x0\x5\x0\x0\x0\x1\x0\x8\x0\x1\x0\x8\x0\x1\x0\xe\x0\x1\x0\x1\x0\x1\x0\x1\x0\x4\x0\x2\x0\x1\x0\x2\x0\x1\x0\x0\x0\x1\x0\x0\x0\x1\x0\x8\x0\x1\x0\x6\x0\x1\x0\x1\x0\x1\x0\x2";
33 
34 static void
test_hb_repack_with_cy_struct(void)35 test_hb_repack_with_cy_struct (void)
36 {
37   hb_object_t *hb_objs = calloc (15, sizeof (hb_object_t));
38 
39   hb_objs[0].head = &(test_gsub_data[100]);
40   hb_objs[0].tail = &(test_gsub_data[105]) + 1;
41   hb_objs[0].num_real_links = 0;
42   hb_objs[0].num_virtual_links = 0;
43   hb_objs[0].real_links = NULL;
44   hb_objs[0].virtual_links = NULL;
45 
46   hb_objs[1].head = &(test_gsub_data[94]);
47   hb_objs[1].tail = &(test_gsub_data[100]);
48   hb_objs[1].num_real_links = 1;
49   hb_objs[1].num_virtual_links = 0;
50   hb_objs[1].real_links = malloc (sizeof (hb_link_t));
51   hb_objs[1].real_links[0].width = 2;
52   hb_objs[1].real_links[0].position = 2;
53   hb_objs[1].real_links[0].objidx = 1;
54   hb_objs[1].virtual_links = NULL;
55 
56 
57   hb_objs[2].head = &(test_gsub_data[86]);
58   hb_objs[2].tail = &(test_gsub_data[94]);
59   hb_objs[2].num_real_links = 1;
60   hb_objs[2].num_virtual_links = 0;
61   hb_objs[2].real_links = malloc (sizeof (hb_link_t));
62   hb_objs[2].real_links[0].width = 2;
63   hb_objs[2].real_links[0].position = 6;
64   hb_objs[2].real_links[0].objidx = 2;
65   hb_objs[2].virtual_links = NULL;
66 
67   hb_objs[3].head = &(test_gsub_data[76]);
68   hb_objs[3].tail = &(test_gsub_data[86]);
69   hb_objs[3].num_real_links = 0;
70   hb_objs[3].num_virtual_links = 0;
71   hb_objs[3].real_links = NULL;
72   hb_objs[3].virtual_links = NULL;
73 
74   hb_objs[4].head = &(test_gsub_data[72]);
75   hb_objs[4].tail = &(test_gsub_data[76]);
76   hb_objs[4].num_real_links = 1;
77   hb_objs[4].num_virtual_links = 0;
78   hb_objs[4].real_links = malloc (sizeof (hb_link_t));
79   hb_objs[4].real_links[0].width = 2;
80   hb_objs[4].real_links[0].position = 2;
81   hb_objs[4].real_links[0].objidx = 4;
82   hb_objs[4].virtual_links = NULL;
83 
84   hb_objs[5].head = &(test_gsub_data[66]);
85   hb_objs[5].tail = &(test_gsub_data[72]);
86   hb_objs[5].num_real_links = 0;
87   hb_objs[5].num_virtual_links = 0;
88   hb_objs[5].real_links = NULL;
89   hb_objs[5].virtual_links = NULL;
90 
91   hb_objs[6].head = &(test_gsub_data[58]);
92   hb_objs[6].tail = &(test_gsub_data[66]);
93   hb_objs[6].num_real_links = 2;
94   hb_objs[6].num_virtual_links = 0;
95   hb_objs[6].real_links = calloc (2, sizeof (hb_link_t));
96   hb_objs[6].real_links[0].width = 2;
97   hb_objs[6].real_links[0].position = 6;
98   hb_objs[6].real_links[0].objidx = 5;
99   hb_objs[6].real_links[1].width = 2;
100   hb_objs[6].real_links[1].position = 2;
101   hb_objs[6].real_links[1].objidx = 6;
102   hb_objs[6].virtual_links = NULL;
103 
104   hb_objs[7].head = &(test_gsub_data[50]);
105   hb_objs[7].tail = &(test_gsub_data[58]);
106   hb_objs[7].num_real_links = 1;
107   hb_objs[7].num_virtual_links = 0;
108   hb_objs[7].real_links = malloc (sizeof (hb_link_t));
109   hb_objs[7].real_links[0].width = 2;
110   hb_objs[7].real_links[0].position = 6;
111   hb_objs[7].real_links[0].objidx = 7;
112   hb_objs[7].virtual_links = NULL;
113 
114   hb_objs[8].head = &(test_gsub_data[44]);
115   hb_objs[8].tail = &(test_gsub_data[50]);
116   hb_objs[8].num_real_links = 2;
117   hb_objs[8].num_virtual_links = 0;
118   hb_objs[8].real_links = calloc (2, sizeof (hb_link_t));
119   hb_objs[8].real_links[0].width = 2;
120   hb_objs[8].real_links[0].position = 2;
121   hb_objs[8].real_links[0].objidx = 3;
122   hb_objs[8].real_links[1].width = 2;
123   hb_objs[8].real_links[1].position = 4;
124   hb_objs[8].real_links[1].objidx = 8;
125   hb_objs[8].virtual_links = NULL;
126 
127   hb_objs[9].head = &(test_gsub_data[38]);
128   hb_objs[9].tail = &(test_gsub_data[44]);
129   hb_objs[9].num_real_links = 0;
130   hb_objs[9].num_virtual_links = 0;
131   hb_objs[9].real_links = NULL;
132   hb_objs[9].virtual_links = NULL;
133 
134   hb_objs[10].head = &(test_gsub_data[30]);
135   hb_objs[10].tail = &(test_gsub_data[38]);
136   hb_objs[10].num_real_links = 1;
137   hb_objs[10].num_virtual_links = 0;
138   hb_objs[10].real_links = malloc (sizeof (hb_link_t));
139   hb_objs[10].real_links[0].width = 2;
140   hb_objs[10].real_links[0].position = 6;
141   hb_objs[10].real_links[0].objidx = 10;
142   hb_objs[10].virtual_links = NULL;
143 
144   hb_objs[11].head = &(test_gsub_data[22]);
145   hb_objs[11].tail = &(test_gsub_data[30]);
146   hb_objs[11].num_real_links = 0;
147   hb_objs[11].num_virtual_links = 0;
148   hb_objs[11].real_links = NULL;
149   hb_objs[11].virtual_links = NULL;
150 
151   hb_objs[12].head = &(test_gsub_data[18]);
152   hb_objs[12].tail = &(test_gsub_data[22]);
153   hb_objs[12].num_real_links = 1;
154   hb_objs[12].num_virtual_links = 0;
155   hb_objs[12].real_links = malloc (sizeof (hb_link_t));
156   hb_objs[12].real_links[0].width = 2;
157   hb_objs[12].real_links[0].position = 0;
158   hb_objs[12].real_links[0].objidx = 12;
159   hb_objs[12].virtual_links = NULL;
160 
161   hb_objs[13].head = &(test_gsub_data[10]);
162   hb_objs[13].tail = &(test_gsub_data[18]);
163   hb_objs[13].num_real_links = 1;
164   hb_objs[13].num_virtual_links = 0;
165   hb_objs[13].real_links = malloc (sizeof (hb_link_t));
166   hb_objs[13].real_links[0].width = 2;
167   hb_objs[13].real_links[0].position = 6;
168   hb_objs[13].real_links[0].objidx = 13;
169   hb_objs[13].virtual_links = NULL;
170 
171   hb_objs[14].head = &(test_gsub_data[0]);
172   hb_objs[14].tail = &(test_gsub_data[10]);
173   hb_objs[14].num_real_links = 3;
174   hb_objs[14].num_virtual_links = 0;
175   hb_objs[14].real_links = calloc (3, sizeof (hb_link_t));
176   hb_objs[14].real_links[0].width = 2;
177   hb_objs[14].real_links[0].position = 8;
178   hb_objs[14].real_links[0].objidx = 9;
179   hb_objs[14].real_links[1].width = 2;
180   hb_objs[14].real_links[1].position = 6;
181   hb_objs[14].real_links[1].objidx = 11;
182   hb_objs[14].real_links[2].width = 2;
183   hb_objs[14].real_links[2].position = 4;
184   hb_objs[14].real_links[2].objidx = 14;
185   hb_objs[14].virtual_links = NULL;
186 
187   hb_blob_t *result = hb_subset_repack_or_fail (HB_TAG_NONE, hb_objs, 15);
188 
189   hb_face_t *face_expected = hb_test_open_font_file ("fonts/repacker_expected.otf");
190   hb_blob_t *expected_blob = hb_face_reference_table (face_expected, HB_TAG ('G','S','U','B'));
191   fprintf(stderr, "expected %d bytes, actual %d bytes\n", hb_blob_get_length(expected_blob), hb_blob_get_length (result));
192 
193   if (hb_blob_get_length (expected_blob) != 0 ||
194       hb_blob_get_length (result) != 0)
195     hb_test_assert_blobs_equal (expected_blob, result);
196 
197   hb_face_destroy (face_expected);
198   hb_blob_destroy (expected_blob);
199   hb_blob_destroy (result);
200 
201   for (unsigned i = 0 ; i < 15; i++)
202   {
203     if (hb_objs[i].real_links != NULL)
204       free (hb_objs[i].real_links);
205   }
206 
207   free (hb_objs);
208 }
209 
210 
211 int
main(int argc,char ** argv)212 main (int argc, char **argv)
213 {
214   hb_test_init (&argc, &argv);
215 
216   hb_test_add (test_hb_repack_with_cy_struct);
217 
218   return hb_test_run();
219 }
220 #else
main(int argc HB_UNUSED,char ** argv HB_UNUSED)221 int main (int argc HB_UNUSED, char **argv HB_UNUSED)
222 {
223   return 0;
224 }
225 #endif
226