2010-03-14 10:44:25 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/graphics/ellipsization.cpp
|
|
|
|
// Purpose: wxControlBase::*Ellipsize* unit test
|
|
|
|
// Author: Francesco Montorsi
|
|
|
|
// Created: 2010-03-10
|
|
|
|
// Copyright: (c) 2010 Francesco Montorsi
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/control.h"
|
|
|
|
#include "wx/dcmemory.h"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class EllipsizationTestCase : public CppUnit::TestCase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EllipsizationTestCase() { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
CPPUNIT_TEST_SUITE( EllipsizationTestCase );
|
2011-02-09 14:52:50 -05:00
|
|
|
CPPUNIT_TEST( NormalCase );
|
|
|
|
CPPUNIT_TEST( EnoughSpace );
|
|
|
|
CPPUNIT_TEST( VeryLittleSpace );
|
|
|
|
CPPUNIT_TEST( HasThreeDots );
|
2010-03-14 10:44:25 -04:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
2011-02-09 14:52:50 -05:00
|
|
|
void NormalCase();
|
|
|
|
void EnoughSpace();
|
|
|
|
void VeryLittleSpace();
|
|
|
|
void HasThreeDots();
|
2010-03-14 10:44:25 -04:00
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_NO_COPY_CLASS(EllipsizationTestCase);
|
2010-03-14 10:44:25 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// register in the unnamed registry so that these tests are run by default
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( EllipsizationTestCase );
|
|
|
|
|
2011-04-30 06:57:04 -04:00
|
|
|
// also include in its own registry so that these tests can be run alone
|
2010-03-14 10:44:25 -04:00
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EllipsizationTestCase, "EllipsizationTestCase" );
|
|
|
|
|
2011-02-09 14:52:50 -05:00
|
|
|
void EllipsizationTestCase::NormalCase()
|
2010-03-14 10:44:25 -04:00
|
|
|
{
|
|
|
|
wxMemoryDC dc;
|
|
|
|
|
2010-03-14 10:47:11 -04:00
|
|
|
static const char *stringsToTest[] =
|
|
|
|
{
|
|
|
|
"N",
|
|
|
|
".",
|
|
|
|
"x",
|
|
|
|
"foobar",
|
|
|
|
"\xCE\xB1", // U03B1 (GREEK SMALL LETTER ALPHA)
|
|
|
|
"Another test",
|
|
|
|
"a very very very very very very very long string",
|
|
|
|
// alpha+beta+gamma+delta+epsilon+zeta+eta+theta+iota
|
|
|
|
"\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5\xCE\xB6\xCE\xB7\xCE\xB8\xCE\xB9",
|
2010-03-14 10:44:25 -04:00
|
|
|
"\t", "\t\t\t\t\t", "a\tstring\twith\ttabs",
|
|
|
|
"\n", "\n\n\n\n\n", "a\nstring\nwith\nnewlines",
|
|
|
|
"&", "&&&&&&&", "a&string&with&newlines",
|
|
|
|
"\t\n&", "a\t\n&string\t\n&with\t\n&many\t\n&chars"
|
|
|
|
};
|
2010-03-14 10:47:11 -04:00
|
|
|
|
|
|
|
static const int flagsToTest[] =
|
|
|
|
{
|
|
|
|
0,
|
|
|
|
wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS,
|
|
|
|
wxELLIPSIZE_FLAGS_EXPAND_TABS,
|
|
|
|
wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS | wxELLIPSIZE_FLAGS_EXPAND_TABS
|
|
|
|
};
|
|
|
|
|
|
|
|
static const wxEllipsizeMode modesToTest[] =
|
|
|
|
{
|
|
|
|
wxELLIPSIZE_START,
|
|
|
|
wxELLIPSIZE_MIDDLE,
|
|
|
|
wxELLIPSIZE_END
|
|
|
|
};
|
|
|
|
|
2016-02-26 09:09:39 -05:00
|
|
|
const int charWidth = dc.GetCharWidth();
|
|
|
|
int widthsToTest[] = { 6*charWidth, 10*charWidth, 15*charWidth };
|
2010-03-14 10:44:25 -04:00
|
|
|
|
2010-03-14 10:47:11 -04:00
|
|
|
for ( unsigned int s = 0; s < WXSIZEOF(stringsToTest); s++ )
|
|
|
|
{
|
|
|
|
const wxString str = wxString::FromUTF8(stringsToTest[s]);
|
|
|
|
|
|
|
|
for ( unsigned int f = 0; f < WXSIZEOF(flagsToTest); f++ )
|
|
|
|
{
|
|
|
|
for ( unsigned int m = 0; m < WXSIZEOF(modesToTest); m++ )
|
|
|
|
{
|
|
|
|
for ( unsigned int w = 0; w < WXSIZEOF(widthsToTest); w++ )
|
2010-03-14 10:44:25 -04:00
|
|
|
{
|
2011-02-09 14:52:50 -05:00
|
|
|
wxString ret = wxControl::Ellipsize
|
2010-03-14 10:47:11 -04:00
|
|
|
(
|
|
|
|
str,
|
|
|
|
dc,
|
|
|
|
modesToTest[m],
|
|
|
|
widthsToTest[w],
|
|
|
|
flagsToTest[f]
|
|
|
|
);
|
2010-03-14 10:44:25 -04:00
|
|
|
|
2010-03-14 10:47:11 -04:00
|
|
|
WX_ASSERT_MESSAGE
|
|
|
|
(
|
2011-02-09 14:52:50 -05:00
|
|
|
(
|
2016-02-26 09:09:39 -05:00
|
|
|
"Test #(%u,%u.%u): \"%s\" -> \"%s\"; width=%dpx > %dpx",
|
|
|
|
s, f, m,
|
2011-02-09 14:52:50 -05:00
|
|
|
str,
|
2016-02-26 09:09:39 -05:00
|
|
|
ret,
|
2011-02-09 14:52:50 -05:00
|
|
|
dc.GetMultiLineTextExtent(ret).GetWidth(),
|
|
|
|
widthsToTest[w]
|
|
|
|
),
|
2010-03-14 10:47:11 -04:00
|
|
|
dc.GetMultiLineTextExtent(ret).GetWidth() <= widthsToTest[w]
|
|
|
|
);
|
2010-03-14 10:44:25 -04:00
|
|
|
}
|
2010-03-14 10:47:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-14 10:44:25 -04:00
|
|
|
}
|
2011-02-09 14:52:50 -05:00
|
|
|
|
|
|
|
|
|
|
|
void EllipsizationTestCase::EnoughSpace()
|
|
|
|
{
|
|
|
|
// No ellipsization should occur if there's plenty of space.
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EllipsizationTestCase::VeryLittleSpace()
|
|
|
|
{
|
|
|
|
// If there's not enough space, the shortened label should still contain "..." and one character
|
|
|
|
|
|
|
|
wxMemoryDC dc;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL("...l",
|
|
|
|
wxControl::Ellipsize("some label", dc, wxELLIPSIZE_START, 5));
|
|
|
|
CPPUNIT_ASSERT_EQUAL("s...",
|
|
|
|
wxControl::Ellipsize("some label", dc, wxELLIPSIZE_MIDDLE, 5));
|
|
|
|
CPPUNIT_ASSERT_EQUAL("s...",
|
|
|
|
wxControl::Ellipsize("some label1", dc, wxELLIPSIZE_MIDDLE, 5));
|
|
|
|
CPPUNIT_ASSERT_EQUAL("s...",
|
|
|
|
wxControl::Ellipsize("some label", dc, wxELLIPSIZE_END, 5));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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("...") );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( wxControl::Ellipsize("some longer text", dc, wxELLIPSIZE_END, 80).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("...") );
|
|
|
|
}
|