]>
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
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
20 #include "wx/listctrl.h"
21 #include "listbasetest.h"
23 class ListViewTestCase
: public ListBaseTestCase
, public CppUnit::TestCase
26 ListViewTestCase() { }
29 virtual void tearDown();
31 virtual wxListCtrl
*GetList() const { return m_list
; }
34 CPPUNIT_TEST_SUITE( ListViewTestCase
);
36 CPPUNIT_TEST( Selection
);
37 CPPUNIT_TEST( Focus
);
38 CPPUNIT_TEST_SUITE_END();
45 DECLARE_NO_COPY_CLASS(ListViewTestCase
)
48 // register in the unnamed registry so that these tests are run by default
49 CPPUNIT_TEST_SUITE_REGISTRATION( ListViewTestCase
);
51 // also include in it's own registry so that these tests can be run alone
52 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListViewTestCase
, "ListViewTestCase" );
54 void ListViewTestCase::setUp()
56 m_list
= new wxListView(wxTheApp
->GetTopWindow());
57 m_list
->SetWindowStyle(wxLC_REPORT
);
58 m_list
->SetSize(400, 200);
61 void ListViewTestCase::tearDown()
66 void ListViewTestCase::Selection()
68 m_list
->InsertColumn(0, "Column 0");
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");
79 CPPUNIT_ASSERT(m_list
->IsSelected(0));
80 CPPUNIT_ASSERT(!m_list
->IsSelected(1));
82 long sel
= m_list
->GetFirstSelected();
84 CPPUNIT_ASSERT_EQUAL(0, sel
);
86 sel
= m_list
->GetNextSelected(sel
);
88 CPPUNIT_ASSERT_EQUAL(2, sel
);
90 sel
= m_list
->GetNextSelected(sel
);
92 CPPUNIT_ASSERT_EQUAL(3, sel
);
94 sel
= m_list
->GetNextSelected(sel
);
96 CPPUNIT_ASSERT_EQUAL(-1, sel
);
98 m_list
->Select(0, false);
100 CPPUNIT_ASSERT(!m_list
->IsSelected(0));
101 CPPUNIT_ASSERT_EQUAL(2, m_list
->GetFirstSelected());
104 void ListViewTestCase::Focus()
106 m_list
->InsertColumn(0, "Column 0");
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");
113 CPPUNIT_ASSERT_EQUAL(-1, m_list
->GetFocusedItem());
117 CPPUNIT_ASSERT_EQUAL(0, m_list
->GetFocusedItem());