Garret Rieger | 15fc45b | 2018-02-21 17:59:57 -0800 | [diff] [blame] | 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 | |
Garret Rieger | 15fc45b | 2018-02-21 17:59:57 -0800 | [diff] [blame] | 27 | #include "hb-test.h" |
| 28 | #include "hb-subset-test.h" |
| 29 | |
| 30 | /* Unit tests for hdmx subsetting */ |
| 31 | |
| 32 | |
| 33 | static void |
| 34 | test_subset_hdmx_simple_subset (void) |
| 35 | { |
Ebrahim Byagowi | c110878 | 2018-10-21 11:07:17 +0330 | [diff] [blame] | 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"); |
Garret Rieger | 15fc45b | 2018-02-21 17:59:57 -0800 | [diff] [blame] | 38 | |
| 39 | hb_set_t *codepoints = hb_set_create (); |
Chun-wei Fan | 831d4a2 | 2018-03-12 13:48:55 +0800 | [diff] [blame] | 40 | hb_face_t *face_abc_subset; |
Garret Rieger | 15fc45b | 2018-02-21 17:59:57 -0800 | [diff] [blame] | 41 | hb_set_add (codepoints, 'a'); |
| 42 | hb_set_add (codepoints, 'c'); |
Chun-wei Fan | 831d4a2 | 2018-03-12 13:48:55 +0800 | [diff] [blame] | 43 | face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints)); |
Garret Rieger | 15fc45b | 2018-02-21 17:59:57 -0800 | [diff] [blame] | 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 |
Garret Rieger | 21bf147 | 2018-09-05 18:04:52 -0700 | [diff] [blame] | 54 | test_subset_hdmx_multiple_device_records (void) |
| 55 | { |
Ebrahim Byagowi | c110878 | 2018-10-21 11:07:17 +0330 | [diff] [blame] | 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"); |
Garret Rieger | 21bf147 | 2018-09-05 18:04:52 -0700 | [diff] [blame] | 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 |
Garret Rieger | 3531efd | 2018-03-20 16:31:21 -0700 | [diff] [blame] | 73 | test_subset_hdmx_invalid (void) |
| 74 | { |
Ebrahim Byagowi | c110878 | 2018-10-21 11:07:17 +0330 | [diff] [blame] | 75 | hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/crash-ccc61c92d589f895174cdef6ff2e3b20e9999a1a"); |
Garret Rieger | 3531efd | 2018-03-20 16:31:21 -0700 | [diff] [blame] | 76 | |
| 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 Fan | 4035158 | 2018-07-25 18:26:10 +0800 | [diff] [blame] | 79 | hb_face_t *subset; |
| 80 | |
Garret Rieger | 3531efd | 2018-03-20 16:31:21 -0700 | [diff] [blame] | 81 | hb_set_add (codepoints, 'a'); |
| 82 | hb_set_add (codepoints, 'b'); |
| 83 | hb_set_add (codepoints, 'c'); |
| 84 | |
Garret Rieger | 9ab751a | 2021-06-23 13:38:47 -0700 | [diff] [blame] | 85 | subset = hb_subset_or_fail (face, input); |
| 86 | g_assert (!subset); |
Garret Rieger | 3531efd | 2018-03-20 16:31:21 -0700 | [diff] [blame] | 87 | |
| 88 | hb_subset_input_destroy (input); |
Garret Rieger | 3531efd | 2018-03-20 16:31:21 -0700 | [diff] [blame] | 89 | hb_face_destroy (subset); |
| 90 | hb_face_destroy (face); |
| 91 | } |
| 92 | |
| 93 | static void |
Garret Rieger | 15fc45b | 2018-02-21 17:59:57 -0800 | [diff] [blame] | 94 | test_subset_hdmx_noop (void) |
| 95 | { |
Ebrahim Byagowi | c110878 | 2018-10-21 11:07:17 +0330 | [diff] [blame] | 96 | hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf"); |
Garret Rieger | 15fc45b | 2018-02-21 17:59:57 -0800 | [diff] [blame] | 97 | |
| 98 | hb_set_t *codepoints = hb_set_create(); |
Chun-wei Fan | 831d4a2 | 2018-03-12 13:48:55 +0800 | [diff] [blame] | 99 | hb_face_t *face_abc_subset; |
Garret Rieger | 15fc45b | 2018-02-21 17:59:57 -0800 | [diff] [blame] | 100 | hb_set_add (codepoints, 'a'); |
| 101 | hb_set_add (codepoints, 'b'); |
| 102 | hb_set_add (codepoints, 'c'); |
Chun-wei Fan | 831d4a2 | 2018-03-12 13:48:55 +0800 | [diff] [blame] | 103 | face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints)); |
Garret Rieger | 15fc45b | 2018-02-21 17:59:57 -0800 | [diff] [blame] | 104 | 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 | |
| 112 | int |
| 113 | main (int argc, char **argv) |
| 114 | { |
| 115 | hb_test_init (&argc, &argv); |
| 116 | |
| 117 | hb_test_add (test_subset_hdmx_simple_subset); |
Garret Rieger | 21bf147 | 2018-09-05 18:04:52 -0700 | [diff] [blame] | 118 | hb_test_add (test_subset_hdmx_multiple_device_records); |
Garret Rieger | 3531efd | 2018-03-20 16:31:21 -0700 | [diff] [blame] | 119 | hb_test_add (test_subset_hdmx_invalid); |
Garret Rieger | 15fc45b | 2018-02-21 17:59:57 -0800 | [diff] [blame] | 120 | hb_test_add (test_subset_hdmx_noop); |
| 121 | |
| 122 | return hb_test_run(); |
| 123 | } |