]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/listviewtest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/listviewtest.cpp
3 // Purpose: wxListView unit test
4 // Author: Steven Lamerton
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
19 #include "wx/listctrl.h"
20 #include "listbasetest.h"
22 class ListViewTestCase
: public ListBaseTestCase
, public CppUnit::TestCase
25 ListViewTestCase() { }
28 virtual void tearDown();
30 virtual wxListCtrl
*GetList() const { return m_list
; }
33 CPPUNIT_TEST_SUITE( ListViewTestCase
);
35 CPPUNIT_TEST( Selection
);
36 CPPUNIT_TEST( Focus
);
37 CPPUNIT_TEST_SUITE_END();
44 DECLARE_NO_COPY_CLASS(ListViewTestCase
)
47 // register in the unnamed registry so that these tests are run by default
48 CPPUNIT_TEST_SUITE_REGISTRATION( ListViewTestCase
);
50 // also include in its own registry so that these tests can be run alone
51 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListViewTestCase
, "ListViewTestCase" );
53 void ListViewTestCase::setUp()
55 m_list
= new wxListView(wxTheApp
->GetTopWindow());
56 m_list
->SetWindowStyle(wxLC_REPORT
);
57 m_list
->SetSize(400, 200);
60 void ListViewTestCase::tearDown()
65 void ListViewTestCase::Selection()
67 m_list
->InsertColumn(0, "Column 0");
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");
78 CPPUNIT_ASSERT(m_list
->IsSelected(0));
79 CPPUNIT_ASSERT(!m_list
->IsSelected(1));
81 long sel
= m_list
->GetFirstSelected();
83 CPPUNIT_ASSERT_EQUAL(0, sel
);
85 sel
= m_list
->GetNextSelected(sel
);
87 CPPUNIT_ASSERT_EQUAL(2, sel
);
89 sel
= m_list
->GetNextSelected(sel
);
91 CPPUNIT_ASSERT_EQUAL(3, sel
);
93 sel
= m_list
->GetNextSelected(sel
);
95 CPPUNIT_ASSERT_EQUAL(-1, sel
);
97 m_list
->Select(0, false);
99 CPPUNIT_ASSERT(!m_list
->IsSelected(0));
100 CPPUNIT_ASSERT_EQUAL(2, m_list
->GetFirstSelected());
103 void ListViewTestCase::Focus()
105 m_list
->InsertColumn(0, "Column 0");
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");
112 CPPUNIT_ASSERT_EQUAL(-1, m_list
->GetFocusedItem());
116 CPPUNIT_ASSERT_EQUAL(0, m_list
->GetFocusedItem());