]>
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 // ----------------------------------------------------------------------------
24 #include "wx/listctrl.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 class ListCtrlTestCase
: public CppUnit::TestCase
33 ListCtrlTestCase() { }
36 virtual void tearDown();
39 CPPUNIT_TEST_SUITE( ListCtrlTestCase
);
40 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
41 CPPUNIT_TEST( ColumnsOrder
);
42 #endif // wxHAS_LISTCTRL_COLUMN_ORDER
43 CPPUNIT_TEST_SUITE_END();
45 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
47 #endif // wxHAS_LISTCTRL_COLUMN_ORDER
51 DECLARE_NO_COPY_CLASS(ListCtrlTestCase
)
54 // register in the unnamed registry so that these tests are run by default
55 CPPUNIT_TEST_SUITE_REGISTRATION( ListCtrlTestCase
);
57 // also include in it's own registry so that these tests can be run alone
58 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListCtrlTestCase
, "ListCtrlTestCase" );
60 // ----------------------------------------------------------------------------
61 // test initialization
62 // ----------------------------------------------------------------------------
64 void ListCtrlTestCase::setUp()
66 m_list
= new wxListCtrl(wxTheApp
->GetTopWindow());
69 void ListCtrlTestCase::tearDown()
75 // ----------------------------------------------------------------------------
76 // the tests themselves
77 // ----------------------------------------------------------------------------
79 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
81 void ListCtrlTestCase::ColumnsOrder()
83 static const int NUM_COLS
;
86 li
.SetMask(wxLIST_MASK_TEXT
);
88 // first set up some columns
89 m_list
->InsertColumn(0, "Column 0");
90 m_list
->InsertColumn(1, "Column 1");
91 m_list
->InsertColumn(2, "Column 2");
93 // and a couple of test items too
94 m_list
->InsertItem(0, "Item 0");
95 m_list
->SetItem(0, 1, "first in first");
97 m_list
->InsertItem(1, "Item 1");
98 m_list
->SetItem(1, 2, "second in second");
101 // check that the order is natural in the beginning
102 const wxArrayInt orderOrig
= m_list
->GetColumnsOrder();
103 for ( n
= 0; n
< NUM_COLS
; n
++ )
104 CPPUNIT_ASSERT_EQUAL( n
, orderOrig
[n
] );
106 // then rearrange them: using { 2, 0, 1 } order means that column 2 is
107 // shown first, then column 0 and finally column 1
112 m_list
->SetColumnsOrder(order
);
114 // check that we get back the same order as we set
115 const wxArrayInt orderNew
= m_list
->GetColumnsOrder();
116 for ( n
= 0; n
< NUM_COLS
; n
++ )
117 CPPUNIT_ASSERT_EQUAL( order
[n
], orderNew
[n
] );
119 // and the order -> index mappings for individual columns
120 for ( n
= 0; n
< NUM_COLS
; n
++ )
121 CPPUNIT_ASSERT_EQUAL( order
[n
], m_list
->GetColumnIndexFromOrder(n
) );
123 // and also the reverse mapping
124 CPPUNIT_ASSERT_EQUAL( 1, m_list
->GetColumnOrder(0) );
125 CPPUNIT_ASSERT_EQUAL( 2, m_list
->GetColumnOrder(1) );
126 CPPUNIT_ASSERT_EQUAL( 0, m_list
->GetColumnOrder(2) );
129 // finally check that accessors still use indices, not order
130 CPPUNIT_ASSERT( m_list
->GetColumn(0, li
) );
131 CPPUNIT_ASSERT_EQUAL( "Column 0", li
.GetText() );
135 CPPUNIT_ASSERT( m_list
->GetItem(li
) );
136 CPPUNIT_ASSERT_EQUAL( "first in first", li
.GetText() );
140 CPPUNIT_ASSERT( m_list
->GetItem(li
) );
141 CPPUNIT_ASSERT_EQUAL( "second in second", li
.GetText() );
144 #endif // wxHAS_LISTCTRL_COLUMN_ORDER