Merge branch 'upstream' into tizen
[platform/upstream/harfbuzz.git] / test / api / test-subset-cbdt.c
1 /*
2  * Copyright © 2020  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  * Google Author(s): Calder Kitagawa
25  */
26
27 #include "hb-test.h"
28 #include "hb-subset-test.h"
29
30 /* Unit tests for CBDT/CBLC subsetting */
31
32 static void
33 test_subset_cbdt_noop (void)
34 {
35   hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.ttf");
36
37   hb_set_t *codepoints = hb_set_create ();
38   hb_face_t *face_subset;
39   hb_set_add (codepoints, 0x38);
40   hb_set_add (codepoints, 0x39);
41   hb_set_add (codepoints, 0xAE);
42   hb_set_add (codepoints, 0x2049);
43   hb_set_add (codepoints, 0x20E3);
44   face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
45   hb_set_destroy (codepoints);
46
47   hb_subset_test_check (face, face_subset, HB_TAG ('C','B','L','C'));
48   hb_subset_test_check (face, face_subset, HB_TAG ('C','B','D','T'));
49
50   hb_face_destroy (face_subset);
51   hb_face_destroy (face);
52 }
53
54 static void
55 test_subset_cbdt_keep_one (void)
56 {
57   hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.ttf");
58   hb_face_t *face_expected = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.default.39.ttf");
59
60   hb_set_t *codepoints = hb_set_create ();
61   hb_face_t *face_subset;
62   hb_set_add (codepoints, 0x39);
63   face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
64   hb_set_destroy (codepoints);
65
66   hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','L','C'));
67   hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','D','T'));
68
69   hb_face_destroy (face_subset);
70   hb_face_destroy (face_expected);
71   hb_face_destroy (face);
72 }
73
74 static void
75 test_subset_cbdt_keep_one_last_subtable (void)
76 {
77   hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.ttf");
78   hb_face_t *face_expected = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.default.2049.ttf");
79
80   hb_set_t *codepoints = hb_set_create ();
81   hb_face_t *face_subset;
82   hb_set_add (codepoints, 0x2049);
83   face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
84   hb_set_destroy (codepoints);
85
86   hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','L','C'));
87   hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','D','T'));
88
89   hb_face_destroy (face_subset);
90   hb_face_destroy (face_expected);
91   hb_face_destroy (face);
92 }
93
94 static void
95 test_subset_cbdt_keep_multiple_subtables (void)
96 {
97   hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.multiple_size_tables.ttf");
98   hb_face_t *face_expected = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.multiple_size_tables.default.38,AE,2049.ttf");
99
100   hb_set_t *codepoints = hb_set_create ();
101   hb_face_t *face_subset;
102   hb_set_add (codepoints, 0x38);
103   hb_set_add (codepoints, 0xAE);
104   hb_set_add (codepoints, 0x2049);
105   face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
106   hb_set_destroy (codepoints);
107
108   hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','L','C'));
109   hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','D','T'));
110
111   hb_face_destroy (face_subset);
112   hb_face_destroy (face_expected);
113   hb_face_destroy (face);
114 }
115
116 static void
117 test_subset_cbdt_index_format_3 (void)
118 {
119   hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.index_format3.ttf");
120   hb_face_t *face_expected = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.index_format3.default.38,AE,2049.ttf");
121
122   hb_set_t *codepoints = hb_set_create ();
123   hb_face_t *face_subset;
124   hb_set_add (codepoints, 0x38);
125   hb_set_add (codepoints, 0xAE);
126   hb_set_add (codepoints, 0x2049);
127   face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
128   hb_set_destroy (codepoints);
129
130   hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','L','C'));
131   hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','D','T'));
132
133   hb_face_destroy (face_subset);
134   hb_face_destroy (face_expected);
135   hb_face_destroy (face);
136 }
137
138 // TODO: add support/tests for index formats 2,4,5 (image formats are treated as
139 // opaque blobs when subsetting so don't need to be tested separately).
140 // TODO: add a test that keeps no codepoints.
141
142 int
143 main (int argc, char **argv)
144 {
145   hb_test_init (&argc, &argv);
146
147   hb_test_add (test_subset_cbdt_noop);
148   hb_test_add (test_subset_cbdt_keep_one);
149   hb_test_add (test_subset_cbdt_keep_one_last_subtable);
150   // The following use manually crafted expectation files as they are not
151   // binary compatible with FontTools.
152   hb_test_add (test_subset_cbdt_keep_multiple_subtables);
153   // Can use FontTools after https://github.com/fonttools/fonttools/issues/1817
154   // is resolved.
155   hb_test_add (test_subset_cbdt_index_format_3);
156
157   return hb_test_run();
158 }