• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2019  Ebrahim Byagowi
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 
25 #include "hb-test.h"
26 
27 #include <hb-ot.h>
28 
29 /* Unit tests for hb-ot-meta.h */
30 
31 static void
test_ot_meta_get_entries(void)32 test_ot_meta_get_entries (void)
33 {
34   hb_face_t *face = hb_test_open_font_file ("fonts/meta.ttf");
35   hb_ot_meta_tag_t entries[2];
36 
37   unsigned int entries_count = 2;
38   g_assert_cmpint (hb_ot_meta_get_entry_tags (face, 0, &entries_count, entries), ==, 5);
39   g_assert_cmpint (entries_count, ==, 2);
40   g_assert_cmpint (entries[0], ==, HB_TAG ('a','p','p','l'));
41   g_assert_cmpint (entries[1], ==, HB_TAG ('b','i','l','d'));
42 
43   entries_count = 1;
44   g_assert_cmpint (hb_ot_meta_get_entry_tags (face, 2, &entries_count, entries), ==, 5);
45   g_assert_cmpint (entries_count, ==, 1);
46   g_assert_cmpint (entries[0], ==, HB_TAG ('d','l','n','g'));
47 
48   entries_count = 2;
49   g_assert_cmpint (hb_ot_meta_get_entry_tags (face, 4, &entries_count, entries), ==, 5);
50   g_assert_cmpint (entries_count, ==, 1);
51   g_assert_cmpint (entries[0], ==, HB_TAG ('s','l','n','g'));
52 
53   hb_face_destroy (face);
54 }
55 
56 static void
test_ot_meta_reference_entry(void)57 test_ot_meta_reference_entry (void)
58 {
59   hb_face_t *face = hb_test_open_font_file ("fonts/meta.ttf");
60   hb_blob_t *dlng = hb_ot_meta_reference_entry (face, HB_OT_META_TAG_DESIGN_LANGUAGES);
61   g_assert_cmpint (hb_blob_get_length (dlng), ==, 8);
62   g_assert_cmpmem (hb_blob_get_data (dlng, NULL), 8, "ar,de,fa", 8);
63   hb_blob_destroy (dlng);
64   hb_blob_t *fslf = hb_ot_meta_reference_entry (face, (hb_ot_meta_tag_t) HB_TAG ('f','s','l','f'));
65   g_assert_cmpint (hb_blob_get_length (fslf), ==, 12);
66   hb_blob_destroy (fslf);
67   hb_blob_t *nacl = hb_ot_meta_reference_entry (face, (hb_ot_meta_tag_t) HB_TAG ('n','a','c','l'));
68   g_assert_cmpint (hb_blob_get_length (nacl), ==, 0);
69   hb_blob_destroy (nacl);
70   hb_blob_t *slng = hb_ot_meta_reference_entry (face, HB_OT_META_TAG_SUPPORTED_LANGUAGES);
71   g_assert_cmpint (hb_blob_get_length (slng), ==, 11);
72   g_assert_cmpmem (hb_blob_get_data (slng, NULL), 11, "ar,de,en,fa", 11);
73   hb_blob_destroy (slng);
74   hb_face_destroy (face);
75 }
76 
77 int
main(int argc,char ** argv)78 main (int argc, char **argv)
79 {
80   hb_test_init (&argc, &argv);
81   hb_test_add (test_ot_meta_get_entries);
82   hb_test_add (test_ot_meta_reference_entry);
83   return hb_test_run ();
84 }
85