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