(root)/
harfbuzz-8.3.0/
test/
api/
test-subset-hdmx.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 hdmx subsetting */
      31  
      32  
      33  static 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
      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
      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_or_fail (face, input);
      86    g_assert (!subset);
      87  
      88    hb_subset_input_destroy (input);
      89    hb_face_destroy (subset);
      90    hb_face_destroy (face);
      91  }
      92  
      93  static void
      94  test_subset_hdmx_noop (void)
      95  {
      96    hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
      97  
      98    hb_set_t *codepoints = hb_set_create();
      99    hb_face_t *face_abc_subset;
     100    hb_set_add (codepoints, 'a');
     101    hb_set_add (codepoints, 'b');
     102    hb_set_add (codepoints, 'c');
     103    face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints));
     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);
     118    hb_test_add (test_subset_hdmx_multiple_device_records);
     119    hb_test_add (test_subset_hdmx_invalid);
     120    hb_test_add (test_subset_hdmx_noop);
     121  
     122    return hb_test_run();
     123  }