]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/listctrltest.cpp
split AddCatalog docs for the two overloads
[wxWidgets.git] / tests / controls / listctrltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/listctrltest.cpp
3 // Purpose: wxListCtrl unit test
4 // Author: Vadim Zeitlin
5 // Created: 2008-11-26
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WX_PRECOMP
21 #include "wx/app.h"
22 #include "wx/listctrl.h"
23 #endif // WX_PRECOMP
24
25 // ----------------------------------------------------------------------------
26 // test class
27 // ----------------------------------------------------------------------------
28
29 class ListCtrlTestCase : public CppUnit::TestCase
30 {
31 public:
32 ListCtrlTestCase() { }
33
34 virtual void setUp();
35 virtual void tearDown();
36
37 private:
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();
43
44 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
45 void ColumnsOrder();
46 #endif // wxHAS_LISTCTRL_COLUMN_ORDER
47
48 wxListCtrl *m_list;
49
50 DECLARE_NO_COPY_CLASS(ListCtrlTestCase)
51 };
52
53 // register in the unnamed registry so that these tests are run by default
54 CPPUNIT_TEST_SUITE_REGISTRATION( ListCtrlTestCase );
55
56 // also include in it's own registry so that these tests can be run alone
57 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListCtrlTestCase, "ListCtrlTestCase" );
58
59 // ----------------------------------------------------------------------------
60 // test initialization
61 // ----------------------------------------------------------------------------
62
63 void ListCtrlTestCase::setUp()
64 {
65 m_list = new wxListCtrl(wxTheApp->GetTopWindow());
66 }
67
68 void ListCtrlTestCase::tearDown()
69 {
70 delete m_list;
71 m_list = NULL;
72 }
73
74 // ----------------------------------------------------------------------------
75 // the tests themselves
76 // ----------------------------------------------------------------------------
77
78 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
79
80 void ListCtrlTestCase::ColumnsOrder()
81 {
82 static const int NUM_COLS;
83 int n;
84 wxListItem li;
85 li.SetMask(wxLIST_MASK_TEXT);
86
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");
91
92 // and a couple of test items too
93 m_list->InsertItem(0, "Item 0");
94 m_list->SetItem(0, 1, "first in first");
95
96 m_list->InsertItem(1, "Item 1");
97 m_list->SetItem(1, 2, "second in second");
98
99
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] );
104
105 // then rearrange them: using { 2, 0, 1 } order means that column 2 is
106 // shown first, then column 0 and finally column 1
107 wxArrayInt order(3);
108 order[0] = 2;
109 order[1] = 0;
110 order[2] = 1;
111 m_list->SetColumnsOrder(order);
112
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] );
117
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) );
121
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) );
126
127
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() );
131
132 li.SetId(0);
133 li.SetColumn(1);
134 CPPUNIT_ASSERT( m_list->GetItem(li) );
135 CPPUNIT_ASSERT_EQUAL( "first in first", li.GetText() );
136
137 li.SetId(1);
138 li.SetColumn(2);
139 CPPUNIT_ASSERT( m_list->GetItem(li) );
140 CPPUNIT_ASSERT_EQUAL( "second in second", li.GetText() );
141 }
142
143 #endif // wxHAS_LISTCTRL_COLUMN_ORDER