]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/listctrltest.cpp
Don't document wxSortedArrayString as deriving from wxArrayString.
[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 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 // (c) 2010 Steven Lamerton
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 #include "listbasetest.h"
28 #include "testableframe.h"
29 #include "wx/uiaction.h"
30
31 // ----------------------------------------------------------------------------
32 // test class
33 // ----------------------------------------------------------------------------
34
35 class ListCtrlTestCase : public ListBaseTestCase, public CppUnit::TestCase
36 {
37 public:
38 ListCtrlTestCase() { }
39
40 virtual void setUp();
41 virtual void tearDown();
42
43 virtual wxListCtrl *GetList() const { return m_list; }
44
45 private:
46 CPPUNIT_TEST_SUITE( ListCtrlTestCase );
47 wxLIST_BASE_TESTS();
48 CPPUNIT_TEST( EditLabel );
49 WXUISIM_TEST( ColumnClick );
50 WXUISIM_TEST( ColumnDrag );
51 CPPUNIT_TEST_SUITE_END();
52
53 void EditLabel();
54 #if wxUSE_UIACTIONSIMULATOR
55 // Column events are only supported in wxListCtrl currently so we test them
56 // here rather than in ListBaseTest
57 void ColumnClick();
58 void ColumnDrag();
59 #endif // wxUSE_UIACTIONSIMULATOR
60
61 wxListCtrl *m_list;
62
63 DECLARE_NO_COPY_CLASS(ListCtrlTestCase)
64 };
65
66 // register in the unnamed registry so that these tests are run by default
67 CPPUNIT_TEST_SUITE_REGISTRATION( ListCtrlTestCase );
68
69 // also include in its own registry so that these tests can be run alone
70 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListCtrlTestCase, "ListCtrlTestCase" );
71
72 // ----------------------------------------------------------------------------
73 // test initialization
74 // ----------------------------------------------------------------------------
75
76 void ListCtrlTestCase::setUp()
77 {
78 m_list = new wxListCtrl(wxTheApp->GetTopWindow());
79 m_list->SetWindowStyle(wxLC_REPORT);
80 m_list->SetSize(400, 200);
81 }
82
83 void ListCtrlTestCase::tearDown()
84 {
85 delete m_list;
86 m_list = NULL;
87 }
88
89 void ListCtrlTestCase::EditLabel()
90 {
91 m_list->InsertColumn(0, "Column 0");
92 m_list->InsertItem(0, "foo");
93 m_list->EditLabel(0);
94 }
95
96 #if wxUSE_UIACTIONSIMULATOR
97 void ListCtrlTestCase::ColumnDrag()
98 {
99 EventCounter begindrag(m_list, wxEVT_LIST_COL_BEGIN_DRAG);
100 EventCounter dragging(m_list, wxEVT_LIST_COL_DRAGGING);
101 EventCounter enddrag(m_list, wxEVT_LIST_COL_END_DRAG);
102
103 m_list->InsertColumn(0, "Column 0");
104 m_list->InsertColumn(1, "Column 1");
105 m_list->InsertColumn(2, "Column 2");
106 m_list->Update();
107 m_list->SetFocus();
108
109 wxUIActionSimulator sim;
110
111 wxPoint pt = m_list->ClientToScreen(wxPoint(m_list->GetColumnWidth(0), 5));
112
113 sim.MouseMove(pt);
114 wxYield();
115
116 sim.MouseDown();
117 wxYield();
118
119 sim.MouseMove(pt.x + 50, pt.y);
120 wxYield();
121
122 sim.MouseUp();
123 wxYield();
124
125 CPPUNIT_ASSERT_EQUAL(1, begindrag.GetCount());
126 CPPUNIT_ASSERT(dragging.GetCount() > 0);
127 CPPUNIT_ASSERT_EQUAL(1, enddrag.GetCount());
128
129 m_list->ClearAll();
130 }
131
132 void ListCtrlTestCase::ColumnClick()
133 {
134 EventCounter colclick(m_list, wxEVT_LIST_COL_CLICK);
135 EventCounter colrclick(m_list, wxEVT_LIST_COL_RIGHT_CLICK);
136
137
138 m_list->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT, 60);
139
140 wxUIActionSimulator sim;
141
142 sim.MouseMove(m_list->ClientToScreen(wxPoint(4, 4)));
143 wxYield();
144
145 sim.MouseClick();
146 sim.MouseClick(wxMOUSE_BTN_RIGHT);
147 wxYield();
148
149 CPPUNIT_ASSERT_EQUAL(1, colclick.GetCount());
150 CPPUNIT_ASSERT_EQUAL(1, colrclick.GetCount());
151
152 m_list->ClearAll();
153 }
154 #endif // wxUSE_UIACTIONSIMULATOR
155
156 #endif // wxUSE_LISTCTRL