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