]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/dataviewctrltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/treectrltest.cpp
3 // Purpose: wxDataViewCtrl unit test
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2011 Vaclav Slavik <vslavik@gmail.com>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
16 #if wxUSE_DATAVIEWCTRL
23 #include "wx/dataview.h"
25 #include "testableframe.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 class DataViewCtrlTestCase
: public CppUnit::TestCase
34 DataViewCtrlTestCase() { }
37 virtual void tearDown();
40 CPPUNIT_TEST_SUITE( DataViewCtrlTestCase
);
41 CPPUNIT_TEST( DeleteSelected
);
42 CPPUNIT_TEST( DeleteNotSelected
);
43 CPPUNIT_TEST_SUITE_END();
45 void DeleteSelected();
46 void DeleteNotSelected();
48 // the dataview control itself
49 wxDataViewTreeCtrl
*m_dvc
;
51 // and some of its items
52 wxDataViewItem m_root
,
57 DECLARE_NO_COPY_CLASS(DataViewCtrlTestCase
)
60 // register in the unnamed registry so that these tests are run by default
61 CPPUNIT_TEST_SUITE_REGISTRATION( DataViewCtrlTestCase
);
63 // also include in its own registry so that these tests can be run alone
64 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DataViewCtrlTestCase
, "DataViewCtrlTestCase" );
66 // ----------------------------------------------------------------------------
67 // test initialization
68 // ----------------------------------------------------------------------------
70 void DataViewCtrlTestCase::setUp()
72 m_dvc
= new wxDataViewTreeCtrl(wxTheApp
->GetTopWindow(),
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");
83 m_dvc
->SetSize(400, 200);
84 m_dvc
->ExpandAncestors(m_root
);
89 void DataViewCtrlTestCase::tearDown()
97 m_grandchild
= wxDataViewItem();
100 // ----------------------------------------------------------------------------
101 // the tests themselves
102 // ----------------------------------------------------------------------------
104 void DataViewCtrlTestCase::DeleteSelected()
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
);
112 // delete a selected item
113 m_dvc
->DeleteItem(m_child1
);
115 m_dvc
->GetSelections(sel
);
117 // m_child1 and its children should be removed from the selection now
118 CPPUNIT_ASSERT_EQUAL( 1, sel
.size() );
119 CPPUNIT_ASSERT( sel
[0] == m_child2
);
122 void DataViewCtrlTestCase::DeleteNotSelected()
124 wxDataViewItemArray sel
;
125 sel
.push_back(m_child1
);
126 sel
.push_back(m_grandchild
);
127 m_dvc
->SetSelections(sel
);
129 // delete unselected item
130 m_dvc
->DeleteItem(m_child2
);
132 m_dvc
->GetSelections(sel
);
134 // m_child1 and its children should be removed from the selection now
135 CPPUNIT_ASSERT_EQUAL( 2, sel
.size() );
136 CPPUNIT_ASSERT( sel
[0] == m_child1
);
137 CPPUNIT_ASSERT( sel
[1] == m_grandchild
);
140 #endif //wxUSE_TREECTRL