test-collect-unicodes.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. #include "hb-test.h"
  27. #include "hb-subset-test.h"
  28. static void
  29. test_collect_unicodes_format4 (void)
  30. {
  31. hb_face_t *face = hb_test_open_font_file ("fonts/Roboto-Regular.abc.format4.ttf");
  32. hb_set_t *codepoints = hb_set_create();
  33. hb_codepoint_t cp;
  34. hb_face_collect_unicodes (face, codepoints);
  35. cp = HB_SET_VALUE_INVALID;
  36. g_assert (hb_set_next (codepoints, &cp));
  37. g_assert_cmpuint (0x61, ==, cp);
  38. g_assert (hb_set_next (codepoints, &cp));
  39. g_assert_cmpuint (0x62, ==, cp);
  40. g_assert (hb_set_next (codepoints, &cp));
  41. g_assert_cmpuint (0x63, ==, cp);
  42. g_assert (!hb_set_next (codepoints, &cp));
  43. hb_set_destroy (codepoints);
  44. hb_face_destroy (face);
  45. }
  46. static void
  47. test_collect_unicodes_format12_notdef (void)
  48. {
  49. hb_face_t *face = hb_test_open_font_file ("fonts/cmunrm.otf");
  50. hb_set_t *codepoints = hb_set_create();
  51. hb_codepoint_t cp;
  52. hb_face_collect_unicodes (face, codepoints);
  53. cp = HB_SET_VALUE_INVALID;
  54. g_assert (hb_set_next (codepoints, &cp));
  55. g_assert_cmpuint (0x20, ==, cp);
  56. g_assert (hb_set_next (codepoints, &cp));
  57. g_assert_cmpuint (0x21, ==, cp);
  58. g_assert (hb_set_next (codepoints, &cp));
  59. g_assert_cmpuint (0x22, ==, cp);
  60. hb_set_destroy (codepoints);
  61. hb_face_destroy (face);
  62. }
  63. static void
  64. test_collect_unicodes_format12 (void)
  65. {
  66. hb_face_t *face = hb_test_open_font_file ("fonts/Roboto-Regular.abc.format12.ttf");
  67. hb_set_t *codepoints = hb_set_create();
  68. hb_codepoint_t cp;
  69. hb_face_collect_unicodes (face, codepoints);
  70. cp = HB_SET_VALUE_INVALID;
  71. g_assert (hb_set_next (codepoints, &cp));
  72. g_assert_cmpuint (0x61, ==, cp);
  73. g_assert (hb_set_next (codepoints, &cp));
  74. g_assert_cmpuint (0x62, ==, cp);
  75. g_assert (hb_set_next (codepoints, &cp));
  76. g_assert_cmpuint (0x63, ==, cp);
  77. g_assert (!hb_set_next (codepoints, &cp));
  78. hb_set_destroy (codepoints);
  79. hb_face_destroy (face);
  80. }
  81. static void
  82. test_collect_unicodes (void)
  83. {
  84. hb_face_t *face = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
  85. hb_set_t *codepoints = hb_set_create();
  86. hb_set_t *codepoints2 = hb_set_create();
  87. hb_map_t *mapping = hb_map_create();
  88. hb_codepoint_t cp;
  89. hb_face_collect_unicodes (face, codepoints);
  90. hb_face_collect_nominal_glyph_mapping (face, mapping, codepoints2);
  91. g_assert (hb_set_is_equal (codepoints, codepoints2));
  92. g_assert_cmpuint (hb_set_get_population (codepoints), ==, 3);
  93. g_assert_cmpuint (hb_map_get_population (mapping), ==, 3);
  94. cp = HB_SET_VALUE_INVALID;
  95. g_assert (hb_set_next (codepoints, &cp));
  96. g_assert (hb_map_has (mapping, cp));
  97. g_assert_cmpuint (0x61, ==, cp);
  98. g_assert (hb_set_next (codepoints, &cp));
  99. g_assert (hb_map_has (mapping, cp));
  100. g_assert_cmpuint (0x62, ==, cp);
  101. g_assert (hb_set_next (codepoints, &cp));
  102. g_assert (hb_map_has (mapping, cp));
  103. g_assert_cmpuint (0x63, ==, cp);
  104. g_assert (!hb_set_next (codepoints, &cp));
  105. hb_set_destroy (codepoints);
  106. hb_set_destroy (codepoints2);
  107. hb_map_destroy (mapping);
  108. hb_face_destroy (face);
  109. }
  110. int
  111. main (int argc, char **argv)
  112. {
  113. hb_test_init (&argc, &argv);
  114. hb_test_add (test_collect_unicodes);
  115. hb_test_add (test_collect_unicodes_format4);
  116. hb_test_add (test_collect_unicodes_format12);
  117. hb_test_add (test_collect_unicodes_format12_notdef);
  118. return hb_test_run();
  119. }