]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/gridtest.cpp
fixing typo
[wxWidgets.git] / tests / controls / gridtest.cpp
CommitLineData
232fdc63
VZ
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
784130d2
VZ
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
232fdc63
VZ
41class GridTestCase : public CppUnit::TestCase
42{
43public:
44 GridTestCase() { }
45
46 virtual void setUp();
47 virtual void tearDown();
48
49private:
50 CPPUNIT_TEST_SUITE( GridTestCase );
51 WXUISIM_TEST( CellEdit );
784130d2
VZ
52 NONGTK_TEST( CellClick );
53 NONGTK_TEST( CellSelect );
54 NONGTK_TEST( LabelClick );
55 NONGTK_TEST( SortClick );
232fdc63 56 WXUISIM_TEST( Size );
784130d2 57 NONGTK_TEST( RangeSelect );
232fdc63
VZ
58 CPPUNIT_TEST( Cursor );
59 CPPUNIT_TEST( Selection );
60 CPPUNIT_TEST( AddRowCol );
61 CPPUNIT_TEST( ColumnOrder );
d929eddf 62 CPPUNIT_TEST( ColumnVisibility );
232fdc63
VZ
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 );
784130d2
VZ
71 NONGTK_TEST( LabelClick );
72 NONGTK_TEST( SortClick );
232fdc63
VZ
73 CPPUNIT_TEST( ColumnOrder );
74 CPPUNIT_TEST( PseudoTest_NativeLabels );
784130d2
VZ
75 NONGTK_TEST( LabelClick );
76 NONGTK_TEST( SortClick );
232fdc63
VZ
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();
d929eddf 91 void ColumnVisibility();
232fdc63
VZ
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
112CPPUNIT_TEST_SUITE_REGISTRATION( GridTestCase );
113
e3778b4d 114// also include in its own registry so that these tests can be run alone
232fdc63
VZ
115CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( GridTestCase, "GridTestCase" );
116
117//initialise the static variable
118bool GridTestCase::ms_nativeheader = false;
119bool GridTestCase::ms_nativelabels = false;
120
121void 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
137void GridTestCase::tearDown()
138{
7c7bd972
VZ
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
232fdc63
VZ
151 wxDELETE(m_grid);
152}
153
154void GridTestCase::CellEdit()
155{
156#if wxUSE_UIACTIONSIMULATOR
744d91d4
SL
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);
232fdc63
VZ
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
744d91d4
SL
172 CPPUNIT_ASSERT_EQUAL(1, created.GetCount());
173 CPPUNIT_ASSERT_EQUAL(1, changing.GetCount());
174 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
232fdc63
VZ
175#endif
176}
177
178void GridTestCase::CellClick()
179{
180#if wxUSE_UIACTIONSIMULATOR
744d91d4
SL
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);
232fdc63
VZ
185
186
187 wxUIActionSimulator sim;
188
189 wxRect rect = m_grid->CellToRect(0, 0);
190 wxPoint point = m_grid->CalcScrolledPosition(rect.GetPosition());
744d91d4
SL
191 point = m_grid->ClientToScreen(point + wxPoint(m_grid->GetRowLabelSize(),
192 m_grid->GetColLabelSize())
193 + wxPoint(2, 2));
232fdc63
VZ
194
195 sim.MouseMove(point);
196 wxYield();
197
198 sim.MouseClick();
199 wxYield();
200
744d91d4
SL
201 CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount());
202 lclick.Clear();
232fdc63
VZ
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
744d91d4
SL
209 CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount());
210 CPPUNIT_ASSERT_EQUAL(1, ldclick.GetCount());
232fdc63
VZ
211
212 sim.MouseClick(wxMOUSE_BTN_RIGHT);
213 wxYield();
214
744d91d4
SL
215 CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
216 rclick.Clear();
232fdc63
VZ
217
218 sim.MouseDblClick(wxMOUSE_BTN_RIGHT);
219 wxYield();
220
744d91d4
SL
221 CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
222 CPPUNIT_ASSERT_EQUAL(1, rdclick.GetCount());
232fdc63
VZ
223#endif
224}
225
226void GridTestCase::CellSelect()
227{
228#if wxUSE_UIACTIONSIMULATOR
744d91d4 229 EventCounter cell(m_grid, wxEVT_GRID_SELECT_CELL);
232fdc63
VZ
230
231 wxUIActionSimulator sim;
232
233 wxRect rect = m_grid->CellToRect(0, 0);
234 wxPoint point = m_grid->CalcScrolledPosition(rect.GetPosition());
744d91d4
SL
235 point = m_grid->ClientToScreen(point + wxPoint(m_grid->GetRowLabelSize(),
236 m_grid->GetColLabelSize())
237 + wxPoint(4, 4));
232fdc63
VZ
238
239 sim.MouseMove(point);
240 wxYield();
241
242 sim.MouseClick();
243 wxYield();
244
744d91d4
SL
245 CPPUNIT_ASSERT_EQUAL(1, cell.GetCount());
246
247 cell.Clear();
232fdc63
VZ
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
744d91d4 258 CPPUNIT_ASSERT_EQUAL(3, cell.GetCount());
232fdc63
VZ
259#endif
260}
261
262void GridTestCase::LabelClick()
263{
da7ae357 264#if wxUSE_UIACTIONSIMULATOR
744d91d4
SL
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);
232fdc63
VZ
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
744d91d4 281 CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount());
232fdc63
VZ
282
283 sim.MouseDblClick();
284 wxYield();
285
744d91d4 286 CPPUNIT_ASSERT_EQUAL(1, ldclick.GetCount());
232fdc63
VZ
287
288 sim.MouseClick(wxMOUSE_BTN_RIGHT);
289 wxYield();
290
744d91d4
SL
291 CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
292 rclick.Clear();
232fdc63
VZ
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
744d91d4 301 CPPUNIT_ASSERT_EQUAL(2, rclick.GetCount());
232fdc63
VZ
302 }
303 else
304 {
744d91d4
SL
305 CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
306 CPPUNIT_ASSERT_EQUAL(1, rdclick.GetCount());
232fdc63
VZ
307 }
308#endif
309}
310
311void GridTestCase::SortClick()
312{
da7ae357 313#if wxUSE_UIACTIONSIMULATOR
232fdc63
VZ
314 m_grid->SetSortingColumn(0);
315
744d91d4 316 EventCounter sort(m_grid, wxEVT_GRID_COL_SORT);
232fdc63
VZ
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
744d91d4 329 CPPUNIT_ASSERT_EQUAL(1, sort.GetCount());
232fdc63
VZ
330#endif
331}
332
333void GridTestCase::Size()
334{
335#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
744d91d4
SL
336 EventCounter colsize(m_grid, wxEVT_GRID_COL_SIZE);
337 EventCounter rowsize(m_grid, wxEVT_GRID_ROW_SIZE);
232fdc63
VZ
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
744d91d4 356 CPPUNIT_ASSERT_EQUAL(1, colsize.GetCount());
232fdc63
VZ
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
744d91d4 364 CPPUNIT_ASSERT_EQUAL(1, rowsize.GetCount());
232fdc63
VZ
365#endif
366}
367
368void GridTestCase::RangeSelect()
369{
370#if wxUSE_UIACTIONSIMULATOR
744d91d4 371 EventCounter select(m_grid, wxEVT_GRID_RANGE_SELECT);
232fdc63
VZ
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
744d91d4 392 CPPUNIT_ASSERT_EQUAL(1, select.GetCount());
232fdc63
VZ
393#endif
394}
395
396void 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
441void 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
475void 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
499void 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
d929eddf
VZ
531void 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
232fdc63
VZ
544void 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
559void 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
581void 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
604void 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
e4aadc2f
VZ
615 wxArrayInt selectedRows = m_grid->GetSelectedRows();
616 CPPUNIT_ASSERT_EQUAL(1, selectedRows.Count());
617 CPPUNIT_ASSERT_EQUAL(3, selectedRows[0]);
232fdc63
VZ
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
e4aadc2f
VZ
628 wxArrayInt selectedCols = m_grid->GetSelectedCols();
629 CPPUNIT_ASSERT_EQUAL(1, selectedCols.Count());
630 CPPUNIT_ASSERT_EQUAL(1, selectedCols[0]);
232fdc63
VZ
631
632 CPPUNIT_ASSERT_EQUAL(wxGrid::wxGridSelectColumns,
633 m_grid->GetSelectionMode());
634}
635
636void 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
4a04898f
VZ
658#if WXWIN_COMPATIBILITY_2_8
659 m_grid->SetCellAlignment(wxALIGN_CENTRE, 0, 0);
232fdc63
VZ
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);
4a04898f 664#endif // WXWIN_COMPATIBILITY_2_8
232fdc63
VZ
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
4a04898f
VZ
672#if WXWIN_COMPATIBILITY_2_8
673 m_grid->SetCellTextColour(*wxRED, 0, 0);
232fdc63 674 CPPUNIT_ASSERT_EQUAL(*wxRED, m_grid->GetCellTextColour(0, 0));
4a04898f 675#endif // WXWIN_COMPATIBILITY_2_8
232fdc63
VZ
676
677 m_grid->SetCellTextColour(0, 0, *wxGREEN);
232fdc63
VZ
678 CPPUNIT_ASSERT_EQUAL(*wxGREEN, m_grid->GetCellTextColour(0, 0));
679}
680
681void GridTestCase::Editable()
682{
683#if wxUSE_UIACTIONSIMULATOR
232fdc63 684 //As the grid is not editable we shouldn't create an editor
744d91d4 685 EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED);
232fdc63
VZ
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
744d91d4 705 CPPUNIT_ASSERT_EQUAL(0, created.GetCount());
232fdc63
VZ
706#endif
707}
708
709void GridTestCase::ReadOnly()
710{
711#if wxUSE_UIACTIONSIMULATOR
232fdc63 712 //As the cell is readonly we shouldn't create an editor
744d91d4 713 EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED);
232fdc63
VZ
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
744d91d4 736 CPPUNIT_ASSERT_EQUAL(0, created.GetCount());
232fdc63
VZ
737#endif
738}
739
740#endif //wxUSE_GRID