]>
Commit | Line | Data |
---|---|---|
232fdc63 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/controls/bookctrlbasetest.cpp | |
3 | // Purpose: wxBookCtrlBase unit test | |
4 | // Author: Steven Lamerton | |
5 | // Created: 2010-07-02 | |
232fdc63 VZ |
6 | // Copyright: (c) 2010 Steven Lamerton |
7 | /////////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | #include "testprec.h" | |
10 | ||
11 | #ifndef WX_PRECOMP | |
12 | #include "wx/app.h" | |
13 | #include "wx/panel.h" | |
14 | #endif // WX_PRECOMP | |
15 | ||
16 | #include "wx/artprov.h" | |
17 | #include "wx/imaglist.h" | |
18 | #include "wx/bookctrl.h" | |
232fdc63 VZ |
19 | #include "bookctrlbasetest.h" |
20 | #include "testableframe.h" | |
21 | ||
22 | void BookCtrlBaseTestCase::AddPanels() | |
23 | { | |
24 | wxBookCtrlBase * const base = GetBase(); | |
25 | ||
26 | wxSize size(32, 32); | |
27 | ||
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)); | |
32 | ||
33 | base->AssignImageList(m_list); | |
34 | ||
6f71e062 | 35 | Realize(); |
232fdc63 VZ |
36 | |
37 | m_panel1 = new wxPanel(base); | |
38 | m_panel2 = new wxPanel(base); | |
39 | m_panel3 = new wxPanel(base); | |
40 | ||
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); | |
44 | } | |
45 | ||
46 | void BookCtrlBaseTestCase::Selection() | |
47 | { | |
48 | wxBookCtrlBase * const base = GetBase(); | |
49 | ||
50 | base->SetSelection(0); | |
51 | ||
52 | CPPUNIT_ASSERT_EQUAL(0, base->GetSelection()); | |
53 | CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1, wxWindow), base->GetCurrentPage()); | |
54 | ||
55 | base->AdvanceSelection(false); | |
56 | ||
57 | CPPUNIT_ASSERT_EQUAL(2, base->GetSelection()); | |
58 | CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel3, wxWindow), base->GetCurrentPage()); | |
59 | ||
60 | base->AdvanceSelection(); | |
61 | ||
62 | CPPUNIT_ASSERT_EQUAL(0, base->GetSelection()); | |
63 | CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel1, wxWindow), base->GetCurrentPage()); | |
64 | ||
65 | base->ChangeSelection(1); | |
66 | ||
67 | CPPUNIT_ASSERT_EQUAL(1, base->GetSelection()); | |
68 | CPPUNIT_ASSERT_EQUAL(wxStaticCast(m_panel2, wxWindow), base->GetCurrentPage()); | |
69 | } | |
70 | ||
71 | void BookCtrlBaseTestCase::Text() | |
72 | { | |
73 | wxBookCtrlBase * const base = GetBase(); | |
74 | ||
75 | CPPUNIT_ASSERT_EQUAL("Panel 1", base->GetPageText(0)); | |
76 | ||
77 | base->SetPageText(1, "Some other string"); | |
78 | ||
79 | CPPUNIT_ASSERT_EQUAL("Some other string", base->GetPageText(1)); | |
80 | ||
81 | base->SetPageText(2, "string with /nline break"); | |
82 | ||
83 | CPPUNIT_ASSERT_EQUAL("string with /nline break", base->GetPageText(2)); | |
84 | } | |
85 | ||
86 | void BookCtrlBaseTestCase::PageManagement() | |
87 | { | |
88 | wxBookCtrlBase * const base = GetBase(); | |
89 | ||
90 | base->InsertPage(0, new wxPanel(base), "New Panel", true, 0); | |
91 | ||
6f71e062 | 92 | Realize(); |
232fdc63 VZ |
93 | |
94 | CPPUNIT_ASSERT_EQUAL(0, base->GetSelection()); | |
95 | CPPUNIT_ASSERT_EQUAL(4, base->GetPageCount()); | |
96 | ||
4f9ccec5 VZ |
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()); | |
101 | ||
232fdc63 VZ |
102 | base->DeletePage(1); |
103 | ||
104 | CPPUNIT_ASSERT_EQUAL(3, base->GetPageCount()); | |
4f9ccec5 | 105 | CPPUNIT_ASSERT_EQUAL(1, base->GetSelection()); |
232fdc63 VZ |
106 | |
107 | base->RemovePage(0); | |
108 | ||
109 | CPPUNIT_ASSERT_EQUAL(2, base->GetPageCount()); | |
4f9ccec5 | 110 | CPPUNIT_ASSERT_EQUAL(0, base->GetSelection()); |
232fdc63 VZ |
111 | |
112 | base->DeleteAllPages(); | |
113 | ||
114 | CPPUNIT_ASSERT_EQUAL(0, base->GetPageCount()); | |
4f9ccec5 | 115 | CPPUNIT_ASSERT_EQUAL(-1, base->GetSelection()); |
232fdc63 VZ |
116 | } |
117 | ||
118 | void BookCtrlBaseTestCase::ChangeEvents() | |
119 | { | |
232fdc63 VZ |
120 | wxBookCtrlBase * const base = GetBase(); |
121 | ||
122 | base->SetSelection(0); | |
123 | ||
744d91d4 SL |
124 | EventCounter changing(base, GetChangingEvent()); |
125 | EventCounter changed(base, GetChangedEvent()); | |
232fdc63 VZ |
126 | |
127 | base->SetSelection(1); | |
128 | ||
744d91d4 SL |
129 | CPPUNIT_ASSERT_EQUAL(1, changing.GetCount()); |
130 | CPPUNIT_ASSERT_EQUAL(1, changed.GetCount()); | |
232fdc63 | 131 | |
744d91d4 SL |
132 | changed.Clear(); |
133 | changing.Clear(); | |
232fdc63 VZ |
134 | base->ChangeSelection(2); |
135 | ||
744d91d4 SL |
136 | CPPUNIT_ASSERT_EQUAL(0, changing.GetCount()); |
137 | CPPUNIT_ASSERT_EQUAL(0, changed.GetCount()); | |
232fdc63 VZ |
138 | |
139 | base->AdvanceSelection(); | |
140 | ||
744d91d4 SL |
141 | CPPUNIT_ASSERT_EQUAL(1, changing.GetCount()); |
142 | CPPUNIT_ASSERT_EQUAL(1, changed.GetCount()); | |
232fdc63 | 143 | |
744d91d4 SL |
144 | changed.Clear(); |
145 | changing.Clear(); | |
232fdc63 VZ |
146 | base->AdvanceSelection(false); |
147 | ||
744d91d4 SL |
148 | CPPUNIT_ASSERT_EQUAL(1, changing.GetCount()); |
149 | CPPUNIT_ASSERT_EQUAL(1, changed.GetCount()); | |
232fdc63 VZ |
150 | } |
151 | ||
152 | void BookCtrlBaseTestCase::Image() | |
153 | { | |
154 | wxBookCtrlBase * const base = GetBase(); | |
155 | ||
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)); | |
161 | ||
162 | base->SetPageImage(0, 2); | |
163 | ||
164 | CPPUNIT_ASSERT_EQUAL(2, base->GetPageImage(2)); | |
165 | } |