]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/dataviewctrltest.cpp
Improved BMP decoding.
[wxWidgets.git] / tests / controls / dataviewctrltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/treectrltest.cpp
3 // Purpose: wxDataViewCtrl unit test
4 // Author: Vaclav Slavik
5 // Created: 2011-08-08
6 // RCS-ID: $Id$
7 // Copyright: (c) 2011 Vaclav Slavik <vslavik@gmail.com>
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 #if wxUSE_DATAVIEWCTRL
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #include "wx/app.h"
23 #include "wx/dataview.h"
24
25 #include "testableframe.h"
26
27 // ----------------------------------------------------------------------------
28 // test class
29 // ----------------------------------------------------------------------------
30
31 class DataViewCtrlTestCase : public CppUnit::TestCase
32 {
33 public:
34 DataViewCtrlTestCase() { }
35
36 virtual void setUp();
37 virtual void tearDown();
38
39 private:
40 CPPUNIT_TEST_SUITE( DataViewCtrlTestCase );
41 CPPUNIT_TEST( DeleteSelected );
42 CPPUNIT_TEST( DeleteNotSelected );
43 CPPUNIT_TEST_SUITE_END();
44
45 void DeleteSelected();
46 void DeleteNotSelected();
47
48 // the dataview control itself
49 wxDataViewTreeCtrl *m_dvc;
50
51 // and some of its items
52 wxDataViewItem m_root,
53 m_child1,
54 m_child2,
55 m_grandchild;
56
57 DECLARE_NO_COPY_CLASS(DataViewCtrlTestCase)
58 };
59
60 // register in the unnamed registry so that these tests are run by default
61 CPPUNIT_TEST_SUITE_REGISTRATION( DataViewCtrlTestCase );
62
63 // also include in its own registry so that these tests can be run alone
64 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DataViewCtrlTestCase, "DataViewCtrlTestCase" );
65
66 // ----------------------------------------------------------------------------
67 // test initialization
68 // ----------------------------------------------------------------------------
69
70 void DataViewCtrlTestCase::setUp()
71 {
72 m_dvc = new wxDataViewTreeCtrl(wxTheApp->GetTopWindow(),
73 wxID_ANY,
74 wxDefaultPosition,
75 wxSize(400, 200),
76 wxDV_MULTIPLE);
77
78 m_root = m_dvc->AppendContainer(wxDataViewItem(), "The root");
79 m_child1 = m_dvc->AppendContainer(m_root, "child1");
80 m_grandchild = m_dvc->AppendItem(m_child1, "grandchild");
81 m_child2 = m_dvc->AppendItem(m_root, "child2");
82
83 m_dvc->SetSize(400, 200);
84 m_dvc->ExpandAncestors(m_root);
85 m_dvc->Refresh();
86 m_dvc->Update();
87 }
88
89 void DataViewCtrlTestCase::tearDown()
90 {
91 delete m_dvc;
92 m_dvc = NULL;
93
94 m_root =
95 m_child1 =
96 m_child2 =
97 m_grandchild = wxDataViewItem();
98 }
99
100 // ----------------------------------------------------------------------------
101 // the tests themselves
102 // ----------------------------------------------------------------------------
103
104 void DataViewCtrlTestCase::DeleteSelected()
105 {
106 wxDataViewItemArray sel;
107 sel.push_back(m_child1);
108 sel.push_back(m_grandchild);
109 sel.push_back(m_child2);
110 m_dvc->SetSelections(sel);
111
112 // delete a selected item
113 m_dvc->DeleteItem(m_child1);
114
115 m_dvc->GetSelections(sel);
116
117 // m_child1 and its children should be removed from the selection now
118 CPPUNIT_ASSERT( sel.size() == 1 );
119 CPPUNIT_ASSERT( sel[0] == m_child2 );
120 }
121
122 void DataViewCtrlTestCase::DeleteNotSelected()
123 {
124 wxDataViewItemArray sel;
125 sel.push_back(m_child1);
126 sel.push_back(m_grandchild);
127 m_dvc->SetSelections(sel);
128
129 // delete unselected item
130 m_dvc->DeleteItem(m_child2);
131
132 m_dvc->GetSelections(sel);
133
134 // m_child1 and its children should be removed from the selection now
135 CPPUNIT_ASSERT( sel.size() == 2 );
136 CPPUNIT_ASSERT( sel[0] == m_child1 );
137 CPPUNIT_ASSERT( sel[1] == m_grandchild );
138 }
139
140 #endif //wxUSE_TREECTRL