]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/choicetest.cpp
Fix install_name_tool calls in OS X "make install".
[wxWidgets.git] / tests / controls / choicetest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/choice.cpp
3 // Purpose: wxChoice unit test
4 // Author: Steven Lamerton
5 // Created: 2010-06-29
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "testprec.h"
10
11 #if wxUSE_CHOICE
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #ifndef WX_PRECOMP
18 #include "wx/app.h"
19 #include "wx/choice.h"
20 #endif // WX_PRECOMP
21
22 #include "itemcontainertest.h"
23
24 class ChoiceTestCase : public ItemContainerTestCase, public CppUnit::TestCase
25 {
26 public:
27 ChoiceTestCase() { }
28
29 virtual void setUp();
30 virtual void tearDown();
31
32 private:
33 virtual wxItemContainer *GetContainer() const { return m_choice; }
34 virtual wxWindow *GetContainerWindow() const { return m_choice; }
35
36 CPPUNIT_TEST_SUITE( ChoiceTestCase );
37 wxITEM_CONTAINER_TESTS();
38 CPPUNIT_TEST( Sort );
39 CPPUNIT_TEST_SUITE_END();
40
41 void Sort();
42
43 wxChoice* m_choice;
44
45 DECLARE_NO_COPY_CLASS(ChoiceTestCase)
46 };
47
48 // register in the unnamed registry so that these tests are run by default
49 CPPUNIT_TEST_SUITE_REGISTRATION( ChoiceTestCase );
50
51 // also include in its own registry so that these tests can be run alone
52 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ChoiceTestCase, "ChoiceTestCase" );
53
54 void ChoiceTestCase::setUp()
55 {
56 m_choice = new wxChoice(wxTheApp->GetTopWindow(), wxID_ANY);
57 }
58
59 void ChoiceTestCase::tearDown()
60 {
61 wxDELETE(m_choice);
62 }
63
64 void ChoiceTestCase::Sort()
65 {
66 #if !defined(__WXOSX__)
67 wxDELETE(m_choice);
68 m_choice = new wxChoice(wxTheApp->GetTopWindow(), wxID_ANY,
69 wxDefaultPosition, wxDefaultSize, 0, 0,
70 wxCB_SORT);
71
72 wxArrayString testitems;
73 testitems.Add("aaa");
74 testitems.Add("Aaa");
75 testitems.Add("aba");
76 testitems.Add("aaab");
77 testitems.Add("aab");
78 testitems.Add("AAA");
79
80 m_choice->Append(testitems);
81
82 CPPUNIT_ASSERT_EQUAL("AAA", m_choice->GetString(0));
83 CPPUNIT_ASSERT_EQUAL("Aaa", m_choice->GetString(1));
84 CPPUNIT_ASSERT_EQUAL("aaa", m_choice->GetString(2));
85 CPPUNIT_ASSERT_EQUAL("aaab", m_choice->GetString(3));
86 CPPUNIT_ASSERT_EQUAL("aab", m_choice->GetString(4));
87 CPPUNIT_ASSERT_EQUAL("aba", m_choice->GetString(5));
88
89 m_choice->Append("a");
90
91 CPPUNIT_ASSERT_EQUAL("a", m_choice->GetString(0));
92 #endif
93 }
94
95 #endif //wxUSE_CHOICE