Browse Source

Text: improve and test an assertion.

pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
f23ff655fd
  1. 2
      src/Magnum/Text/AbstractFont.cpp
  2. 22
      src/Magnum/Text/Test/AbstractLayouterTest.cpp

2
src/Magnum/Text/AbstractFont.cpp

@ -309,7 +309,7 @@ AbstractLayouter::AbstractLayouter(UnsignedInt glyphCount): _glyphCount(glyphCou
AbstractLayouter::~AbstractLayouter() = default;
std::pair<Range2D, Range2D> AbstractLayouter::renderGlyph(const UnsignedInt i, Vector2& cursorPosition, Range2D& rectangle) {
CORRADE_ASSERT(i < glyphCount(), "Text::AbstractLayouter::renderGlyph(): glyph index out of bounds", {});
CORRADE_ASSERT(i < glyphCount(), "Text::AbstractLayouter::renderGlyph(): index" << i << "out of range for" << glyphCount() << "glyphs", {});
/* Render the glyph */
Range2D quadPosition, textureCoordinates;

22
src/Magnum/Text/Test/AbstractLayouterTest.cpp

@ -23,7 +23,9 @@
DEALINGS IN THE SOFTWARE.
*/
#include <sstream>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h> /** @todo remove once Debug is stream-free */
#include "Magnum/Math/Range.h"
#include "Magnum/Text/AbstractFont.h"
@ -34,10 +36,12 @@ struct AbstractLayouterTest: TestSuite::Tester {
explicit AbstractLayouterTest();
void renderGlyph();
void renderGlyphOutOfBounds();
};
AbstractLayouterTest::AbstractLayouterTest() {
addTests({&AbstractLayouterTest::renderGlyph});
addTests({&AbstractLayouterTest::renderGlyph,
&AbstractLayouterTest::renderGlyphOutOfBounds});
}
void AbstractLayouterTest::renderGlyph() {
@ -78,6 +82,22 @@ void AbstractLayouterTest::renderGlyph() {
CORRADE_COMPARE(rectangle, Range2D({2.0f, 0.5f}, {6.1f, 3.0f}));
}
void AbstractLayouterTest::renderGlyphOutOfBounds() {
struct Layouter: AbstractLayouter {
explicit Layouter(): AbstractLayouter{3} {}
std::tuple<Range2D, Range2D, Vector2> doRenderGlyph(UnsignedInt) override { return {}; }
} layouter;
Range2D rectangle;
Vector2 cursorPosition;
std::ostringstream out;
Error redirectError{&out};
layouter.renderGlyph(3, cursorPosition, rectangle);
CORRADE_COMPARE(out.str(), "Text::AbstractLayouter::renderGlyph(): index 3 out of range for 3 glyphs\n");
}
}}}}
CORRADE_TEST_MAIN(Magnum::Text::Test::AbstractLayouterTest)

Loading…
Cancel
Save