]>
Commit | Line | Data |
---|---|---|
232fdc63 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/controls/gridtest.cpp | |
3 | // Purpose: wxGrid unit test | |
4 | // Author: Steven Lamerton | |
5 | // Created: 2010-06-25 | |
232fdc63 VZ |
6 | // Copyright: (c) 2010 Steven Lamerton |
7 | /////////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | #include "testprec.h" | |
10 | ||
11 | #if wxUSE_GRID | |
12 | ||
13 | #ifdef __BORLANDC__ | |
14 | #pragma hdrstop | |
15 | #endif | |
16 | ||
17 | #ifndef WX_PRECOMP | |
18 | #include "wx/app.h" | |
19 | #endif // WX_PRECOMP | |
20 | ||
21 | #include "wx/grid.h" | |
22 | #include "testableframe.h" | |
23 | #include "asserthelper.h" | |
24 | #include "wx/uiaction.h" | |
25 | ||
784130d2 VZ |
26 | // FIXME: A lot of mouse-related tests sporadically fail in wxGTK. This happens |
27 | // almost all the time but sometimes the tests do pass and the failure | |
28 | // doesn't happen when debugging so this looks like some kind of event | |
29 | // dispatching/simulating problem rather than a real problem in wxGrid. | |
30 | // | |
31 | // Just disable these tests for now but it would be really great to | |
32 | // really fix the problem. | |
33 | #ifdef __WXGTK__ | |
34 | #define NONGTK_TEST(test) | |
35 | #else | |
36 | #define NONGTK_TEST(test) WXUISIM_TEST(test) | |
37 | #endif | |
38 | ||
39 | ||
232fdc63 VZ |
40 | class GridTestCase : public CppUnit::TestCase |
41 | { | |
42 | public: | |
43 | GridTestCase() { } | |
44 | ||
45 | virtual void setUp(); | |
46 | virtual void tearDown(); | |
47 | ||
48 | private: | |
49 | CPPUNIT_TEST_SUITE( GridTestCase ); | |
50 | WXUISIM_TEST( CellEdit ); | |
784130d2 VZ |
51 | NONGTK_TEST( CellClick ); |
52 | NONGTK_TEST( CellSelect ); | |
53 | NONGTK_TEST( LabelClick ); | |
54 | NONGTK_TEST( SortClick ); | |
232fdc63 | 55 | WXUISIM_TEST( Size ); |
784130d2 | 56 | NONGTK_TEST( RangeSelect ); |
232fdc63 VZ |
57 | CPPUNIT_TEST( Cursor ); |
58 | CPPUNIT_TEST( Selection ); | |
59 | CPPUNIT_TEST( AddRowCol ); | |
60 | CPPUNIT_TEST( ColumnOrder ); | |
d929eddf | 61 | CPPUNIT_TEST( ColumnVisibility ); |
232fdc63 VZ |
62 | CPPUNIT_TEST( LineFormatting ); |
63 | CPPUNIT_TEST( SortSupport ); | |
64 | CPPUNIT_TEST( Labels ); | |
65 | CPPUNIT_TEST( SelectionMode ); | |
66 | CPPUNIT_TEST( CellFormatting ); | |
67 | WXUISIM_TEST( Editable ); | |
68 | WXUISIM_TEST( ReadOnly ); | |
69 | CPPUNIT_TEST( PseudoTest_NativeHeader ); | |
784130d2 VZ |
70 | NONGTK_TEST( LabelClick ); |
71 | NONGTK_TEST( SortClick ); | |
232fdc63 VZ |
72 | CPPUNIT_TEST( ColumnOrder ); |
73 | CPPUNIT_TEST( PseudoTest_NativeLabels ); | |
784130d2 VZ |
74 | NONGTK_TEST( LabelClick ); |
75 | NONGTK_TEST( SortClick ); | |
232fdc63 VZ |
76 | CPPUNIT_TEST( ColumnOrder ); |
77 | CPPUNIT_TEST_SUITE_END(); | |
78 | ||
79 | void CellEdit(); | |
80 | void CellClick(); | |
81 | void CellSelect(); | |
82 | void LabelClick(); | |
83 | void SortClick(); | |
84 | void Size(); | |
85 | void RangeSelect(); | |
86 | void Cursor(); | |
87 | void Selection(); | |
88 | void AddRowCol(); | |
89 | void ColumnOrder(); | |
d929eddf | 90 | void ColumnVisibility(); |
232fdc63 VZ |
91 | void LineFormatting(); |
92 | void SortSupport(); | |
93 | void Labels(); | |
94 | void SelectionMode(); | |
95 | void CellFormatting(); | |
96 | void Editable(); | |
97 | void ReadOnly(); | |
98 | void PseudoTest_NativeHeader() { ms_nativeheader = true; } | |
99 | void PseudoTest_NativeLabels() { ms_nativeheader = false; | |
100 | ms_nativelabels = true; } | |
101 | ||
102 | static bool ms_nativeheader; | |
103 | static bool ms_nativelabels; | |
104 | ||
105 | wxGrid *m_grid; | |
106 | ||
107 | DECLARE_NO_COPY_CLASS(GridTestCase) | |
108 | }; | |
109 | ||
110 | // register in the unnamed registry so that these tests are run by default | |
111 | CPPUNIT_TEST_SUITE_REGISTRATION( GridTestCase ); | |
112 | ||
e3778b4d | 113 | // also include in its own registry so that these tests can be run alone |
232fdc63 VZ |
114 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( GridTestCase, "GridTestCase" ); |
115 | ||
116 | //initialise the static variable | |
117 | bool GridTestCase::ms_nativeheader = false; | |
118 | bool GridTestCase::ms_nativelabels = false; | |
119 | ||
120 | void GridTestCase::setUp() | |
121 | { | |
122 | m_grid = new wxGrid(wxTheApp->GetTopWindow(), wxID_ANY); | |
123 | m_grid->CreateGrid(10, 2); | |
124 | m_grid->SetSize(400, 200); | |
125 | ||
126 | if( ms_nativeheader ) | |
127 | m_grid->UseNativeColHeader(); | |
128 | ||
129 | if( ms_nativelabels ) | |
130 | m_grid->SetUseNativeColLabels(); | |
131 | ||
132 | m_grid->Refresh(); | |
133 | m_grid->Update(); | |
134 | } | |
135 | ||
136 | void GridTestCase::tearDown() | |
137 | { | |
7c7bd972 VZ |
138 | // This is just a hack to continue the rest of the tests to run: if we |
139 | // destroy the header control while it has capture, this results in an | |
140 | // assert failure and while handling an exception from it more bad things | |
141 | // happen (as it's thrown from a dtor), resulting in simply aborting | |
142 | // everything. So ensure that it doesn't have capture in any case. | |
143 | // | |
144 | // Of course, the right thing to do would be to understand why does it | |
145 | // still have capture when the grid is destroyed sometimes. | |
146 | wxWindow* const win = wxWindow::GetCapture(); | |
147 | if ( win ) | |
148 | win->ReleaseMouse(); | |
149 | ||
232fdc63 VZ |
150 | wxDELETE(m_grid); |
151 | } | |
152 | ||
153 | void GridTestCase::CellEdit() | |
154 | { | |
e1004654 SC |
155 | // TODO on OSX when running the grid test suite solo this works |
156 | // but not when running it together with other tests | |
157 | #if wxUSE_UIACTIONSIMULATOR && !defined(__WXOSX__) | |
744d91d4 SL |
158 | EventCounter changing(m_grid, wxEVT_GRID_CELL_CHANGING); |
159 | EventCounter changed(m_grid, wxEVT_GRID_CELL_CHANGED); | |
160 | EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED); | |
232fdc63 VZ |
161 | |
162 | wxUIActionSimulator sim; | |
163 | ||
164 | m_grid->SetFocus(); | |
165 | m_grid->SetGridCursor(1, 1); | |
166 | m_grid->ShowCellEditControl(); | |
167 | ||
168 | sim.Text("abab"); | |
169 | sim.Char(WXK_RETURN); | |
170 | ||
171 | wxYield(); | |
172 | ||
744d91d4 SL |
173 | CPPUNIT_ASSERT_EQUAL(1, created.GetCount()); |
174 | CPPUNIT_ASSERT_EQUAL(1, changing.GetCount()); | |
175 | CPPUNIT_ASSERT_EQUAL(1, changed.GetCount()); | |
232fdc63 VZ |
176 | #endif |
177 | } | |
178 | ||
179 | void GridTestCase::CellClick() | |
180 | { | |
181 | #if wxUSE_UIACTIONSIMULATOR | |
744d91d4 SL |
182 | EventCounter lclick(m_grid, wxEVT_GRID_CELL_LEFT_CLICK); |
183 | EventCounter ldclick(m_grid, wxEVT_GRID_CELL_LEFT_DCLICK); | |
184 | EventCounter rclick(m_grid, wxEVT_GRID_CELL_RIGHT_CLICK); | |
185 | EventCounter rdclick(m_grid, wxEVT_GRID_CELL_RIGHT_DCLICK); | |
232fdc63 VZ |
186 | |
187 | ||
188 | wxUIActionSimulator sim; | |
189 | ||
190 | wxRect rect = m_grid->CellToRect(0, 0); | |
191 | wxPoint point = m_grid->CalcScrolledPosition(rect.GetPosition()); | |
744d91d4 SL |
192 | point = m_grid->ClientToScreen(point + wxPoint(m_grid->GetRowLabelSize(), |
193 | m_grid->GetColLabelSize()) | |
194 | + wxPoint(2, 2)); | |
232fdc63 VZ |
195 | |
196 | sim.MouseMove(point); | |
197 | wxYield(); | |
198 | ||
199 | sim.MouseClick(); | |
200 | wxYield(); | |
201 | ||
744d91d4 SL |
202 | CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount()); |
203 | lclick.Clear(); | |
232fdc63 VZ |
204 | |
205 | sim.MouseDblClick(); | |
206 | wxYield(); | |
207 | ||
208 | //A double click event sends a single click event first | |
209 | //test to ensure this still happens in the future | |
744d91d4 SL |
210 | CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount()); |
211 | CPPUNIT_ASSERT_EQUAL(1, ldclick.GetCount()); | |
232fdc63 VZ |
212 | |
213 | sim.MouseClick(wxMOUSE_BTN_RIGHT); | |
214 | wxYield(); | |
215 | ||
744d91d4 SL |
216 | CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount()); |
217 | rclick.Clear(); | |
232fdc63 VZ |
218 | |
219 | sim.MouseDblClick(wxMOUSE_BTN_RIGHT); | |
220 | wxYield(); | |
221 | ||
744d91d4 SL |
222 | CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount()); |
223 | CPPUNIT_ASSERT_EQUAL(1, rdclick.GetCount()); | |
232fdc63 VZ |
224 | #endif |
225 | } | |
226 | ||
227 | void GridTestCase::CellSelect() | |
228 | { | |
229 | #if wxUSE_UIACTIONSIMULATOR | |
744d91d4 | 230 | EventCounter cell(m_grid, wxEVT_GRID_SELECT_CELL); |
232fdc63 VZ |
231 | |
232 | wxUIActionSimulator sim; | |
233 | ||
234 | wxRect rect = m_grid->CellToRect(0, 0); | |
235 | wxPoint point = m_grid->CalcScrolledPosition(rect.GetPosition()); | |
744d91d4 SL |
236 | point = m_grid->ClientToScreen(point + wxPoint(m_grid->GetRowLabelSize(), |
237 | m_grid->GetColLabelSize()) | |
238 | + wxPoint(4, 4)); | |
232fdc63 VZ |
239 | |
240 | sim.MouseMove(point); | |
241 | wxYield(); | |
242 | ||
243 | sim.MouseClick(); | |
244 | wxYield(); | |
245 | ||
744d91d4 SL |
246 | CPPUNIT_ASSERT_EQUAL(1, cell.GetCount()); |
247 | ||
248 | cell.Clear(); | |
232fdc63 VZ |
249 | |
250 | m_grid->SetGridCursor(1, 1); | |
251 | m_grid->GoToCell(1, 0); | |
252 | ||
253 | sim.MouseMove(point); | |
254 | wxYield(); | |
255 | ||
256 | sim.MouseDblClick(); | |
257 | wxYield(); | |
258 | ||
744d91d4 | 259 | CPPUNIT_ASSERT_EQUAL(3, cell.GetCount()); |
232fdc63 VZ |
260 | #endif |
261 | } | |
262 | ||
263 | void GridTestCase::LabelClick() | |
264 | { | |
da7ae357 | 265 | #if wxUSE_UIACTIONSIMULATOR |
744d91d4 SL |
266 | EventCounter lclick(m_grid, wxEVT_GRID_LABEL_LEFT_CLICK); |
267 | EventCounter ldclick(m_grid, wxEVT_GRID_LABEL_LEFT_DCLICK); | |
268 | EventCounter rclick(m_grid, wxEVT_GRID_LABEL_RIGHT_CLICK); | |
269 | EventCounter rdclick(m_grid, wxEVT_GRID_LABEL_RIGHT_DCLICK); | |
232fdc63 VZ |
270 | |
271 | wxUIActionSimulator sim; | |
272 | ||
273 | wxPoint pos(m_grid->GetRowLabelSize() + 2, 2); | |
274 | pos = m_grid->ClientToScreen(pos); | |
275 | ||
276 | sim.MouseMove(pos); | |
277 | wxYield(); | |
278 | ||
279 | sim.MouseClick(); | |
280 | wxYield(); | |
281 | ||
744d91d4 | 282 | CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount()); |
232fdc63 VZ |
283 | |
284 | sim.MouseDblClick(); | |
285 | wxYield(); | |
286 | ||
744d91d4 | 287 | CPPUNIT_ASSERT_EQUAL(1, ldclick.GetCount()); |
232fdc63 VZ |
288 | |
289 | sim.MouseClick(wxMOUSE_BTN_RIGHT); | |
290 | wxYield(); | |
291 | ||
744d91d4 SL |
292 | CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount()); |
293 | rclick.Clear(); | |
232fdc63 VZ |
294 | |
295 | sim.MouseDblClick(wxMOUSE_BTN_RIGHT); | |
296 | wxYield(); | |
297 | ||
298 | if( ms_nativeheader ) | |
299 | { | |
300 | //Right double click not supported with native headers so we get two | |
301 | //right click events | |
744d91d4 | 302 | CPPUNIT_ASSERT_EQUAL(2, rclick.GetCount()); |
232fdc63 VZ |
303 | } |
304 | else | |
305 | { | |
744d91d4 SL |
306 | CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount()); |
307 | CPPUNIT_ASSERT_EQUAL(1, rdclick.GetCount()); | |
232fdc63 VZ |
308 | } |
309 | #endif | |
310 | } | |
311 | ||
312 | void GridTestCase::SortClick() | |
313 | { | |
da7ae357 | 314 | #if wxUSE_UIACTIONSIMULATOR |
232fdc63 VZ |
315 | m_grid->SetSortingColumn(0); |
316 | ||
744d91d4 | 317 | EventCounter sort(m_grid, wxEVT_GRID_COL_SORT); |
232fdc63 VZ |
318 | |
319 | wxUIActionSimulator sim; | |
320 | ||
321 | wxPoint pos(m_grid->GetRowLabelSize() + 4, 4); | |
322 | pos = m_grid->ClientToScreen(pos); | |
323 | ||
324 | sim.MouseMove(pos); | |
325 | wxYield(); | |
326 | ||
327 | sim.MouseClick(); | |
328 | wxYield(); | |
329 | ||
744d91d4 | 330 | CPPUNIT_ASSERT_EQUAL(1, sort.GetCount()); |
232fdc63 VZ |
331 | #endif |
332 | } | |
333 | ||
334 | void GridTestCase::Size() | |
335 | { | |
e1004654 SC |
336 | // TODO on OSX resizing interactively works, but not automated |
337 | #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__) && !defined(__WXOSX__) | |
744d91d4 SL |
338 | EventCounter colsize(m_grid, wxEVT_GRID_COL_SIZE); |
339 | EventCounter rowsize(m_grid, wxEVT_GRID_ROW_SIZE); | |
232fdc63 VZ |
340 | |
341 | wxUIActionSimulator sim; | |
342 | ||
343 | wxPoint pt = m_grid->ClientToScreen(wxPoint(m_grid->GetRowLabelSize() + | |
344 | m_grid->GetColSize(0), 5)); | |
345 | ||
346 | sim.MouseMove(pt); | |
347 | wxYield(); | |
348 | ||
349 | sim.MouseDown(); | |
350 | wxYield(); | |
351 | ||
352 | sim.MouseMove(pt.x + 50, pt.y); | |
353 | wxYield(); | |
354 | ||
355 | sim.MouseUp(); | |
356 | wxYield(); | |
357 | ||
744d91d4 | 358 | CPPUNIT_ASSERT_EQUAL(1, colsize.GetCount()); |
232fdc63 VZ |
359 | |
360 | pt = m_grid->ClientToScreen(wxPoint(5, m_grid->GetColLabelSize() + | |
361 | m_grid->GetRowSize(0))); | |
362 | ||
363 | sim.MouseDragDrop(pt.x, pt.y, pt.x, pt.y + 50); | |
364 | wxYield(); | |
365 | ||
744d91d4 | 366 | CPPUNIT_ASSERT_EQUAL(1, rowsize.GetCount()); |
232fdc63 VZ |
367 | #endif |
368 | } | |
369 | ||
370 | void GridTestCase::RangeSelect() | |
371 | { | |
372 | #if wxUSE_UIACTIONSIMULATOR | |
744d91d4 | 373 | EventCounter select(m_grid, wxEVT_GRID_RANGE_SELECT); |
232fdc63 VZ |
374 | |
375 | wxUIActionSimulator sim; | |
376 | ||
377 | //We add the extra 10 to ensure that we are inside the cell | |
378 | wxPoint pt = m_grid->ClientToScreen(wxPoint(m_grid->GetRowLabelSize() + 10, | |
379 | m_grid->GetColLabelSize() + 10) | |
380 | ); | |
381 | ||
382 | sim.MouseMove(pt); | |
383 | wxYield(); | |
384 | ||
385 | sim.MouseDown(); | |
386 | wxYield(); | |
387 | ||
388 | sim.MouseMove(pt.x + 50, pt.y + 50); | |
389 | wxYield(); | |
390 | ||
391 | sim.MouseUp(); | |
392 | wxYield(); | |
393 | ||
744d91d4 | 394 | CPPUNIT_ASSERT_EQUAL(1, select.GetCount()); |
232fdc63 VZ |
395 | #endif |
396 | } | |
397 | ||
398 | void GridTestCase::Cursor() | |
399 | { | |
400 | m_grid->SetGridCursor(1, 1); | |
401 | ||
402 | CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol()); | |
403 | CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorRow()); | |
404 | ||
405 | m_grid->MoveCursorDown(false); | |
406 | m_grid->MoveCursorLeft(false); | |
407 | m_grid->MoveCursorUp(false); | |
408 | m_grid->MoveCursorUp(false); | |
409 | m_grid->MoveCursorRight(false); | |
410 | ||
411 | CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol()); | |
412 | CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorRow()); | |
413 | ||
414 | m_grid->SetCellValue(0, 0, "some text"); | |
415 | m_grid->SetCellValue(3, 0, "other text"); | |
416 | m_grid->SetCellValue(0, 1, "more text"); | |
417 | m_grid->SetCellValue(3, 1, "extra text"); | |
418 | ||
419 | m_grid->Update(); | |
420 | m_grid->Refresh(); | |
421 | ||
422 | m_grid->MoveCursorLeftBlock(false); | |
423 | ||
424 | CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorCol()); | |
425 | CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorRow()); | |
426 | ||
427 | m_grid->MoveCursorDownBlock(false); | |
428 | ||
429 | CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorCol()); | |
430 | CPPUNIT_ASSERT_EQUAL(3, m_grid->GetGridCursorRow()); | |
431 | ||
432 | m_grid->MoveCursorRightBlock(false); | |
433 | ||
434 | CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol()); | |
435 | CPPUNIT_ASSERT_EQUAL(3, m_grid->GetGridCursorRow()); | |
436 | ||
437 | m_grid->MoveCursorUpBlock(false); | |
438 | ||
439 | CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol()); | |
440 | CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorRow()); | |
441 | } | |
442 | ||
443 | void GridTestCase::Selection() | |
444 | { | |
445 | m_grid->SelectAll(); | |
446 | ||
447 | CPPUNIT_ASSERT(m_grid->IsSelection()); | |
448 | CPPUNIT_ASSERT(m_grid->IsInSelection(0, 0)); | |
449 | CPPUNIT_ASSERT(m_grid->IsInSelection(9, 1)); | |
450 | ||
451 | m_grid->SelectBlock(1, 0, 3, 1); | |
452 | ||
453 | wxGridCellCoordsArray topleft = m_grid->GetSelectionBlockTopLeft(); | |
454 | wxGridCellCoordsArray bottomright = m_grid->GetSelectionBlockBottomRight(); | |
455 | ||
456 | CPPUNIT_ASSERT_EQUAL(1, topleft.Count()); | |
457 | CPPUNIT_ASSERT_EQUAL(1, bottomright.Count()); | |
458 | ||
459 | CPPUNIT_ASSERT_EQUAL(0, topleft.Item(0).GetCol()); | |
460 | CPPUNIT_ASSERT_EQUAL(1, topleft.Item(0).GetRow()); | |
461 | CPPUNIT_ASSERT_EQUAL(1, bottomright.Item(0).GetCol()); | |
462 | CPPUNIT_ASSERT_EQUAL(3, bottomright.Item(0).GetRow()); | |
463 | ||
464 | m_grid->SelectCol(1); | |
465 | ||
466 | CPPUNIT_ASSERT(m_grid->IsInSelection(0, 1)); | |
467 | CPPUNIT_ASSERT(m_grid->IsInSelection(9, 1)); | |
468 | CPPUNIT_ASSERT(!m_grid->IsInSelection(3, 0)); | |
469 | ||
470 | m_grid->SelectRow(4); | |
471 | ||
472 | CPPUNIT_ASSERT(m_grid->IsInSelection(4, 0)); | |
473 | CPPUNIT_ASSERT(m_grid->IsInSelection(4, 1)); | |
474 | CPPUNIT_ASSERT(!m_grid->IsInSelection(3, 0)); | |
475 | } | |
476 | ||
477 | void GridTestCase::AddRowCol() | |
478 | { | |
479 | CPPUNIT_ASSERT_EQUAL(10, m_grid->GetNumberRows()); | |
480 | CPPUNIT_ASSERT_EQUAL(2, m_grid->GetNumberCols()); | |
481 | ||
482 | m_grid->AppendCols(); | |
483 | m_grid->AppendRows(); | |
484 | ||
485 | CPPUNIT_ASSERT_EQUAL(11, m_grid->GetNumberRows()); | |
486 | CPPUNIT_ASSERT_EQUAL(3, m_grid->GetNumberCols()); | |
487 | ||
488 | m_grid->AppendCols(2); | |
489 | m_grid->AppendRows(2); | |
490 | ||
491 | CPPUNIT_ASSERT_EQUAL(13, m_grid->GetNumberRows()); | |
492 | CPPUNIT_ASSERT_EQUAL(5, m_grid->GetNumberCols()); | |
493 | ||
494 | m_grid->InsertCols(1, 2); | |
495 | m_grid->InsertRows(2, 3); | |
496 | ||
497 | CPPUNIT_ASSERT_EQUAL(16, m_grid->GetNumberRows()); | |
498 | CPPUNIT_ASSERT_EQUAL(7, m_grid->GetNumberCols()); | |
499 | } | |
500 | ||
501 | void GridTestCase::ColumnOrder() | |
502 | { | |
503 | m_grid->AppendCols(2); | |
504 | ||
505 | CPPUNIT_ASSERT_EQUAL(4, m_grid->GetNumberCols()); | |
506 | ||
507 | wxArrayInt neworder; | |
508 | neworder.push_back(1); | |
509 | neworder.push_back(3); | |
510 | neworder.push_back(2); | |
511 | neworder.push_back(0); | |
512 | ||
513 | m_grid->SetColumnsOrder(neworder); | |
514 | ||
515 | CPPUNIT_ASSERT_EQUAL(0, m_grid->GetColPos(1)); | |
516 | CPPUNIT_ASSERT_EQUAL(1, m_grid->GetColPos(3)); | |
517 | CPPUNIT_ASSERT_EQUAL(2, m_grid->GetColPos(2)); | |
518 | CPPUNIT_ASSERT_EQUAL(3, m_grid->GetColPos(0)); | |
519 | ||
520 | CPPUNIT_ASSERT_EQUAL(1, m_grid->GetColAt(0)); | |
521 | CPPUNIT_ASSERT_EQUAL(3, m_grid->GetColAt(1)); | |
522 | CPPUNIT_ASSERT_EQUAL(2, m_grid->GetColAt(2)); | |
523 | CPPUNIT_ASSERT_EQUAL(0, m_grid->GetColAt(3)); | |
524 | ||
525 | m_grid->ResetColPos(); | |
526 | ||
527 | CPPUNIT_ASSERT_EQUAL(0, m_grid->GetColPos(0)); | |
528 | CPPUNIT_ASSERT_EQUAL(1, m_grid->GetColPos(1)); | |
529 | CPPUNIT_ASSERT_EQUAL(2, m_grid->GetColPos(2)); | |
530 | CPPUNIT_ASSERT_EQUAL(3, m_grid->GetColPos(3)); | |
531 | } | |
532 | ||
d929eddf VZ |
533 | void GridTestCase::ColumnVisibility() |
534 | { | |
535 | m_grid->AppendCols(3); | |
536 | CPPUNIT_ASSERT( m_grid->IsColShown(1) ); | |
537 | ||
538 | m_grid->HideCol(1); | |
539 | CPPUNIT_ASSERT( !m_grid->IsColShown(1) ); | |
540 | CPPUNIT_ASSERT( m_grid->IsColShown(2) ); | |
541 | ||
542 | m_grid->ShowCol(1); | |
543 | CPPUNIT_ASSERT( m_grid->IsColShown(1) ); | |
544 | } | |
545 | ||
232fdc63 VZ |
546 | void GridTestCase::LineFormatting() |
547 | { | |
548 | CPPUNIT_ASSERT(m_grid->GridLinesEnabled()); | |
549 | ||
550 | m_grid->EnableGridLines(false); | |
551 | ||
552 | CPPUNIT_ASSERT(!m_grid->GridLinesEnabled()); | |
553 | ||
554 | m_grid->EnableGridLines(); | |
555 | ||
556 | m_grid->SetGridLineColour(*wxRED); | |
557 | ||
558 | CPPUNIT_ASSERT_EQUAL(m_grid->GetGridLineColour(), *wxRED); | |
559 | } | |
560 | ||
561 | void GridTestCase::SortSupport() | |
562 | { | |
563 | CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, m_grid->GetSortingColumn()); | |
564 | ||
565 | m_grid->SetSortingColumn(1); | |
566 | ||
567 | CPPUNIT_ASSERT(!m_grid->IsSortingBy(0)); | |
568 | CPPUNIT_ASSERT(m_grid->IsSortingBy(1)); | |
569 | CPPUNIT_ASSERT(m_grid->IsSortOrderAscending()); | |
570 | ||
571 | m_grid->SetSortingColumn(0, false); | |
572 | ||
573 | CPPUNIT_ASSERT(m_grid->IsSortingBy(0)); | |
574 | CPPUNIT_ASSERT(!m_grid->IsSortingBy(1)); | |
575 | CPPUNIT_ASSERT(!m_grid->IsSortOrderAscending()); | |
576 | ||
577 | m_grid->UnsetSortingColumn(); | |
578 | ||
579 | CPPUNIT_ASSERT(!m_grid->IsSortingBy(0)); | |
580 | CPPUNIT_ASSERT(!m_grid->IsSortingBy(1)); | |
581 | } | |
582 | ||
583 | void GridTestCase::Labels() | |
584 | { | |
585 | CPPUNIT_ASSERT_EQUAL("A", m_grid->GetColLabelValue(0)); | |
586 | CPPUNIT_ASSERT_EQUAL("1", m_grid->GetRowLabelValue(0)); | |
587 | ||
588 | m_grid->SetColLabelValue(0, "Column 1"); | |
589 | m_grid->SetRowLabelValue(0, "Row 1"); | |
590 | ||
591 | CPPUNIT_ASSERT_EQUAL("Column 1", m_grid->GetColLabelValue(0)); | |
592 | CPPUNIT_ASSERT_EQUAL("Row 1", m_grid->GetRowLabelValue(0)); | |
593 | ||
594 | m_grid->SetLabelTextColour(*wxGREEN); | |
595 | m_grid->SetLabelBackgroundColour(*wxRED); | |
596 | ||
597 | CPPUNIT_ASSERT_EQUAL(*wxGREEN, m_grid->GetLabelTextColour()); | |
598 | CPPUNIT_ASSERT_EQUAL(*wxRED, m_grid->GetLabelBackgroundColour()); | |
599 | ||
600 | m_grid->SetColLabelTextOrientation(wxVERTICAL); | |
601 | ||
602 | CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxVERTICAL), | |
603 | static_cast<int>(m_grid->GetColLabelTextOrientation())); | |
604 | } | |
605 | ||
606 | void GridTestCase::SelectionMode() | |
607 | { | |
608 | //We already test this mode in Select | |
609 | CPPUNIT_ASSERT_EQUAL(wxGrid::wxGridSelectCells, | |
610 | m_grid->GetSelectionMode()); | |
611 | ||
612 | //Test row selection be selecting a single cell and checking the whole | |
613 | //row is selected | |
614 | m_grid->SetSelectionMode(wxGrid::wxGridSelectRows); | |
615 | m_grid->SelectBlock(3, 1, 3, 1); | |
616 | ||
e4aadc2f VZ |
617 | wxArrayInt selectedRows = m_grid->GetSelectedRows(); |
618 | CPPUNIT_ASSERT_EQUAL(1, selectedRows.Count()); | |
619 | CPPUNIT_ASSERT_EQUAL(3, selectedRows[0]); | |
232fdc63 VZ |
620 | |
621 | CPPUNIT_ASSERT_EQUAL(wxGrid::wxGridSelectRows, | |
622 | m_grid->GetSelectionMode()); | |
623 | ||
624 | ||
625 | //Test column selection be selecting a single cell and checking the whole | |
626 | //column is selected | |
627 | m_grid->SetSelectionMode(wxGrid::wxGridSelectColumns); | |
628 | m_grid->SelectBlock(3, 1, 3, 1); | |
629 | ||
e4aadc2f VZ |
630 | wxArrayInt selectedCols = m_grid->GetSelectedCols(); |
631 | CPPUNIT_ASSERT_EQUAL(1, selectedCols.Count()); | |
632 | CPPUNIT_ASSERT_EQUAL(1, selectedCols[0]); | |
232fdc63 VZ |
633 | |
634 | CPPUNIT_ASSERT_EQUAL(wxGrid::wxGridSelectColumns, | |
635 | m_grid->GetSelectionMode()); | |
636 | } | |
637 | ||
638 | void GridTestCase::CellFormatting() | |
639 | { | |
640 | //Check that initial alignment is default | |
641 | int horiz, cellhoriz, vert, cellvert; | |
642 | ||
643 | m_grid->GetDefaultCellAlignment(&horiz, &vert); | |
644 | m_grid->GetCellAlignment(0, 0, &cellhoriz, &cellvert); | |
645 | ||
646 | CPPUNIT_ASSERT_EQUAL(cellhoriz, horiz); | |
647 | CPPUNIT_ASSERT_EQUAL(cellvert, vert); | |
648 | ||
649 | //Check initial text colour and background colour are default | |
650 | wxColour text, back; | |
651 | ||
652 | back = m_grid->GetDefaultCellBackgroundColour(); | |
653 | ||
654 | CPPUNIT_ASSERT_EQUAL(back, m_grid->GetCellBackgroundColour(0, 0)); | |
655 | ||
656 | back = m_grid->GetDefaultCellTextColour(); | |
657 | ||
658 | CPPUNIT_ASSERT_EQUAL(back, m_grid->GetCellTextColour(0, 0)); | |
659 | ||
4a04898f VZ |
660 | #if WXWIN_COMPATIBILITY_2_8 |
661 | m_grid->SetCellAlignment(wxALIGN_CENTRE, 0, 0); | |
232fdc63 VZ |
662 | m_grid->GetCellAlignment(0, 0, &cellhoriz, &cellvert); |
663 | ||
664 | CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_CENTRE), cellhoriz); | |
665 | CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_CENTRE), cellvert); | |
4a04898f | 666 | #endif // WXWIN_COMPATIBILITY_2_8 |
232fdc63 VZ |
667 | |
668 | m_grid->SetCellAlignment(0, 0, wxALIGN_LEFT, wxALIGN_BOTTOM); | |
669 | m_grid->GetCellAlignment(0, 0, &cellhoriz, &cellvert); | |
670 | ||
671 | CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_LEFT), cellhoriz); | |
672 | CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_BOTTOM), cellvert); | |
673 | ||
4a04898f VZ |
674 | #if WXWIN_COMPATIBILITY_2_8 |
675 | m_grid->SetCellTextColour(*wxRED, 0, 0); | |
232fdc63 | 676 | CPPUNIT_ASSERT_EQUAL(*wxRED, m_grid->GetCellTextColour(0, 0)); |
4a04898f | 677 | #endif // WXWIN_COMPATIBILITY_2_8 |
232fdc63 VZ |
678 | |
679 | m_grid->SetCellTextColour(0, 0, *wxGREEN); | |
232fdc63 VZ |
680 | CPPUNIT_ASSERT_EQUAL(*wxGREEN, m_grid->GetCellTextColour(0, 0)); |
681 | } | |
682 | ||
683 | void GridTestCase::Editable() | |
684 | { | |
685 | #if wxUSE_UIACTIONSIMULATOR | |
232fdc63 | 686 | //As the grid is not editable we shouldn't create an editor |
744d91d4 | 687 | EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED); |
232fdc63 VZ |
688 | |
689 | wxUIActionSimulator sim; | |
690 | ||
691 | CPPUNIT_ASSERT(m_grid->IsEditable()); | |
692 | ||
693 | m_grid->EnableEditing(false); | |
694 | ||
695 | CPPUNIT_ASSERT(!m_grid->IsEditable()); | |
696 | ||
697 | m_grid->SetFocus(); | |
698 | m_grid->SetGridCursor(1, 1); | |
699 | m_grid->ShowCellEditControl(); | |
700 | ||
701 | sim.Text("abab"); | |
702 | wxYield(); | |
703 | ||
704 | sim.Char(WXK_RETURN); | |
705 | wxYield(); | |
706 | ||
744d91d4 | 707 | CPPUNIT_ASSERT_EQUAL(0, created.GetCount()); |
232fdc63 VZ |
708 | #endif |
709 | } | |
710 | ||
711 | void GridTestCase::ReadOnly() | |
712 | { | |
713 | #if wxUSE_UIACTIONSIMULATOR | |
232fdc63 | 714 | //As the cell is readonly we shouldn't create an editor |
744d91d4 | 715 | EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED); |
232fdc63 VZ |
716 | |
717 | wxUIActionSimulator sim; | |
718 | ||
719 | CPPUNIT_ASSERT(!m_grid->IsReadOnly(1, 1)); | |
720 | ||
721 | m_grid->SetReadOnly(1, 1); | |
722 | ||
723 | CPPUNIT_ASSERT(m_grid->IsReadOnly(1, 1)); | |
724 | ||
725 | m_grid->SetFocus(); | |
726 | m_grid->SetGridCursor(1, 1); | |
727 | ||
728 | CPPUNIT_ASSERT(m_grid->IsCurrentCellReadOnly()); | |
729 | ||
730 | m_grid->ShowCellEditControl(); | |
731 | ||
732 | sim.Text("abab"); | |
733 | wxYield(); | |
734 | ||
735 | sim.Char(WXK_RETURN); | |
736 | wxYield(); | |
737 | ||
744d91d4 | 738 | CPPUNIT_ASSERT_EQUAL(0, created.GetCount()); |
232fdc63 VZ |
739 | #endif |
740 | } | |
741 | ||
742 | #endif //wxUSE_GRID |