]>
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
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
16 #include "wx/artprov.h"
17 #include "wx/imaglist.h"
18 #include "wx/bookctrl.h"
19 #include "bookctrlbasetest.h"
20 #include "testableframe.h"
22 void BookCtrlBaseTestCase::AddPanels()
24 wxBookCtrlBase
* const base
= GetBase();
28 m_list
= new wxImageList(size
.x
, size
.y
);
29 m_list
->Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, size
));
30 m_list
->Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, size
));
31 m_list
->Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, size
));
33 base
->AssignImageList(m_list
);
37 m_panel1
= new wxPanel(base
);
38 m_panel2
= new wxPanel(base
);
39 m_panel3
= new wxPanel(base
);
41 base
->AddPage(m_panel1
, "Panel 1", false, 0);
42 base
->AddPage(m_panel2
, "Panel 2", false, 1);
43 base
->AddPage(m_panel3
, "Panel 3", false, 2);
46 void BookCtrlBaseTestCase::Selection()
48 wxBookCtrlBase
* const base
= GetBase();
50 base
->SetSelection(0);
52 CPPUNIT_ASSERT_EQUAL(0, base
->GetSelection());
53 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1
, wxWindow
), base
->GetCurrentPage());
55 base
->AdvanceSelection(false);
57 CPPUNIT_ASSERT_EQUAL(2, base
->GetSelection());
58 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel3
, wxWindow
), base
->GetCurrentPage());
60 base
->AdvanceSelection();
62 CPPUNIT_ASSERT_EQUAL(0, base
->GetSelection());
63 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1
, wxWindow
), base
->GetCurrentPage());
65 base
->ChangeSelection(1);
67 CPPUNIT_ASSERT_EQUAL(1, base
->GetSelection());
68 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel2
, wxWindow
), base
->GetCurrentPage());
71 void BookCtrlBaseTestCase::Text()
73 wxBookCtrlBase
* const base
= GetBase();
75 CPPUNIT_ASSERT_EQUAL("Panel 1", base
->GetPageText(0));
77 base
->SetPageText(1, "Some other string");
79 CPPUNIT_ASSERT_EQUAL("Some other string", base
->GetPageText(1));
81 base
->SetPageText(2, "string with /nline break");
83 CPPUNIT_ASSERT_EQUAL("string with /nline break", base
->GetPageText(2));
86 void BookCtrlBaseTestCase::PageManagement()
88 wxBookCtrlBase
* const base
= GetBase();
90 base
->InsertPage(0, new wxPanel(base
), "New Panel", true, 0);
94 CPPUNIT_ASSERT_EQUAL(0, base
->GetSelection());
95 CPPUNIT_ASSERT_EQUAL(4, base
->GetPageCount());
97 // Change the selection to verify that deleting a page before the currently
98 // selected one correctly updates the selection.
99 base
->SetSelection(2);
100 CPPUNIT_ASSERT_EQUAL(2, base
->GetSelection());
104 CPPUNIT_ASSERT_EQUAL(3, base
->GetPageCount());
105 CPPUNIT_ASSERT_EQUAL(1, base
->GetSelection());
109 CPPUNIT_ASSERT_EQUAL(2, base
->GetPageCount());
110 CPPUNIT_ASSERT_EQUAL(0, base
->GetSelection());
112 base
->DeleteAllPages();
114 CPPUNIT_ASSERT_EQUAL(0, base
->GetPageCount());
115 CPPUNIT_ASSERT_EQUAL(-1, base
->GetSelection());
118 void BookCtrlBaseTestCase::ChangeEvents()
120 wxBookCtrlBase
* const base
= GetBase();
122 base
->SetSelection(0);
124 EventCounter
changing(base
, GetChangingEvent());
125 EventCounter
changed(base
, GetChangedEvent());
127 base
->SetSelection(1);
129 CPPUNIT_ASSERT_EQUAL(1, changing
.GetCount());
130 CPPUNIT_ASSERT_EQUAL(1, changed
.GetCount());
134 base
->ChangeSelection(2);
136 CPPUNIT_ASSERT_EQUAL(0, changing
.GetCount());
137 CPPUNIT_ASSERT_EQUAL(0, changed
.GetCount());
139 base
->AdvanceSelection();
141 CPPUNIT_ASSERT_EQUAL(1, changing
.GetCount());
142 CPPUNIT_ASSERT_EQUAL(1, changed
.GetCount());
146 base
->AdvanceSelection(false);
148 CPPUNIT_ASSERT_EQUAL(1, changing
.GetCount());
149 CPPUNIT_ASSERT_EQUAL(1, changed
.GetCount());
152 void BookCtrlBaseTestCase::Image()
154 wxBookCtrlBase
* const base
= GetBase();
156 //Check AddPanels() set things correctly
157 CPPUNIT_ASSERT_EQUAL(m_list
, base
->GetImageList());
158 CPPUNIT_ASSERT_EQUAL(0, base
->GetPageImage(0));
159 CPPUNIT_ASSERT_EQUAL(1, base
->GetPageImage(1));
160 CPPUNIT_ASSERT_EQUAL(2, base
->GetPageImage(2));
162 base
->SetPageImage(0, 2);
164 CPPUNIT_ASSERT_EQUAL(2, base
->GetPageImage(2));