]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/label.cpp
remove wxFileConfig tests: FileConfigTestCase already tests features tested by consol...
[wxWidgets.git] / tests / controls / label.cpp
CommitLineData
32ee98eb
FM
1///////////////////////////////////////////////////////////////////////////////\r
2// Name: tests/controls/label.cpp\r
3// Purpose: wxControl and wxStaticText label tests\r
4// Author: Francesco Montorsi\r
5// Created: 2010-3-21\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#ifndef WX_PRECOMP\r
21 #include "wx/app.h"\r
22#endif // WX_PRECOMP\r
23\r
24#include "wx/control.h"\r
25#include "wx/stattext.h"\r
26#include "wx/checkbox.h"\r
27\r
28// ----------------------------------------------------------------------------\r
29// test class\r
30// ----------------------------------------------------------------------------\r
31\r
32class LabelTestCase : public CppUnit::TestCase\r
33{\r
34public:\r
35 LabelTestCase() { }\r
36\r
37 virtual void setUp();\r
38 virtual void tearDown();\r
39\r
40private:\r
41 CPPUNIT_TEST_SUITE( LabelTestCase );\r
42 CPPUNIT_TEST( GetLabel );\r
43 CPPUNIT_TEST( GetLabelText );\r
44 CPPUNIT_TEST( Statics );\r
45 CPPUNIT_TEST_SUITE_END();\r
46\r
47 void GetLabel();\r
48 void GetLabelText();\r
49 void Statics();\r
50\r
51 wxStaticText *m_st, *m_stWithMarkup;\r
52\r
53 // we cannot test wxControl directly (it's abstract) so we rather test wxCheckBox\r
54 wxCheckBox *m_cb;\r
55\r
56 DECLARE_NO_COPY_CLASS(LabelTestCase)\r
57};\r
58\r
59// register in the unnamed registry so that these tests are run by default\r
60CPPUNIT_TEST_SUITE_REGISTRATION( LabelTestCase );\r
61\r
62// also include in it's own registry so that these tests can be run alone\r
63CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( LabelTestCase, "LabelTestCase" );\r
64\r
65// ----------------------------------------------------------------------------\r
66// test initialization\r
67// ----------------------------------------------------------------------------\r
68\r
69#define ORIGINAL_LABEL "original label"\r
70\r
71void LabelTestCase::setUp()\r
72{\r
73 m_st = new wxStaticText(wxTheApp->GetTopWindow(), wxID_ANY, ORIGINAL_LABEL);\r
74 m_stWithMarkup = new wxStaticText(wxTheApp->GetTopWindow(), wxID_ANY, ORIGINAL_LABEL,\r
75 wxDefaultPosition, wxDefaultSize, wxST_MARKUP);\r
76\r
77 m_cb = new wxCheckBox(wxTheApp->GetTopWindow(), wxID_ANY, ORIGINAL_LABEL);\r
78\r
79 CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL, m_st->GetLabel() );\r
80 CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL, m_stWithMarkup->GetLabel() );\r
81 CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL, m_cb->GetLabel() );\r
82}\r
83\r
84void LabelTestCase::tearDown()\r
85{\r
86 wxDELETE(m_st);\r
87 wxDELETE(m_stWithMarkup);\r
88 wxDELETE(m_cb);\r
89}\r
90\r
91// ----------------------------------------------------------------------------\r
92// the tests themselves\r
93// ----------------------------------------------------------------------------\r
94\r
95#define SET_LABEL(str) \\r
96 m_st->SetLabel(str); \\r
97 m_stWithMarkup->SetLabel(str); \\r
98 m_cb->SetLabel(str);\r
99\r
100#define SET_LABEL_TEXT(str) \\r
101 m_st->SetLabelText(str); \\r
102 m_stWithMarkup->SetLabelText(str); \\r
103 m_cb->SetLabelText(str);\r
104\r
105void LabelTestCase::GetLabel()\r
106{\r
107 const wxString testLabelArray[] = {\r
108 "label without mnemonics and markup",\r
109 "label with &mnemonic",\r
110 "label with <span foreground='blue'>some</span> <b>markup</b>",\r
111 "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic",\r
112 };\r
113\r
114 // test calls to SetLabel() and then to GetLabel()\r
115\r
116 for ( unsigned int s = 0; s < WXSIZEOF(testLabelArray); s++ )\r
117 {\r
118 SET_LABEL(testLabelArray[s]);\r
119\r
120 // GetLabel() should always return the string passed to SetLabel()\r
121 CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_st->GetLabel() );\r
122 CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_stWithMarkup->GetLabel() );\r
123 CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_cb->GetLabel() );\r
124 }\r
125\r
126\r
127 // test calls to SetLabelText() and then to GetLabel()\r
128\r
129 const wxString& testLabel = "label without mnemonics and markup";\r
130 SET_LABEL_TEXT(testLabel);\r
131 CPPUNIT_ASSERT_EQUAL( testLabel, m_st->GetLabel() );\r
132 CPPUNIT_ASSERT_EQUAL( testLabel, m_stWithMarkup->GetLabel() );\r
133 CPPUNIT_ASSERT_EQUAL( testLabel, m_cb->GetLabel() );\r
134\r
135 const wxString& testLabel2 = "label with &mnemonic";\r
136 const wxString& testLabelText2 = "label with &&mnemonic";\r
137 SET_LABEL_TEXT(testLabel2);\r
138 CPPUNIT_ASSERT_EQUAL( testLabelText2, m_st->GetLabel() );\r
139 CPPUNIT_ASSERT_EQUAL( "label with &amp;mnemonic", m_stWithMarkup->GetLabel() );\r
140 CPPUNIT_ASSERT_EQUAL( testLabelText2, m_cb->GetLabel() );\r
141\r
142 const wxString& testLabel3 = "label with <span foreground='blue'>some</span> <b>markup</b>";\r
143 SET_LABEL_TEXT(testLabel3);\r
144 CPPUNIT_ASSERT_EQUAL( testLabel3, m_st->GetLabel() );\r
145 CPPUNIT_ASSERT_EQUAL( "label with &lt;span foreground=&apos;blue&apos;&gt;some&lt;/span&gt; &lt;b&gt;markup&lt;/b&gt;", m_stWithMarkup->GetLabel() );\r
146 CPPUNIT_ASSERT_EQUAL( testLabel3, m_cb->GetLabel() );\r
147\r
148 const wxString& testLabel4 = "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic";\r
149 const wxString& testLabelText4 = "label with <span foreground='blue'>some</span> <b>markup</b> and &&mnemonic";\r
150 SET_LABEL_TEXT(testLabel4);\r
151 CPPUNIT_ASSERT_EQUAL( testLabelText4, m_st->GetLabel() );\r
152 CPPUNIT_ASSERT_EQUAL( "label with &lt;span foreground=&apos;blue&apos;&gt;some&lt;/span&gt; &lt;b&gt;markup&lt;/b&gt; and &amp;mnemonic", m_stWithMarkup->GetLabel() );\r
153 CPPUNIT_ASSERT_EQUAL( testLabelText4, m_cb->GetLabel() );\r
154}\r
155\r
156void LabelTestCase::GetLabelText()\r
157{\r
158 // test calls to SetLabel() and then to GetLabelText()\r
159\r
160 const wxString& testLabel = "label without mnemonics and markup";\r
161 SET_LABEL(testLabel);\r
162 CPPUNIT_ASSERT_EQUAL( testLabel, m_st->GetLabelText() );\r
163 CPPUNIT_ASSERT_EQUAL( testLabel, m_stWithMarkup->GetLabelText() );\r
164 CPPUNIT_ASSERT_EQUAL( testLabel, m_cb->GetLabelText() );\r
165\r
166 const wxString& testLabel2 = "label with &mnemonic";\r
167 const wxString& testLabelText2 = "label with mnemonic";\r
168 SET_LABEL(testLabel2);\r
169 CPPUNIT_ASSERT_EQUAL( testLabelText2, m_st->GetLabelText() );\r
170 CPPUNIT_ASSERT_EQUAL( testLabelText2, m_stWithMarkup->GetLabelText() );\r
171 CPPUNIT_ASSERT_EQUAL( testLabelText2, m_cb->GetLabelText() );\r
172\r
173 const wxString& testLabel3 = "label with <span foreground='blue'>some</span> <b>markup</b>";\r
174 SET_LABEL(testLabel3);\r
175 CPPUNIT_ASSERT_EQUAL( testLabel3, m_st->GetLabelText() );\r
176 CPPUNIT_ASSERT_EQUAL( "label with some markup", m_stWithMarkup->GetLabelText() );\r
177 CPPUNIT_ASSERT_EQUAL( testLabel3, m_cb->GetLabelText() );\r
178\r
179 const wxString& testLabel4 = "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic";\r
180 const wxString& testLabelText4 = "label with <span foreground='blue'>some</span> <b>markup</b> and mnemonic";\r
181 SET_LABEL(testLabel4);\r
182 CPPUNIT_ASSERT_EQUAL( testLabelText4, m_st->GetLabelText() );\r
183 CPPUNIT_ASSERT_EQUAL( "label with some markup and mnemonic", m_stWithMarkup->GetLabelText() );\r
184 CPPUNIT_ASSERT_EQUAL( testLabelText4, m_cb->GetLabelText() );\r
185\r
186\r
187 const wxString testLabelArray[] = {\r
188 "label without mnemonics and markup",\r
189 "label with &mnemonic",\r
190 "label with <span foreground='blue'>some</span> <b>markup</b>",\r
191 "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic",\r
192 };\r
193\r
194 // test calls to SetLabelText() and then to GetLabelText()\r
195\r
196 for ( unsigned int s = 0; s < WXSIZEOF(testLabelArray); s++ )\r
197 {\r
198 SET_LABEL_TEXT(testLabelArray[s]);\r
199\r
200 // GetLabelText() should always return the string passed to SetLabelText()\r
201 CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_st->GetLabelText() );\r
202 CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_stWithMarkup->GetLabelText() );\r
203 CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_cb->GetLabelText() );\r
204 }\r
205}\r
206\r
207void LabelTestCase::Statics()\r
208{\r
209 CPPUNIT_ASSERT_EQUAL( "mnemonic", wxControl::RemoveMnemonics("&mnemonic") );\r
210 CPPUNIT_ASSERT_EQUAL( "&mnemonic", wxControl::RemoveMnemonics("&&mnemonic") );\r
211 CPPUNIT_ASSERT_EQUAL( "&mnemonic", wxControl::RemoveMnemonics("&&&mnemonic") );\r
212 CPPUNIT_ASSERT_EQUAL( "", wxStaticText::RemoveMarkup("<b></b>") );\r
213}\r