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 wxString stringsToTest
[] =
54 "N", ".", "x", "foobar", wxS("\u03B1"), "Another test", "a very very very very very very very long string",
55 "\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5\xCE\xB6\xCE\xB7\xCE\xB8\xCE\xB9",
56 // alpha+beta+gamma+delta+epsilon+zeta+eta+theta+iota
57 "\t", "\t\t\t\t\t", "a\tstring\twith\ttabs",
58 "\n", "\n\n\n\n\n", "a\nstring\nwith\nnewlines",
59 "&", "&&&&&&&", "a&string&with&newlines",
60 "\t\n&", "a\t\n&string\t\n&with\t\n&many\t\n&chars"
62 int flagsToTest
[] = { 0, wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS
, wxELLIPSIZE_FLAGS_EXPAND_TABS
,
63 wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS
|wxELLIPSIZE_FLAGS_EXPAND_TABS
};
64 wxEllipsizeMode modesToTest
[] = { wxELLIPSIZE_START
, wxELLIPSIZE_MIDDLE
, wxELLIPSIZE_END
};
65 int widthsToTest
[] = { 0, 1, 2, 3, 10, 20, 100 };
67 for (unsigned int s
=0; s
<WXSIZEOF(stringsToTest
); s
++)
68 for (unsigned int f
=0; f
<WXSIZEOF(flagsToTest
); f
++)
69 for (unsigned int m
=0; m
<WXSIZEOF(modesToTest
); m
++)
70 for (unsigned int w
=0; w
<WXSIZEOF(widthsToTest
); w
++)
72 wxString ret
= wxControlBase
::Ellipsize(stringsToTest
[s
], dc
, modesToTest
[m
],
73 widthsToTest
[w
], flagsToTest
[f
]);
75 CPPUNIT_ASSERT_MESSAGE((std
::string
)("invalid ellipsization for: " + stringsToTest
[s
]),
76 dc
.GetMultiLineTextExtent(ret
).GetWidth() <= widthsToTest
[w
]);