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