1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/listctrltest.cpp
3 // Purpose: wxListCtrl unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // (c) 2010 Steven Lamerton
9 ///////////////////////////////////////////////////////////////////////////////
11 // ----------------------------------------------------------------------------
13 // ----------------------------------------------------------------------------
27 #include "wx/listctrl.h"
28 #include "listbasetest.h"
29 #include "testableframe.h"
30 #include "wx/uiaction.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 class ListCtrlTestCase
: public ListBaseTestCase
, public CppUnit::TestCase
39 ListCtrlTestCase() { }
42 virtual void tearDown();
44 virtual wxListCtrl
*GetList() const { return m_list
; }
47 CPPUNIT_TEST_SUITE( ListCtrlTestCase
);
49 CPPUNIT_TEST( EditLabel
);
50 WXUISIM_TEST( ColumnClick
);
51 WXUISIM_TEST( ColumnDrag
);
52 CPPUNIT_TEST_SUITE_END();
55 #if wxUSE_UIACTIONSIMULATOR
56 // Column events are only supported in wxListCtrl currently so we test them
57 // here rather than in ListBaseTest
60 #endif // wxUSE_UIACTIONSIMULATOR
64 DECLARE_NO_COPY_CLASS(ListCtrlTestCase
)
67 // register in the unnamed registry so that these tests are run by default
68 CPPUNIT_TEST_SUITE_REGISTRATION( ListCtrlTestCase
);
70 // also include in it's own registry so that these tests can be run alone
71 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListCtrlTestCase
, "ListCtrlTestCase" );
73 // ----------------------------------------------------------------------------
74 // test initialization
75 // ----------------------------------------------------------------------------
77 void ListCtrlTestCase::setUp()
79 m_list
= new wxListCtrl(wxTheApp
->GetTopWindow());
80 m_list
->SetWindowStyle(wxLC_REPORT
);
81 m_list
->SetSize(400, 200);
84 void ListCtrlTestCase::tearDown()
90 void ListCtrlTestCase::EditLabel()
92 m_list
->InsertColumn(0, "Column 0");
93 m_list
->InsertItem(0, "foo");
97 #if wxUSE_UIACTIONSIMULATOR
98 void ListCtrlTestCase::ColumnDrag()
100 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
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
);
107 m_list
->InsertColumn(0, "Column 0");
108 m_list
->InsertColumn(1, "Column 1");
109 m_list
->InsertColumn(2, "Column 2");
113 wxUIActionSimulator sim
;
115 wxPoint pt
= m_list
->ClientToScreen(wxPoint(m_list
->GetColumnWidth(0), 5));
123 sim
.MouseMove(pt
.x
+ 50, pt
.y
);
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
));
136 void ListCtrlTestCase::ColumnClick()
138 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
141 EventCounter
count(m_list
, wxEVT_COMMAND_LIST_COL_CLICK
);
142 EventCounter
count1(m_list
, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
);
145 m_list
->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT
, 60);
147 wxUIActionSimulator sim
;
149 sim
.MouseMove(m_list
->ClientToScreen(wxPoint(4, 4)));
153 sim
.MouseClick(wxMOUSE_BTN_RIGHT
);
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
));
161 #endif // wxUSE_UIACTIONSIMULATOR
163 #endif // wxUSE_LISTCTRL