diff --git a/tests/controls/dataviewctrltest.cpp b/tests/controls/dataviewctrltest.cpp index 45c10cf253..d8b20740ed 100644 --- a/tests/controls/dataviewctrltest.cpp +++ b/tests/controls/dataviewctrltest.cpp @@ -27,30 +27,13 @@ // test class // ---------------------------------------------------------------------------- -class DataViewCtrlTestCase : public CppUnit::TestCase +class DataViewCtrlTestCase { public: - DataViewCtrlTestCase() { } - - virtual void setUp() wxOVERRIDE; - virtual void tearDown() wxOVERRIDE; - -private: - CPPUNIT_TEST_SUITE( DataViewCtrlTestCase ); - CPPUNIT_TEST( DeleteSelected ); - CPPUNIT_TEST( DeleteNotSelected ); - CPPUNIT_TEST( GetSelectionForMulti ); - CPPUNIT_TEST( GetSelectionForSingle ); - CPPUNIT_TEST_SUITE_END(); - - // Create wxDataViewTreeCtrl with the given style. - void Create(long style); - - void DeleteSelected(); - void DeleteNotSelected(); - void GetSelectionForMulti(); - void GetSelectionForSingle(); + explicit DataViewCtrlTestCase(long style); + ~DataViewCtrlTestCase(); +protected: void TestSelectionFor0and1(); // the dataview control itself @@ -65,17 +48,29 @@ private: wxDECLARE_NO_COPY_CLASS(DataViewCtrlTestCase); }; -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( DataViewCtrlTestCase ); +class SingleSelectDataViewCtrlTestCase : public DataViewCtrlTestCase +{ +public: + SingleSelectDataViewCtrlTestCase() + : DataViewCtrlTestCase(wxDV_SINGLE) + { + } +}; -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DataViewCtrlTestCase, "DataViewCtrlTestCase" ); +class MultiSelectDataViewCtrlTestCase : public DataViewCtrlTestCase +{ +public: + MultiSelectDataViewCtrlTestCase() + : DataViewCtrlTestCase(wxDV_MULTIPLE) + { + } +}; // ---------------------------------------------------------------------------- // test initialization // ---------------------------------------------------------------------------- -void DataViewCtrlTestCase::Create(long style) +DataViewCtrlTestCase::DataViewCtrlTestCase(long style) { m_dvc = new wxDataViewTreeCtrl(wxTheApp->GetTopWindow(), wxID_ANY, @@ -94,27 +89,18 @@ void DataViewCtrlTestCase::Create(long style) m_dvc->Update(); } -void DataViewCtrlTestCase::setUp() -{ - Create(wxDV_MULTIPLE); -} - -void DataViewCtrlTestCase::tearDown() +DataViewCtrlTestCase::~DataViewCtrlTestCase() { delete m_dvc; - m_dvc = NULL; - - m_root = - m_child1 = - m_child2 = - m_grandchild = wxDataViewItem(); } // ---------------------------------------------------------------------------- // the tests themselves // ---------------------------------------------------------------------------- -void DataViewCtrlTestCase::DeleteSelected() +TEST_CASE_METHOD(MultiSelectDataViewCtrlTestCase, + "wxDVC::DeleteSelected", + "[wxDataViewCtrl][delete]") { wxDataViewItemArray sel; sel.push_back(m_child1); @@ -128,14 +114,18 @@ void DataViewCtrlTestCase::DeleteSelected() m_dvc->GetSelections(sel); // m_child1 and its children should be removed from the selection now - CPPUNIT_ASSERT_EQUAL( 1, sel.size() ); - CPPUNIT_ASSERT( sel[0] == m_child2 ); + REQUIRE( sel.size() == 1 ); + CHECK( sel[0] == m_child2 ); } -void DataViewCtrlTestCase::DeleteNotSelected() +TEST_CASE_METHOD(MultiSelectDataViewCtrlTestCase, + "wxDVC::DeleteNotSelected", + "[wxDataViewCtrl][delete]") { // TODO not working on OS X as expected -#ifndef __WXOSX__ +#ifdef __WXOSX__ + WARN("Disabled under MacOS because this test currently fails"); +#else wxDataViewItemArray sel; sel.push_back(m_child1); sel.push_back(m_grandchild); @@ -147,9 +137,9 @@ void DataViewCtrlTestCase::DeleteNotSelected() m_dvc->GetSelections(sel); // m_child1 and its children should be unaffected - CPPUNIT_ASSERT_EQUAL( 2, sel.size() ); - CPPUNIT_ASSERT( sel[0] == m_child1 ); - CPPUNIT_ASSERT( sel[1] == m_grandchild ); + REQUIRE( sel.size() == 2 ); + CHECK( sel[0] == m_child1 ); + CHECK( sel[1] == m_grandchild ); #endif } @@ -158,43 +148,43 @@ void DataViewCtrlTestCase::TestSelectionFor0and1() wxDataViewItemArray selections; // Initially there is no selection. - CPPUNIT_ASSERT_EQUAL( 0, m_dvc->GetSelectedItemsCount() ); - CPPUNIT_ASSERT( !m_dvc->HasSelection() ); - CPPUNIT_ASSERT( !m_dvc->GetSelection().IsOk() ); + CHECK( m_dvc->GetSelectedItemsCount() == 0 ); + CHECK( !m_dvc->HasSelection() ); + CHECK( !m_dvc->GetSelection().IsOk() ); - CPPUNIT_ASSERT( !m_dvc->GetSelections(selections) ); - CPPUNIT_ASSERT( selections.empty() ); + CHECK( !m_dvc->GetSelections(selections) ); + CHECK( selections.empty() ); // Select one item. m_dvc->Select(m_child1); - CPPUNIT_ASSERT_EQUAL( 1, m_dvc->GetSelectedItemsCount() ); - CPPUNIT_ASSERT( m_dvc->HasSelection() ); - CPPUNIT_ASSERT( m_dvc->GetSelection().IsOk() ); - CPPUNIT_ASSERT_EQUAL( 1, m_dvc->GetSelections(selections) ); - CPPUNIT_ASSERT( selections[0] == m_child1 ); + CHECK( m_dvc->GetSelectedItemsCount() == 1 ); + CHECK( m_dvc->HasSelection() ); + CHECK( m_dvc->GetSelection().IsOk() ); + REQUIRE( m_dvc->GetSelections(selections) == 1 ); + CHECK( selections[0] == m_child1 ); } -void DataViewCtrlTestCase::GetSelectionForMulti() +TEST_CASE_METHOD(MultiSelectDataViewCtrlTestCase, + "wxDVC::GetSelectionForMulti", + "[wxDataViewCtrl][select]") { wxDataViewItemArray selections; TestSelectionFor0and1(); - // Also test with more than one selected item. m_dvc->Select(m_child2); - CPPUNIT_ASSERT_EQUAL( 2, m_dvc->GetSelectedItemsCount() ); - CPPUNIT_ASSERT( m_dvc->HasSelection() ); - CPPUNIT_ASSERT( !m_dvc->GetSelection().IsOk() ); - CPPUNIT_ASSERT_EQUAL( 2, m_dvc->GetSelections(selections) ); - CPPUNIT_ASSERT( selections[1] == m_child2 ); + CHECK( m_dvc->GetSelectedItemsCount() == 2 ); + CHECK( m_dvc->HasSelection() ); + CHECK( !m_dvc->GetSelection().IsOk() ); + REQUIRE( m_dvc->GetSelections(selections) == 2 ); + CHECK( selections[1] == m_child2 ); } -void DataViewCtrlTestCase::GetSelectionForSingle() +TEST_CASE_METHOD(SingleSelectDataViewCtrlTestCase, + "wxDVC::SingleSelection", + "[wxDataViewCtrl][selection]") { - delete m_dvc; - Create(0); - TestSelectionFor0and1(); }