test-ot-glyphname.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright © 2019 Adobe, 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. * Adobe Author(s): Michiharu Ariza
  25. */
  26. #include "hb-test.h"
  27. #include "hb-ot.h"
  28. static void
  29. test_one_glyph (hb_font_t *font, hb_codepoint_t gid, const char *name)
  30. {
  31. char buf[64];
  32. hb_codepoint_t glyph;
  33. g_assert(hb_font_get_glyph_name (font, gid, buf, sizeof (buf)));
  34. g_assert_cmpstr(buf, ==, name);
  35. g_assert(hb_font_get_glyph_from_name (font, name, -1, &glyph));
  36. g_assert_cmpint(glyph, ==, gid);
  37. }
  38. /* Unit tests for CFF glyph names */
  39. static void
  40. test_standard_names (void)
  41. {
  42. hb_face_t *face = hb_test_open_font_file ("fonts/MathTestFontFull.otf");
  43. hb_font_t *font = hb_font_create (face);
  44. test_one_glyph (font, 0, ".notdef");
  45. test_one_glyph (font, 27, "Z");
  46. hb_font_destroy (font);
  47. hb_face_destroy (face);
  48. }
  49. static void
  50. test_non_standard_names (void)
  51. {
  52. hb_face_t *face = hb_test_open_font_file ("fonts/MathTestFontFull.otf");
  53. hb_font_t *font = hb_font_create (face);
  54. test_one_glyph (font, 46, "arrowdblright");
  55. test_one_glyph (font, 138, "uni21E7_size5");
  56. hb_font_destroy (font);
  57. hb_face_destroy (face);
  58. }
  59. static void
  60. test_predef_charset_names (void)
  61. {
  62. hb_face_t *face = hb_test_open_font_file ("fonts/cff1_expert.otf");
  63. hb_font_t *font = hb_font_create (face);
  64. test_one_glyph (font, 0, ".notdef");
  65. test_one_glyph (font, 29, "centsuperior");
  66. test_one_glyph (font, 86, "commainferior");
  67. hb_font_destroy (font);
  68. hb_face_destroy (face);
  69. }
  70. int
  71. main (int argc, char **argv)
  72. {
  73. hb_test_init (&argc, &argv);
  74. hb_test_add (test_standard_names);
  75. hb_test_add (test_non_standard_names);
  76. hb_test_add (test_predef_charset_names);
  77. return hb_test_run();
  78. }