6d2bf06e1d352857025baf3d3d278f01c1d77604
[platform/upstream/harfbuzz.git] / test / api / test-subset.c
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 hb-subset-glyf.h */
31
32 static void
33 test_subset_32_tables (void)
34 {
35   hb_face_t *face = hb_subset_test_open_font("fonts/oom-6ef8c96d3710262511bcc730dce9c00e722cb653");
36
37   hb_subset_input_t *input = hb_subset_input_create_or_fail ();
38   hb_set_t *codepoints = hb_subset_input_unicode_set (input);
39   hb_set_add (codepoints, 'a');
40   hb_set_add (codepoints, 'b');
41   hb_set_add (codepoints, 'c');
42
43   hb_subset_profile_t *profile = hb_subset_profile_create();
44   hb_face_t *subset = hb_subset (face, profile, input);
45   g_assert (subset);
46   g_assert (subset != hb_face_get_empty ());
47
48   hb_subset_input_destroy (input);
49   hb_subset_profile_destroy (profile);
50   hb_face_destroy (subset);
51   hb_face_destroy (face);
52 }
53
54 static void
55 test_subset_no_inf_loop (void)
56 {
57   hb_face_t *face = hb_subset_test_open_font("fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5521982557782016");
58
59   hb_subset_input_t *input = hb_subset_input_create_or_fail ();
60   hb_set_t *codepoints = hb_subset_input_unicode_set (input);
61   hb_set_add (codepoints, 'a');
62   hb_set_add (codepoints, 'b');
63   hb_set_add (codepoints, 'c');
64
65   hb_subset_profile_t *profile = hb_subset_profile_create();
66   hb_face_t *subset = hb_subset (face, profile, input);
67   g_assert (subset);
68   g_assert (subset == hb_face_get_empty ());
69
70   hb_subset_input_destroy (input);
71   hb_subset_profile_destroy (profile);
72   hb_face_destroy (subset);
73   hb_face_destroy (face);
74 }
75
76 static void
77 test_subset_crash (void)
78 {
79   hb_face_t *face = hb_subset_test_open_font("fonts/crash-4b60576767ee4d9fe1cc10959d89baf73d4e8249");
80
81   hb_subset_input_t *input = hb_subset_input_create_or_fail ();
82   hb_set_t *codepoints = hb_subset_input_unicode_set (input);
83   hb_set_add (codepoints, 'a');
84   hb_set_add (codepoints, 'b');
85   hb_set_add (codepoints, 'c');
86
87   hb_subset_profile_t *profile = hb_subset_profile_create();
88   hb_face_t *subset = hb_subset (face, profile, input);
89   g_assert (subset);
90   g_assert (subset == hb_face_get_empty ());
91
92   hb_subset_input_destroy (input);
93   hb_subset_profile_destroy (profile);
94   hb_face_destroy (subset);
95   hb_face_destroy (face);
96 }
97
98 int
99 main (int argc, char **argv)
100 {
101   hb_test_init (&argc, &argv);
102
103   hb_test_add (test_subset_32_tables);
104   hb_test_add (test_subset_no_inf_loop);
105   hb_test_add (test_subset_crash);
106
107   return hb_test_run();
108 }