• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * Google Author(s): Garret Rieger
25  */
26 
27 #include "hb-test.h"
28 #include "hb-subset-test.h"
29 
30 /* Unit tests for hdmx subsetting */
31 
32 
33 static void
test_subset_hdmx_simple_subset(void)34 test_subset_hdmx_simple_subset (void)
35 {
36   hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
37   hb_face_t *face_ac = hb_test_open_font_file ("fonts/Roboto-Regular.ac.ttf");
38 
39   hb_set_t *codepoints = hb_set_create ();
40   hb_face_t *face_abc_subset;
41   hb_set_add (codepoints, 'a');
42   hb_set_add (codepoints, 'c');
43   face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints));
44   hb_set_destroy (codepoints);
45 
46   hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('h','d','m','x'));
47 
48   hb_face_destroy (face_abc_subset);
49   hb_face_destroy (face_abc);
50   hb_face_destroy (face_ac);
51 }
52 
53 static void
test_subset_hdmx_multiple_device_records(void)54 test_subset_hdmx_multiple_device_records (void)
55 {
56   hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.multihdmx.abc.ttf");
57   hb_face_t *face_a = hb_test_open_font_file ("fonts/Roboto-Regular.multihdmx.a.ttf");
58 
59   hb_set_t *codepoints = hb_set_create ();
60   hb_face_t *face_abc_subset;
61   hb_set_add (codepoints, 'a');
62   face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints));
63   hb_set_destroy (codepoints);
64 
65   hb_subset_test_check (face_a, face_abc_subset, HB_TAG ('h','d','m','x'));
66 
67   hb_face_destroy (face_abc_subset);
68   hb_face_destroy (face_abc);
69   hb_face_destroy (face_a);
70 }
71 
72 static void
test_subset_hdmx_invalid(void)73 test_subset_hdmx_invalid (void)
74 {
75   hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/crash-ccc61c92d589f895174cdef6ff2e3b20e9999a1a");
76 
77   hb_subset_input_t *input = hb_subset_input_create_or_fail ();
78   hb_set_t *codepoints = hb_subset_input_unicode_set (input);
79   hb_face_t *subset;
80 
81   hb_set_add (codepoints, 'a');
82   hb_set_add (codepoints, 'b');
83   hb_set_add (codepoints, 'c');
84 
85   subset = hb_subset (face, input);
86   g_assert (subset);
87   g_assert (subset == hb_face_get_empty ());
88 
89   hb_subset_input_destroy (input);
90   hb_face_destroy (subset);
91   hb_face_destroy (face);
92 }
93 
94 static void
test_subset_hdmx_noop(void)95 test_subset_hdmx_noop (void)
96 {
97   hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
98 
99   hb_set_t *codepoints = hb_set_create();
100   hb_face_t *face_abc_subset;
101   hb_set_add (codepoints, 'a');
102   hb_set_add (codepoints, 'b');
103   hb_set_add (codepoints, 'c');
104   face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints));
105   hb_set_destroy (codepoints);
106 
107   hb_subset_test_check (face_abc, face_abc_subset, HB_TAG ('h','d','m','x'));
108 
109   hb_face_destroy (face_abc_subset);
110   hb_face_destroy (face_abc);
111 }
112 
113 int
main(int argc,char ** argv)114 main (int argc, char **argv)
115 {
116   hb_test_init (&argc, &argv);
117 
118   hb_test_add (test_subset_hdmx_simple_subset);
119   hb_test_add (test_subset_hdmx_multiple_device_records);
120   hb_test_add (test_subset_hdmx_invalid);
121   hb_test_add (test_subset_hdmx_noop);
122 
123   return hb_test_run();
124 }
125