]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/bookctrlbasetest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/bookctrlbasetest.cpp
3 // Purpose: wxBookCtrlBase unit test
4 // Author: Steven Lamerton
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
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"
25 void BookCtrlBaseTestCase::AddPanels()
27 wxBookCtrlBase
* const base
= GetBase();
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
));
36 base
->AssignImageList(m_list
);
38 //We need to realize the toolbar if we ware running the wxToolbook tests
39 wxToolbook
*book
= wxDynamicCast(base
, wxToolbook
);
42 book
->GetToolBar()->Realize();
44 m_panel1
= new wxPanel(base
);
45 m_panel2
= new wxPanel(base
);
46 m_panel3
= new wxPanel(base
);
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);
53 void BookCtrlBaseTestCase::Selection()
55 wxBookCtrlBase
* const base
= GetBase();
57 base
->SetSelection(0);
59 CPPUNIT_ASSERT_EQUAL(0, base
->GetSelection());
60 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1
, wxWindow
), base
->GetCurrentPage());
62 base
->AdvanceSelection(false);
64 CPPUNIT_ASSERT_EQUAL(2, base
->GetSelection());
65 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel3
, wxWindow
), base
->GetCurrentPage());
67 base
->AdvanceSelection();
69 CPPUNIT_ASSERT_EQUAL(0, base
->GetSelection());
70 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1
, wxWindow
), base
->GetCurrentPage());
72 base
->ChangeSelection(1);
74 CPPUNIT_ASSERT_EQUAL(1, base
->GetSelection());
75 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel2
, wxWindow
), base
->GetCurrentPage());
78 void BookCtrlBaseTestCase::Text()
80 wxBookCtrlBase
* const base
= GetBase();
82 CPPUNIT_ASSERT_EQUAL("Panel 1", base
->GetPageText(0));
84 base
->SetPageText(1, "Some other string");
86 CPPUNIT_ASSERT_EQUAL("Some other string", base
->GetPageText(1));
88 base
->SetPageText(2, "string with /nline break");
90 CPPUNIT_ASSERT_EQUAL("string with /nline break", base
->GetPageText(2));
93 void BookCtrlBaseTestCase::PageManagement()
95 wxBookCtrlBase
* const base
= GetBase();
97 base
->InsertPage(0, new wxPanel(base
), "New Panel", true, 0);
99 //We need to realize the toolbar if we ware running the wxToolbook tests
100 wxToolbook
*book
= wxDynamicCast(base
, wxToolbook
);
103 book
->GetToolBar()->Realize();
105 CPPUNIT_ASSERT_EQUAL(0, base
->GetSelection());
106 CPPUNIT_ASSERT_EQUAL(4, base
->GetPageCount());
110 CPPUNIT_ASSERT_EQUAL(3, base
->GetPageCount());
114 CPPUNIT_ASSERT_EQUAL(2, base
->GetPageCount());
116 base
->DeleteAllPages();
118 CPPUNIT_ASSERT_EQUAL(0, base
->GetPageCount());
123 void BookCtrlBaseTestCase::ChangeEvents()
125 wxBookCtrlBase
* const base
= GetBase();
127 base
->SetSelection(0);
129 EventCounter
changing(base
, GetChangingEvent());
130 EventCounter
changed(base
, GetChangedEvent());
132 base
->SetSelection(1);
134 CPPUNIT_ASSERT_EQUAL(1, changing
.GetCount());
135 CPPUNIT_ASSERT_EQUAL(1, changed
.GetCount());
139 base
->ChangeSelection(2);
141 CPPUNIT_ASSERT_EQUAL(0, changing
.GetCount());
142 CPPUNIT_ASSERT_EQUAL(0, changed
.GetCount());
144 base
->AdvanceSelection();
146 CPPUNIT_ASSERT_EQUAL(1, changing
.GetCount());
147 CPPUNIT_ASSERT_EQUAL(1, changed
.GetCount());
151 base
->AdvanceSelection(false);
153 CPPUNIT_ASSERT_EQUAL(1, changing
.GetCount());
154 CPPUNIT_ASSERT_EQUAL(1, changed
.GetCount());
157 void BookCtrlBaseTestCase::Image()
159 wxBookCtrlBase
* const base
= GetBase();
161 //Check AddPanels() set things correctly
162 CPPUNIT_ASSERT_EQUAL(m_list
, base
->GetImageList());
163 CPPUNIT_ASSERT_EQUAL(0, base
->GetPageImage(0));
164 CPPUNIT_ASSERT_EQUAL(1, base
->GetPageImage(1));
165 CPPUNIT_ASSERT_EQUAL(2, base
->GetPageImage(2));
167 base
->SetPageImage(0, 2);
169 CPPUNIT_ASSERT_EQUAL(2, base
->GetPageImage(2));