]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/rearrangelisttest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/rearrangelisttest.cpp
3 // Purpose: wxRearrangeList unit test
4 // Author: Steven Lamerton
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
19 #include "wx/rearrangectrl.h"
20 #include "itemcontainertest.h"
21 #include "testableframe.h"
23 class RearrangeListTestCase
: public ItemContainerTestCase
, public CppUnit::TestCase
26 RearrangeListTestCase() { }
29 virtual void tearDown();
32 virtual wxItemContainer
*GetContainer() const { return m_rearrange
; }
33 virtual wxWindow
*GetContainerWindow() const { return m_rearrange
; }
35 CPPUNIT_TEST_SUITE( RearrangeListTestCase
);
36 wxITEM_CONTAINER_TESTS();
38 CPPUNIT_TEST( MoveClientData
);
39 CPPUNIT_TEST_SUITE_END();
42 void MoveClientData();
44 wxRearrangeList
* m_rearrange
;
46 DECLARE_NO_COPY_CLASS(RearrangeListTestCase
)
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( RearrangeListTestCase
);
52 // also include in its own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RearrangeListTestCase
, "RearrangeListTestCase" );
55 void RearrangeListTestCase::setUp()
57 //We do not add items here as the wxITEM_CONTAINER_TESTS add their own
61 m_rearrange
= new wxRearrangeList(wxTheApp
->GetTopWindow(), wxID_ANY
,
62 wxDefaultPosition
, wxDefaultSize
, order
,
66 void RearrangeListTestCase::tearDown()
68 wxDELETE(m_rearrange
);
71 void RearrangeListTestCase::Move()
79 items
.push_back("first");
80 items
.push_back("second");
81 items
.push_back("third");
83 wxDELETE(m_rearrange
);
85 m_rearrange
= new wxRearrangeList(wxTheApp
->GetTopWindow(), wxID_ANY
,
86 wxDefaultPosition
, wxDefaultSize
, order
,
89 //Confusingly setselection sets the physical item rather than the
90 //item specified in the constructor
91 m_rearrange
->SetSelection(0);
93 CPPUNIT_ASSERT(!m_rearrange
->CanMoveCurrentUp());
94 CPPUNIT_ASSERT(m_rearrange
->CanMoveCurrentDown());
96 m_rearrange
->SetSelection(1);
98 CPPUNIT_ASSERT(m_rearrange
->CanMoveCurrentUp());
99 CPPUNIT_ASSERT(m_rearrange
->CanMoveCurrentDown());
101 m_rearrange
->SetSelection(2);
103 CPPUNIT_ASSERT(m_rearrange
->CanMoveCurrentUp());
104 CPPUNIT_ASSERT(!m_rearrange
->CanMoveCurrentDown());
106 m_rearrange
->MoveCurrentUp();
107 m_rearrange
->SetSelection(0);
108 m_rearrange
->MoveCurrentDown();
110 wxArrayInt neworder
= m_rearrange
->GetCurrentOrder();
112 CPPUNIT_ASSERT_EQUAL(neworder
[0], 0);
113 CPPUNIT_ASSERT_EQUAL(neworder
[1], 1);
114 CPPUNIT_ASSERT_EQUAL(neworder
[2], ~2);
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));
121 void RearrangeListTestCase::MoveClientData()
129 items
.push_back("first");
130 items
.push_back("second");
131 items
.push_back("third");
133 wxClientData
* item0data
= new wxStringClientData("item0data");
134 wxClientData
* item1data
= new wxStringClientData("item1data");
135 wxClientData
* item2data
= new wxStringClientData("item2data");
137 wxDELETE(m_rearrange
);
139 m_rearrange
= new wxRearrangeList(wxTheApp
->GetTopWindow(), wxID_ANY
,
140 wxDefaultPosition
, wxDefaultSize
, order
,
143 m_rearrange
->SetClientObject(0, item0data
);
144 m_rearrange
->SetClientObject(1, item1data
);
145 m_rearrange
->SetClientObject(2, item2data
);
147 m_rearrange
->SetSelection(0);
148 m_rearrange
->MoveCurrentDown();
150 m_rearrange
->SetSelection(2);
151 m_rearrange
->MoveCurrentUp();
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));
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));