From b245e4a5714de4df6e04f12c69fefcff25437b1b Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 14 Aug 2019 20:41:10 +0200 Subject: [PATCH] Use dynamic widths in ellipsization tests so they will work for any font size --- tests/graphics/ellipsization.cpp | 40 +++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/tests/graphics/ellipsization.cpp b/tests/graphics/ellipsization.cpp index d7c90242b7..9181ed4e31 100644 --- a/tests/graphics/ellipsization.cpp +++ b/tests/graphics/ellipsization.cpp @@ -143,12 +143,15 @@ void EllipsizationTestCase::EnoughSpace() wxMemoryDC dc; - CPPUNIT_ASSERT_EQUAL("some label", - wxControl::Ellipsize("some label", dc, wxELLIPSIZE_START, 200)); - CPPUNIT_ASSERT_EQUAL("some label", - wxControl::Ellipsize("some label", dc, wxELLIPSIZE_MIDDLE, 200)); - CPPUNIT_ASSERT_EQUAL("some label", - wxControl::Ellipsize("some label", dc, wxELLIPSIZE_END, 200)); + wxString testString("some label"); + const int width = dc.GetTextExtent(testString).GetWidth() + 50; + + CPPUNIT_ASSERT_EQUAL(testString, + wxControl::Ellipsize(testString, dc, wxELLIPSIZE_START, width)); + CPPUNIT_ASSERT_EQUAL(testString, + wxControl::Ellipsize(testString, dc, wxELLIPSIZE_MIDDLE, width)); + CPPUNIT_ASSERT_EQUAL(testString, + wxControl::Ellipsize(testString, dc, wxELLIPSIZE_END, width)); } @@ -158,14 +161,16 @@ void EllipsizationTestCase::VeryLittleSpace() wxMemoryDC dc; + const int width = dc.GetTextExtent("s...").GetWidth(); + CPPUNIT_ASSERT_EQUAL("...l", - wxControl::Ellipsize("some label", dc, wxELLIPSIZE_START, 5)); + wxControl::Ellipsize("some label", dc, wxELLIPSIZE_START, width)); CPPUNIT_ASSERT_EQUAL("s...", - wxControl::Ellipsize("some label", dc, wxELLIPSIZE_MIDDLE, 5)); + wxControl::Ellipsize("some label", dc, wxELLIPSIZE_MIDDLE, width)); CPPUNIT_ASSERT_EQUAL("s...", - wxControl::Ellipsize("some label1", dc, wxELLIPSIZE_MIDDLE, 5)); + wxControl::Ellipsize("some label1", dc, wxELLIPSIZE_MIDDLE, width)); CPPUNIT_ASSERT_EQUAL("s...", - wxControl::Ellipsize("some label", dc, wxELLIPSIZE_END, 5)); + wxControl::Ellipsize("some label", dc, wxELLIPSIZE_END, width)); } @@ -173,12 +178,15 @@ void EllipsizationTestCase::HasThreeDots() { wxMemoryDC dc; - CPPUNIT_ASSERT( wxControl::Ellipsize("some longer text", dc, wxELLIPSIZE_START, 80).StartsWith("...") ); - CPPUNIT_ASSERT( !wxControl::Ellipsize("some longer text", dc, wxELLIPSIZE_START, 80).EndsWith("...") ); + wxString testString("some longer text"); + const int width = dc.GetTextExtent(testString).GetWidth() - 5; - CPPUNIT_ASSERT( wxControl::Ellipsize("some longer text", dc, wxELLIPSIZE_END, 80).EndsWith("...") ); + CPPUNIT_ASSERT( wxControl::Ellipsize(testString, dc, wxELLIPSIZE_START, width).StartsWith("...") ); + CPPUNIT_ASSERT( !wxControl::Ellipsize(testString, dc, wxELLIPSIZE_START, width).EndsWith("...") ); - CPPUNIT_ASSERT( wxControl::Ellipsize("some longer text", dc, wxELLIPSIZE_MIDDLE, 80).Contains("...") ); - CPPUNIT_ASSERT( !wxControl::Ellipsize("some longer text", dc, wxELLIPSIZE_MIDDLE, 80).StartsWith("...") ); - CPPUNIT_ASSERT( !wxControl::Ellipsize("some longer text", dc, wxELLIPSIZE_MIDDLE, 80).EndsWith("...") ); + CPPUNIT_ASSERT( wxControl::Ellipsize(testString, dc, wxELLIPSIZE_END, width).EndsWith("...") ); + + CPPUNIT_ASSERT( wxControl::Ellipsize(testString, dc, wxELLIPSIZE_MIDDLE, width).Contains("...") ); + CPPUNIT_ASSERT( !wxControl::Ellipsize(testString, dc, wxELLIPSIZE_MIDDLE, width).StartsWith("...") ); + CPPUNIT_ASSERT( !wxControl::Ellipsize(testString, dc, wxELLIPSIZE_MIDDLE, width).EndsWith("...") ); }