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