1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/listbasetest.cpp
3 // Purpose: Base class for wxListCtrl and wxListView tests
4 // Author: Steven Lamerton
5 // Created: 2010-07-20
6 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>,
7 // (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "testprec.h"
11
12 #if wxUSE_LISTCTRL
13
14
15 #ifndef WX_PRECOMP
16 #include "wx/app.h"
17 #endif // WX_PRECOMP
18
19 #include "wx/listctrl.h"
20 #include "listbasetest.h"
21 #include "testableframe.h"
22 #include "asserthelper.h"
23 #include "wx/uiaction.h"
24 #include "wx/imaglist.h"
25 #include "wx/artprov.h"
26 #include "wx/stopwatch.h"
27
ColumnsOrder()28 void ListBaseTestCase::ColumnsOrder()
29 {
30 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
31 wxListCtrl* const list = GetList();
32
33 int n;
34 wxListItem li;
35 li.SetMask(wxLIST_MASK_TEXT);
36
37 // first set up some columns
38 static const int NUM_COLS = 3;
39
40 list->InsertColumn(0, "Column 0");
41 list->InsertColumn(1, "Column 1");
42 list->InsertColumn(2, "Column 2");
43
44 // and a couple of test items too
45 list->InsertItem(0, "Item 0");
46 list->SetItem(0, 1, "first in first");
47
48 list->InsertItem(1, "Item 1");
49 list->SetItem(1, 2, "second in second");
50
51
52 // check that the order is natural in the beginning
53 const wxArrayInt orderOrig = list->GetColumnsOrder();
54 for ( n = 0; n < NUM_COLS; n++ )
55 CPPUNIT_ASSERT_EQUAL( n, orderOrig[n] );
56
57 // then rearrange them: using { 2, 0, 1 } order means that column 2 is
58 // shown first, then column 0 and finally column 1
59 wxArrayInt order(3);
60 order[0] = 2;
61 order[1] = 0;
62 order[2] = 1;
63 list->SetColumnsOrder(order);
64
65 // check that we get back the same order as we set
66 const wxArrayInt orderNew = list->GetColumnsOrder();
67 for ( n = 0; n < NUM_COLS; n++ )
68 CPPUNIT_ASSERT_EQUAL( order[n], orderNew[n] );
69
70 // and the order -> index mappings for individual columns
71 for ( n = 0; n < NUM_COLS; n++ )
72 CPPUNIT_ASSERT_EQUAL( order[n], list->GetColumnIndexFromOrder(n) );
73
74 // and also the reverse mapping
75 CPPUNIT_ASSERT_EQUAL( 1, list->GetColumnOrder(0) );
76 CPPUNIT_ASSERT_EQUAL( 2, list->GetColumnOrder(1) );
77 CPPUNIT_ASSERT_EQUAL( 0, list->GetColumnOrder(2) );
78
79
80 // finally check that accessors still use indices, not order
81 CPPUNIT_ASSERT( list->GetColumn(0, li) );
82 CPPUNIT_ASSERT_EQUAL( "Column 0", li.GetText() );
83
84 li.SetId(0);
85 li.SetColumn(1);
86 CPPUNIT_ASSERT( list->GetItem(li) );
87 CPPUNIT_ASSERT_EQUAL( "first in first", li.GetText() );
88
89 li.SetId(1);
90 li.SetColumn(2);
91 CPPUNIT_ASSERT( list->GetItem(li) );
92 CPPUNIT_ASSERT_EQUAL( "second in second", li.GetText() );
93 #endif // wxHAS_LISTCTRL_COLUMN_ORDER
94 }
95
96
97
ItemRect()98 void ListBaseTestCase::ItemRect()
99 {
100 wxListCtrl* const list = GetList();
101
102 // set up for the test
103 list->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT, 60);
104 list->InsertColumn(1, "Column 1", wxLIST_FORMAT_LEFT, 50);
105 list->InsertColumn(2, "Column 2", wxLIST_FORMAT_LEFT, 40);
106
107 list->InsertItem(0, "Item 0");
108 list->SetItem(0, 1, "first column");
109 list->SetItem(0, 1, "second column");
110
111 // do test
112 wxRect r;
113 WX_ASSERT_FAILS_WITH_ASSERT( list->GetItemRect(1, r) );
114 CPPUNIT_ASSERT( list->GetItemRect(0, r) );
115 CPPUNIT_ASSERT_EQUAL( 150, r.GetWidth() );
116
117 CPPUNIT_ASSERT( list->GetSubItemRect(0, 0, r) );
118 CPPUNIT_ASSERT_EQUAL( 60, r.GetWidth() );
119
120 CPPUNIT_ASSERT( list->GetSubItemRect(0, 1, r) );
121 CPPUNIT_ASSERT_EQUAL( 50, r.GetWidth() );
122
123 CPPUNIT_ASSERT( list->GetSubItemRect(0, 2, r) );
124 CPPUNIT_ASSERT_EQUAL( 40, r.GetWidth() );
125
126 WX_ASSERT_FAILS_WITH_ASSERT( list->GetSubItemRect(0, 3, r) );
127
128
129 // As we have a header, the top item shouldn't be at (0, 0), but somewhere
130 // below the header.
131 //
132 // Notice that we consider that the header can't be less than 10 pixels
133 // because we don't know its exact height.
134 CPPUNIT_ASSERT( list->GetItemRect(0, r) );
135 CPPUNIT_ASSERT( r.y >= 10 );
136
137 // However if we remove the header now, the item should be at (0, 0).
138 list->SetWindowStyle(wxLC_REPORT | wxLC_NO_HEADER);
139 CPPUNIT_ASSERT( list->GetItemRect(0, r) );
140 CPPUNIT_ASSERT_EQUAL( 0, r.y );
141 }
142
ItemText()143 void ListBaseTestCase::ItemText()
144 {
145 wxListCtrl* const list = GetList();
146
147 list->InsertColumn(0, "First");
148 list->InsertColumn(1, "Second");
149
150 list->InsertItem(0, "0,0");
151 CPPUNIT_ASSERT_EQUAL( "0,0", list->GetItemText(0) );
152 CPPUNIT_ASSERT_EQUAL( "", list->GetItemText(0, 1) );
153
154 list->SetItem(0, 1, "0,1");
155 CPPUNIT_ASSERT_EQUAL( "0,1", list->GetItemText(0, 1) );
156 }
157
ChangeMode()158 void ListBaseTestCase::ChangeMode()
159 {
160 wxListCtrl* const list = GetList();
161
162 list->InsertColumn(0, "Header");
163 list->InsertItem(0, "First");
164 list->InsertItem(1, "Second");
165 CPPUNIT_ASSERT_EQUAL( 2, list->GetItemCount() );
166
167 // check that switching the mode preserves the items
168 list->SetWindowStyle(wxLC_ICON);
169 CPPUNIT_ASSERT_EQUAL( 2, list->GetItemCount() );
170 CPPUNIT_ASSERT_EQUAL( "First", list->GetItemText(0) );
171
172 // and so does switching back
173 list->SetWindowStyle(wxLC_REPORT);
174 CPPUNIT_ASSERT_EQUAL( 2, list->GetItemCount() );
175 CPPUNIT_ASSERT_EQUAL( "First", list->GetItemText(0) );
176 }
177
MultiSelect()178 void ListBaseTestCase::MultiSelect()
179 {
180 #if wxUSE_UIACTIONSIMULATOR
181
182 #ifndef __WXMSW__
183 // FIXME: This test fails on Travis CI although works fine on
184 // development machine, no idea why though!
185 if ( IsAutomaticTest() )
186 return;
187 #endif // !__WXMSW__
188
189 wxListCtrl* const list = GetList();
190
191 EventCounter focused(list, wxEVT_LIST_ITEM_FOCUSED);
192 EventCounter selected(list, wxEVT_LIST_ITEM_SELECTED);
193 EventCounter deselected(list, wxEVT_LIST_ITEM_DESELECTED);
194
195 list->InsertColumn(0, "Header");
196
197 for ( int i = 0; i < 10; ++i )
198 list->InsertItem(i, wxString::Format("Item %d", i));
199
200 wxUIActionSimulator sim;
201
202 wxRect pos;
203 list->GetItemRect(2, pos); // Choose the third item as anchor
204
205 // We move in slightly so we are not on the edge
206 wxPoint point = list->ClientToScreen(pos.GetPosition()) + wxPoint(10, 10);
207
208 sim.MouseMove(point);
209 wxYield();
210
211 sim.MouseClick(); // select the anchor
212 wxYield();
213
214 list->GetItemRect(5, pos);
215 point = list->ClientToScreen(pos.GetPosition()) + wxPoint(10, 10);
216
217 sim.MouseMove(point);
218 wxYield();
219
220 sim.KeyDown(WXK_SHIFT);
221 sim.MouseClick();
222 sim.KeyUp(WXK_SHIFT);
223 wxYield();
224
225 // when the first item was selected the focus changes to it, but not
226 // on subsequent clicks
227 CPPUNIT_ASSERT_EQUAL(4, list->GetSelectedItemCount()); // item 2 to 5 (inclusive) are selected
228 CPPUNIT_ASSERT_EQUAL(2, focused.GetCount()); // count the focus which was on the anchor
229 CPPUNIT_ASSERT_EQUAL(4, selected.GetCount());
230 CPPUNIT_ASSERT_EQUAL(0, deselected.GetCount());
231
232 focused.Clear();
233 selected.Clear();
234 deselected.Clear();
235
236 sim.Char(WXK_END, wxMOD_SHIFT); // extend the selection to the last item
237 wxYield();
238
239 CPPUNIT_ASSERT_EQUAL(8, list->GetSelectedItemCount()); // item 2 to 9 (inclusive) are selected
240 CPPUNIT_ASSERT_EQUAL(1, focused.GetCount()); // focus is on the last item
241 CPPUNIT_ASSERT_EQUAL(4, selected.GetCount()); // only newly selected items got the event
242 CPPUNIT_ASSERT_EQUAL(0, deselected.GetCount());
243
244 focused.Clear();
245 selected.Clear();
246 deselected.Clear();
247
248 sim.Char(WXK_HOME, wxMOD_SHIFT); // select from anchor to the first item
249 wxYield();
250
251 CPPUNIT_ASSERT_EQUAL(3, list->GetSelectedItemCount()); // item 0 to 2 (inclusive) are selected
252 CPPUNIT_ASSERT_EQUAL(1, focused.GetCount()); // focus is on item 0
253 CPPUNIT_ASSERT_EQUAL(2, selected.GetCount()); // events are only generated for item 0 and 1
254 CPPUNIT_ASSERT_EQUAL(7, deselected.GetCount()); // item 2 (exclusive) to 9 are deselected
255
256 focused.Clear();
257 selected.Clear();
258 deselected.Clear();
259
260 list->EnsureVisible(0);
261 wxYield();
262
263 list->GetItemRect(2, pos);
264 point = list->ClientToScreen(pos.GetPosition()) + wxPoint(10, 10);
265
266 sim.MouseMove(point);
267 wxYield();
268
269 sim.MouseClick();
270 wxYield();
271
272 CPPUNIT_ASSERT_EQUAL(1, list->GetSelectedItemCount()); // anchor is the only selected item
273 CPPUNIT_ASSERT_EQUAL(1, focused.GetCount()); // because the focus changed from item 0 to anchor
274 CPPUNIT_ASSERT_EQUAL(0, selected.GetCount()); // anchor is already in selection state
275 CPPUNIT_ASSERT_EQUAL(2, deselected.GetCount()); // items 0 and 1 are deselected
276 #endif // wxUSE_UIACTIONSIMULATOR
277 }
278
ItemClick()279 void ListBaseTestCase::ItemClick()
280 {
281 #if wxUSE_UIACTIONSIMULATOR
282
283 #ifdef __WXMSW__
284 // FIXME: This test fails on MSW buildbot slaves although works fine on
285 // development machine, no idea why. It seems to be a problem with
286 // wxUIActionSimulator rather the wxListCtrl control itself however.
287 if ( IsAutomaticTest() )
288 return;
289 #endif // __WXMSW__
290
291 wxListCtrl* const list = GetList();
292
293 list->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT, 60);
294 list->InsertColumn(1, "Column 1", wxLIST_FORMAT_LEFT, 50);
295 list->InsertColumn(2, "Column 2", wxLIST_FORMAT_LEFT, 40);
296
297 list->InsertItem(0, "Item 0");
298 list->SetItem(0, 1, "first column");
299 list->SetItem(0, 2, "second column");
300
301 EventCounter selected(list, wxEVT_LIST_ITEM_SELECTED);
302 EventCounter focused(list, wxEVT_LIST_ITEM_FOCUSED);
303 EventCounter activated(list, wxEVT_LIST_ITEM_ACTIVATED);
304 EventCounter rclick(list, wxEVT_LIST_ITEM_RIGHT_CLICK);
305 EventCounter deselected(list, wxEVT_LIST_ITEM_DESELECTED);
306
307 wxUIActionSimulator sim;
308
309 wxRect pos;
310 list->GetItemRect(0, pos);
311
312 //We move in slightly so we are not on the edge
313 wxPoint point = list->ClientToScreen(pos.GetPosition()) + wxPoint(10, 10);
314
315 sim.MouseMove(point);
316 wxYield();
317
318 sim.MouseClick();
319 wxYield();
320
321 sim.MouseDblClick();
322 wxYield();
323
324 sim.MouseClick(wxMOUSE_BTN_RIGHT);
325 wxYield();
326
327 // We want a point within the listctrl but below any items
328 point = list->ClientToScreen(pos.GetPosition()) + wxPoint(10, 50);
329
330 sim.MouseMove(point);
331 wxYield();
332
333 sim.MouseClick();
334 wxYield();
335
336 // when the first item was selected the focus changes to it, but not
337 // on subsequent clicks
338 CPPUNIT_ASSERT_EQUAL(1, focused.GetCount());
339 CPPUNIT_ASSERT_EQUAL(1, selected.GetCount());
340 CPPUNIT_ASSERT_EQUAL(1, deselected.GetCount());
341 CPPUNIT_ASSERT_EQUAL(1, activated.GetCount());
342 CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
343 #endif // wxUSE_UIACTIONSIMULATOR
344 }
345
KeyDown()346 void ListBaseTestCase::KeyDown()
347 {
348 #if wxUSE_UIACTIONSIMULATOR
349 wxListCtrl* const list = GetList();
350
351 EventCounter keydown(list, wxEVT_LIST_KEY_DOWN);
352
353 wxUIActionSimulator sim;
354
355 list->SetFocus();
356 wxYield();
357 sim.Text("aAbB"); // 4 letters + 2 shift mods.
358 wxYield();
359
360 CPPUNIT_ASSERT_EQUAL(6, keydown.GetCount());
361 #endif
362 }
363
DeleteItems()364 void ListBaseTestCase::DeleteItems()
365 {
366 #ifndef __WXOSX__
367 wxListCtrl* const list = GetList();
368
369 EventCounter deleteitem(list, wxEVT_LIST_DELETE_ITEM);
370 EventCounter deleteall(list, wxEVT_LIST_DELETE_ALL_ITEMS);
371
372
373 list->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT, 60);
374 list->InsertColumn(1, "Column 1", wxLIST_FORMAT_LEFT, 50);
375 list->InsertColumn(2, "Column 2", wxLIST_FORMAT_LEFT, 40);
376
377 list->InsertItem(0, "Item 0");
378 list->InsertItem(1, "Item 1");
379 list->InsertItem(2, "Item 1");
380
381 list->DeleteItem(0);
382 list->DeleteItem(0);
383 list->DeleteAllItems();
384
385 //Add some new items to tests ClearAll with
386 list->InsertColumn(0, "Column 0");
387 list->InsertItem(0, "Item 0");
388 list->InsertItem(1, "Item 1");
389
390 //Check that ClearAll actually sends a DELETE_ALL_ITEMS event
391 list->ClearAll();
392
393 //ClearAll and DeleteAllItems shouldn't send an event if there was nothing
394 //to clear
395 list->ClearAll();
396 list->DeleteAllItems();
397
398 CPPUNIT_ASSERT_EQUAL(2, deleteitem.GetCount());
399 CPPUNIT_ASSERT_EQUAL(2, deleteall.GetCount());
400 #endif
401 }
402
InsertItem()403 void ListBaseTestCase::InsertItem()
404 {
405 wxListCtrl* const list = GetList();
406
407 EventCounter insert(list, wxEVT_LIST_INSERT_ITEM);
408
409 list->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT, 60);
410
411 wxListItem item;
412 item.SetId(0);
413 item.SetText("some text");
414
415 list->InsertItem(item);
416 list->InsertItem(1, "more text");
417
418 CPPUNIT_ASSERT_EQUAL(2, insert.GetCount());
419 }
420
Find()421 void ListBaseTestCase::Find()
422 {
423 wxListCtrl* const list = GetList();
424
425 // set up for the test
426 list->InsertColumn(0, "Column 0");
427 list->InsertColumn(1, "Column 1");
428
429 list->InsertItem(0, "Item 0");
430 list->SetItem(0, 1, "first column");
431
432 list->InsertItem(1, "Item 1");
433 list->SetItem(1, 1, "first column");
434
435 list->InsertItem(2, "Item 40");
436 list->SetItem(2, 1, "first column");
437
438 list->InsertItem(3, "ITEM 01");
439 list->SetItem(3, 1, "first column");
440
441 CPPUNIT_ASSERT_EQUAL(1, list->FindItem(-1, "Item 1"));
442 CPPUNIT_ASSERT_EQUAL(2, list->FindItem(-1, "Item 4", true));
443 CPPUNIT_ASSERT_EQUAL(2, list->FindItem(1, "Item 40"));
444 CPPUNIT_ASSERT_EQUAL(3, list->FindItem(2, "Item 0", true));
445 }
446
Visible()447 void ListBaseTestCase::Visible()
448 {
449 wxListCtrl* const list = GetList();
450
451 list->InsertColumn(0, "Column 0");
452
453 int count = list->GetCountPerPage();
454
455 for( int i = 0; i < count + 10; i++ )
456 {
457 list->InsertItem(i, wxString::Format("string %d", i));
458 }
459
460 CPPUNIT_ASSERT_EQUAL(count + 10, list->GetItemCount());
461 CPPUNIT_ASSERT_EQUAL(0, list->GetTopItem());
462
463 list->EnsureVisible(count + 9);
464
465 CPPUNIT_ASSERT(list->GetTopItem() != 0);
466 }
467
ItemFormatting()468 void ListBaseTestCase::ItemFormatting()
469 {
470 wxListCtrl* const list = GetList();
471
472 list->InsertColumn(0, "Column 0");
473
474 list->InsertItem(0, "Item 0");
475 list->InsertItem(1, "Item 1");
476 list->InsertItem(2, "Item 2");
477
478 list->SetTextColour(*wxYELLOW);
479 list->SetBackgroundColour(*wxGREEN);
480 list->SetItemTextColour(0, *wxRED);
481 list->SetItemBackgroundColour(1, *wxBLUE);
482
483 CPPUNIT_ASSERT_EQUAL(*wxGREEN, list->GetBackgroundColour());
484 CPPUNIT_ASSERT_EQUAL(*wxBLUE,list->GetItemBackgroundColour(1));
485
486 CPPUNIT_ASSERT_EQUAL(*wxYELLOW, list->GetTextColour());
487 CPPUNIT_ASSERT_EQUAL(*wxRED, list->GetItemTextColour(0));
488 }
489
EditLabel()490 void ListBaseTestCase::EditLabel()
491 {
492 #if wxUSE_UIACTIONSIMULATOR
493 wxListCtrl* const list = GetList();
494
495 list->SetWindowStyleFlag(wxLC_REPORT | wxLC_EDIT_LABELS);
496
497 list->InsertColumn(0, "Column 0");
498
499 list->InsertItem(0, "Item 0");
500 list->InsertItem(1, "Item 1");
501
502 EventCounter beginedit(list, wxEVT_LIST_BEGIN_LABEL_EDIT);
503 EventCounter endedit(list, wxEVT_LIST_END_LABEL_EDIT);
504
505 wxUIActionSimulator sim;
506
507 list->EditLabel(0);
508 wxYield();
509
510 sim.Text("sometext");
511 wxYield();
512
513 sim.Char(WXK_RETURN);
514
515 wxYield();
516
517 CPPUNIT_ASSERT_EQUAL(1, beginedit.GetCount());
518 CPPUNIT_ASSERT_EQUAL(1, endedit.GetCount());
519 #endif
520 }
521
ImageList()522 void ListBaseTestCase::ImageList()
523 {
524 wxListCtrl* const list = GetList();
525
526 wxSize size(32, 32);
527
528 wxImageList* imglist = new wxImageList(size.x, size.y);
529 imglist->Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, size));
530 imglist->Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, size));
531 imglist->Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, size));
532
533 list->AssignImageList(imglist, wxIMAGE_LIST_NORMAL);
534
535 CPPUNIT_ASSERT_EQUAL(imglist, list->GetImageList(wxIMAGE_LIST_NORMAL));
536 }
537
HitTest()538 void ListBaseTestCase::HitTest()
539 {
540 #ifdef __WXMSW__ // ..until proven to work with other platforms
541 wxListCtrl* const list = GetList();
542 list->SetWindowStyle(wxLC_REPORT);
543
544 // set small image list
545 wxSize size(16, 16);
546 wxImageList* m_imglistSmall = new wxImageList(size.x, size.y);
547 m_imglistSmall->Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_LIST, size));
548 list->AssignImageList(m_imglistSmall, wxIMAGE_LIST_SMALL);
549
550 // insert 2 columns
551 list->InsertColumn(0, "Column 0");
552 list->InsertColumn(1, "Column 1");
553
554 // and a couple of test items too
555 list->InsertItem(0, "Item 0", 0);
556 list->SetItem(0, 1, "0, 1");
557
558 list->InsertItem(1, "Item 1", 0);
559
560 // enable checkboxes to test state icon
561 list->EnableCheckBoxes();
562
563 // get coordinates
564 wxRect rectSubItem0, rectIcon;
565 list->GetSubItemRect(0, 0, rectSubItem0); // column 0
566 list->GetItemRect(0, rectIcon, wxLIST_RECT_ICON); // icon
567 int y = rectSubItem0.GetTop() + (rectSubItem0.GetBottom() -
568 rectSubItem0.GetTop()) / 2;
569 int flags = 0;
570
571 // state icon (checkbox)
572 int xCheckBox = rectSubItem0.GetLeft() + (rectIcon.GetLeft() -
573 rectSubItem0.GetLeft()) / 2;
574 list->HitTest(wxPoint(xCheckBox, y), flags);
575 CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected wxLIST_HITTEST_ONITEMSTATEICON",
576 wxLIST_HITTEST_ONITEMSTATEICON, flags);
577
578 // icon
579 int xIcon = rectIcon.GetLeft() + (rectIcon.GetRight() - rectIcon.GetLeft()) / 2;
580 list->HitTest(wxPoint(xIcon, y), flags);
581 CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected wxLIST_HITTEST_ONITEMICON",
582 wxLIST_HITTEST_ONITEMICON, flags);
583
584 // label, beyond column 0
585 wxRect rectItem;
586 list->GetItemRect(0, rectItem); // entire item
587 int xHit = rectSubItem0.GetRight() + (rectItem.GetRight() - rectSubItem0.GetRight()) / 2;
588 list->HitTest(wxPoint(xHit, y), flags);
589 CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected wxLIST_HITTEST_ONITEMLABEL",
590 wxLIST_HITTEST_ONITEMLABEL, flags);
591 #endif // __WXMSW__
592 }
593
594 namespace
595 {
596 //From the sample but fixed so it actually inverts
597 int wxCALLBACK
MyCompareFunction(wxIntPtr item1,wxIntPtr item2,wxIntPtr WXUNUSED (sortData))598 MyCompareFunction(wxIntPtr item1, wxIntPtr item2, wxIntPtr WXUNUSED(sortData))
599 {
600 // inverse the order
601 if (item1 < item2)
602 return 1;
603 if (item1 > item2)
604 return -1;
605
606 return 0;
607 }
608
609 }
610
Sort()611 void ListBaseTestCase::Sort()
612 {
613 wxListCtrl* const list = GetList();
614
615 list->InsertColumn(0, "Column 0");
616
617 list->InsertItem(0, "Item 0");
618 list->SetItemData(0, 0);
619 list->InsertItem(1, "Item 1");
620 list->SetItemData(1, 1);
621
622 list->SortItems(MyCompareFunction, 0);
623
624 CPPUNIT_ASSERT_EQUAL("Item 1", list->GetItemText(0));
625 CPPUNIT_ASSERT_EQUAL("Item 0", list->GetItemText(1));
626 }
627
628 #endif //wxUSE_LISTCTRL
629