]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/bookctrlbasetest.cpp
Add new wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED event. Implement for all backends, exten...
[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 "wx/toolbook.h"
21 #include "wx/toolbar.h"
22 #include "bookctrlbasetest.h"
23 #include "testableframe.h"
24
25 void BookCtrlBaseTestCase::AddPanels()
26 {
27 wxBookCtrlBase * const base = GetBase();
28
29 wxSize size(32, 32);
30
31 m_list = new wxImageList(size.x, size.y);
32 m_list->Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, size));
33 m_list->Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, size));
34 m_list->Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, size));
35
36 base->AssignImageList(m_list);
37
38 //We need to realize the toolbar if we ware running the wxToolbook tests
39 wxToolbook *book = wxDynamicCast(base, wxToolbook);
40
41 if(book)
42 book->GetToolBar()->Realize();
43
44 m_panel1 = new wxPanel(base);
45 m_panel2 = new wxPanel(base);
46 m_panel3 = new wxPanel(base);
47
48 base->AddPage(m_panel1, "Panel 1", false, 0);
49 base->AddPage(m_panel2, "Panel 2", false, 1);
50 base->AddPage(m_panel3, "Panel 3", false, 2);
51 }
52
53 void BookCtrlBaseTestCase::Selection()
54 {
55 wxBookCtrlBase * const base = GetBase();
56
57 base->SetSelection(0);
58
59 CPPUNIT_ASSERT_EQUAL(0, base->GetSelection());
60 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1, wxWindow), base->GetCurrentPage());
61
62 base->AdvanceSelection(false);
63
64 CPPUNIT_ASSERT_EQUAL(2, base->GetSelection());
65 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel3, wxWindow), base->GetCurrentPage());
66
67 base->AdvanceSelection();
68
69 CPPUNIT_ASSERT_EQUAL(0, base->GetSelection());
70 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1, wxWindow), base->GetCurrentPage());
71
72 base->ChangeSelection(1);
73
74 CPPUNIT_ASSERT_EQUAL(1, base->GetSelection());
75 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel2, wxWindow), base->GetCurrentPage());
76 }
77
78 void BookCtrlBaseTestCase::Text()
79 {
80 wxBookCtrlBase * const base = GetBase();
81
82 CPPUNIT_ASSERT_EQUAL("Panel 1", base->GetPageText(0));
83
84 base->SetPageText(1, "Some other string");
85
86 CPPUNIT_ASSERT_EQUAL("Some other string", base->GetPageText(1));
87
88 base->SetPageText(2, "string with /nline break");
89
90 CPPUNIT_ASSERT_EQUAL("string with /nline break", base->GetPageText(2));
91 }
92
93 void BookCtrlBaseTestCase::PageManagement()
94 {
95 wxBookCtrlBase * const base = GetBase();
96
97 base->InsertPage(0, new wxPanel(base), "New Panel", true, 0);
98
99 //We need to realize the toolbar if we ware running the wxToolbook tests
100 wxToolbook *book = wxDynamicCast(base, wxToolbook);
101
102 if(book)
103 book->GetToolBar()->Realize();
104
105 CPPUNIT_ASSERT_EQUAL(0, base->GetSelection());
106 CPPUNIT_ASSERT_EQUAL(4, base->GetPageCount());
107
108 base->DeletePage(1);
109
110 CPPUNIT_ASSERT_EQUAL(3, base->GetPageCount());
111
112 base->RemovePage(0);
113
114 CPPUNIT_ASSERT_EQUAL(2, base->GetPageCount());
115
116 base->DeleteAllPages();
117
118 CPPUNIT_ASSERT_EQUAL(0, base->GetPageCount());
119
120 AddPanels();
121 }
122
123 void BookCtrlBaseTestCase::ChangeEvents()
124 {
125 wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
126 wxTestableFrame);
127
128 wxBookCtrlBase * const base = GetBase();
129
130 base->SetSelection(0);
131
132 EventCounter count(base, GetChangingEvent());
133 EventCounter count1(base, GetChangedEvent());
134
135 base->SetSelection(1);
136
137 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(GetChangingEvent()));
138 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(GetChangedEvent()));
139
140 base->ChangeSelection(2);
141
142 CPPUNIT_ASSERT_EQUAL(0, frame->GetEventCount(GetChangingEvent()));
143 CPPUNIT_ASSERT_EQUAL(0, frame->GetEventCount(GetChangedEvent()));
144
145 base->AdvanceSelection();
146
147 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(GetChangingEvent()));
148 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(GetChangedEvent()));
149
150 base->AdvanceSelection(false);
151
152 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(GetChangingEvent()));
153 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(GetChangedEvent()));
154 }
155
156 void BookCtrlBaseTestCase::Image()
157 {
158 wxBookCtrlBase * const base = GetBase();
159
160 //Check AddPanels() set things correctly
161 CPPUNIT_ASSERT_EQUAL(m_list, base->GetImageList());
162 CPPUNIT_ASSERT_EQUAL(0, base->GetPageImage(0));
163 CPPUNIT_ASSERT_EQUAL(1, base->GetPageImage(1));
164 CPPUNIT_ASSERT_EQUAL(2, base->GetPageImage(2));
165
166 base->SetPageImage(0, 2);
167
168 CPPUNIT_ASSERT_EQUAL(2, base->GetPageImage(2));
169 }