Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / tests / controls / virtlistctrltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/virtlistctrltest.cpp
3 // Purpose: wxListCtrl unit tests for virtual mode
4 // Author: Vadim Zeitlin
5 // Created: 2010-11-13
6 // Copyright: (c) 2010 Vadim Zeitlin <vadim@wxwidgets.org>
7 ///////////////////////////////////////////////////////////////////////////////
8
9 // ----------------------------------------------------------------------------
10 // headers
11 // ----------------------------------------------------------------------------
12
13 #include "testprec.h"
14
15 #if wxUSE_LISTCTRL
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 #ifndef WX_PRECOMP
22 #include "wx/app.h"
23 #endif // WX_PRECOMP
24
25 #include "wx/listctrl.h"
26
27 // ----------------------------------------------------------------------------
28 // test class
29 // ----------------------------------------------------------------------------
30
31 class VirtListCtrlTestCase : public CppUnit::TestCase
32 {
33 public:
34 VirtListCtrlTestCase() { }
35
36 virtual void setUp();
37 virtual void tearDown();
38
39 private:
40 CPPUNIT_TEST_SUITE( VirtListCtrlTestCase );
41 CPPUNIT_TEST( UpdateSelection );
42 CPPUNIT_TEST_SUITE_END();
43
44 void UpdateSelection();
45
46 wxListCtrl *m_list;
47
48 wxDECLARE_NO_COPY_CLASS(VirtListCtrlTestCase);
49 };
50
51 // register in the unnamed registry so that these tests are run by default
52 CPPUNIT_TEST_SUITE_REGISTRATION( VirtListCtrlTestCase );
53
54 // also include in its own registry so that these tests can be run alone
55 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VirtListCtrlTestCase, "VirtListCtrlTestCase" );
56
57 // ----------------------------------------------------------------------------
58 // test initialization
59 // ----------------------------------------------------------------------------
60
61 void VirtListCtrlTestCase::setUp()
62 {
63 // Define a class overriding OnGetItemText() which must be overridden for
64 // any virtual list control.
65 class VirtListCtrl : public wxListCtrl
66 {
67 public:
68 VirtListCtrl()
69 : wxListCtrl(wxTheApp->GetTopWindow(), wxID_ANY,
70 wxPoint(0, 0), wxSize(400, 200),
71 wxLC_REPORT | wxLC_VIRTUAL)
72 {
73 }
74
75 protected:
76 virtual wxString OnGetItemText(long item, long column) const
77 {
78 return wxString::Format("Row %ld, col %ld", item, column);
79 }
80 };
81
82 m_list = new VirtListCtrl;
83 }
84
85 void VirtListCtrlTestCase::tearDown()
86 {
87 delete m_list;
88 m_list = NULL;
89 }
90
91 void VirtListCtrlTestCase::UpdateSelection()
92 {
93 m_list->SetItemCount(10);
94 CPPUNIT_ASSERT_EQUAL( 0, m_list->GetSelectedItemCount() );
95
96 m_list->SetItemState(7, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
97 CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() );
98
99 m_list->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
100 CPPUNIT_ASSERT_EQUAL( 2, m_list->GetSelectedItemCount() );
101
102 // The item 7 is now invalid and so shouldn't be counted as selected any
103 // more.
104 m_list->SetItemCount(5);
105 CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() );
106 }
107
108 #endif // wxUSE_LISTCTRL