Imported Upstream version 2.6.7
[platform/upstream/harfbuzz.git] / test / api / test-subset-colr.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 COLR subsetting */
31
32 static void
33 test_subset_colr_noop (void)
34 {
35   hb_face_t *face = hb_test_open_font_file ("fonts/TwemojiMozilla.subset.ttf");
36
37   hb_set_t *codepoints = hb_set_create ();
38   hb_face_t *face_subset;
39   hb_set_add (codepoints, '2');
40   hb_set_add (codepoints, 0x3297);
41   hb_set_add (codepoints, 0x3299);
42   face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
43   hb_set_destroy (codepoints);
44
45   hb_subset_test_check (face, face_subset, HB_TAG ('C','O','L','R'));
46
47   hb_face_destroy (face_subset);
48   hb_face_destroy (face);
49 }
50
51 static void
52 test_subset_colr_keep_one_colr_glyph (void)
53 {
54   hb_face_t *face = hb_test_open_font_file ("fonts/TwemojiMozilla.subset.ttf");
55   hb_face_t *face_expected = hb_test_open_font_file ("fonts/TwemojiMozilla.subset.default.3297.ttf");
56
57   hb_set_t *codepoints = hb_set_create ();
58   hb_face_t *face_subset;
59   hb_set_add (codepoints, 0x3297);
60   face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
61   hb_set_destroy (codepoints);
62
63   hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','O','L','R'));
64
65   hb_face_destroy (face_subset);
66   hb_face_destroy (face_expected);
67   hb_face_destroy (face);
68 }
69
70 static void
71 test_subset_colr_keep_mixed_glyph (void)
72 {
73   hb_face_t *face = hb_test_open_font_file ("fonts/TwemojiMozilla.subset.ttf");
74   hb_face_t *face_expected = hb_test_open_font_file ("fonts/TwemojiMozilla.subset.default.32,3299.ttf");
75
76   hb_set_t *codepoints = hb_set_create ();
77   hb_face_t *face_subset;
78   hb_set_add (codepoints, '2');
79   hb_set_add (codepoints, 0x3299);
80   face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
81   hb_set_destroy (codepoints);
82
83   hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','O','L','R'));
84
85   hb_face_destroy (face_subset);
86   hb_face_destroy (face_expected);
87   hb_face_destroy (face);
88 }
89
90 static void
91 test_subset_colr_keep_no_colr_glyph (void)
92 {
93   hb_face_t *face = hb_test_open_font_file ("fonts/TwemojiMozilla.subset.ttf");
94   hb_face_t *face_expected = hb_test_open_font_file ("fonts/TwemojiMozilla.subset.default.32.ttf");
95
96   hb_set_t *codepoints = hb_set_create ();
97   hb_face_t *face_subset;
98   hb_set_add (codepoints, '2');
99   face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
100   hb_set_destroy (codepoints);
101
102   hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','O','L','R'));
103
104   hb_face_destroy (face_subset);
105   hb_face_destroy (face_expected);
106   hb_face_destroy (face);
107 }
108
109 int
110 main (int argc, char **argv)
111 {
112   hb_test_init (&argc, &argv);
113
114   hb_test_add (test_subset_colr_noop);
115   hb_test_add (test_subset_colr_keep_one_colr_glyph);
116   hb_test_add (test_subset_colr_keep_mixed_glyph);
117   hb_test_add (test_subset_colr_keep_no_colr_glyph);
118
119   return hb_test_run();
120 }