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