]>
Commit | Line | Data |
---|---|---|
80cc5fc7 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/controls/listctrltest.cpp | |
3 | // Purpose: wxListCtrl unit test | |
4 | // Author: Vadim Zeitlin | |
5 | // Created: 2008-11-26 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org> | |
232fdc63 | 8 | // (c) 2010 Steven Lamerton |
80cc5fc7 VZ |
9 | /////////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | // ---------------------------------------------------------------------------- | |
12 | // headers | |
13 | // ---------------------------------------------------------------------------- | |
14 | ||
15 | #include "testprec.h" | |
16 | ||
232fdc63 VZ |
17 | #if wxUSE_LISTCTRL |
18 | ||
80cc5fc7 VZ |
19 | #ifdef __BORLANDC__ |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/app.h" | |
80cc5fc7 VZ |
25 | #endif // WX_PRECOMP |
26 | ||
497c7dff | 27 | #include "wx/listctrl.h" |
232fdc63 VZ |
28 | #include "listbasetest.h" |
29 | #include "testableframe.h" | |
30 | #include "wx/uiaction.h" | |
497c7dff | 31 | |
80cc5fc7 VZ |
32 | // ---------------------------------------------------------------------------- |
33 | // test class | |
34 | // ---------------------------------------------------------------------------- | |
35 | ||
232fdc63 | 36 | class ListCtrlTestCase : public ListBaseTestCase, public CppUnit::TestCase |
80cc5fc7 VZ |
37 | { |
38 | public: | |
39 | ListCtrlTestCase() { } | |
40 | ||
41 | virtual void setUp(); | |
42 | virtual void tearDown(); | |
43 | ||
232fdc63 VZ |
44 | virtual wxListCtrl *GetList() const { return m_list; } |
45 | ||
80cc5fc7 VZ |
46 | private: |
47 | CPPUNIT_TEST_SUITE( ListCtrlTestCase ); | |
232fdc63 | 48 | wxLIST_BASE_TESTS(); |
93f6e00d | 49 | CPPUNIT_TEST( EditLabel ); |
232fdc63 VZ |
50 | WXUISIM_TEST( ColumnClick ); |
51 | WXUISIM_TEST( ColumnDrag ); | |
80cc5fc7 VZ |
52 | CPPUNIT_TEST_SUITE_END(); |
53 | ||
93f6e00d | 54 | void EditLabel(); |
232fdc63 VZ |
55 | #if wxUSE_UIACTIONSIMULATOR |
56 | // Column events are only supported in wxListCtrl currently so we test them | |
57 | // here rather than in ListBaseTest | |
58 | void ColumnClick(); | |
59 | void ColumnDrag(); | |
60 | #endif // wxUSE_UIACTIONSIMULATOR | |
80cc5fc7 VZ |
61 | |
62 | wxListCtrl *m_list; | |
63 | ||
64 | DECLARE_NO_COPY_CLASS(ListCtrlTestCase) | |
65 | }; | |
66 | ||
67 | // register in the unnamed registry so that these tests are run by default | |
68 | CPPUNIT_TEST_SUITE_REGISTRATION( ListCtrlTestCase ); | |
69 | ||
70 | // also include in it's own registry so that these tests can be run alone | |
71 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListCtrlTestCase, "ListCtrlTestCase" ); | |
72 | ||
73 | // ---------------------------------------------------------------------------- | |
74 | // test initialization | |
75 | // ---------------------------------------------------------------------------- | |
76 | ||
77 | void ListCtrlTestCase::setUp() | |
78 | { | |
79 | m_list = new wxListCtrl(wxTheApp->GetTopWindow()); | |
67561862 | 80 | m_list->SetWindowStyle(wxLC_REPORT); |
232fdc63 | 81 | m_list->SetSize(400, 200); |
80cc5fc7 VZ |
82 | } |
83 | ||
84 | void ListCtrlTestCase::tearDown() | |
85 | { | |
86 | delete m_list; | |
87 | m_list = NULL; | |
88 | } | |
89 | ||
93f6e00d VZ |
90 | void ListCtrlTestCase::EditLabel() |
91 | { | |
92 | m_list->InsertColumn(0, "Column 0"); | |
93 | m_list->InsertItem(0, "foo"); | |
94 | m_list->EditLabel(0); | |
95 | } | |
96 | ||
232fdc63 VZ |
97 | #if wxUSE_UIACTIONSIMULATOR |
98 | void ListCtrlTestCase::ColumnDrag() | |
80cc5fc7 | 99 | { |
232fdc63 VZ |
100 | wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(), |
101 | wxTestableFrame); | |
80cc5fc7 | 102 | |
232fdc63 VZ |
103 | EventCounter count(m_list, wxEVT_COMMAND_LIST_COL_BEGIN_DRAG); |
104 | EventCounter count1(m_list, wxEVT_COMMAND_LIST_COL_DRAGGING); | |
105 | EventCounter count2(m_list, wxEVT_COMMAND_LIST_COL_END_DRAG); | |
ffdb0ee5 | 106 | |
80cc5fc7 VZ |
107 | m_list->InsertColumn(0, "Column 0"); |
108 | m_list->InsertColumn(1, "Column 1"); | |
109 | m_list->InsertColumn(2, "Column 2"); | |
232fdc63 VZ |
110 | m_list->Update(); |
111 | m_list->SetFocus(); | |
80cc5fc7 | 112 | |
232fdc63 | 113 | wxUIActionSimulator sim; |
80cc5fc7 | 114 | |
232fdc63 | 115 | wxPoint pt = m_list->ClientToScreen(wxPoint(m_list->GetColumnWidth(0), 5)); |
80cc5fc7 | 116 | |
232fdc63 VZ |
117 | sim.MouseMove(pt); |
118 | wxYield(); | |
80cc5fc7 | 119 | |
232fdc63 VZ |
120 | sim.MouseDown(); |
121 | wxYield(); | |
80cc5fc7 | 122 | |
232fdc63 VZ |
123 | sim.MouseMove(pt.x + 50, pt.y); |
124 | wxYield(); | |
80cc5fc7 | 125 | |
232fdc63 VZ |
126 | sim.MouseUp(); |
127 | wxYield(); | |
80cc5fc7 | 128 | |
232fdc63 VZ |
129 | CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG)); |
130 | CPPUNIT_ASSERT(frame->GetEventCount(wxEVT_COMMAND_LIST_COL_DRAGGING) > 0); | |
131 | CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_END_DRAG)); | |
80cc5fc7 | 132 | |
232fdc63 | 133 | m_list->ClearAll(); |
80cc5fc7 VZ |
134 | } |
135 | ||
232fdc63 | 136 | void ListCtrlTestCase::ColumnClick() |
67561862 | 137 | { |
232fdc63 VZ |
138 | wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(), |
139 | wxTestableFrame); | |
67561862 | 140 | |
232fdc63 VZ |
141 | EventCounter count(m_list, wxEVT_COMMAND_LIST_COL_CLICK); |
142 | EventCounter count1(m_list, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK); | |
67561862 | 143 | |
67561862 | 144 | |
232fdc63 | 145 | m_list->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT, 60); |
b6812a6f | 146 | |
232fdc63 | 147 | wxUIActionSimulator sim; |
b6812a6f | 148 | |
232fdc63 VZ |
149 | sim.MouseMove(m_list->ClientToScreen(wxPoint(4, 4))); |
150 | wxYield(); | |
b6812a6f | 151 | |
232fdc63 VZ |
152 | sim.MouseClick(); |
153 | sim.MouseClick(wxMOUSE_BTN_RIGHT); | |
154 | wxYield(); | |
b7923f2a | 155 | |
232fdc63 VZ |
156 | CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_CLICK)); |
157 | CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK)); | |
b7923f2a | 158 | |
232fdc63 | 159 | m_list->ClearAll(); |
b7923f2a | 160 | } |
232fdc63 | 161 | #endif // wxUSE_UIACTIONSIMULATOR |
b7923f2a | 162 | |
232fdc63 | 163 | #endif // wxUSE_LISTCTRL |