Rewrite wxDataViewCtrl unit test without using CppUnit macros

Use CATCH API directly, this simplifies the code and makes adding new
tests simpler.

No real changes yet.
This commit is contained in:
Vadim Zeitlin
2018-11-04 14:34:49 +01:00
parent 84d3ee10cc
commit fe865a1743

View File

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