]>
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
6 // Copyright: (c) 2010 Vadim Zeitlin <vadim@wxwidgets.org>
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
25 #include "wx/listctrl.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 class VirtListCtrlTestCase
: public CppUnit::TestCase
34 VirtListCtrlTestCase() { }
37 virtual void tearDown();
40 CPPUNIT_TEST_SUITE( VirtListCtrlTestCase
);
41 CPPUNIT_TEST( UpdateSelection
);
42 CPPUNIT_TEST_SUITE_END();
44 void UpdateSelection();
48 wxDECLARE_NO_COPY_CLASS(VirtListCtrlTestCase
);
51 // register in the unnamed registry so that these tests are run by default
52 CPPUNIT_TEST_SUITE_REGISTRATION( VirtListCtrlTestCase
);
54 // also include in its own registry so that these tests can be run alone
55 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VirtListCtrlTestCase
, "VirtListCtrlTestCase" );
57 // ----------------------------------------------------------------------------
58 // test initialization
59 // ----------------------------------------------------------------------------
61 void VirtListCtrlTestCase::setUp()
63 // Define a class overriding OnGetItemText() which must be overridden for
64 // any virtual list control.
65 class VirtListCtrl
: public wxListCtrl
69 : wxListCtrl(wxTheApp
->GetTopWindow(), wxID_ANY
,
70 wxPoint(0, 0), wxSize(400, 200),
71 wxLC_REPORT
| wxLC_VIRTUAL
)
76 virtual wxString
OnGetItemText(long item
, long column
) const
78 return wxString::Format("Row %ld, col %ld", item
, column
);
82 m_list
= new VirtListCtrl
;
85 void VirtListCtrlTestCase::tearDown()
91 void VirtListCtrlTestCase::UpdateSelection()
93 m_list
->SetItemCount(10);
94 CPPUNIT_ASSERT_EQUAL( 0, m_list
->GetSelectedItemCount() );
96 m_list
->SetItemState(7, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
97 CPPUNIT_ASSERT_EQUAL( 1, m_list
->GetSelectedItemCount() );
99 m_list
->SetItemState(0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
100 CPPUNIT_ASSERT_EQUAL( 2, m_list
->GetSelectedItemCount() );
102 // The item 7 is now invalid and so shouldn't be counted as selected any
104 m_list
->SetItemCount(5);
105 CPPUNIT_ASSERT_EQUAL( 1, m_list
->GetSelectedItemCount() );
108 #endif // wxUSE_LISTCTRL