]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/listctrltest.cpp
reusing existing API
[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 CPPUNIT_TEST( EditLabel );
50 WXUISIM_TEST( ColumnClick );
51 WXUISIM_TEST( ColumnDrag );
52 CPPUNIT_TEST_SUITE_END();
53
54 void EditLabel();
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
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 its 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());
80 m_list->SetWindowStyle(wxLC_REPORT);
81 m_list->SetSize(400, 200);
82 }
83
84 void ListCtrlTestCase::tearDown()
85 {
86 delete m_list;
87 m_list = NULL;
88 }
89
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
97 #if wxUSE_UIACTIONSIMULATOR
98 void ListCtrlTestCase::ColumnDrag()
99 {
100 EventCounter begindrag(m_list, wxEVT_LIST_COL_BEGIN_DRAG);
101 EventCounter dragging(m_list, wxEVT_LIST_COL_DRAGGING);
102 EventCounter enddrag(m_list, wxEVT_LIST_COL_END_DRAG);
103
104 m_list->InsertColumn(0, "Column 0");
105 m_list->InsertColumn(1, "Column 1");
106 m_list->InsertColumn(2, "Column 2");
107 m_list->Update();
108 m_list->SetFocus();
109
110 wxUIActionSimulator sim;
111
112 wxPoint pt = m_list->ClientToScreen(wxPoint(m_list->GetColumnWidth(0), 5));
113
114 sim.MouseMove(pt);
115 wxYield();
116
117 sim.MouseDown();
118 wxYield();
119
120 sim.MouseMove(pt.x + 50, pt.y);
121 wxYield();
122
123 sim.MouseUp();
124 wxYield();
125
126 CPPUNIT_ASSERT_EQUAL(1, begindrag.GetCount());
127 CPPUNIT_ASSERT(dragging.GetCount() > 0);
128 CPPUNIT_ASSERT_EQUAL(1, enddrag.GetCount());
129
130 m_list->ClearAll();
131 }
132
133 void ListCtrlTestCase::ColumnClick()
134 {
135 EventCounter colclick(m_list, wxEVT_LIST_COL_CLICK);
136 EventCounter colrclick(m_list, wxEVT_LIST_COL_RIGHT_CLICK);
137
138
139 m_list->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT, 60);
140
141 wxUIActionSimulator sim;
142
143 sim.MouseMove(m_list->ClientToScreen(wxPoint(4, 4)));
144 wxYield();
145
146 sim.MouseClick();
147 sim.MouseClick(wxMOUSE_BTN_RIGHT);
148 wxYield();
149
150 CPPUNIT_ASSERT_EQUAL(1, colclick.GetCount());
151 CPPUNIT_ASSERT_EQUAL(1, colrclick.GetCount());
152
153 m_list->ClearAll();
154 }
155 #endif // wxUSE_UIACTIONSIMULATOR
156
157 #endif // wxUSE_LISTCTRL