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