]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/headerctrltest.cpp
No changes, just fix unused variables and parameters warnings.
[wxWidgets.git] / tests / controls / headerctrltest.cpp
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"
22 #endif // WX_PRECOMP
23
24 #include "wx/headerctrl.h"
25
26 // ----------------------------------------------------------------------------
27 // test class
28 // ----------------------------------------------------------------------------
29
30 class HeaderCtrlTestCase : public CppUnit::TestCase
31 {
32 public:
33 HeaderCtrlTestCase() { }
34
35 virtual void setUp();
36 virtual void tearDown();
37
38 private:
39 CPPUNIT_TEST_SUITE( HeaderCtrlTestCase );
40 CPPUNIT_TEST( AddDelete );
41 CPPUNIT_TEST( BestSize );
42 CPPUNIT_TEST( Reorder );
43 CPPUNIT_TEST_SUITE_END();
44
45 void AddDelete();
46 void BestSize();
47 void Reorder();
48
49 wxHeaderCtrlSimple *m_header;
50
51 DECLARE_NO_COPY_CLASS(HeaderCtrlTestCase)
52 };
53
54 // register in the unnamed registry so that these tests are run by default
55 CPPUNIT_TEST_SUITE_REGISTRATION( HeaderCtrlTestCase );
56
57 // also include in it's own registry so that these tests can be run alone
58 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HeaderCtrlTestCase, "HeaderCtrlTestCase" );
59
60 // ----------------------------------------------------------------------------
61 // test initialization
62 // ----------------------------------------------------------------------------
63
64 void HeaderCtrlTestCase::setUp()
65 {
66 m_header = new wxHeaderCtrlSimple(wxTheApp->GetTopWindow());
67 }
68
69 void HeaderCtrlTestCase::tearDown()
70 {
71 delete m_header;
72 m_header = NULL;
73 }
74
75 // ----------------------------------------------------------------------------
76 // the tests themselves
77 // ----------------------------------------------------------------------------
78
79 void HeaderCtrlTestCase::AddDelete()
80 {
81 CPPUNIT_ASSERT_EQUAL( 0, m_header->GetColumnCount() );
82
83 m_header->AppendColumn(wxHeaderColumnSimple("Column 1"));
84 CPPUNIT_ASSERT_EQUAL( 1, m_header->GetColumnCount() );
85
86 m_header->AppendColumn(wxHeaderColumnSimple("Column 2"));
87 CPPUNIT_ASSERT_EQUAL( 2, m_header->GetColumnCount() );
88
89 m_header->InsertColumn(wxHeaderColumnSimple("Column 0"), 0);
90 CPPUNIT_ASSERT_EQUAL( 3, m_header->GetColumnCount() );
91
92 m_header->DeleteColumn(2);
93 CPPUNIT_ASSERT_EQUAL( 2, m_header->GetColumnCount() );
94 }
95
96 void HeaderCtrlTestCase::BestSize()
97 {
98 const wxSize sizeEmpty = m_header->GetBestSize();
99 // this fails under wxGTK where wxControl::GetBestSize() is 0 in horizontal
100 // direction
101 //CPPUNIT_ASSERT( sizeEmpty.x > 0 );
102 CPPUNIT_ASSERT( sizeEmpty.y > 0 );
103
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 );
108 }
109
110 void 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