e1fed94ae4806daa8744acb39c2a0365cbe7232a
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/headerctrltest.cpp
3 // Purpose: wxHeaderCtrl unit test
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
23 #include "wx/headerctrl.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 class HeaderCtrlTestCase
: public CppUnit::TestCase
32 HeaderCtrlTestCase() { }
35 virtual void tearDown();
38 CPPUNIT_TEST_SUITE( HeaderCtrlTestCase
);
39 CPPUNIT_TEST( AddDelete
);
40 CPPUNIT_TEST( BestSize
);
41 CPPUNIT_TEST( Reorder
);
42 CPPUNIT_TEST_SUITE_END();
48 wxHeaderCtrlSimple
*m_header
;
50 DECLARE_NO_COPY_CLASS(HeaderCtrlTestCase
)
53 // register in the unnamed registry so that these tests are run by default
54 CPPUNIT_TEST_SUITE_REGISTRATION( HeaderCtrlTestCase
);
56 // also include in its own registry so that these tests can be run alone
57 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HeaderCtrlTestCase
, "HeaderCtrlTestCase" );
59 // ----------------------------------------------------------------------------
60 // test initialization
61 // ----------------------------------------------------------------------------
63 void HeaderCtrlTestCase::setUp()
65 m_header
= new wxHeaderCtrlSimple(wxTheApp
->GetTopWindow());
68 void HeaderCtrlTestCase::tearDown()
74 // ----------------------------------------------------------------------------
75 // the tests themselves
76 // ----------------------------------------------------------------------------
78 void HeaderCtrlTestCase::AddDelete()
80 CPPUNIT_ASSERT_EQUAL( 0, m_header
->GetColumnCount() );
82 m_header
->AppendColumn(wxHeaderColumnSimple("Column 1"));
83 CPPUNIT_ASSERT_EQUAL( 1, m_header
->GetColumnCount() );
85 m_header
->AppendColumn(wxHeaderColumnSimple("Column 2"));
86 CPPUNIT_ASSERT_EQUAL( 2, m_header
->GetColumnCount() );
88 m_header
->InsertColumn(wxHeaderColumnSimple("Column 0"), 0);
89 CPPUNIT_ASSERT_EQUAL( 3, m_header
->GetColumnCount() );
91 m_header
->DeleteColumn(2);
92 CPPUNIT_ASSERT_EQUAL( 2, m_header
->GetColumnCount() );
95 void HeaderCtrlTestCase::BestSize()
97 const wxSize sizeEmpty
= m_header
->GetBestSize();
98 // this fails under wxGTK where wxControl::GetBestSize() is 0 in horizontal
100 //CPPUNIT_ASSERT( sizeEmpty.x > 0 );
101 CPPUNIT_ASSERT( sizeEmpty
.y
> 0 );
103 m_header
->AppendColumn(wxHeaderColumnSimple("Foo"));
104 m_header
->AppendColumn(wxHeaderColumnSimple("Bar"));
105 const wxSize size
= m_header
->GetBestSize();
106 CPPUNIT_ASSERT_EQUAL( sizeEmpty
.y
, size
.y
);
109 void HeaderCtrlTestCase::Reorder()
111 static const int COL_COUNT
= 4;
115 for ( n
= 0; n
< COL_COUNT
; n
++ )
116 m_header
->AppendColumn(wxHeaderColumnSimple(wxString::Format("%d", n
)));
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
] );
122 wxHeaderCtrl::MoveColumnInOrderArray(order
, 0, 2);
123 m_header
->SetColumnsOrder(order
); // change order to [1 2 0 3]
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] );
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] );
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] );