]>
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
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 ();
51 wxStaticText
* m_st
, * m_stWithMarkup
;
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 it's 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
);
74 m_stWithMarkup
= new wxStaticText ( wxTheApp
-> GetTopWindow (), wxID_ANY
, ORIGINAL_LABEL
,
75 wxDefaultPosition
, wxDefaultSize
, wxST_MARKUP
);
77 m_cb
= new wxCheckBox ( wxTheApp
-> GetTopWindow (), wxID_ANY
, ORIGINAL_LABEL
);
79 CPPUNIT_ASSERT_EQUAL ( ORIGINAL_LABEL
, m_st
-> GetLabel () );
80 CPPUNIT_ASSERT_EQUAL ( ORIGINAL_LABEL
, m_stWithMarkup
-> GetLabel () );
81 CPPUNIT_ASSERT_EQUAL ( ORIGINAL_LABEL
, m_cb
-> GetLabel () );
84 void LabelTestCase :: tearDown ()
87 wxDELETE ( m_stWithMarkup
);
91 // ----------------------------------------------------------------------------
92 // the tests themselves
93 // ----------------------------------------------------------------------------
95 #define SET_LABEL(str) \
96 m_st->SetLabel(str); \
97 m_stWithMarkup->SetLabel(str); \
100 #define SET_LABEL_TEXT(str) \
101 m_st->SetLabelText(str); \
102 m_stWithMarkup->SetLabelText(str); \
103 m_cb->SetLabelText(str);
105 void LabelTestCase :: GetLabel ()
107 const wxString testLabelArray
[] = {
108 "label without mnemonics and markup" ,
109 "label with &mnemonic" ,
110 "label with <span foreground='blue'>some</span> <b>markup</b>" ,
111 "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic" ,
114 // test calls to SetLabel() and then to GetLabel()
116 for ( unsigned int s
= 0 ; s
< WXSIZEOF ( testLabelArray
); s
++ )
118 SET_LABEL ( testLabelArray
[ s
]);
120 // GetLabel() should always return the string passed to SetLabel()
121 CPPUNIT_ASSERT_EQUAL ( testLabelArray
[ s
], m_st
-> GetLabel () );
122 CPPUNIT_ASSERT_EQUAL ( testLabelArray
[ s
], m_stWithMarkup
-> GetLabel () );
123 CPPUNIT_ASSERT_EQUAL ( testLabelArray
[ s
], m_cb
-> GetLabel () );
127 // test calls to SetLabelText() and then to GetLabel()
129 const wxString
& testLabel
= "label without mnemonics and markup" ;
130 SET_LABEL_TEXT ( testLabel
);
131 CPPUNIT_ASSERT_EQUAL ( testLabel
, m_st
-> GetLabel () );
132 CPPUNIT_ASSERT_EQUAL ( testLabel
, m_stWithMarkup
-> GetLabel () );
133 CPPUNIT_ASSERT_EQUAL ( testLabel
, m_cb
-> GetLabel () );
135 const wxString
& testLabel2
= "label with &mnemonic" ;
136 const wxString
& testLabelText2
= "label with &&mnemonic" ;
137 SET_LABEL_TEXT ( testLabel2
);
138 CPPUNIT_ASSERT_EQUAL ( testLabelText2
, m_st
-> GetLabel () );
139 CPPUNIT_ASSERT_EQUAL ( "label with &mnemonic" , m_stWithMarkup
-> GetLabel () );
140 CPPUNIT_ASSERT_EQUAL ( testLabelText2
, m_cb
-> GetLabel () );
142 const wxString
& testLabel3
= "label with <span foreground='blue'>some</span> <b>markup</b>" ;
143 SET_LABEL_TEXT ( testLabel3
);
144 CPPUNIT_ASSERT_EQUAL ( testLabel3
, m_st
-> GetLabel () );
145 CPPUNIT_ASSERT_EQUAL ( "label with <span foreground='blue'>some</span> <b>markup</b>" , m_stWithMarkup
-> GetLabel () );
146 CPPUNIT_ASSERT_EQUAL ( testLabel3
, m_cb
-> GetLabel () );
148 const wxString
& testLabel4
= "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic" ;
149 const wxString
& testLabelText4
= "label with <span foreground='blue'>some</span> <b>markup</b> and &&mnemonic" ;
150 SET_LABEL_TEXT ( testLabel4
);
151 CPPUNIT_ASSERT_EQUAL ( testLabelText4
, m_st
-> GetLabel () );
152 CPPUNIT_ASSERT_EQUAL ( "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic" , m_stWithMarkup
-> GetLabel () );
153 CPPUNIT_ASSERT_EQUAL ( testLabelText4
, m_cb
-> GetLabel () );
156 void LabelTestCase :: GetLabelText ()
158 // test calls to SetLabel() and then to GetLabelText()
160 const wxString
& testLabel
= "label without mnemonics and markup" ;
161 SET_LABEL ( testLabel
);
162 CPPUNIT_ASSERT_EQUAL ( testLabel
, m_st
-> GetLabelText () );
163 CPPUNIT_ASSERT_EQUAL ( testLabel
, m_stWithMarkup
-> GetLabelText () );
164 CPPUNIT_ASSERT_EQUAL ( testLabel
, m_cb
-> GetLabelText () );
166 const wxString
& testLabel2
= "label with &mnemonic" ;
167 const wxString
& testLabelText2
= "label with mnemonic" ;
168 SET_LABEL ( testLabel2
);
169 CPPUNIT_ASSERT_EQUAL ( testLabelText2
, m_st
-> GetLabelText () );
170 CPPUNIT_ASSERT_EQUAL ( testLabelText2
, m_stWithMarkup
-> GetLabelText () );
171 CPPUNIT_ASSERT_EQUAL ( testLabelText2
, m_cb
-> GetLabelText () );
173 const wxString
& testLabel3
= "label with <span foreground='blue'>some</span> <b>markup</b>" ;
174 SET_LABEL ( testLabel3
);
175 CPPUNIT_ASSERT_EQUAL ( testLabel3
, m_st
-> GetLabelText () );
176 CPPUNIT_ASSERT_EQUAL ( "label with some markup" , m_stWithMarkup
-> GetLabelText () );
177 CPPUNIT_ASSERT_EQUAL ( testLabel3
, m_cb
-> GetLabelText () );
179 const wxString
& testLabel4
= "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic" ;
180 const wxString
& testLabelText4
= "label with <span foreground='blue'>some</span> <b>markup</b> and mnemonic" ;
181 SET_LABEL ( testLabel4
);
182 CPPUNIT_ASSERT_EQUAL ( testLabelText4
, m_st
-> GetLabelText () );
183 CPPUNIT_ASSERT_EQUAL ( "label with some markup and mnemonic" , m_stWithMarkup
-> GetLabelText () );
184 CPPUNIT_ASSERT_EQUAL ( testLabelText4
, m_cb
-> GetLabelText () );
187 const wxString testLabelArray
[] = {
188 "label without mnemonics and markup" ,
189 "label with &mnemonic" ,
190 "label with <span foreground='blue'>some</span> <b>markup</b>" ,
191 "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic" ,
194 // test calls to SetLabelText() and then to GetLabelText()
196 for ( unsigned int s
= 0 ; s
< WXSIZEOF ( testLabelArray
); s
++ )
198 SET_LABEL_TEXT ( testLabelArray
[ s
]);
200 // GetLabelText() should always return the string passed to SetLabelText()
201 CPPUNIT_ASSERT_EQUAL ( testLabelArray
[ s
], m_st
-> GetLabelText () );
202 CPPUNIT_ASSERT_EQUAL ( testLabelArray
[ s
], m_stWithMarkup
-> GetLabelText () );
203 CPPUNIT_ASSERT_EQUAL ( testLabelArray
[ s
], m_cb
-> GetLabelText () );
207 void LabelTestCase :: Statics ()
209 CPPUNIT_ASSERT_EQUAL ( "mnemonic" , wxControl :: RemoveMnemonics ( "&mnemonic" ) );
210 CPPUNIT_ASSERT_EQUAL ( "&mnemonic" , wxControl :: RemoveMnemonics ( "&&mnemonic" ) );
211 CPPUNIT_ASSERT_EQUAL ( "&mnemonic" , wxControl :: RemoveMnemonics ( "&&&mnemonic" ) );
212 CPPUNIT_ASSERT_EQUAL ( "" , wxStaticText :: RemoveMarkup ( "<b></b>" ) );