]>
Commit | Line | Data |
---|---|---|
681694bc VZ |
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 | ||
e3778b4d | 55 | // also include in its own registry so that these tests can be run alone |
681694bc VZ |
56 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VirtListCtrlTestCase, "VirtListCtrlTestCase" ); |
57 | ||
58 | // ---------------------------------------------------------------------------- | |
59 | // test initialization | |
60 | // ---------------------------------------------------------------------------- | |
61 | ||
62 | void VirtListCtrlTestCase::setUp() | |
63 | { | |
80e13ad3 VZ |
64 | // Define a class overriding OnGetItemText() which must be overridden for |
65 | // any virtual list control. | |
66 | class VirtListCtrl : public wxListCtrl | |
67 | { | |
68 | public: | |
69 | VirtListCtrl() | |
70 | : wxListCtrl(wxTheApp->GetTopWindow(), wxID_ANY, | |
71 | wxPoint(0, 0), wxSize(400, 200), | |
72 | wxLC_REPORT | wxLC_VIRTUAL) | |
73 | { | |
74 | } | |
75 | ||
76 | protected: | |
77 | virtual wxString OnGetItemText(long item, long column) const | |
78 | { | |
79 | return wxString::Format("Row %ld, col %ld", item, column); | |
80 | } | |
81 | }; | |
82 | ||
83 | m_list = new VirtListCtrl; | |
681694bc VZ |
84 | } |
85 | ||
86 | void VirtListCtrlTestCase::tearDown() | |
87 | { | |
88 | delete m_list; | |
89 | m_list = NULL; | |
90 | } | |
91 | ||
92 | void VirtListCtrlTestCase::UpdateSelection() | |
93 | { | |
94 | m_list->SetItemCount(10); | |
95 | CPPUNIT_ASSERT_EQUAL( 0, m_list->GetSelectedItemCount() ); | |
96 | ||
97 | m_list->SetItemState(7, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); | |
98 | CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() ); | |
99 | ||
100 | m_list->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); | |
101 | CPPUNIT_ASSERT_EQUAL( 2, m_list->GetSelectedItemCount() ); | |
102 | ||
103 | // The item 7 is now invalid and so shouldn't be counted as selected any | |
104 | // more. | |
105 | m_list->SetItemCount(5); | |
106 | CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() ); | |
107 | } | |
108 | ||
109 | #endif // wxUSE_LISTCTRL |