|
38 | 38 |
|
39 | 39 | namespace TestFontfile { |
40 | 40 |
|
| 41 | +#ifdef MODULE_FREETYPE_ENABLED |
| 42 | +// Macro to generate tests for getters. |
| 43 | +#define GETTER_TEST(m_name, m_getter, m_default_value) \ |
| 44 | + TEST_CASE("[FontFile] Load Dynamic Font - get-set " m_name) { \ |
| 45 | + String test_dynamic_font = "thirdparty/fonts/NotoSansHebrew_Regular.woff2"; \ |
| 46 | + Ref<FontFile> ff; \ |
| 47 | + ff.instantiate(); \ |
| 48 | + CHECK(ff->load_dynamic_font(test_dynamic_font) == OK); \ |
| 49 | + CHECK_MESSAGE(ff->m_getter == m_default_value, "Unexpected original value for ", m_name, " : ", ff->m_getter, " != ", m_default_value); \ |
| 50 | + } |
| 51 | + |
| 52 | +#define GETTER_TEST_REAL(m_name, m_getter, m_default_value) \ |
| 53 | + TEST_CASE("[FontFile] Load Dynamic Font - get-set " m_name) { \ |
| 54 | + String test_dynamic_font = "thirdparty/fonts/NotoSansHebrew_Regular.woff2"; \ |
| 55 | + Ref<FontFile> ff; \ |
| 56 | + ff.instantiate(); \ |
| 57 | + CHECK(ff->load_dynamic_font(test_dynamic_font) == OK); \ |
| 58 | + CHECK_MESSAGE(ff->m_getter == doctest::Approx(m_default_value), "Unexpected original value for ", m_name, " : ", ff->m_getter, " != ", m_default_value); \ |
| 59 | + } |
| 60 | + |
| 61 | +Dictionary expected_ot_name_strings() { |
| 62 | + Dictionary d = Dictionary(); |
| 63 | + d["en"] = Dictionary(); |
| 64 | + ((Dictionary)d["en"])["copyright"] = "Copyright 2022 The Noto Project Authors (https://github.com/notofonts/hebrew)"; |
| 65 | + ((Dictionary)d["en"])["family_name"] = "Noto Sans Hebrew"; |
| 66 | + ((Dictionary)d["en"])["subfamily_name"] = "Regular"; |
| 67 | + ((Dictionary)d["en"])["full_name"] = "Noto Sans Hebrew Regular"; |
| 68 | + ((Dictionary)d["en"])["unique_identifier"] = "2.003;GOOG;NotoSansHebrew-Regular"; |
| 69 | + ((Dictionary)d["en"])["version"] = "Version 2.003"; |
| 70 | + ((Dictionary)d["en"])["postscript_name"] = "NotoSansHebrew-Regular"; |
| 71 | + ((Dictionary)d["en"])["trademark"] = "Noto is a trademark of Google Inc."; |
| 72 | + ((Dictionary)d["en"])["license"] = "This Font Software is licensed under the SIL Open Font License, Version 1.1. This license is available with a FAQ at: https://scripts.sil.org/OFL"; |
| 73 | + ((Dictionary)d["en"])["license_url"] = "https://scripts.sil.org/OFL"; |
| 74 | + ((Dictionary)d["en"])["designer"] = "Monotype Design Team"; |
| 75 | + ((Dictionary)d["en"])["designer_url"] = "http://www.monotype.com/studio"; |
| 76 | + ((Dictionary)d["en"])["description"] = "Designed by Monotype design team."; |
| 77 | + ((Dictionary)d["en"])["manufacturer"] = "Monotype Imaging Inc."; |
| 78 | + ((Dictionary)d["en"])["vendor_url"] = "http://www.google.com/get/noto/"; |
| 79 | + |
| 80 | + return d; |
| 81 | +} |
| 82 | + |
| 83 | +// These properties come from the font file itself. |
| 84 | +GETTER_TEST("font_name", get_font_name(), "Noto Sans Hebrew") |
| 85 | +GETTER_TEST("font_style_name", get_font_style_name(), "Regular") |
| 86 | +GETTER_TEST("font_weight", get_font_weight(), 400) |
| 87 | +GETTER_TEST("font_stretch", get_font_stretch(), 100) |
| 88 | +GETTER_TEST("opentype_features", get_opentype_features(), Dictionary()) |
| 89 | +GETTER_TEST("ot_name_strings", get_ot_name_strings(), expected_ot_name_strings()) |
| 90 | + |
| 91 | +// These are dependent on size and potentially other state. Act as regression tests based of arbitrary small size 10 and large size 100. |
| 92 | +GETTER_TEST_REAL("height-small", get_height(10), (real_t)14) |
| 93 | +GETTER_TEST_REAL("ascent-small", get_ascent(10), (real_t)11) |
| 94 | +GETTER_TEST_REAL("descent-small", get_descent(10), (real_t)3) |
| 95 | +GETTER_TEST_REAL("underline_position-small", get_underline_position(10), (real_t)1.25) |
| 96 | +GETTER_TEST_REAL("underline_thickness-small", get_underline_thickness(10), (real_t)0.5) |
| 97 | + |
| 98 | +GETTER_TEST_REAL("height-large", get_height(100), (real_t)137) |
| 99 | +GETTER_TEST_REAL("ascent-large", get_ascent(100), (real_t)107) |
| 100 | +GETTER_TEST_REAL("descent-large", get_descent(100), (real_t)30) |
| 101 | +GETTER_TEST_REAL("underline_position-large", get_underline_position(100), (real_t)12.5) |
| 102 | +GETTER_TEST_REAL("underline_thickness-large", get_underline_thickness(100), (real_t)5) |
| 103 | + |
| 104 | +#endif |
| 105 | + |
41 | 106 | TEST_CASE("[FontFile] Create font file and check data") { |
42 | 107 | // Create test instance. |
43 | 108 | Ref<FontFile> font_file; |
|
0 commit comments