test-ot-meta.c 3.1 KB

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