1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/graphics/ellipsization.cpp
3 // Purpose: wxControlBase::*Ellipsize* unit test
4 // Author: Francesco Montorsi
7 // Copyright: (c) 2010 Francesco Montorsi
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
20 #include "wx/control.h"
21 #include "wx/dcmemory.h"
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 class EllipsizationTestCase
: public CppUnit::TestCase
30 EllipsizationTestCase() { }
33 CPPUNIT_TEST_SUITE( EllipsizationTestCase
);
34 CPPUNIT_TEST( Ellipsize
);
35 CPPUNIT_TEST_SUITE_END();
39 DECLARE_NO_COPY_CLASS(EllipsizationTestCase
)
42 // register in the unnamed registry so that these tests are run by default
43 CPPUNIT_TEST_SUITE_REGISTRATION( EllipsizationTestCase
);
45 // also include in it's own registry so that these tests can be run alone
46 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EllipsizationTestCase
, "EllipsizationTestCase" );
48 void EllipsizationTestCase::Ellipsize()
52 static const char *stringsToTest
[] =
58 "\xCE\xB1", // U03B1 (GREEK SMALL LETTER ALPHA)
60 "a very very very very very very very long string",
61 // alpha+beta+gamma+delta+epsilon+zeta+eta+theta+iota
62 "\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5\xCE\xB6\xCE\xB7\xCE\xB8\xCE\xB9",
63 "\t", "\t\t\t\t\t", "a\tstring\twith\ttabs",
64 "\n", "\n\n\n\n\n", "a\nstring\nwith\nnewlines",
65 "&", "&&&&&&&", "a&string&with&newlines",
66 "\t\n&", "a\t\n&string\t\n&with\t\n&many\t\n&chars"
69 static const int flagsToTest
[] =
72 wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS
,
73 wxELLIPSIZE_FLAGS_EXPAND_TABS
,
74 wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS
| wxELLIPSIZE_FLAGS_EXPAND_TABS
77 static const wxEllipsizeMode modesToTest
[] =
84 int widthsToTest
[] = { 0, 1, 2, 3, 10, 20, 100 };
86 for ( unsigned int s
= 0; s
< WXSIZEOF(stringsToTest
); s
++ )
88 const wxString str
= wxString::FromUTF8(stringsToTest
[s
]);
90 for ( unsigned int f
= 0; f
< WXSIZEOF(flagsToTest
); f
++ )
92 for ( unsigned int m
= 0; m
< WXSIZEOF(modesToTest
); m
++ )
94 for ( unsigned int w
= 0; w
< WXSIZEOF(widthsToTest
); w
++ )
96 wxString ret
= wxControlBase::Ellipsize
107 ("invalid ellipsization for \"%s\"", str
),
108 dc
.GetMultiLineTextExtent(ret
).GetWidth() <= widthsToTest
[w
]