]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/virtlistctrltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/virtlistctrltest.cpp
3 // Purpose: wxListCtrl unit tests for virtual mode
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2010 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
26 #include "wx/listctrl.h"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 class VirtListCtrlTestCase
: public CppUnit::TestCase
35 VirtListCtrlTestCase() { }
38 virtual void tearDown();
41 CPPUNIT_TEST_SUITE( VirtListCtrlTestCase
);
42 CPPUNIT_TEST( UpdateSelection
);
43 CPPUNIT_TEST_SUITE_END();
45 void UpdateSelection();
49 wxDECLARE_NO_COPY_CLASS(VirtListCtrlTestCase
);
52 // register in the unnamed registry so that these tests are run by default
53 CPPUNIT_TEST_SUITE_REGISTRATION( VirtListCtrlTestCase
);
55 // also include in its own registry so that these tests can be run alone
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VirtListCtrlTestCase
, "VirtListCtrlTestCase" );
58 // ----------------------------------------------------------------------------
59 // test initialization
60 // ----------------------------------------------------------------------------
62 void VirtListCtrlTestCase::setUp()
64 // Define a class overriding OnGetItemText() which must be overridden for
65 // any virtual list control.
66 class VirtListCtrl
: public wxListCtrl
70 : wxListCtrl(wxTheApp
->GetTopWindow(), wxID_ANY
,
71 wxPoint(0, 0), wxSize(400, 200),
72 wxLC_REPORT
| wxLC_VIRTUAL
)
77 virtual wxString
OnGetItemText(long item
, long column
) const
79 return wxString::Format("Row %ld, col %ld", item
, column
);
83 m_list
= new VirtListCtrl
;
86 void VirtListCtrlTestCase::tearDown()
92 void VirtListCtrlTestCase::UpdateSelection()
94 m_list
->SetItemCount(10);
95 CPPUNIT_ASSERT_EQUAL( 0, m_list
->GetSelectedItemCount() );
97 m_list
->SetItemState(7, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
98 CPPUNIT_ASSERT_EQUAL( 1, m_list
->GetSelectedItemCount() );
100 m_list
->SetItemState(0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
101 CPPUNIT_ASSERT_EQUAL( 2, m_list
->GetSelectedItemCount() );
103 // The item 7 is now invalid and so shouldn't be counted as selected any
105 m_list
->SetItemCount(5);
106 CPPUNIT_ASSERT_EQUAL( 1, m_list
->GetSelectedItemCount() );
109 #endif // wxUSE_LISTCTRL