]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/headerctrltest.cpp
f13f4a891ff2d872194508af88239b5bc3ae5ec2
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/headerctrltest.cpp
3 // Purpose: wxHeaderCtrl unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
24 #include "wx/headerctrl.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 class HeaderCtrlTestCase
: public CppUnit::TestCase
33 HeaderCtrlTestCase() { }
36 virtual void tearDown();
39 CPPUNIT_TEST_SUITE( HeaderCtrlTestCase
);
40 CPPUNIT_TEST( AddDelete
);
41 CPPUNIT_TEST( BestSize
);
42 CPPUNIT_TEST( Reorder
);
43 CPPUNIT_TEST_SUITE_END();
49 wxHeaderCtrlSimple
*m_header
;
51 DECLARE_NO_COPY_CLASS(HeaderCtrlTestCase
)
54 // register in the unnamed registry so that these tests are run by default
55 CPPUNIT_TEST_SUITE_REGISTRATION( HeaderCtrlTestCase
);
57 // also include in it's own registry so that these tests can be run alone
58 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HeaderCtrlTestCase
, "HeaderCtrlTestCase" );
60 // ----------------------------------------------------------------------------
61 // test initialization
62 // ----------------------------------------------------------------------------
64 void HeaderCtrlTestCase::setUp()
66 m_header
= new wxHeaderCtrlSimple(wxTheApp
->GetTopWindow());
69 void HeaderCtrlTestCase::tearDown()
75 // ----------------------------------------------------------------------------
76 // the tests themselves
77 // ----------------------------------------------------------------------------
79 void HeaderCtrlTestCase::AddDelete()
81 CPPUNIT_ASSERT_EQUAL( 0, m_header
->GetColumnCount() );
83 m_header
->AppendColumn(wxHeaderColumnSimple("Column 1"));
84 CPPUNIT_ASSERT_EQUAL( 1, m_header
->GetColumnCount() );
86 m_header
->AppendColumn(wxHeaderColumnSimple("Column 2"));
87 CPPUNIT_ASSERT_EQUAL( 2, m_header
->GetColumnCount() );
89 m_header
->InsertColumn(wxHeaderColumnSimple("Column 0"), 0);
90 CPPUNIT_ASSERT_EQUAL( 3, m_header
->GetColumnCount() );
92 m_header
->DeleteColumn(2);
93 CPPUNIT_ASSERT_EQUAL( 2, m_header
->GetColumnCount() );
96 void HeaderCtrlTestCase::BestSize()
98 const wxSize sizeEmpty
= m_header
->GetBestSize();
99 // this fails under wxGTK where wxControl::GetBestSize() is 0 in horizontal
101 //CPPUNIT_ASSERT( sizeEmpty.x > 0 );
102 CPPUNIT_ASSERT( sizeEmpty
.y
> 0 );
104 m_header
->AppendColumn(wxHeaderColumnSimple("Foo"));
105 m_header
->AppendColumn(wxHeaderColumnSimple("Bar"));
106 const wxSize size
= m_header
->GetBestSize();
107 CPPUNIT_ASSERT_EQUAL( sizeEmpty
.y
, size
.y
);
110 void HeaderCtrlTestCase::Reorder()
112 static const int COL_COUNT
= 4;
116 for ( n
= 0; n
< COL_COUNT
; n
++ )
117 m_header
->AppendColumn(wxHeaderColumnSimple(wxString::Format("%d", n
)));
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
] );
123 wxHeaderCtrl::MoveColumnInOrderArray(order
, 0, 2);
124 m_header
->SetColumnsOrder(order
); // change order to [1 2 0 3]
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] );
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] );
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] );