Add a unit test checking selection updating in virtual wxListCtrl.
[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 // RCS-ID: $Id$
7 // Copyright: (c) 2010 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 #if wxUSE_LISTCTRL
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #ifndef WX_PRECOMP
23 #include "wx/app.h"
24 #endif // WX_PRECOMP
25
26 #include "wx/listctrl.h"
27
28 // ----------------------------------------------------------------------------
29 // test class
30 // ----------------------------------------------------------------------------
31
32 class VirtListCtrlTestCase : public CppUnit::TestCase
33 {
34 public:
35 VirtListCtrlTestCase() { }
36
37 virtual void setUp();
38 virtual void tearDown();
39
40 private:
41 CPPUNIT_TEST_SUITE( VirtListCtrlTestCase );
42 CPPUNIT_TEST( UpdateSelection );
43 CPPUNIT_TEST_SUITE_END();
44
45 void UpdateSelection();
46
47 wxListCtrl *m_list;
48
49 wxDECLARE_NO_COPY_CLASS(VirtListCtrlTestCase);
50 };
51
52 // register in the unnamed registry so that these tests are run by default
53 CPPUNIT_TEST_SUITE_REGISTRATION( VirtListCtrlTestCase );
54
55 // also include in it's own registry so that these tests can be run alone
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VirtListCtrlTestCase, "VirtListCtrlTestCase" );
57
58 // ----------------------------------------------------------------------------
59 // test initialization
60 // ----------------------------------------------------------------------------
61
62 void VirtListCtrlTestCase::setUp()
63 {
64 m_list = new wxListCtrl(wxTheApp->GetTopWindow(), wxID_ANY,
65 wxPoint(0, 0), wxSize(400, 200),
66 wxLC_REPORT | wxLC_VIRTUAL);
67 }
68
69 void VirtListCtrlTestCase::tearDown()
70 {
71 delete m_list;
72 m_list = NULL;
73 }
74
75 void VirtListCtrlTestCase::UpdateSelection()
76 {
77 m_list->SetItemCount(10);
78 CPPUNIT_ASSERT_EQUAL( 0, m_list->GetSelectedItemCount() );
79
80 m_list->SetItemState(7, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
81 CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() );
82
83 m_list->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
84 CPPUNIT_ASSERT_EQUAL( 2, m_list->GetSelectedItemCount() );
85
86 // The item 7 is now invalid and so shouldn't be counted as selected any
87 // more.
88 m_list->SetItemCount(5);
89 CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() );
90 }
91
92 #endif // wxUSE_LISTCTRL