]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/listctrltest.cpp
added wxProtocolLog class for logging network requests/responses (closes #7464)
[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>
8///////////////////////////////////////////////////////////////////////////////
9
10// ----------------------------------------------------------------------------
11// headers
12// ----------------------------------------------------------------------------
13
14#include "testprec.h"
15
16#ifdef __BORLANDC__
17 #pragma hdrstop
18#endif
19
20#ifndef WX_PRECOMP
21 #include "wx/app.h"
80cc5fc7
VZ
22#endif // WX_PRECOMP
23
497c7dff
VZ
24#include "wx/listctrl.h"
25
80cc5fc7
VZ
26// ----------------------------------------------------------------------------
27// test class
28// ----------------------------------------------------------------------------
29
30class ListCtrlTestCase : public CppUnit::TestCase
31{
32public:
33 ListCtrlTestCase() { }
34
35 virtual void setUp();
36 virtual void tearDown();
37
38private:
39 CPPUNIT_TEST_SUITE( ListCtrlTestCase );
40#ifdef wxHAS_LISTCTRL_COLUMN_ORDER
41 CPPUNIT_TEST( ColumnsOrder );
42#endif // wxHAS_LISTCTRL_COLUMN_ORDER
67561862 43 CPPUNIT_TEST( ItemRect );
80cc5fc7
VZ
44 CPPUNIT_TEST_SUITE_END();
45
46#ifdef wxHAS_LISTCTRL_COLUMN_ORDER
47 void ColumnsOrder();
48#endif // wxHAS_LISTCTRL_COLUMN_ORDER
67561862 49 void ItemRect();
80cc5fc7
VZ
50
51 wxListCtrl *m_list;
52
53 DECLARE_NO_COPY_CLASS(ListCtrlTestCase)
54};
55
56// register in the unnamed registry so that these tests are run by default
57CPPUNIT_TEST_SUITE_REGISTRATION( ListCtrlTestCase );
58
59// also include in it's own registry so that these tests can be run alone
60CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListCtrlTestCase, "ListCtrlTestCase" );
61
62// ----------------------------------------------------------------------------
63// test initialization
64// ----------------------------------------------------------------------------
65
66void ListCtrlTestCase::setUp()
67{
68 m_list = new wxListCtrl(wxTheApp->GetTopWindow());
67561862 69 m_list->SetWindowStyle(wxLC_REPORT);
80cc5fc7
VZ
70}
71
72void ListCtrlTestCase::tearDown()
73{
74 delete m_list;
75 m_list = NULL;
76}
77
78// ----------------------------------------------------------------------------
79// the tests themselves
80// ----------------------------------------------------------------------------
81
82#ifdef wxHAS_LISTCTRL_COLUMN_ORDER
83
84void ListCtrlTestCase::ColumnsOrder()
85{
86 static const int NUM_COLS;
87 int n;
88 wxListItem li;
89 li.SetMask(wxLIST_MASK_TEXT);
90
91 // first set up some columns
92 m_list->InsertColumn(0, "Column 0");
93 m_list->InsertColumn(1, "Column 1");
94 m_list->InsertColumn(2, "Column 2");
95
96 // and a couple of test items too
97 m_list->InsertItem(0, "Item 0");
98 m_list->SetItem(0, 1, "first in first");
99
100 m_list->InsertItem(1, "Item 1");
101 m_list->SetItem(1, 2, "second in second");
102
103
104 // check that the order is natural in the beginning
105 const wxArrayInt orderOrig = m_list->GetColumnsOrder();
106 for ( n = 0; n < NUM_COLS; n++ )
107 CPPUNIT_ASSERT_EQUAL( n, orderOrig[n] );
108
109 // then rearrange them: using { 2, 0, 1 } order means that column 2 is
110 // shown first, then column 0 and finally column 1
111 wxArrayInt order(3);
112 order[0] = 2;
113 order[1] = 0;
114 order[2] = 1;
115 m_list->SetColumnsOrder(order);
116
117 // check that we get back the same order as we set
118 const wxArrayInt orderNew = m_list->GetColumnsOrder();
119 for ( n = 0; n < NUM_COLS; n++ )
120 CPPUNIT_ASSERT_EQUAL( order[n], orderNew[n] );
121
122 // and the order -> index mappings for individual columns
123 for ( n = 0; n < NUM_COLS; n++ )
124 CPPUNIT_ASSERT_EQUAL( order[n], m_list->GetColumnIndexFromOrder(n) );
125
126 // and also the reverse mapping
127 CPPUNIT_ASSERT_EQUAL( 1, m_list->GetColumnOrder(0) );
128 CPPUNIT_ASSERT_EQUAL( 2, m_list->GetColumnOrder(1) );
129 CPPUNIT_ASSERT_EQUAL( 0, m_list->GetColumnOrder(2) );
130
131
132 // finally check that accessors still use indices, not order
133 CPPUNIT_ASSERT( m_list->GetColumn(0, li) );
134 CPPUNIT_ASSERT_EQUAL( "Column 0", li.GetText() );
135
136 li.SetId(0);
137 li.SetColumn(1);
138 CPPUNIT_ASSERT( m_list->GetItem(li) );
139 CPPUNIT_ASSERT_EQUAL( "first in first", li.GetText() );
140
141 li.SetId(1);
142 li.SetColumn(2);
143 CPPUNIT_ASSERT( m_list->GetItem(li) );
144 CPPUNIT_ASSERT_EQUAL( "second in second", li.GetText() );
145}
146
c0ccc082
VZ
147#endif // wxHAS_LISTCTRL_COLUMN_ORDER
148
67561862
VZ
149void ListCtrlTestCase::ItemRect()
150{
151 // set up for the test
152 m_list->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT, 60);
153 m_list->InsertColumn(1, "Column 1", wxLIST_FORMAT_LEFT, 50);
154 m_list->InsertColumn(2, "Column 2", wxLIST_FORMAT_LEFT, 40);
155
156 m_list->InsertItem(0, "Item 0");
157 m_list->SetItem(0, 1, "first column");
158 m_list->SetItem(0, 1, "second column");
159
160 // do test
161 wxRect r;
8d1a4101 162 WX_ASSERT_FAILS_WITH_ASSERT( m_list->GetItemRect(1, r) );
67561862
VZ
163 CPPUNIT_ASSERT( m_list->GetItemRect(0, r) );
164 CPPUNIT_ASSERT_EQUAL( 150, r.GetWidth() );
165
166 CPPUNIT_ASSERT( m_list->GetSubItemRect(0, 0, r) );
167 CPPUNIT_ASSERT_EQUAL( 60, r.GetWidth() );
168
169 CPPUNIT_ASSERT( m_list->GetSubItemRect(0, 1, r) );
170 CPPUNIT_ASSERT_EQUAL( 50, r.GetWidth() );
171
172 CPPUNIT_ASSERT( m_list->GetSubItemRect(0, 2, r) );
173 CPPUNIT_ASSERT_EQUAL( 40, r.GetWidth() );
174
0468a58a 175 WX_ASSERT_FAILS_WITH_ASSERT( m_list->GetSubItemRect(0, 3, r) );
67561862
VZ
176}
177