]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/bookctrlbasetest.cpp
acd787f6fad5e90a0ab6d5e5ae80569d724f498e
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 "bookctrlbasetest.h"
21 #include "testableframe.h"
23 void BookCtrlBaseTestCase::AddPanels()
25 wxBookCtrlBase
* const base
= GetBase();
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
));
34 base
->AssignImageList(m_list
);
38 m_panel1
= new wxPanel(base
);
39 m_panel2
= new wxPanel(base
);
40 m_panel3
= new wxPanel(base
);
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);
47 void BookCtrlBaseTestCase::Selection()
49 wxBookCtrlBase
* const base
= GetBase();
51 base
->SetSelection(0);
53 CPPUNIT_ASSERT_EQUAL(0, base
->GetSelection());
54 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1
, wxWindow
), base
->GetCurrentPage());
56 base
->AdvanceSelection(false);
58 CPPUNIT_ASSERT_EQUAL(2, base
->GetSelection());
59 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel3
, wxWindow
), base
->GetCurrentPage());
61 base
->AdvanceSelection();
63 CPPUNIT_ASSERT_EQUAL(0, base
->GetSelection());
64 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1
, wxWindow
), base
->GetCurrentPage());
66 base
->ChangeSelection(1);
68 CPPUNIT_ASSERT_EQUAL(1, base
->GetSelection());
69 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel2
, wxWindow
), base
->GetCurrentPage());
72 void BookCtrlBaseTestCase::Text()
74 wxBookCtrlBase
* const base
= GetBase();
76 CPPUNIT_ASSERT_EQUAL("Panel 1", base
->GetPageText(0));
78 base
->SetPageText(1, "Some other string");
80 CPPUNIT_ASSERT_EQUAL("Some other string", base
->GetPageText(1));
82 base
->SetPageText(2, "string with /nline break");
84 CPPUNIT_ASSERT_EQUAL("string with /nline break", base
->GetPageText(2));
87 void BookCtrlBaseTestCase::PageManagement()
89 wxBookCtrlBase
* const base
= GetBase();
91 base
->InsertPage(0, new wxPanel(base
), "New Panel", true, 0);
95 CPPUNIT_ASSERT_EQUAL(0, base
->GetSelection());
96 CPPUNIT_ASSERT_EQUAL(4, base
->GetPageCount());
98 // Change the selection to verify that deleting a page before the currently
99 // selected one correctly updates the selection.
100 base
->SetSelection(2);
101 CPPUNIT_ASSERT_EQUAL(2, base
->GetSelection());
105 CPPUNIT_ASSERT_EQUAL(3, base
->GetPageCount());
106 CPPUNIT_ASSERT_EQUAL(1, base
->GetSelection());
110 CPPUNIT_ASSERT_EQUAL(2, base
->GetPageCount());
111 CPPUNIT_ASSERT_EQUAL(0, base
->GetSelection());
113 base
->DeleteAllPages();
115 CPPUNIT_ASSERT_EQUAL(0, base
->GetPageCount());
116 CPPUNIT_ASSERT_EQUAL(-1, base
->GetSelection());
119 void BookCtrlBaseTestCase::ChangeEvents()
121 wxBookCtrlBase
* const base
= GetBase();
123 base
->SetSelection(0);
125 EventCounter
changing(base
, GetChangingEvent());
126 EventCounter
changed(base
, GetChangedEvent());
128 base
->SetSelection(1);
130 CPPUNIT_ASSERT_EQUAL(1, changing
.GetCount());
131 CPPUNIT_ASSERT_EQUAL(1, changed
.GetCount());
135 base
->ChangeSelection(2);
137 CPPUNIT_ASSERT_EQUAL(0, changing
.GetCount());
138 CPPUNIT_ASSERT_EQUAL(0, changed
.GetCount());
140 base
->AdvanceSelection();
142 CPPUNIT_ASSERT_EQUAL(1, changing
.GetCount());
143 CPPUNIT_ASSERT_EQUAL(1, changed
.GetCount());
147 base
->AdvanceSelection(false);
149 CPPUNIT_ASSERT_EQUAL(1, changing
.GetCount());
150 CPPUNIT_ASSERT_EQUAL(1, changed
.GetCount());
153 void BookCtrlBaseTestCase::Image()
155 wxBookCtrlBase
* const base
= GetBase();
157 //Check AddPanels() set things correctly
158 CPPUNIT_ASSERT_EQUAL(m_list
, base
->GetImageList());
159 CPPUNIT_ASSERT_EQUAL(0, base
->GetPageImage(0));
160 CPPUNIT_ASSERT_EQUAL(1, base
->GetPageImage(1));
161 CPPUNIT_ASSERT_EQUAL(2, base
->GetPageImage(2));
163 base
->SetPageImage(0, 2);
165 CPPUNIT_ASSERT_EQUAL(2, base
->GetPageImage(2));