The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
test_pango_text.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2026
3 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY.
11
12 See the COPYING file for more details.
13*/
14
15#define GETTEXT_DOMAIN "wesnoth-test"
16
17#include <boost/test/unit_test.hpp>
18
20
21#include "font/font_options.hpp"
22#include "font/text.hpp"
23#include "sdl/point.hpp"
24
25#include <string>
26#include <vector>
27
28
36
38
39BOOST_AUTO_TEST_CASE(pango_text_wraps_at_maximum_width)
40{
41 const std::string text = "Alle Spieler erhalten das gleiche Einkommen in regelmäßigen Abständen. Alles andere Einkommen ist deaktiviert.\n\nInspiriert vom gleichnamigen 'Earth 2150' Spielmodus.";
42
44 BOOST_REQUIRE(renderer.set_text(text, true));
45
46 const auto configure = [&](int width) {
47 renderer.clear_attributes();
49 .set_family_class(font::family_class::sans_serif)
50 .set_font_size(15)
51 .set_font_style(font::pango_text::STYLE_NORMAL)
52 .set_alignment(PANGO_ALIGN_LEFT)
53 .set_maximum_width(width)
54 .set_maximum_height(-1, true)
55 .set_ellipse_mode(PANGO_ELLIPSIZE_NONE)
56 .set_characters_per_line(0);
57 };
58
59 const auto measure_and_get_size = [&](int width) {
60 configure(width);
61 return renderer.get_size();
62 };
63
64 const auto lines_at = [&](int width) {
65 configure(width);
66 return renderer.get_lines();
67 };
68
69 for(int width : {420, 400, 399, 398}) {
70 const auto size = measure_and_get_size(width);
71 const auto wrapped_at_width = lines_at(width);
72 const auto wrapped_at_size = lines_at(size.x); // feed the resulting size/width back and expect the same layout/lines
73 BOOST_TEST(wrapped_at_size == wrapped_at_width, "wrap at " << width << " changes at " << size.x);
74 }
75}
76
77BOOST_AUTO_TEST_SUITE_END()
Text class.
Definition text.hpp:78
static SDL_Renderer * renderer()
Definition draw.cpp:33
const config & get_test_config_ref()
BOOST_FIXTURE_TEST_SUITE(test_map_location, MLFixture)
BOOST_AUTO_TEST_CASE(pango_text_wraps_at_maximum_width)