]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/gridtest.cpp
Fix VC++ warnings about __has_include().
[wxWidgets.git] / tests / controls / gridtest.cpp
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 // TODO on OSX when running the grid test suite solo this works
157 // but not when running it together with other tests
158 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXOSX__)
159 EventCounter changing(m_grid, wxEVT_GRID_CELL_CHANGING);
160 EventCounter changed(m_grid, wxEVT_GRID_CELL_CHANGED);
161 EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED);
162
163 wxUIActionSimulator sim;
164
165 m_grid->SetFocus();
166 m_grid->SetGridCursor(1, 1);
167 m_grid->ShowCellEditControl();
168
169 sim.Text("abab");
170 sim.Char(WXK_RETURN);
171
172 wxYield();
173
174 CPPUNIT_ASSERT_EQUAL(1, created.GetCount());
175 CPPUNIT_ASSERT_EQUAL(1, changing.GetCount());
176 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
177 #endif
178 }
179
180 void GridTestCase::CellClick()
181 {
182 #if wxUSE_UIACTIONSIMULATOR
183 EventCounter lclick(m_grid, wxEVT_GRID_CELL_LEFT_CLICK);
184 EventCounter ldclick(m_grid, wxEVT_GRID_CELL_LEFT_DCLICK);
185 EventCounter rclick(m_grid, wxEVT_GRID_CELL_RIGHT_CLICK);
186 EventCounter rdclick(m_grid, wxEVT_GRID_CELL_RIGHT_DCLICK);
187
188
189 wxUIActionSimulator sim;
190
191 wxRect rect = m_grid->CellToRect(0, 0);
192 wxPoint point = m_grid->CalcScrolledPosition(rect.GetPosition());
193 point = m_grid->ClientToScreen(point + wxPoint(m_grid->GetRowLabelSize(),
194 m_grid->GetColLabelSize())
195 + wxPoint(2, 2));
196
197 sim.MouseMove(point);
198 wxYield();
199
200 sim.MouseClick();
201 wxYield();
202
203 CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount());
204 lclick.Clear();
205
206 sim.MouseDblClick();
207 wxYield();
208
209 //A double click event sends a single click event first
210 //test to ensure this still happens in the future
211 CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount());
212 CPPUNIT_ASSERT_EQUAL(1, ldclick.GetCount());
213
214 sim.MouseClick(wxMOUSE_BTN_RIGHT);
215 wxYield();
216
217 CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
218 rclick.Clear();
219
220 sim.MouseDblClick(wxMOUSE_BTN_RIGHT);
221 wxYield();
222
223 CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
224 CPPUNIT_ASSERT_EQUAL(1, rdclick.GetCount());
225 #endif
226 }
227
228 void GridTestCase::CellSelect()
229 {
230 #if wxUSE_UIACTIONSIMULATOR
231 EventCounter cell(m_grid, wxEVT_GRID_SELECT_CELL);
232
233 wxUIActionSimulator sim;
234
235 wxRect rect = m_grid->CellToRect(0, 0);
236 wxPoint point = m_grid->CalcScrolledPosition(rect.GetPosition());
237 point = m_grid->ClientToScreen(point + wxPoint(m_grid->GetRowLabelSize(),
238 m_grid->GetColLabelSize())
239 + wxPoint(4, 4));
240
241 sim.MouseMove(point);
242 wxYield();
243
244 sim.MouseClick();
245 wxYield();
246
247 CPPUNIT_ASSERT_EQUAL(1, cell.GetCount());
248
249 cell.Clear();
250
251 m_grid->SetGridCursor(1, 1);
252 m_grid->GoToCell(1, 0);
253
254 sim.MouseMove(point);
255 wxYield();
256
257 sim.MouseDblClick();
258 wxYield();
259
260 CPPUNIT_ASSERT_EQUAL(3, cell.GetCount());
261 #endif
262 }
263
264 void GridTestCase::LabelClick()
265 {
266 #if wxUSE_UIACTIONSIMULATOR
267 EventCounter lclick(m_grid, wxEVT_GRID_LABEL_LEFT_CLICK);
268 EventCounter ldclick(m_grid, wxEVT_GRID_LABEL_LEFT_DCLICK);
269 EventCounter rclick(m_grid, wxEVT_GRID_LABEL_RIGHT_CLICK);
270 EventCounter rdclick(m_grid, wxEVT_GRID_LABEL_RIGHT_DCLICK);
271
272 wxUIActionSimulator sim;
273
274 wxPoint pos(m_grid->GetRowLabelSize() + 2, 2);
275 pos = m_grid->ClientToScreen(pos);
276
277 sim.MouseMove(pos);
278 wxYield();
279
280 sim.MouseClick();
281 wxYield();
282
283 CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount());
284
285 sim.MouseDblClick();
286 wxYield();
287
288 CPPUNIT_ASSERT_EQUAL(1, ldclick.GetCount());
289
290 sim.MouseClick(wxMOUSE_BTN_RIGHT);
291 wxYield();
292
293 CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
294 rclick.Clear();
295
296 sim.MouseDblClick(wxMOUSE_BTN_RIGHT);
297 wxYield();
298
299 if( ms_nativeheader )
300 {
301 //Right double click not supported with native headers so we get two
302 //right click events
303 CPPUNIT_ASSERT_EQUAL(2, rclick.GetCount());
304 }
305 else
306 {
307 CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
308 CPPUNIT_ASSERT_EQUAL(1, rdclick.GetCount());
309 }
310 #endif
311 }
312
313 void GridTestCase::SortClick()
314 {
315 #if wxUSE_UIACTIONSIMULATOR
316 m_grid->SetSortingColumn(0);
317
318 EventCounter sort(m_grid, wxEVT_GRID_COL_SORT);
319
320 wxUIActionSimulator sim;
321
322 wxPoint pos(m_grid->GetRowLabelSize() + 4, 4);
323 pos = m_grid->ClientToScreen(pos);
324
325 sim.MouseMove(pos);
326 wxYield();
327
328 sim.MouseClick();
329 wxYield();
330
331 CPPUNIT_ASSERT_EQUAL(1, sort.GetCount());
332 #endif
333 }
334
335 void GridTestCase::Size()
336 {
337 // TODO on OSX resizing interactively works, but not automated
338 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__) && !defined(__WXOSX__)
339 EventCounter colsize(m_grid, wxEVT_GRID_COL_SIZE);
340 EventCounter rowsize(m_grid, wxEVT_GRID_ROW_SIZE);
341
342 wxUIActionSimulator sim;
343
344 wxPoint pt = m_grid->ClientToScreen(wxPoint(m_grid->GetRowLabelSize() +
345 m_grid->GetColSize(0), 5));
346
347 sim.MouseMove(pt);
348 wxYield();
349
350 sim.MouseDown();
351 wxYield();
352
353 sim.MouseMove(pt.x + 50, pt.y);
354 wxYield();
355
356 sim.MouseUp();
357 wxYield();
358
359 CPPUNIT_ASSERT_EQUAL(1, colsize.GetCount());
360
361 pt = m_grid->ClientToScreen(wxPoint(5, m_grid->GetColLabelSize() +
362 m_grid->GetRowSize(0)));
363
364 sim.MouseDragDrop(pt.x, pt.y, pt.x, pt.y + 50);
365 wxYield();
366
367 CPPUNIT_ASSERT_EQUAL(1, rowsize.GetCount());
368 #endif
369 }
370
371 void GridTestCase::RangeSelect()
372 {
373 #if wxUSE_UIACTIONSIMULATOR
374 EventCounter select(m_grid, wxEVT_GRID_RANGE_SELECT);
375
376 wxUIActionSimulator sim;
377
378 //We add the extra 10 to ensure that we are inside the cell
379 wxPoint pt = m_grid->ClientToScreen(wxPoint(m_grid->GetRowLabelSize() + 10,
380 m_grid->GetColLabelSize() + 10)
381 );
382
383 sim.MouseMove(pt);
384 wxYield();
385
386 sim.MouseDown();
387 wxYield();
388
389 sim.MouseMove(pt.x + 50, pt.y + 50);
390 wxYield();
391
392 sim.MouseUp();
393 wxYield();
394
395 CPPUNIT_ASSERT_EQUAL(1, select.GetCount());
396 #endif
397 }
398
399 void GridTestCase::Cursor()
400 {
401 m_grid->SetGridCursor(1, 1);
402
403 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol());
404 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorRow());
405
406 m_grid->MoveCursorDown(false);
407 m_grid->MoveCursorLeft(false);
408 m_grid->MoveCursorUp(false);
409 m_grid->MoveCursorUp(false);
410 m_grid->MoveCursorRight(false);
411
412 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol());
413 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorRow());
414
415 m_grid->SetCellValue(0, 0, "some text");
416 m_grid->SetCellValue(3, 0, "other text");
417 m_grid->SetCellValue(0, 1, "more text");
418 m_grid->SetCellValue(3, 1, "extra text");
419
420 m_grid->Update();
421 m_grid->Refresh();
422
423 m_grid->MoveCursorLeftBlock(false);
424
425 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorCol());
426 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorRow());
427
428 m_grid->MoveCursorDownBlock(false);
429
430 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorCol());
431 CPPUNIT_ASSERT_EQUAL(3, m_grid->GetGridCursorRow());
432
433 m_grid->MoveCursorRightBlock(false);
434
435 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol());
436 CPPUNIT_ASSERT_EQUAL(3, m_grid->GetGridCursorRow());
437
438 m_grid->MoveCursorUpBlock(false);
439
440 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol());
441 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorRow());
442 }
443
444 void GridTestCase::Selection()
445 {
446 m_grid->SelectAll();
447
448 CPPUNIT_ASSERT(m_grid->IsSelection());
449 CPPUNIT_ASSERT(m_grid->IsInSelection(0, 0));
450 CPPUNIT_ASSERT(m_grid->IsInSelection(9, 1));
451
452 m_grid->SelectBlock(1, 0, 3, 1);
453
454 wxGridCellCoordsArray topleft = m_grid->GetSelectionBlockTopLeft();
455 wxGridCellCoordsArray bottomright = m_grid->GetSelectionBlockBottomRight();
456
457 CPPUNIT_ASSERT_EQUAL(1, topleft.Count());
458 CPPUNIT_ASSERT_EQUAL(1, bottomright.Count());
459
460 CPPUNIT_ASSERT_EQUAL(0, topleft.Item(0).GetCol());
461 CPPUNIT_ASSERT_EQUAL(1, topleft.Item(0).GetRow());
462 CPPUNIT_ASSERT_EQUAL(1, bottomright.Item(0).GetCol());
463 CPPUNIT_ASSERT_EQUAL(3, bottomright.Item(0).GetRow());
464
465 m_grid->SelectCol(1);
466
467 CPPUNIT_ASSERT(m_grid->IsInSelection(0, 1));
468 CPPUNIT_ASSERT(m_grid->IsInSelection(9, 1));
469 CPPUNIT_ASSERT(!m_grid->IsInSelection(3, 0));
470
471 m_grid->SelectRow(4);
472
473 CPPUNIT_ASSERT(m_grid->IsInSelection(4, 0));
474 CPPUNIT_ASSERT(m_grid->IsInSelection(4, 1));
475 CPPUNIT_ASSERT(!m_grid->IsInSelection(3, 0));
476 }
477
478 void GridTestCase::AddRowCol()
479 {
480 CPPUNIT_ASSERT_EQUAL(10, m_grid->GetNumberRows());
481 CPPUNIT_ASSERT_EQUAL(2, m_grid->GetNumberCols());
482
483 m_grid->AppendCols();
484 m_grid->AppendRows();
485
486 CPPUNIT_ASSERT_EQUAL(11, m_grid->GetNumberRows());
487 CPPUNIT_ASSERT_EQUAL(3, m_grid->GetNumberCols());
488
489 m_grid->AppendCols(2);
490 m_grid->AppendRows(2);
491
492 CPPUNIT_ASSERT_EQUAL(13, m_grid->GetNumberRows());
493 CPPUNIT_ASSERT_EQUAL(5, m_grid->GetNumberCols());
494
495 m_grid->InsertCols(1, 2);
496 m_grid->InsertRows(2, 3);
497
498 CPPUNIT_ASSERT_EQUAL(16, m_grid->GetNumberRows());
499 CPPUNIT_ASSERT_EQUAL(7, m_grid->GetNumberCols());
500 }
501
502 void GridTestCase::ColumnOrder()
503 {
504 m_grid->AppendCols(2);
505
506 CPPUNIT_ASSERT_EQUAL(4, m_grid->GetNumberCols());
507
508 wxArrayInt neworder;
509 neworder.push_back(1);
510 neworder.push_back(3);
511 neworder.push_back(2);
512 neworder.push_back(0);
513
514 m_grid->SetColumnsOrder(neworder);
515
516 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetColPos(1));
517 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetColPos(3));
518 CPPUNIT_ASSERT_EQUAL(2, m_grid->GetColPos(2));
519 CPPUNIT_ASSERT_EQUAL(3, m_grid->GetColPos(0));
520
521 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetColAt(0));
522 CPPUNIT_ASSERT_EQUAL(3, m_grid->GetColAt(1));
523 CPPUNIT_ASSERT_EQUAL(2, m_grid->GetColAt(2));
524 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetColAt(3));
525
526 m_grid->ResetColPos();
527
528 CPPUNIT_ASSERT_EQUAL(0, m_grid->GetColPos(0));
529 CPPUNIT_ASSERT_EQUAL(1, m_grid->GetColPos(1));
530 CPPUNIT_ASSERT_EQUAL(2, m_grid->GetColPos(2));
531 CPPUNIT_ASSERT_EQUAL(3, m_grid->GetColPos(3));
532 }
533
534 void GridTestCase::ColumnVisibility()
535 {
536 m_grid->AppendCols(3);
537 CPPUNIT_ASSERT( m_grid->IsColShown(1) );
538
539 m_grid->HideCol(1);
540 CPPUNIT_ASSERT( !m_grid->IsColShown(1) );
541 CPPUNIT_ASSERT( m_grid->IsColShown(2) );
542
543 m_grid->ShowCol(1);
544 CPPUNIT_ASSERT( m_grid->IsColShown(1) );
545 }
546
547 void GridTestCase::LineFormatting()
548 {
549 CPPUNIT_ASSERT(m_grid->GridLinesEnabled());
550
551 m_grid->EnableGridLines(false);
552
553 CPPUNIT_ASSERT(!m_grid->GridLinesEnabled());
554
555 m_grid->EnableGridLines();
556
557 m_grid->SetGridLineColour(*wxRED);
558
559 CPPUNIT_ASSERT_EQUAL(m_grid->GetGridLineColour(), *wxRED);
560 }
561
562 void GridTestCase::SortSupport()
563 {
564 CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, m_grid->GetSortingColumn());
565
566 m_grid->SetSortingColumn(1);
567
568 CPPUNIT_ASSERT(!m_grid->IsSortingBy(0));
569 CPPUNIT_ASSERT(m_grid->IsSortingBy(1));
570 CPPUNIT_ASSERT(m_grid->IsSortOrderAscending());
571
572 m_grid->SetSortingColumn(0, false);
573
574 CPPUNIT_ASSERT(m_grid->IsSortingBy(0));
575 CPPUNIT_ASSERT(!m_grid->IsSortingBy(1));
576 CPPUNIT_ASSERT(!m_grid->IsSortOrderAscending());
577
578 m_grid->UnsetSortingColumn();
579
580 CPPUNIT_ASSERT(!m_grid->IsSortingBy(0));
581 CPPUNIT_ASSERT(!m_grid->IsSortingBy(1));
582 }
583
584 void GridTestCase::Labels()
585 {
586 CPPUNIT_ASSERT_EQUAL("A", m_grid->GetColLabelValue(0));
587 CPPUNIT_ASSERT_EQUAL("1", m_grid->GetRowLabelValue(0));
588
589 m_grid->SetColLabelValue(0, "Column 1");
590 m_grid->SetRowLabelValue(0, "Row 1");
591
592 CPPUNIT_ASSERT_EQUAL("Column 1", m_grid->GetColLabelValue(0));
593 CPPUNIT_ASSERT_EQUAL("Row 1", m_grid->GetRowLabelValue(0));
594
595 m_grid->SetLabelTextColour(*wxGREEN);
596 m_grid->SetLabelBackgroundColour(*wxRED);
597
598 CPPUNIT_ASSERT_EQUAL(*wxGREEN, m_grid->GetLabelTextColour());
599 CPPUNIT_ASSERT_EQUAL(*wxRED, m_grid->GetLabelBackgroundColour());
600
601 m_grid->SetColLabelTextOrientation(wxVERTICAL);
602
603 CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxVERTICAL),
604 static_cast<int>(m_grid->GetColLabelTextOrientation()));
605 }
606
607 void GridTestCase::SelectionMode()
608 {
609 //We already test this mode in Select
610 CPPUNIT_ASSERT_EQUAL(wxGrid::wxGridSelectCells,
611 m_grid->GetSelectionMode());
612
613 //Test row selection be selecting a single cell and checking the whole
614 //row is selected
615 m_grid->SetSelectionMode(wxGrid::wxGridSelectRows);
616 m_grid->SelectBlock(3, 1, 3, 1);
617
618 wxArrayInt selectedRows = m_grid->GetSelectedRows();
619 CPPUNIT_ASSERT_EQUAL(1, selectedRows.Count());
620 CPPUNIT_ASSERT_EQUAL(3, selectedRows[0]);
621
622 CPPUNIT_ASSERT_EQUAL(wxGrid::wxGridSelectRows,
623 m_grid->GetSelectionMode());
624
625
626 //Test column selection be selecting a single cell and checking the whole
627 //column is selected
628 m_grid->SetSelectionMode(wxGrid::wxGridSelectColumns);
629 m_grid->SelectBlock(3, 1, 3, 1);
630
631 wxArrayInt selectedCols = m_grid->GetSelectedCols();
632 CPPUNIT_ASSERT_EQUAL(1, selectedCols.Count());
633 CPPUNIT_ASSERT_EQUAL(1, selectedCols[0]);
634
635 CPPUNIT_ASSERT_EQUAL(wxGrid::wxGridSelectColumns,
636 m_grid->GetSelectionMode());
637 }
638
639 void GridTestCase::CellFormatting()
640 {
641 //Check that initial alignment is default
642 int horiz, cellhoriz, vert, cellvert;
643
644 m_grid->GetDefaultCellAlignment(&horiz, &vert);
645 m_grid->GetCellAlignment(0, 0, &cellhoriz, &cellvert);
646
647 CPPUNIT_ASSERT_EQUAL(cellhoriz, horiz);
648 CPPUNIT_ASSERT_EQUAL(cellvert, vert);
649
650 //Check initial text colour and background colour are default
651 wxColour text, back;
652
653 back = m_grid->GetDefaultCellBackgroundColour();
654
655 CPPUNIT_ASSERT_EQUAL(back, m_grid->GetCellBackgroundColour(0, 0));
656
657 back = m_grid->GetDefaultCellTextColour();
658
659 CPPUNIT_ASSERT_EQUAL(back, m_grid->GetCellTextColour(0, 0));
660
661 #if WXWIN_COMPATIBILITY_2_8
662 m_grid->SetCellAlignment(wxALIGN_CENTRE, 0, 0);
663 m_grid->GetCellAlignment(0, 0, &cellhoriz, &cellvert);
664
665 CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_CENTRE), cellhoriz);
666 CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_CENTRE), cellvert);
667 #endif // WXWIN_COMPATIBILITY_2_8
668
669 m_grid->SetCellAlignment(0, 0, wxALIGN_LEFT, wxALIGN_BOTTOM);
670 m_grid->GetCellAlignment(0, 0, &cellhoriz, &cellvert);
671
672 CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_LEFT), cellhoriz);
673 CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_BOTTOM), cellvert);
674
675 #if WXWIN_COMPATIBILITY_2_8
676 m_grid->SetCellTextColour(*wxRED, 0, 0);
677 CPPUNIT_ASSERT_EQUAL(*wxRED, m_grid->GetCellTextColour(0, 0));
678 #endif // WXWIN_COMPATIBILITY_2_8
679
680 m_grid->SetCellTextColour(0, 0, *wxGREEN);
681 CPPUNIT_ASSERT_EQUAL(*wxGREEN, m_grid->GetCellTextColour(0, 0));
682 }
683
684 void GridTestCase::Editable()
685 {
686 #if wxUSE_UIACTIONSIMULATOR
687 //As the grid is not editable we shouldn't create an editor
688 EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED);
689
690 wxUIActionSimulator sim;
691
692 CPPUNIT_ASSERT(m_grid->IsEditable());
693
694 m_grid->EnableEditing(false);
695
696 CPPUNIT_ASSERT(!m_grid->IsEditable());
697
698 m_grid->SetFocus();
699 m_grid->SetGridCursor(1, 1);
700 m_grid->ShowCellEditControl();
701
702 sim.Text("abab");
703 wxYield();
704
705 sim.Char(WXK_RETURN);
706 wxYield();
707
708 CPPUNIT_ASSERT_EQUAL(0, created.GetCount());
709 #endif
710 }
711
712 void GridTestCase::ReadOnly()
713 {
714 #if wxUSE_UIACTIONSIMULATOR
715 //As the cell is readonly we shouldn't create an editor
716 EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED);
717
718 wxUIActionSimulator sim;
719
720 CPPUNIT_ASSERT(!m_grid->IsReadOnly(1, 1));
721
722 m_grid->SetReadOnly(1, 1);
723
724 CPPUNIT_ASSERT(m_grid->IsReadOnly(1, 1));
725
726 m_grid->SetFocus();
727 m_grid->SetGridCursor(1, 1);
728
729 CPPUNIT_ASSERT(m_grid->IsCurrentCellReadOnly());
730
731 m_grid->ShowCellEditControl();
732
733 sim.Text("abab");
734 wxYield();
735
736 sim.Char(WXK_RETURN);
737 wxYield();
738
739 CPPUNIT_ASSERT_EQUAL(0, created.GetCount());
740 #endif
741 }
742
743 #endif //wxUSE_GRID