]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/label.cpp
8be19c5c66558c51db9851fddbe9fc40cf8e674f
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/label.cpp
3 // Purpose: wxControl and wxStaticText label tests
4 // Author: Francesco Montorsi
7 // Copyright: (c) 2010 Francesco Montorsi
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
24 #include "wx/control.h"
25 #include "wx/stattext.h"
26 #include "wx/checkbox.h"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 class LabelTestCase
: public CppUnit::TestCase
38 virtual void tearDown();
41 CPPUNIT_TEST_SUITE( LabelTestCase
);
42 CPPUNIT_TEST( GetLabel
);
43 CPPUNIT_TEST( GetLabelText
);
44 CPPUNIT_TEST( Statics
);
45 CPPUNIT_TEST_SUITE_END();
53 // we cannot test wxControl directly (it's abstract) so we rather test wxCheckBox
56 DECLARE_NO_COPY_CLASS(LabelTestCase
)
59 // register in the unnamed registry so that these tests are run by default
60 CPPUNIT_TEST_SUITE_REGISTRATION( LabelTestCase
);
62 // also include in its own registry so that these tests can be run alone
63 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( LabelTestCase
, "LabelTestCase" );
65 // ----------------------------------------------------------------------------
66 // test initialization
67 // ----------------------------------------------------------------------------
69 #define ORIGINAL_LABEL "original label"
71 void LabelTestCase::setUp()
73 m_st
= new wxStaticText(wxTheApp
->GetTopWindow(), wxID_ANY
, ORIGINAL_LABEL
);
75 m_cb
= new wxCheckBox(wxTheApp
->GetTopWindow(), wxID_ANY
, ORIGINAL_LABEL
);
77 CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL
, m_st
->GetLabel() );
78 CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL
, m_cb
->GetLabel() );
81 void LabelTestCase::tearDown()
87 // ----------------------------------------------------------------------------
88 // the tests themselves
89 // ----------------------------------------------------------------------------
91 #define SET_LABEL(str) \
92 m_st->SetLabel(str); \
95 #define SET_LABEL_TEXT(str) \
96 m_st->SetLabelText(str); \
97 m_cb->SetLabelText(str);
99 void LabelTestCase::GetLabel()
101 const wxString testLabelArray
[] = {
102 "label without mnemonics and markup",
103 "label with &mnemonic",
104 "label with <span foreground='blue'>some</span> <b>markup</b>",
105 "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic",
108 // test calls to SetLabel() and then to GetLabel()
110 for ( unsigned int s
= 0; s
< WXSIZEOF(testLabelArray
); s
++ )
112 SET_LABEL(testLabelArray
[s
]);
114 // GetLabel() should always return the string passed to SetLabel()
115 CPPUNIT_ASSERT_EQUAL( testLabelArray
[s
], m_st
->GetLabel() );
116 CPPUNIT_ASSERT_EQUAL( testLabelArray
[s
], m_cb
->GetLabel() );
120 // test calls to SetLabelText() and then to GetLabel()
122 const wxString
& testLabel
= "label without mnemonics and markup";
123 SET_LABEL_TEXT(testLabel
);
124 CPPUNIT_ASSERT_EQUAL( testLabel
, m_st
->GetLabel() );
125 CPPUNIT_ASSERT_EQUAL( testLabel
, m_cb
->GetLabel() );
127 const wxString
& testLabel2
= "label with &mnemonic";
128 const wxString
& testLabelText2
= "label with &&mnemonic";
129 SET_LABEL_TEXT(testLabel2
);
130 CPPUNIT_ASSERT_EQUAL( testLabelText2
, m_st
->GetLabel() );
131 CPPUNIT_ASSERT_EQUAL( testLabelText2
, m_cb
->GetLabel() );
133 const wxString
& testLabel3
= "label with <span foreground='blue'>some</span> <b>markup</b>";
134 SET_LABEL_TEXT(testLabel3
);
135 CPPUNIT_ASSERT_EQUAL( testLabel3
, m_st
->GetLabel() );
136 CPPUNIT_ASSERT_EQUAL( testLabel3
, m_cb
->GetLabel() );
138 const wxString
& testLabel4
= "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic";
139 const wxString
& testLabelText4
= "label with <span foreground='blue'>some</span> <b>markup</b> and &&mnemonic";
140 SET_LABEL_TEXT(testLabel4
);
141 CPPUNIT_ASSERT_EQUAL( testLabelText4
, m_st
->GetLabel() );
142 CPPUNIT_ASSERT_EQUAL( testLabelText4
, m_cb
->GetLabel() );
145 void LabelTestCase::GetLabelText()
147 // test calls to SetLabel() and then to GetLabelText()
149 const wxString
& testLabel
= "label without mnemonics and markup";
150 SET_LABEL(testLabel
);
151 CPPUNIT_ASSERT_EQUAL( testLabel
, m_st
->GetLabelText() );
152 CPPUNIT_ASSERT_EQUAL( testLabel
, m_cb
->GetLabelText() );
154 const wxString
& testLabel2
= "label with &mnemonic";
155 const wxString
& testLabelText2
= "label with mnemonic";
156 SET_LABEL(testLabel2
);
157 CPPUNIT_ASSERT_EQUAL( testLabelText2
, m_st
->GetLabelText() );
158 CPPUNIT_ASSERT_EQUAL( testLabelText2
, m_cb
->GetLabelText() );
160 const wxString
& testLabel3
= "label with <span foreground='blue'>some</span> <b>markup</b>";
161 SET_LABEL(testLabel3
);
162 CPPUNIT_ASSERT_EQUAL( testLabel3
, m_st
->GetLabelText() );
163 CPPUNIT_ASSERT_EQUAL( testLabel3
, m_cb
->GetLabelText() );
165 const wxString
& testLabel4
= "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic";
166 const wxString
& testLabelText4
= "label with <span foreground='blue'>some</span> <b>markup</b> and mnemonic";
167 SET_LABEL(testLabel4
);
168 CPPUNIT_ASSERT_EQUAL( testLabelText4
, m_st
->GetLabelText() );
169 CPPUNIT_ASSERT_EQUAL( testLabelText4
, m_cb
->GetLabelText() );
172 const wxString testLabelArray
[] = {
173 "label without mnemonics and markup",
174 "label with &mnemonic",
175 "label with <span foreground='blue'>some</span> <b>markup</b>",
176 "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic",
179 // test calls to SetLabelText() and then to GetLabelText()
181 for ( unsigned int s
= 0; s
< WXSIZEOF(testLabelArray
); s
++ )
183 SET_LABEL_TEXT(testLabelArray
[s
]);
185 // GetLabelText() should always return the string passed to SetLabelText()
186 CPPUNIT_ASSERT_EQUAL( testLabelArray
[s
], m_st
->GetLabelText() );
187 CPPUNIT_ASSERT_EQUAL( testLabelArray
[s
], m_cb
->GetLabelText() );
191 void LabelTestCase::Statics()
193 CPPUNIT_ASSERT_EQUAL( "mnemonic", wxControl::RemoveMnemonics("&mnemonic") );
194 CPPUNIT_ASSERT_EQUAL( "&mnemonic", wxControl::RemoveMnemonics("&&mnemonic") );
195 CPPUNIT_ASSERT_EQUAL( "&mnemonic", wxControl::RemoveMnemonics("&&&mnemonic") );