]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/bookctrlbasetest.cpp
Disable wxUIActionSimulator wxGrid tests using mouse under wxGTK.
[wxWidgets.git] / tests / controls / bookctrlbasetest.cpp
CommitLineData
232fdc63
VZ
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 "wx/toolbook.h"
21#include "wx/toolbar.h"
22#include "bookctrlbasetest.h"
23#include "testableframe.h"
24
25void BookCtrlBaseTestCase::AddPanels()
26{
27 wxBookCtrlBase * const base = GetBase();
28
29 wxSize size(32, 32);
30
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));
35
36 base->AssignImageList(m_list);
37
38 //We need to realize the toolbar if we ware running the wxToolbook tests
39 wxToolbook *book = wxDynamicCast(base, wxToolbook);
40
41 if(book)
42 book->GetToolBar()->Realize();
43
44 m_panel1 = new wxPanel(base);
45 m_panel2 = new wxPanel(base);
46 m_panel3 = new wxPanel(base);
47
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);
51}
52
53void BookCtrlBaseTestCase::Selection()
54{
55 wxBookCtrlBase * const base = GetBase();
56
57 base->SetSelection(0);
58
59 CPPUNIT_ASSERT_EQUAL(0, base->GetSelection());
60 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1, wxWindow), base->GetCurrentPage());
61
62 base->AdvanceSelection(false);
63
64 CPPUNIT_ASSERT_EQUAL(2, base->GetSelection());
65 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel3, wxWindow), base->GetCurrentPage());
66
67 base->AdvanceSelection();
68
69 CPPUNIT_ASSERT_EQUAL(0, base->GetSelection());
70 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1, wxWindow), base->GetCurrentPage());
71
72 base->ChangeSelection(1);
73
74 CPPUNIT_ASSERT_EQUAL(1, base->GetSelection());
75 CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel2, wxWindow), base->GetCurrentPage());
76}
77
78void BookCtrlBaseTestCase::Text()
79{
80 wxBookCtrlBase * const base = GetBase();
81
82 CPPUNIT_ASSERT_EQUAL("Panel 1", base->GetPageText(0));
83
84 base->SetPageText(1, "Some other string");
85
86 CPPUNIT_ASSERT_EQUAL("Some other string", base->GetPageText(1));
87
88 base->SetPageText(2, "string with /nline break");
89
90 CPPUNIT_ASSERT_EQUAL("string with /nline break", base->GetPageText(2));
91}
92
93void BookCtrlBaseTestCase::PageManagement()
94{
95 wxBookCtrlBase * const base = GetBase();
96
97 base->InsertPage(0, new wxPanel(base), "New Panel", true, 0);
98
99 //We need to realize the toolbar if we ware running the wxToolbook tests
100 wxToolbook *book = wxDynamicCast(base, wxToolbook);
101
102 if(book)
103 book->GetToolBar()->Realize();
104
105 CPPUNIT_ASSERT_EQUAL(0, base->GetSelection());
106 CPPUNIT_ASSERT_EQUAL(4, base->GetPageCount());
107
108 base->DeletePage(1);
109
110 CPPUNIT_ASSERT_EQUAL(3, base->GetPageCount());
111
112 base->RemovePage(0);
113
114 CPPUNIT_ASSERT_EQUAL(2, base->GetPageCount());
115
116 base->DeleteAllPages();
117
118 CPPUNIT_ASSERT_EQUAL(0, base->GetPageCount());
119
120 AddPanels();
121}
122
123void BookCtrlBaseTestCase::ChangeEvents()
124{
232fdc63
VZ
125 wxBookCtrlBase * const base = GetBase();
126
127 base->SetSelection(0);
128
744d91d4
SL
129 EventCounter changing(base, GetChangingEvent());
130 EventCounter changed(base, GetChangedEvent());
232fdc63
VZ
131
132 base->SetSelection(1);
133
744d91d4
SL
134 CPPUNIT_ASSERT_EQUAL(1, changing.GetCount());
135 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
232fdc63 136
744d91d4
SL
137 changed.Clear();
138 changing.Clear();
232fdc63
VZ
139 base->ChangeSelection(2);
140
744d91d4
SL
141 CPPUNIT_ASSERT_EQUAL(0, changing.GetCount());
142 CPPUNIT_ASSERT_EQUAL(0, changed.GetCount());
232fdc63
VZ
143
144 base->AdvanceSelection();
145
744d91d4
SL
146 CPPUNIT_ASSERT_EQUAL(1, changing.GetCount());
147 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
232fdc63 148
744d91d4
SL
149 changed.Clear();
150 changing.Clear();
232fdc63
VZ
151 base->AdvanceSelection(false);
152
744d91d4
SL
153 CPPUNIT_ASSERT_EQUAL(1, changing.GetCount());
154 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
232fdc63
VZ
155}
156
157void BookCtrlBaseTestCase::Image()
158{
159 wxBookCtrlBase * const base = GetBase();
160
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));
166
167 base->SetPageImage(0, 2);
168
169 CPPUNIT_ASSERT_EQUAL(2, base->GetPageImage(2));
170}