]>
Commit | Line | Data |
---|---|---|
a37da0fa FM |
1 | ///////////////////////////////////////////////////////////////////////////////\r |
2 | // Name: tests/graphics/ellipsization.cpp\r | |
3 | // Purpose: wxControlBase::*Ellipsize* unit test\r | |
4 | // Author: Francesco Montorsi\r | |
5 | // Created: 2010-03-10\r | |
6 | // RCS-ID: $Id$\r | |
7 | // Copyright: (c) 2010 Francesco Montorsi\r | |
8 | ///////////////////////////////////////////////////////////////////////////////\r | |
9 | \r | |
10 | // ----------------------------------------------------------------------------\r | |
11 | // headers\r | |
12 | // ----------------------------------------------------------------------------\r | |
13 | \r | |
14 | #include "testprec.h"\r | |
15 | \r | |
16 | #ifdef __BORLANDC__\r | |
17 | #pragma hdrstop\r | |
18 | #endif\r | |
19 | \r | |
20 | #include "wx/control.h"\r | |
21 | #include "wx/dcmemory.h"\r | |
22 | \r | |
23 | // ----------------------------------------------------------------------------\r | |
24 | // test class\r | |
25 | // ----------------------------------------------------------------------------\r | |
26 | \r | |
27 | class EllipsizationTestCase : public CppUnit::TestCase\r | |
28 | {\r | |
29 | public:\r | |
30 | EllipsizationTestCase() { }\r | |
31 | \r | |
32 | private:\r | |
33 | CPPUNIT_TEST_SUITE( EllipsizationTestCase );\r | |
34 | CPPUNIT_TEST( Ellipsize );\r | |
35 | CPPUNIT_TEST_SUITE_END();\r | |
36 | \r | |
37 | void Ellipsize();\r | |
38 | \r | |
39 | DECLARE_NO_COPY_CLASS(EllipsizationTestCase)\r | |
40 | };\r | |
41 | \r | |
42 | // register in the unnamed registry so that these tests are run by default\r | |
43 | CPPUNIT_TEST_SUITE_REGISTRATION( EllipsizationTestCase );\r | |
44 | \r | |
45 | // also include in it's own registry so that these tests can be run alone\r | |
46 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EllipsizationTestCase, "EllipsizationTestCase" );\r | |
47 | \r | |
48 | void EllipsizationTestCase::Ellipsize()\r | |
49 | {\r | |
50 | wxMemoryDC dc;\r | |
51 | \r | |
52 | wxString stringsToTest[] = \r | |
53 | { \r | |
54 | "N", ".", "x", "foobar", wxS("\u03B1"), "Another test", "a very very very very very very very long string",\r | |
55 | "\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5\xCE\xB6\xCE\xB7\xCE\xB8\xCE\xB9", \r | |
56 | // alpha+beta+gamma+delta+epsilon+zeta+eta+theta+iota\r | |
57 | "\t", "\t\t\t\t\t", "a\tstring\twith\ttabs",\r | |
58 | "\n", "\n\n\n\n\n", "a\nstring\nwith\nnewlines",\r | |
59 | "&", "&&&&&&&", "a&string&with&newlines",\r | |
60 | "\t\n&", "a\t\n&string\t\n&with\t\n&many\t\n&chars"\r | |
61 | };\r | |
62 | int flagsToTest[] = { 0, wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS, wxELLIPSIZE_FLAGS_EXPAND_TABS, \r | |
63 | wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS|wxELLIPSIZE_FLAGS_EXPAND_TABS };\r | |
64 | wxEllipsizeMode modesToTest[] = { wxELLIPSIZE_START, wxELLIPSIZE_MIDDLE, wxELLIPSIZE_END };\r | |
65 | int widthsToTest[] = { 0, 1, 2, 3, 10, 20, 100 };\r | |
66 | \r | |
67 | for (unsigned int s=0; s<WXSIZEOF(stringsToTest); s++)\r | |
68 | for (unsigned int f=0; f<WXSIZEOF(flagsToTest); f++)\r | |
69 | for (unsigned int m=0; m<WXSIZEOF(modesToTest); m++)\r | |
70 | for (unsigned int w=0; w<WXSIZEOF(widthsToTest); w++)\r | |
71 | {\r | |
72 | wxString ret = wxControlBase::Ellipsize(stringsToTest[s], dc, modesToTest[m], \r | |
73 | widthsToTest[w], flagsToTest[f]);\r | |
74 | \r | |
75 | CPPUNIT_ASSERT_MESSAGE((std::string)("invalid ellipsization for: " + stringsToTest[s]),\r | |
76 | dc.GetMultiLineTextExtent(ret).GetWidth() <= widthsToTest[w]);\r | |
77 | }\r | |
78 | }\r |