]>
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
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
20 #include "wx/rearrangectrl.h"
21 #include "itemcontainertest.h"
22 #include "testableframe.h"
24 class RearrangeListTestCase
: public ItemContainerTestCase
, public CppUnit::TestCase
27 RearrangeListTestCase() { }
30 virtual void tearDown();
33 virtual wxItemContainer
*GetContainer() const { return m_rearrange
; }
34 virtual wxWindow
*GetContainerWindow() const { return m_rearrange
; }
36 CPPUNIT_TEST_SUITE( RearrangeListTestCase
);
37 wxITEM_CONTAINER_TESTS();
39 CPPUNIT_TEST( MoveClientData
);
40 CPPUNIT_TEST_SUITE_END();
43 void MoveClientData();
45 wxRearrangeList
* m_rearrange
;
47 DECLARE_NO_COPY_CLASS(RearrangeListTestCase
)
50 // register in the unnamed registry so that these tests are run by default
51 CPPUNIT_TEST_SUITE_REGISTRATION( RearrangeListTestCase
);
53 // also include in its own registry so that these tests can be run alone
54 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RearrangeListTestCase
, "RearrangeListTestCase" );
56 void RearrangeListTestCase::setUp()
58 //We do not add items here as the wxITEM_CONTAINER_TESTS add their own
62 m_rearrange
= new wxRearrangeList(wxTheApp
->GetTopWindow(), wxID_ANY
,
63 wxDefaultPosition
, wxDefaultSize
, order
,
67 void RearrangeListTestCase::tearDown()
69 wxDELETE(m_rearrange
);
72 void RearrangeListTestCase::Move()
80 items
.push_back("first");
81 items
.push_back("second");
82 items
.push_back("third");
84 wxDELETE(m_rearrange
);
86 m_rearrange
= new wxRearrangeList(wxTheApp
->GetTopWindow(), wxID_ANY
,
87 wxDefaultPosition
, wxDefaultSize
, order
,
90 //Confusingly setselection sets the physical item rather than the
91 //item specified in the constructor
92 m_rearrange
->SetSelection(0);
94 CPPUNIT_ASSERT(!m_rearrange
->CanMoveCurrentUp());
95 CPPUNIT_ASSERT(m_rearrange
->CanMoveCurrentDown());
97 m_rearrange
->SetSelection(1);
99 CPPUNIT_ASSERT(m_rearrange
->CanMoveCurrentUp());
100 CPPUNIT_ASSERT(m_rearrange
->CanMoveCurrentDown());
102 m_rearrange
->SetSelection(2);
104 CPPUNIT_ASSERT(m_rearrange
->CanMoveCurrentUp());
105 CPPUNIT_ASSERT(!m_rearrange
->CanMoveCurrentDown());
107 m_rearrange
->MoveCurrentUp();
108 m_rearrange
->SetSelection(0);
109 m_rearrange
->MoveCurrentDown();
111 wxArrayInt neworder
= m_rearrange
->GetCurrentOrder();
113 CPPUNIT_ASSERT_EQUAL(neworder
[0], 0);
114 CPPUNIT_ASSERT_EQUAL(neworder
[1], 1);
115 CPPUNIT_ASSERT_EQUAL(neworder
[2], ~2);
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));
122 void RearrangeListTestCase::MoveClientData()
130 items
.push_back("first");
131 items
.push_back("second");
132 items
.push_back("third");
134 wxClientData
* item0data
= new wxStringClientData("item0data");
135 wxClientData
* item1data
= new wxStringClientData("item1data");
136 wxClientData
* item2data
= new wxStringClientData("item2data");
138 wxDELETE(m_rearrange
);
140 m_rearrange
= new wxRearrangeList(wxTheApp
->GetTopWindow(), wxID_ANY
,
141 wxDefaultPosition
, wxDefaultSize
, order
,
144 m_rearrange
->SetClientObject(0, item0data
);
145 m_rearrange
->SetClientObject(1, item1data
);
146 m_rearrange
->SetClientObject(2, item2data
);
148 m_rearrange
->SetSelection(0);
149 m_rearrange
->MoveCurrentDown();
151 m_rearrange
->SetSelection(2);
152 m_rearrange
->MoveCurrentUp();
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));
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));