wxMessageBox off the main thread lost result code.
[wxWidgets.git] / tests / controls / listviewtest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/listviewtest.cpp
3 // Purpose: wxListView unit test
4 // Author: Steven Lamerton
5 // Created: 2010-07-10
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "testprec.h"
10
11 #ifdef __BORLANDC__
12 #pragma hdrstop
13 #endif
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
22 class ListViewTestCase : public ListBaseTestCase, public CppUnit::TestCase
23 {
24 public:
25 ListViewTestCase() { }
26
27 virtual void setUp();
28 virtual void tearDown();
29
30 virtual wxListCtrl *GetList() const { return m_list; }
31
32 private:
33 CPPUNIT_TEST_SUITE( ListViewTestCase );
34 wxLIST_BASE_TESTS();
35 CPPUNIT_TEST( Selection );
36 CPPUNIT_TEST( Focus );
37 CPPUNIT_TEST_SUITE_END();
38
39 void Selection();
40 void Focus();
41
42 wxListView *m_list;
43
44 DECLARE_NO_COPY_CLASS(ListViewTestCase)
45 };
46
47 // register in the unnamed registry so that these tests are run by default
48 CPPUNIT_TEST_SUITE_REGISTRATION( ListViewTestCase );
49
50 // also include in its own registry so that these tests can be run alone
51 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListViewTestCase, "ListViewTestCase" );
52
53 void ListViewTestCase::setUp()
54 {
55 m_list = new wxListView(wxTheApp->GetTopWindow());
56 m_list->SetWindowStyle(wxLC_REPORT);
57 m_list->SetSize(400, 200);
58 }
59
60 void ListViewTestCase::tearDown()
61 {
62 wxDELETE(m_list);
63 }
64
65 void ListViewTestCase::Selection()
66 {
67 m_list->InsertColumn(0, "Column 0");
68
69 m_list->InsertItem(0, "Item 0");
70 m_list->InsertItem(1, "Item 1");
71 m_list->InsertItem(2, "Item 2");
72 m_list->InsertItem(3, "Item 3");
73
74 m_list->Select(0);
75 m_list->Select(2);
76 m_list->Select(3);
77
78 CPPUNIT_ASSERT(m_list->IsSelected(0));
79 CPPUNIT_ASSERT(!m_list->IsSelected(1));
80
81 long sel = m_list->GetFirstSelected();
82
83 CPPUNIT_ASSERT_EQUAL(0, sel);
84
85 sel = m_list->GetNextSelected(sel);
86
87 CPPUNIT_ASSERT_EQUAL(2, sel);
88
89 sel = m_list->GetNextSelected(sel);
90
91 CPPUNIT_ASSERT_EQUAL(3, sel);
92
93 sel = m_list->GetNextSelected(sel);
94
95 CPPUNIT_ASSERT_EQUAL(-1, sel);
96
97 m_list->Select(0, false);
98
99 CPPUNIT_ASSERT(!m_list->IsSelected(0));
100 CPPUNIT_ASSERT_EQUAL(2, m_list->GetFirstSelected());
101 }
102
103 void ListViewTestCase::Focus()
104 {
105 m_list->InsertColumn(0, "Column 0");
106
107 m_list->InsertItem(0, "Item 0");
108 m_list->InsertItem(1, "Item 1");
109 m_list->InsertItem(2, "Item 2");
110 m_list->InsertItem(3, "Item 3");
111
112 CPPUNIT_ASSERT_EQUAL(-1, m_list->GetFocusedItem());
113
114 m_list->Focus(0);
115
116 CPPUNIT_ASSERT_EQUAL(0, m_list->GetFocusedItem());
117 }