]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/rearrangelisttest.cpp
Don't document wxSortedArrayString as deriving from wxArrayString.
[wxWidgets.git] / tests / controls / rearrangelisttest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/rearrangelisttest.cpp
3 // Purpose: wxRearrangeList unit test
4 // Author: Steven Lamerton
5 // Created: 2010-07-05
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "testprec.h"
10
11 #ifdef __BORLANDC__
12 #pragma hdrstop
13 #endif
14
15 #ifndef WX_PRECOMP
16 #include "wx/app.h"
17 #endif // WX_PRECOMP
18
19 #include "wx/rearrangectrl.h"
20 #include "itemcontainertest.h"
21 #include "testableframe.h"
22
23 class RearrangeListTestCase : public ItemContainerTestCase, public CppUnit::TestCase
24 {
25 public:
26 RearrangeListTestCase() { }
27
28 virtual void setUp();
29 virtual void tearDown();
30
31 private:
32 virtual wxItemContainer *GetContainer() const { return m_rearrange; }
33 virtual wxWindow *GetContainerWindow() const { return m_rearrange; }
34
35 CPPUNIT_TEST_SUITE( RearrangeListTestCase );
36 wxITEM_CONTAINER_TESTS();
37 CPPUNIT_TEST( Move );
38 CPPUNIT_TEST( MoveClientData );
39 CPPUNIT_TEST_SUITE_END();
40
41 void Move();
42 void MoveClientData();
43
44 wxRearrangeList* m_rearrange;
45
46 DECLARE_NO_COPY_CLASS(RearrangeListTestCase)
47 };
48
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( RearrangeListTestCase );
51
52 // also include in its own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RearrangeListTestCase, "RearrangeListTestCase" );
54
55 void RearrangeListTestCase::setUp()
56 {
57 //We do not add items here as the wxITEM_CONTAINER_TESTS add their own
58 wxArrayInt order;
59 wxArrayString items;
60
61 m_rearrange = new wxRearrangeList(wxTheApp->GetTopWindow(), wxID_ANY,
62 wxDefaultPosition, wxDefaultSize, order,
63 items);
64 }
65
66 void RearrangeListTestCase::tearDown()
67 {
68 wxDELETE(m_rearrange);
69 }
70
71 void RearrangeListTestCase::Move()
72 {
73 wxArrayInt order;
74 order.push_back(1);
75 order.push_back(~2);
76 order.push_back(0);
77
78 wxArrayString items;
79 items.push_back("first");
80 items.push_back("second");
81 items.push_back("third");
82
83 wxDELETE(m_rearrange);
84
85 m_rearrange = new wxRearrangeList(wxTheApp->GetTopWindow(), wxID_ANY,
86 wxDefaultPosition, wxDefaultSize, order,
87 items);
88
89 //Confusingly setselection sets the physical item rather than the
90 //item specified in the constructor
91 m_rearrange->SetSelection(0);
92
93 CPPUNIT_ASSERT(!m_rearrange->CanMoveCurrentUp());
94 CPPUNIT_ASSERT(m_rearrange->CanMoveCurrentDown());
95
96 m_rearrange->SetSelection(1);
97
98 CPPUNIT_ASSERT(m_rearrange->CanMoveCurrentUp());
99 CPPUNIT_ASSERT(m_rearrange->CanMoveCurrentDown());
100
101 m_rearrange->SetSelection(2);
102
103 CPPUNIT_ASSERT(m_rearrange->CanMoveCurrentUp());
104 CPPUNIT_ASSERT(!m_rearrange->CanMoveCurrentDown());
105
106 m_rearrange->MoveCurrentUp();
107 m_rearrange->SetSelection(0);
108 m_rearrange->MoveCurrentDown();
109
110 wxArrayInt neworder = m_rearrange->GetCurrentOrder();
111
112 CPPUNIT_ASSERT_EQUAL(neworder[0], 0);
113 CPPUNIT_ASSERT_EQUAL(neworder[1], 1);
114 CPPUNIT_ASSERT_EQUAL(neworder[2], ~2);
115
116 CPPUNIT_ASSERT_EQUAL("first", m_rearrange->GetString(0));
117 CPPUNIT_ASSERT_EQUAL("second", m_rearrange->GetString(1));
118 CPPUNIT_ASSERT_EQUAL("third", m_rearrange->GetString(2));
119 }
120
121 void RearrangeListTestCase::MoveClientData()
122 {
123 wxArrayInt order;
124 order.push_back(0);
125 order.push_back(1);
126 order.push_back(2);
127
128 wxArrayString items;
129 items.push_back("first");
130 items.push_back("second");
131 items.push_back("third");
132
133 wxClientData* item0data = new wxStringClientData("item0data");
134 wxClientData* item1data = new wxStringClientData("item1data");
135 wxClientData* item2data = new wxStringClientData("item2data");
136
137 wxDELETE(m_rearrange);
138
139 m_rearrange = new wxRearrangeList(wxTheApp->GetTopWindow(), wxID_ANY,
140 wxDefaultPosition, wxDefaultSize, order,
141 items);
142
143 m_rearrange->SetClientObject(0, item0data);
144 m_rearrange->SetClientObject(1, item1data);
145 m_rearrange->SetClientObject(2, item2data);
146
147 m_rearrange->SetSelection(0);
148 m_rearrange->MoveCurrentDown();
149
150 m_rearrange->SetSelection(2);
151 m_rearrange->MoveCurrentUp();
152
153 CPPUNIT_ASSERT_EQUAL(item1data, m_rearrange->GetClientObject(0));
154 CPPUNIT_ASSERT_EQUAL(item2data, m_rearrange->GetClientObject(1));
155 CPPUNIT_ASSERT_EQUAL(item0data, m_rearrange->GetClientObject(2));
156
157 CPPUNIT_ASSERT_EQUAL("second", m_rearrange->GetString(0));
158 CPPUNIT_ASSERT_EQUAL("third", m_rearrange->GetString(1));
159 CPPUNIT_ASSERT_EQUAL("first", m_rearrange->GetString(2));
160 }