]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/headerctrltest.cpp
Fixed capitalisation
[wxWidgets.git] / tests / controls / headerctrltest.cpp
CommitLineData
56873923
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/controls/headerctrltest.cpp
3// Purpose: wxHeaderCtrl unit test
4// Author: Vadim Zeitlin
5// Created: 2008-11-26
56873923
VZ
6// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7///////////////////////////////////////////////////////////////////////////////
8
9// ----------------------------------------------------------------------------
10// headers
11// ----------------------------------------------------------------------------
12
13#include "testprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20 #include "wx/app.h"
56873923
VZ
21#endif // WX_PRECOMP
22
497c7dff
VZ
23#include "wx/headerctrl.h"
24
56873923
VZ
25// ----------------------------------------------------------------------------
26// test class
27// ----------------------------------------------------------------------------
28
29class HeaderCtrlTestCase : public CppUnit::TestCase
30{
31public:
32 HeaderCtrlTestCase() { }
33
34 virtual void setUp();
35 virtual void tearDown();
36
37private:
38 CPPUNIT_TEST_SUITE( HeaderCtrlTestCase );
39 CPPUNIT_TEST( AddDelete );
40 CPPUNIT_TEST( BestSize );
71d8948f 41 CPPUNIT_TEST( Reorder );
56873923
VZ
42 CPPUNIT_TEST_SUITE_END();
43
44 void AddDelete();
45 void BestSize();
71d8948f 46 void Reorder();
56873923 47
e2bfe673 48 wxHeaderCtrlSimple *m_header;
56873923
VZ
49
50 DECLARE_NO_COPY_CLASS(HeaderCtrlTestCase)
51};
52
53// register in the unnamed registry so that these tests are run by default
54CPPUNIT_TEST_SUITE_REGISTRATION( HeaderCtrlTestCase );
55
e3778b4d 56// also include in its own registry so that these tests can be run alone
56873923
VZ
57CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HeaderCtrlTestCase, "HeaderCtrlTestCase" );
58
59// ----------------------------------------------------------------------------
60// test initialization
61// ----------------------------------------------------------------------------
62
63void HeaderCtrlTestCase::setUp()
64{
e2bfe673 65 m_header = new wxHeaderCtrlSimple(wxTheApp->GetTopWindow());
56873923
VZ
66}
67
68void HeaderCtrlTestCase::tearDown()
69{
70 delete m_header;
71 m_header = NULL;
72}
73
74// ----------------------------------------------------------------------------
75// the tests themselves
76// ----------------------------------------------------------------------------
77
78void HeaderCtrlTestCase::AddDelete()
79{
306f34a3 80 CPPUNIT_ASSERT_EQUAL( 0, m_header->GetColumnCount() );
56873923 81
a1d4adc5 82 m_header->AppendColumn(wxHeaderColumnSimple("Column 1"));
306f34a3 83 CPPUNIT_ASSERT_EQUAL( 1, m_header->GetColumnCount() );
56873923 84
a1d4adc5 85 m_header->AppendColumn(wxHeaderColumnSimple("Column 2"));
306f34a3 86 CPPUNIT_ASSERT_EQUAL( 2, m_header->GetColumnCount() );
56873923 87
a1d4adc5 88 m_header->InsertColumn(wxHeaderColumnSimple("Column 0"), 0);
306f34a3 89 CPPUNIT_ASSERT_EQUAL( 3, m_header->GetColumnCount() );
56873923
VZ
90
91 m_header->DeleteColumn(2);
306f34a3 92 CPPUNIT_ASSERT_EQUAL( 2, m_header->GetColumnCount() );
56873923
VZ
93}
94
95void HeaderCtrlTestCase::BestSize()
96{
97 const wxSize sizeEmpty = m_header->GetBestSize();
3246a508
VZ
98 // this fails under wxGTK where wxControl::GetBestSize() is 0 in horizontal
99 // direction
100 //CPPUNIT_ASSERT( sizeEmpty.x > 0 );
56873923
VZ
101 CPPUNIT_ASSERT( sizeEmpty.y > 0 );
102
a1d4adc5
VZ
103 m_header->AppendColumn(wxHeaderColumnSimple("Foo"));
104 m_header->AppendColumn(wxHeaderColumnSimple("Bar"));
56873923
VZ
105 const wxSize size = m_header->GetBestSize();
106 CPPUNIT_ASSERT_EQUAL( sizeEmpty.y, size.y );
107}
108
71d8948f
VZ
109void HeaderCtrlTestCase::Reorder()
110{
111 static const int COL_COUNT = 4;
112
113 int n;
114
115 for ( n = 0; n < COL_COUNT; n++ )
116 m_header->AppendColumn(wxHeaderColumnSimple(wxString::Format("%d", n)));
117
118 wxArrayInt order = m_header->GetColumnsOrder(); // initial order: [0 1 2 3]
119 for ( n = 0; n < COL_COUNT; n++ )
120 CPPUNIT_ASSERT_EQUAL( n, order[n] );
121
122 wxHeaderCtrl::MoveColumnInOrderArray(order, 0, 2);
123 m_header->SetColumnsOrder(order); // change order to [1 2 0 3]
124
125 order = m_header->GetColumnsOrder();
126 CPPUNIT_ASSERT_EQUAL( 1, order[0] );
127 CPPUNIT_ASSERT_EQUAL( 2, order[1] );
128 CPPUNIT_ASSERT_EQUAL( 0, order[2] );
129 CPPUNIT_ASSERT_EQUAL( 3, order[3] );
130
131 order[2] = 3;
132 order[3] = 0;
133 m_header->SetColumnsOrder(order); // and now [1 2 3 0]
134 order = m_header->GetColumnsOrder();
135 CPPUNIT_ASSERT_EQUAL( 1, order[0] );
136 CPPUNIT_ASSERT_EQUAL( 2, order[1] );
137 CPPUNIT_ASSERT_EQUAL( 3, order[2] );
138 CPPUNIT_ASSERT_EQUAL( 0, order[3] );
139
140 wxHeaderCtrl::MoveColumnInOrderArray(order, 1, 3);
141 m_header->SetColumnsOrder(order); // finally [2 3 0 1]
142 order = m_header->GetColumnsOrder();
143 CPPUNIT_ASSERT_EQUAL( 2, order[0] );
144 CPPUNIT_ASSERT_EQUAL( 3, order[1] );
145 CPPUNIT_ASSERT_EQUAL( 0, order[2] );
146 CPPUNIT_ASSERT_EQUAL( 1, order[3] );
147}
148