1 #include "text.h" 2 #include "pixel_format.h" 3 #include "cache.h" 4 #include "bitmap.h" 5 #include "font.h" 6 #include <iostream> 7 #include "doctest.h" 8 9 TEST_SUITE_BEGIN("Text"); 10 11 constexpr char32_t escape = '\\'; 12 constexpr int width = 240; 13 constexpr int height = 80; 14 constexpr int ch = 12; 15 constexpr int cwh = 6; 16 constexpr int cwf = 12; 17 18 TEST_CASE("TextDrawSystemStrReturn") { 19 Bitmap::SetFormat(format_R8G8B8A8_a().format()); 20 auto font = Font::Default(); 21 auto surface = Bitmap::Create(width, height); 22 auto system = Cache::SysBlack(); 23 __anon44dd795e0102(int x, int y, const auto& text) 24 auto draw = [&](int x, int y, const auto& text) { 25 return Text::Draw(*surface, x, y, *font, *system, 0, text); 26 }; 27 28 REQUIRE_EQ(draw(0, 0, ""), Rect(0, 0, 0, 0)); 29 REQUIRE_EQ(draw(0, 0, "abc"), Rect(0, 0, cwh * 3, ch)); 30 REQUIRE_EQ(draw(3, 17, "$A"), Rect(3, 17, cwf, ch)); 31 REQUIRE_EQ(draw(3, 17, "$A $B"), Rect(3, 17, cwf * 2 + cwh, ch)); 32 } 33 34 TEST_CASE("TextDrawColorStrReturn") { 35 Bitmap::SetFormat(format_R8G8B8A8_a().format()); 36 auto font = Font::Default(); 37 auto surface = Bitmap::Create(width, height); 38 auto color = Color(255,255,255,255); 39 __anon44dd795e0202(int x, int y, const auto& text) 40 auto draw = [&](int x, int y, const auto& text) { 41 return Text::Draw(*surface, x, y, *font, color, text); 42 }; 43 44 REQUIRE_EQ(draw(0, 0, ""), Rect(0, 0, 0, 0)); 45 REQUIRE_EQ(draw(0, 0, "abc"), Rect(0, 0, cwh * 3, ch)); 46 REQUIRE_EQ(draw(3, 17, "\n"), Rect(3, 17, 0, ch)); 47 REQUIRE_EQ(draw(3, 17, "x\nyz"), Rect(3, 17, cwh * 2, ch *2)); 48 REQUIRE_EQ(draw(10, 0, "xy\nz"), Rect(10, 0, cwh * 2, ch *2)); 49 } 50 51 TEST_SUITE_END(); 52