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