]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/label.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/label.cpp
3 // Purpose: wxControl and wxStaticText label tests
4 // Author: Francesco Montorsi
6 // Copyright: (c) 2010 Francesco Montorsi
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
23 #include "wx/control.h"
24 #include "wx/stattext.h"
25 #include "wx/checkbox.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 class LabelTestCase
: public CppUnit::TestCase
37 virtual void tearDown();
40 CPPUNIT_TEST_SUITE( LabelTestCase
);
41 CPPUNIT_TEST( GetLabel
);
42 CPPUNIT_TEST( GetLabelText
);
43 CPPUNIT_TEST( Statics
);
44 CPPUNIT_TEST_SUITE_END();
52 // we cannot test wxControl directly (it's abstract) so we rather test wxCheckBox
55 DECLARE_NO_COPY_CLASS(LabelTestCase
)
58 // register in the unnamed registry so that these tests are run by default
59 CPPUNIT_TEST_SUITE_REGISTRATION( LabelTestCase
);
61 // also include in its own registry so that these tests can be run alone
62 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( LabelTestCase
, "LabelTestCase" );
64 // ----------------------------------------------------------------------------
65 // test initialization
66 // ----------------------------------------------------------------------------
68 #define ORIGINAL_LABEL "original label"
70 void LabelTestCase::setUp()
72 m_st
= new wxStaticText(wxTheApp
->GetTopWindow(), wxID_ANY
, ORIGINAL_LABEL
);
74 m_cb
= new wxCheckBox(wxTheApp
->GetTopWindow(), wxID_ANY
, ORIGINAL_LABEL
);
76 CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL
, m_st
->GetLabel() );
77 CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL
, m_cb
->GetLabel() );
80 void LabelTestCase::tearDown()
86 // ----------------------------------------------------------------------------
87 // the tests themselves
88 // ----------------------------------------------------------------------------
90 #define SET_LABEL(str) \
91 m_st->SetLabel(str); \
94 #define SET_LABEL_TEXT(str) \
95 m_st->SetLabelText(str); \
96 m_cb->SetLabelText(str);
98 void LabelTestCase::GetLabel()
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",
107 // test calls to SetLabel() and then to GetLabel()
109 for ( unsigned int s
= 0; s
< WXSIZEOF(testLabelArray
); s
++ )
111 SET_LABEL(testLabelArray
[s
]);
113 // GetLabel() should always return the string passed to SetLabel()
114 CPPUNIT_ASSERT_EQUAL( testLabelArray
[s
], m_st
->GetLabel() );
115 CPPUNIT_ASSERT_EQUAL( testLabelArray
[s
], m_cb
->GetLabel() );
119 // test calls to SetLabelText() and then to GetLabel()
121 const wxString
& testLabel
= "label without mnemonics and markup";
122 SET_LABEL_TEXT(testLabel
);
123 CPPUNIT_ASSERT_EQUAL( testLabel
, m_st
->GetLabel() );
124 CPPUNIT_ASSERT_EQUAL( testLabel
, m_cb
->GetLabel() );
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() );
130 CPPUNIT_ASSERT_EQUAL( testLabelText2
, m_cb
->GetLabel() );
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() );
135 CPPUNIT_ASSERT_EQUAL( testLabel3
, m_cb
->GetLabel() );
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() );
141 CPPUNIT_ASSERT_EQUAL( testLabelText4
, m_cb
->GetLabel() );
144 void LabelTestCase::GetLabelText()
146 // test calls to SetLabel() and then to GetLabelText()
148 const wxString
& testLabel
= "label without mnemonics and markup";
149 SET_LABEL(testLabel
);
150 CPPUNIT_ASSERT_EQUAL( testLabel
, m_st
->GetLabelText() );
151 CPPUNIT_ASSERT_EQUAL( testLabel
, m_cb
->GetLabelText() );
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() );
157 CPPUNIT_ASSERT_EQUAL( testLabelText2
, m_cb
->GetLabelText() );
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() );
162 CPPUNIT_ASSERT_EQUAL( testLabel3
, m_cb
->GetLabelText() );
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() );
168 CPPUNIT_ASSERT_EQUAL( testLabelText4
, m_cb
->GetLabelText() );
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",
178 // test calls to SetLabelText() and then to GetLabelText()
180 for ( unsigned int s
= 0; s
< WXSIZEOF(testLabelArray
); s
++ )
182 SET_LABEL_TEXT(testLabelArray
[s
]);
184 // GetLabelText() should always return the string passed to SetLabelText()
185 CPPUNIT_ASSERT_EQUAL( testLabelArray
[s
], m_st
->GetLabelText() );
186 CPPUNIT_ASSERT_EQUAL( testLabelArray
[s
], m_cb
->GetLabelText() );
190 void LabelTestCase::Statics()
192 CPPUNIT_ASSERT_EQUAL( "mnemonic", wxControl::RemoveMnemonics("&mnemonic") );
193 CPPUNIT_ASSERT_EQUAL( "&mnemonic", wxControl::RemoveMnemonics("&&mnemonic") );
194 CPPUNIT_ASSERT_EQUAL( "&mnemonic", wxControl::RemoveMnemonics("&&&mnemonic") );