blob: c41a12114e0ca8b0c281286dd15312fac7db5cd1 [file] [log] [blame]
Garret Rieger15fc45b2018-02-21 17:59:57 -08001/*
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
Garret Rieger15fc45b2018-02-21 17:59:57 -080027#include "hb-test.h"
28#include "hb-subset-test.h"
29
30/* Unit tests for hdmx subsetting */
31
32
33static void
34test_subset_hdmx_simple_subset (void)
35{
Ebrahim Byagowic1108782018-10-21 11:07:17 +033036 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");
Garret Rieger15fc45b2018-02-21 17:59:57 -080038
39 hb_set_t *codepoints = hb_set_create ();
Chun-wei Fan831d4a22018-03-12 13:48:55 +080040 hb_face_t *face_abc_subset;
Garret Rieger15fc45b2018-02-21 17:59:57 -080041 hb_set_add (codepoints, 'a');
42 hb_set_add (codepoints, 'c');
Chun-wei Fan831d4a22018-03-12 13:48:55 +080043 face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints));
Garret Rieger15fc45b2018-02-21 17:59:57 -080044 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
53static void
Garret Rieger21bf1472018-09-05 18:04:52 -070054test_subset_hdmx_multiple_device_records (void)
55{
Ebrahim Byagowic1108782018-10-21 11:07:17 +033056 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");
Garret Rieger21bf1472018-09-05 18:04:52 -070058
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
72static void
Garret Rieger3531efd2018-03-20 16:31:21 -070073test_subset_hdmx_invalid (void)
74{
Ebrahim Byagowic1108782018-10-21 11:07:17 +033075 hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/crash-ccc61c92d589f895174cdef6ff2e3b20e9999a1a");
Garret Rieger3531efd2018-03-20 16:31:21 -070076
77 hb_subset_input_t *input = hb_subset_input_create_or_fail ();
78 hb_set_t *codepoints = hb_subset_input_unicode_set (input);
Chun-wei Fan40351582018-07-25 18:26:10 +080079 hb_face_t *subset;
80
Garret Rieger3531efd2018-03-20 16:31:21 -070081 hb_set_add (codepoints, 'a');
82 hb_set_add (codepoints, 'b');
83 hb_set_add (codepoints, 'c');
84
Garret Rieger9ab751a2021-06-23 13:38:47 -070085 subset = hb_subset_or_fail (face, input);
86 g_assert (!subset);
Garret Rieger3531efd2018-03-20 16:31:21 -070087
88 hb_subset_input_destroy (input);
Garret Rieger3531efd2018-03-20 16:31:21 -070089 hb_face_destroy (subset);
90 hb_face_destroy (face);
91}
92
93static void
Garret Rieger15fc45b2018-02-21 17:59:57 -080094test_subset_hdmx_noop (void)
95{
Ebrahim Byagowic1108782018-10-21 11:07:17 +033096 hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
Garret Rieger15fc45b2018-02-21 17:59:57 -080097
98 hb_set_t *codepoints = hb_set_create();
Chun-wei Fan831d4a22018-03-12 13:48:55 +080099 hb_face_t *face_abc_subset;
Garret Rieger15fc45b2018-02-21 17:59:57 -0800100 hb_set_add (codepoints, 'a');
101 hb_set_add (codepoints, 'b');
102 hb_set_add (codepoints, 'c');
Chun-wei Fan831d4a22018-03-12 13:48:55 +0800103 face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints));
Garret Rieger15fc45b2018-02-21 17:59:57 -0800104 hb_set_destroy (codepoints);
105
106 hb_subset_test_check (face_abc, face_abc_subset, HB_TAG ('h','d','m','x'));
107
108 hb_face_destroy (face_abc_subset);
109 hb_face_destroy (face_abc);
110}
111
112int
113main (int argc, char **argv)
114{
115 hb_test_init (&argc, &argv);
116
117 hb_test_add (test_subset_hdmx_simple_subset);
Garret Rieger21bf1472018-09-05 18:04:52 -0700118 hb_test_add (test_subset_hdmx_multiple_device_records);
Garret Rieger3531efd2018-03-20 16:31:21 -0700119 hb_test_add (test_subset_hdmx_invalid);
Garret Rieger15fc45b2018-02-21 17:59:57 -0800120 hb_test_add (test_subset_hdmx_noop);
121
122 return hb_test_run();
123}