1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/listctrltest.cpp
3 // Purpose: wxListCtrl unit test
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 // (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
26 #include "wx/listctrl.h"
27 #include "listbasetest.h"
28 #include "testableframe.h"
29 #include "wx/uiaction.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 class ListCtrlTestCase
: public ListBaseTestCase
, public CppUnit::TestCase
38 ListCtrlTestCase() { }
41 virtual void tearDown();
43 virtual wxListCtrl
*GetList() const { return m_list
; }
46 CPPUNIT_TEST_SUITE( ListCtrlTestCase
);
48 CPPUNIT_TEST( EditLabel
);
49 WXUISIM_TEST( ColumnClick
);
50 WXUISIM_TEST( ColumnDrag
);
51 CPPUNIT_TEST_SUITE_END();
54 #if wxUSE_UIACTIONSIMULATOR
55 // Column events are only supported in wxListCtrl currently so we test them
56 // here rather than in ListBaseTest
59 #endif // wxUSE_UIACTIONSIMULATOR
63 DECLARE_NO_COPY_CLASS(ListCtrlTestCase
)
66 // register in the unnamed registry so that these tests are run by default
67 CPPUNIT_TEST_SUITE_REGISTRATION( ListCtrlTestCase
);
69 // also include in its own registry so that these tests can be run alone
70 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListCtrlTestCase
, "ListCtrlTestCase" );
72 // ----------------------------------------------------------------------------
73 // test initialization
74 // ----------------------------------------------------------------------------
76 void ListCtrlTestCase::setUp()
78 m_list
= new wxListCtrl(wxTheApp
->GetTopWindow());
79 m_list
->SetWindowStyle(wxLC_REPORT
);
80 m_list
->SetSize(400, 200);
83 void ListCtrlTestCase::tearDown()
89 void ListCtrlTestCase::EditLabel()
91 m_list
->InsertColumn(0, "Column 0");
92 m_list
->InsertItem(0, "foo");
96 #if wxUSE_UIACTIONSIMULATOR
97 void ListCtrlTestCase::ColumnDrag()
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
);
103 m_list
->InsertColumn(0, "Column 0");
104 m_list
->InsertColumn(1, "Column 1");
105 m_list
->InsertColumn(2, "Column 2");
109 wxUIActionSimulator sim
;
111 wxPoint pt
= m_list
->ClientToScreen(wxPoint(m_list
->GetColumnWidth(0), 5));
119 sim
.MouseMove(pt
.x
+ 50, pt
.y
);
125 CPPUNIT_ASSERT_EQUAL(1, begindrag
.GetCount());
126 CPPUNIT_ASSERT(dragging
.GetCount() > 0);
127 CPPUNIT_ASSERT_EQUAL(1, enddrag
.GetCount());
132 void ListCtrlTestCase::ColumnClick()
134 EventCounter
colclick(m_list
, wxEVT_LIST_COL_CLICK
);
135 EventCounter
colrclick(m_list
, wxEVT_LIST_COL_RIGHT_CLICK
);
138 m_list
->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT
, 60);
140 wxUIActionSimulator sim
;
142 sim
.MouseMove(m_list
->ClientToScreen(wxPoint(4, 4)));
146 sim
.MouseClick(wxMOUSE_BTN_RIGHT
);
149 CPPUNIT_ASSERT_EQUAL(1, colclick
.GetCount());
150 CPPUNIT_ASSERT_EQUAL(1, colrclick
.GetCount());
154 #endif // wxUSE_UIACTIONSIMULATOR
156 #endif // wxUSE_LISTCTRL