]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/listctrltest.cpp
Preserve page size when changing increment in wxGTK wxSpinCtrlDouble.
[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
6// RCS-ID: $Id$
7// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
232fdc63 8// (c) 2010 Steven Lamerton
80cc5fc7
VZ
9///////////////////////////////////////////////////////////////////////////////
10
11// ----------------------------------------------------------------------------
12// headers
13// ----------------------------------------------------------------------------
14
15#include "testprec.h"
16
232fdc63
VZ
17#if wxUSE_LISTCTRL
18
80cc5fc7
VZ
19#ifdef __BORLANDC__
20 #pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24 #include "wx/app.h"
80cc5fc7
VZ
25#endif // WX_PRECOMP
26
497c7dff 27#include "wx/listctrl.h"
232fdc63
VZ
28#include "listbasetest.h"
29#include "testableframe.h"
30#include "wx/uiaction.h"
497c7dff 31
80cc5fc7
VZ
32// ----------------------------------------------------------------------------
33// test class
34// ----------------------------------------------------------------------------
35
232fdc63 36class ListCtrlTestCase : public ListBaseTestCase, public CppUnit::TestCase
80cc5fc7
VZ
37{
38public:
39 ListCtrlTestCase() { }
40
41 virtual void setUp();
42 virtual void tearDown();
43
232fdc63
VZ
44 virtual wxListCtrl *GetList() const { return m_list; }
45
80cc5fc7
VZ
46private:
47 CPPUNIT_TEST_SUITE( ListCtrlTestCase );
232fdc63
VZ
48 wxLIST_BASE_TESTS();
49 WXUISIM_TEST( ColumnClick );
50 WXUISIM_TEST( ColumnDrag );
80cc5fc7
VZ
51 CPPUNIT_TEST_SUITE_END();
52
232fdc63
VZ
53#if wxUSE_UIACTIONSIMULATOR
54 // Column events are only supported in wxListCtrl currently so we test them
55 // here rather than in ListBaseTest
56 void ColumnClick();
57 void ColumnDrag();
58#endif // wxUSE_UIACTIONSIMULATOR
80cc5fc7
VZ
59
60 wxListCtrl *m_list;
61
62 DECLARE_NO_COPY_CLASS(ListCtrlTestCase)
63};
64
65// register in the unnamed registry so that these tests are run by default
66CPPUNIT_TEST_SUITE_REGISTRATION( ListCtrlTestCase );
67
68// also include in it's own registry so that these tests can be run alone
69CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListCtrlTestCase, "ListCtrlTestCase" );
70
71// ----------------------------------------------------------------------------
72// test initialization
73// ----------------------------------------------------------------------------
74
75void ListCtrlTestCase::setUp()
76{
77 m_list = new wxListCtrl(wxTheApp->GetTopWindow());
67561862 78 m_list->SetWindowStyle(wxLC_REPORT);
232fdc63 79 m_list->SetSize(400, 200);
80cc5fc7
VZ
80}
81
82void ListCtrlTestCase::tearDown()
83{
84 delete m_list;
85 m_list = NULL;
86}
87
232fdc63
VZ
88#if wxUSE_UIACTIONSIMULATOR
89void ListCtrlTestCase::ColumnDrag()
80cc5fc7 90{
232fdc63
VZ
91 wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
92 wxTestableFrame);
80cc5fc7 93
232fdc63
VZ
94 EventCounter count(m_list, wxEVT_COMMAND_LIST_COL_BEGIN_DRAG);
95 EventCounter count1(m_list, wxEVT_COMMAND_LIST_COL_DRAGGING);
96 EventCounter count2(m_list, wxEVT_COMMAND_LIST_COL_END_DRAG);
ffdb0ee5 97
80cc5fc7
VZ
98 m_list->InsertColumn(0, "Column 0");
99 m_list->InsertColumn(1, "Column 1");
100 m_list->InsertColumn(2, "Column 2");
232fdc63
VZ
101 m_list->Update();
102 m_list->SetFocus();
80cc5fc7 103
232fdc63 104 wxUIActionSimulator sim;
80cc5fc7 105
232fdc63 106 wxPoint pt = m_list->ClientToScreen(wxPoint(m_list->GetColumnWidth(0), 5));
80cc5fc7 107
232fdc63
VZ
108 sim.MouseMove(pt);
109 wxYield();
80cc5fc7 110
232fdc63
VZ
111 sim.MouseDown();
112 wxYield();
80cc5fc7 113
232fdc63
VZ
114 sim.MouseMove(pt.x + 50, pt.y);
115 wxYield();
80cc5fc7 116
232fdc63
VZ
117 sim.MouseUp();
118 wxYield();
80cc5fc7 119
232fdc63
VZ
120 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG));
121 CPPUNIT_ASSERT(frame->GetEventCount(wxEVT_COMMAND_LIST_COL_DRAGGING) > 0);
122 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_END_DRAG));
80cc5fc7 123
232fdc63 124 m_list->ClearAll();
80cc5fc7
VZ
125}
126
232fdc63 127void ListCtrlTestCase::ColumnClick()
67561862 128{
232fdc63
VZ
129 wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
130 wxTestableFrame);
67561862 131
232fdc63
VZ
132 EventCounter count(m_list, wxEVT_COMMAND_LIST_COL_CLICK);
133 EventCounter count1(m_list, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK);
67561862 134
67561862 135
232fdc63 136 m_list->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT, 60);
b6812a6f 137
232fdc63 138 wxUIActionSimulator sim;
b6812a6f 139
232fdc63
VZ
140 sim.MouseMove(m_list->ClientToScreen(wxPoint(4, 4)));
141 wxYield();
b6812a6f 142
232fdc63
VZ
143 sim.MouseClick();
144 sim.MouseClick(wxMOUSE_BTN_RIGHT);
145 wxYield();
b7923f2a 146
232fdc63
VZ
147 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_CLICK));
148 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK));
b7923f2a 149
232fdc63 150 m_list->ClearAll();
b7923f2a 151}
232fdc63 152#endif // wxUSE_UIACTIONSIMULATOR
b7923f2a 153
232fdc63 154#endif // wxUSE_LISTCTRL