]> git.saurik.com Git - wxWidgets.git/blob - tests/graphics/ellipsization.cpp
Fix box sizer layout algorithm to respect both proportions and min sizes.
[wxWidgets.git] / tests / graphics / ellipsization.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/graphics/ellipsization.cpp
3 // Purpose: wxControlBase::*Ellipsize* unit test
4 // Author: Francesco Montorsi
5 // Created: 2010-03-10
6 // RCS-ID: $Id$
7 // Copyright: (c) 2010 Francesco Montorsi
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #include "wx/control.h"
21 #include "wx/dcmemory.h"
22
23 // ----------------------------------------------------------------------------
24 // test class
25 // ----------------------------------------------------------------------------
26
27 class EllipsizationTestCase : public CppUnit::TestCase
28 {
29 public:
30 EllipsizationTestCase() { }
31
32 private:
33 CPPUNIT_TEST_SUITE( EllipsizationTestCase );
34 CPPUNIT_TEST( Ellipsize );
35 CPPUNIT_TEST_SUITE_END();
36
37 void Ellipsize();
38
39 DECLARE_NO_COPY_CLASS(EllipsizationTestCase)
40 };
41
42 // register in the unnamed registry so that these tests are run by default
43 CPPUNIT_TEST_SUITE_REGISTRATION( EllipsizationTestCase );
44
45 // also include in it's own registry so that these tests can be run alone
46 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EllipsizationTestCase, "EllipsizationTestCase" );
47
48 void EllipsizationTestCase::Ellipsize()
49 {
50 wxMemoryDC dc;
51
52 static const char *stringsToTest[] =
53 {
54 "N",
55 ".",
56 "x",
57 "foobar",
58 "\xCE\xB1", // U03B1 (GREEK SMALL LETTER ALPHA)
59 "Another test",
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"
67 };
68
69 static const int flagsToTest[] =
70 {
71 0,
72 wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS,
73 wxELLIPSIZE_FLAGS_EXPAND_TABS,
74 wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS | wxELLIPSIZE_FLAGS_EXPAND_TABS
75 };
76
77 static const wxEllipsizeMode modesToTest[] =
78 {
79 wxELLIPSIZE_START,
80 wxELLIPSIZE_MIDDLE,
81 wxELLIPSIZE_END
82 };
83
84 int widthsToTest[] = { 0, 1, 2, 3, 10, 20, 100 };
85
86 for ( unsigned int s = 0; s < WXSIZEOF(stringsToTest); s++ )
87 {
88 const wxString str = wxString::FromUTF8(stringsToTest[s]);
89
90 for ( unsigned int f = 0; f < WXSIZEOF(flagsToTest); f++ )
91 {
92 for ( unsigned int m = 0; m < WXSIZEOF(modesToTest); m++ )
93 {
94 for ( unsigned int w = 0; w < WXSIZEOF(widthsToTest); w++ )
95 {
96 wxString ret = wxControlBase::Ellipsize
97 (
98 str,
99 dc,
100 modesToTest[m],
101 widthsToTest[w],
102 flagsToTest[f]
103 );
104
105 WX_ASSERT_MESSAGE
106 (
107 ("invalid ellipsization for \"%s\"", str),
108 dc.GetMultiLineTextExtent(ret).GetWidth() <= widthsToTest[w]
109 );
110 }
111 }
112 }
113 }
114 }