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