]>
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 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
128 wxBookCtrlBase
* const base
= GetBase();
130 base
->SetSelection(0);
132 EventCounter
count(base
, GetChangingEvent());
133 EventCounter
count1(base
, GetChangedEvent());
135 base
->SetSelection(1);
137 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(GetChangingEvent()));
138 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(GetChangedEvent()));
140 base
->ChangeSelection(2);
142 CPPUNIT_ASSERT_EQUAL(0, frame
->GetEventCount(GetChangingEvent()));
143 CPPUNIT_ASSERT_EQUAL(0, frame
->GetEventCount(GetChangedEvent()));
145 base
->AdvanceSelection();
147 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(GetChangingEvent()));
148 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(GetChangedEvent()));
150 base
->AdvanceSelection(false);
152 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(GetChangingEvent()));
153 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(GetChangedEvent()));
156 void BookCtrlBaseTestCase::Image()
158 wxBookCtrlBase
* const base
= GetBase();
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));
166 base
->SetPageImage(0, 2);
168 CPPUNIT_ASSERT_EQUAL(2, base
->GetPageImage(2));