]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/bookctrlbasetest.cpp
c5065607e286997cd0dcc05bc688dab3ab5618fc
[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 base->DeletePage(1);
99
100 CPPUNIT_ASSERT_EQUAL(3, base->GetPageCount());
101
102 base->RemovePage(0);
103
104 CPPUNIT_ASSERT_EQUAL(2, base->GetPageCount());
105
106 base->DeleteAllPages();
107
108 CPPUNIT_ASSERT_EQUAL(0, base->GetPageCount());
109
110 AddPanels();
111 }
112
113 void BookCtrlBaseTestCase::ChangeEvents()
114 {
115 wxBookCtrlBase * const base = GetBase();
116
117 base->SetSelection(0);
118
119 EventCounter changing(base, GetChangingEvent());
120 EventCounter changed(base, GetChangedEvent());
121
122 base->SetSelection(1);
123
124 CPPUNIT_ASSERT_EQUAL(1, changing.GetCount());
125 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
126
127 changed.Clear();
128 changing.Clear();
129 base->ChangeSelection(2);
130
131 CPPUNIT_ASSERT_EQUAL(0, changing.GetCount());
132 CPPUNIT_ASSERT_EQUAL(0, changed.GetCount());
133
134 base->AdvanceSelection();
135
136 CPPUNIT_ASSERT_EQUAL(1, changing.GetCount());
137 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
138
139 changed.Clear();
140 changing.Clear();
141 base->AdvanceSelection(false);
142
143 CPPUNIT_ASSERT_EQUAL(1, changing.GetCount());
144 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
145 }
146
147 void BookCtrlBaseTestCase::Image()
148 {
149 wxBookCtrlBase * const base = GetBase();
150
151 //Check AddPanels() set things correctly
152 CPPUNIT_ASSERT_EQUAL(m_list, base->GetImageList());
153 CPPUNIT_ASSERT_EQUAL(0, base->GetPageImage(0));
154 CPPUNIT_ASSERT_EQUAL(1, base->GetPageImage(1));
155 CPPUNIT_ASSERT_EQUAL(2, base->GetPageImage(2));
156
157 base->SetPageImage(0, 2);
158
159 CPPUNIT_ASSERT_EQUAL(2, base->GetPageImage(2));
160 }