]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/listctrltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/listctrltest.cpp
3 // Purpose: wxListCtrl unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
22 #include "wx/listctrl.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 class ListCtrlTestCase
: public CppUnit::TestCase
32 ListCtrlTestCase() { }
35 virtual void tearDown();
38 CPPUNIT_TEST_SUITE( ListCtrlTestCase
);
39 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
40 CPPUNIT_TEST( ColumnsOrder
);
41 #endif // wxHAS_LISTCTRL_COLUMN_ORDER
42 CPPUNIT_TEST_SUITE_END();
44 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
46 #endif // wxHAS_LISTCTRL_COLUMN_ORDER
50 DECLARE_NO_COPY_CLASS(ListCtrlTestCase
)
53 // register in the unnamed registry so that these tests are run by default
54 CPPUNIT_TEST_SUITE_REGISTRATION( ListCtrlTestCase
);
56 // also include in it's own registry so that these tests can be run alone
57 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListCtrlTestCase
, "ListCtrlTestCase" );
59 // ----------------------------------------------------------------------------
60 // test initialization
61 // ----------------------------------------------------------------------------
63 void ListCtrlTestCase::setUp()
65 m_list
= new wxListCtrl(wxTheApp
->GetTopWindow());
68 void ListCtrlTestCase::tearDown()
74 // ----------------------------------------------------------------------------
75 // the tests themselves
76 // ----------------------------------------------------------------------------
78 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
80 void ListCtrlTestCase::ColumnsOrder()
82 static const int NUM_COLS
;
85 li
.SetMask(wxLIST_MASK_TEXT
);
87 // first set up some columns
88 m_list
->InsertColumn(0, "Column 0");
89 m_list
->InsertColumn(1, "Column 1");
90 m_list
->InsertColumn(2, "Column 2");
92 // and a couple of test items too
93 m_list
->InsertItem(0, "Item 0");
94 m_list
->SetItem(0, 1, "first in first");
96 m_list
->InsertItem(1, "Item 1");
97 m_list
->SetItem(1, 2, "second in second");
100 // check that the order is natural in the beginning
101 const wxArrayInt orderOrig
= m_list
->GetColumnsOrder();
102 for ( n
= 0; n
< NUM_COLS
; n
++ )
103 CPPUNIT_ASSERT_EQUAL( n
, orderOrig
[n
] );
105 // then rearrange them: using { 2, 0, 1 } order means that column 2 is
106 // shown first, then column 0 and finally column 1
111 m_list
->SetColumnsOrder(order
);
113 // check that we get back the same order as we set
114 const wxArrayInt orderNew
= m_list
->GetColumnsOrder();
115 for ( n
= 0; n
< NUM_COLS
; n
++ )
116 CPPUNIT_ASSERT_EQUAL( order
[n
], orderNew
[n
] );
118 // and the order -> index mappings for individual columns
119 for ( n
= 0; n
< NUM_COLS
; n
++ )
120 CPPUNIT_ASSERT_EQUAL( order
[n
], m_list
->GetColumnIndexFromOrder(n
) );
122 // and also the reverse mapping
123 CPPUNIT_ASSERT_EQUAL( 1, m_list
->GetColumnOrder(0) );
124 CPPUNIT_ASSERT_EQUAL( 2, m_list
->GetColumnOrder(1) );
125 CPPUNIT_ASSERT_EQUAL( 0, m_list
->GetColumnOrder(2) );
128 // finally check that accessors still use indices, not order
129 CPPUNIT_ASSERT( m_list
->GetColumn(0, li
) );
130 CPPUNIT_ASSERT_EQUAL( "Column 0", li
.GetText() );
134 CPPUNIT_ASSERT( m_list
->GetItem(li
) );
135 CPPUNIT_ASSERT_EQUAL( "first in first", li
.GetText() );
139 CPPUNIT_ASSERT( m_list
->GetItem(li
) );
140 CPPUNIT_ASSERT_EQUAL( "second in second", li
.GetText() );
143 #endif // wxHAS_LISTCTRL_COLUMN_ORDER