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