]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/bookctrlbasetest.cpp
Make wxMSW wxSpinCtrl "not enough space" messages more helpful.
[wxWidgets.git] / tests / controls / bookctrlbasetest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/bookctrlbasetest.cpp
3 // Purpose: wxBookCtrlBase unit test
4 // Author: Steven Lamerton
5 // Created: 2010-07-02
6 // RCS-ID: $Id$
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "testprec.h"
11
12 #ifndef WX_PRECOMP
13 #include "wx/app.h"
14 #include "wx/panel.h"
15 #endif // WX_PRECOMP
16
17 #include "wx/artprov.h"
18 #include "wx/imaglist.h"
19 #include "wx/bookctrl.h"
20 #include "bookctrlbasetest.h"
21 #include "testableframe.h"
22
23 void BookCtrlBaseTestCase::AddPanels()
24 {
25 wxBookCtrlBase * const base = GetBase();
26
27 wxSize size(32, 32);
28
29 m_list = new wxImageList(size.x, size.y);
30 m_list->Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, size));
31 m_list->Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, size));
32 m_list->Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, size));
33
34 base->AssignImageList(m_list);
35
36 Realize();
37
38 m_panel1 = new wxPanel(base);
39 m_panel2 = new wxPanel(base);
40 m_panel3 = new wxPanel(base);
41
42 base->AddPage(m_panel1, "Panel 1", false, 0);
43 base->AddPage(m_panel2, "Panel 2", false, 1);
44 base->AddPage(m_panel3, "Panel 3", false, 2);
45 }
46
47 void BookCtrlBaseTestCase::Selection()
48 {
49 wxBookCtrlBase * const base = GetBase();
50
51 base->SetSelection(0);
52
53 CPPUNIT_ASSERT_EQUAL(0, base->GetSelection());
54 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1, wxWindow), base->GetCurrentPage());
55
56 base->AdvanceSelection(false);
57
58 CPPUNIT_ASSERT_EQUAL(2, base->GetSelection());
59 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel3, wxWindow), base->GetCurrentPage());
60
61 base->AdvanceSelection();
62
63 CPPUNIT_ASSERT_EQUAL(0, base->GetSelection());
64 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1, wxWindow), base->GetCurrentPage());
65
66 base->ChangeSelection(1);
67
68 CPPUNIT_ASSERT_EQUAL(1, base->GetSelection());
69 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel2, wxWindow), base->GetCurrentPage());
70 }
71
72 void BookCtrlBaseTestCase::Text()
73 {
74 wxBookCtrlBase * const base = GetBase();
75
76 CPPUNIT_ASSERT_EQUAL("Panel 1", base->GetPageText(0));
77
78 base->SetPageText(1, "Some other string");
79
80 CPPUNIT_ASSERT_EQUAL("Some other string", base->GetPageText(1));
81
82 base->SetPageText(2, "string with /nline break");
83
84 CPPUNIT_ASSERT_EQUAL("string with /nline break", base->GetPageText(2));
85 }
86
87 void BookCtrlBaseTestCase::PageManagement()
88 {
89 wxBookCtrlBase * const base = GetBase();
90
91 base->InsertPage(0, new wxPanel(base), "New Panel", true, 0);
92
93 Realize();
94
95 CPPUNIT_ASSERT_EQUAL(0, base->GetSelection());
96 CPPUNIT_ASSERT_EQUAL(4, base->GetPageCount());
97
98 // Change the selection to verify that deleting a page before the currently
99 // selected one correctly updates the selection.
100 base->SetSelection(2);
101 CPPUNIT_ASSERT_EQUAL(2, base->GetSelection());
102
103 base->DeletePage(1);
104
105 CPPUNIT_ASSERT_EQUAL(3, base->GetPageCount());
106 CPPUNIT_ASSERT_EQUAL(1, base->GetSelection());
107
108 base->RemovePage(0);
109
110 CPPUNIT_ASSERT_EQUAL(2, base->GetPageCount());
111 CPPUNIT_ASSERT_EQUAL(0, base->GetSelection());
112
113 base->DeleteAllPages();
114
115 CPPUNIT_ASSERT_EQUAL(0, base->GetPageCount());
116 CPPUNIT_ASSERT_EQUAL(-1, base->GetSelection());
117 }
118
119 void BookCtrlBaseTestCase::ChangeEvents()
120 {
121 wxBookCtrlBase * const base = GetBase();
122
123 base->SetSelection(0);
124
125 EventCounter changing(base, GetChangingEvent());
126 EventCounter changed(base, GetChangedEvent());
127
128 base->SetSelection(1);
129
130 CPPUNIT_ASSERT_EQUAL(1, changing.GetCount());
131 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
132
133 changed.Clear();
134 changing.Clear();
135 base->ChangeSelection(2);
136
137 CPPUNIT_ASSERT_EQUAL(0, changing.GetCount());
138 CPPUNIT_ASSERT_EQUAL(0, changed.GetCount());
139
140 base->AdvanceSelection();
141
142 CPPUNIT_ASSERT_EQUAL(1, changing.GetCount());
143 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
144
145 changed.Clear();
146 changing.Clear();
147 base->AdvanceSelection(false);
148
149 CPPUNIT_ASSERT_EQUAL(1, changing.GetCount());
150 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
151 }
152
153 void BookCtrlBaseTestCase::Image()
154 {
155 wxBookCtrlBase * const base = GetBase();
156
157 //Check AddPanels() set things correctly
158 CPPUNIT_ASSERT_EQUAL(m_list, base->GetImageList());
159 CPPUNIT_ASSERT_EQUAL(0, base->GetPageImage(0));
160 CPPUNIT_ASSERT_EQUAL(1, base->GetPageImage(1));
161 CPPUNIT_ASSERT_EQUAL(2, base->GetPageImage(2));
162
163 base->SetPageImage(0, 2);
164
165 CPPUNIT_ASSERT_EQUAL(2, base->GetPageImage(2));
166 }