]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/listctrltest.cpp
Consistently handle DST start time in wxDateTime::Set().
[wxWidgets.git] / tests / controls / listctrltest.cpp
CommitLineData
80cc5fc7
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/controls/listctrltest.cpp
3// Purpose: wxListCtrl unit test
4// Author: Vadim Zeitlin
5// Created: 2008-11-26
80cc5fc7 6// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
232fdc63 7// (c) 2010 Steven Lamerton
80cc5fc7
VZ
8///////////////////////////////////////////////////////////////////////////////
9
10// ----------------------------------------------------------------------------
11// headers
12// ----------------------------------------------------------------------------
13
14#include "testprec.h"
15
232fdc63
VZ
16#if wxUSE_LISTCTRL
17
80cc5fc7
VZ
18#ifdef __BORLANDC__
19 #pragma hdrstop
20#endif
21
22#ifndef WX_PRECOMP
23 #include "wx/app.h"
80cc5fc7
VZ
24#endif // WX_PRECOMP
25
497c7dff 26#include "wx/listctrl.h"
232fdc63
VZ
27#include "listbasetest.h"
28#include "testableframe.h"
29#include "wx/uiaction.h"
497c7dff 30
80cc5fc7
VZ
31// ----------------------------------------------------------------------------
32// test class
33// ----------------------------------------------------------------------------
34
232fdc63 35class ListCtrlTestCase : public ListBaseTestCase, public CppUnit::TestCase
80cc5fc7
VZ
36{
37public:
38 ListCtrlTestCase() { }
39
40 virtual void setUp();
41 virtual void tearDown();
42
232fdc63
VZ
43 virtual wxListCtrl *GetList() const { return m_list; }
44
80cc5fc7
VZ
45private:
46 CPPUNIT_TEST_SUITE( ListCtrlTestCase );
232fdc63 47 wxLIST_BASE_TESTS();
93f6e00d 48 CPPUNIT_TEST( EditLabel );
232fdc63
VZ
49 WXUISIM_TEST( ColumnClick );
50 WXUISIM_TEST( ColumnDrag );
80cc5fc7
VZ
51 CPPUNIT_TEST_SUITE_END();
52
93f6e00d 53 void EditLabel();
232fdc63
VZ
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
80cc5fc7
VZ
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
67CPPUNIT_TEST_SUITE_REGISTRATION( ListCtrlTestCase );
68
e3778b4d 69// also include in its own registry so that these tests can be run alone
80cc5fc7
VZ
70CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListCtrlTestCase, "ListCtrlTestCase" );
71
72// ----------------------------------------------------------------------------
73// test initialization
74// ----------------------------------------------------------------------------
75
76void ListCtrlTestCase::setUp()
77{
78 m_list = new wxListCtrl(wxTheApp->GetTopWindow());
67561862 79 m_list->SetWindowStyle(wxLC_REPORT);
232fdc63 80 m_list->SetSize(400, 200);
80cc5fc7
VZ
81}
82
83void ListCtrlTestCase::tearDown()
84{
85 delete m_list;
86 m_list = NULL;
87}
88
93f6e00d
VZ
89void ListCtrlTestCase::EditLabel()
90{
91 m_list->InsertColumn(0, "Column 0");
92 m_list->InsertItem(0, "foo");
93 m_list->EditLabel(0);
94}
95
232fdc63
VZ
96#if wxUSE_UIACTIONSIMULATOR
97void ListCtrlTestCase::ColumnDrag()
80cc5fc7 98{
ce7fe42e
VZ
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);
ffdb0ee5 102
80cc5fc7
VZ
103 m_list->InsertColumn(0, "Column 0");
104 m_list->InsertColumn(1, "Column 1");
105 m_list->InsertColumn(2, "Column 2");
232fdc63
VZ
106 m_list->Update();
107 m_list->SetFocus();
80cc5fc7 108
232fdc63 109 wxUIActionSimulator sim;
80cc5fc7 110
232fdc63 111 wxPoint pt = m_list->ClientToScreen(wxPoint(m_list->GetColumnWidth(0), 5));
80cc5fc7 112
232fdc63
VZ
113 sim.MouseMove(pt);
114 wxYield();
80cc5fc7 115
232fdc63
VZ
116 sim.MouseDown();
117 wxYield();
80cc5fc7 118
232fdc63
VZ
119 sim.MouseMove(pt.x + 50, pt.y);
120 wxYield();
80cc5fc7 121
232fdc63
VZ
122 sim.MouseUp();
123 wxYield();
80cc5fc7 124
744d91d4
SL
125 CPPUNIT_ASSERT_EQUAL(1, begindrag.GetCount());
126 CPPUNIT_ASSERT(dragging.GetCount() > 0);
127 CPPUNIT_ASSERT_EQUAL(1, enddrag.GetCount());
80cc5fc7 128
232fdc63 129 m_list->ClearAll();
80cc5fc7
VZ
130}
131
232fdc63 132void ListCtrlTestCase::ColumnClick()
67561862 133{
ce7fe42e
VZ
134 EventCounter colclick(m_list, wxEVT_LIST_COL_CLICK);
135 EventCounter colrclick(m_list, wxEVT_LIST_COL_RIGHT_CLICK);
67561862 136
67561862 137
232fdc63 138 m_list->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT, 60);
b6812a6f 139
232fdc63 140 wxUIActionSimulator sim;
b6812a6f 141
232fdc63
VZ
142 sim.MouseMove(m_list->ClientToScreen(wxPoint(4, 4)));
143 wxYield();
b6812a6f 144
232fdc63
VZ
145 sim.MouseClick();
146 sim.MouseClick(wxMOUSE_BTN_RIGHT);
147 wxYield();
b7923f2a 148
744d91d4
SL
149 CPPUNIT_ASSERT_EQUAL(1, colclick.GetCount());
150 CPPUNIT_ASSERT_EQUAL(1, colrclick.GetCount());
b7923f2a 151
232fdc63 152 m_list->ClearAll();
b7923f2a 153}
232fdc63 154#endif // wxUSE_UIACTIONSIMULATOR
b7923f2a 155
232fdc63 156#endif // wxUSE_LISTCTRL