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