From cbef7338c1c7763042704c74d5ee6f62c7e10733 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 10 Aug 2011 15:24:25 +0000 Subject: [PATCH] Add some basic tests for wxDataViewCtrl selection handling. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68623 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- tests/Makefile.in | 6 +- tests/controls/dataviewctrltest.cpp | 140 ++++++++++++++++++++++++++++ tests/makefile.bcc | 12 ++- tests/makefile.gcc | 12 ++- tests/makefile.vc | 12 ++- tests/makefile.wat | 12 ++- tests/test.bkl | 1 + tests/test_test_gui.dsp | 12 ++- tests/test_vc7_test_gui.vcproj | 9 +- tests/test_vc8_test_gui.vcproj | 12 ++- tests/test_vc9_test_gui.vcproj | 12 ++- 11 files changed, 208 insertions(+), 32 deletions(-) create mode 100644 tests/controls/dataviewctrltest.cpp diff --git a/tests/Makefile.in b/tests/Makefile.in index 61c235eaee..26ae782b00 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -46,7 +46,7 @@ wx_top_builddir = @wx_top_builddir@ DESTDIR = WX_RELEASE = 2.9 -WX_VERSION = $(WX_RELEASE).2 +WX_VERSION = $(WX_RELEASE).3 LIBDIRNAME = $(wx_top_builddir)/lib TEST_CXXFLAGS = $(__test_PCH_INC) -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) \ $(__DEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) \ @@ -166,6 +166,7 @@ TEST_GUI_OBJECTS = \ test_gui_choicebooktest.o \ test_gui_choicetest.o \ test_gui_comboboxtest.o \ + test_gui_dataviewctrltest.o \ test_gui_datepickerctrltest.o \ test_gui_frametest.o \ test_gui_gaugetest.o \ @@ -732,6 +733,9 @@ test_gui_choicetest.o: $(srcdir)/controls/choicetest.cpp $(TEST_GUI_ODEP) test_gui_comboboxtest.o: $(srcdir)/controls/comboboxtest.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/comboboxtest.cpp +test_gui_dataviewctrltest.o: $(srcdir)/controls/dataviewctrltest.cpp $(TEST_GUI_ODEP) + $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/dataviewctrltest.cpp + test_gui_datepickerctrltest.o: $(srcdir)/controls/datepickerctrltest.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/datepickerctrltest.cpp diff --git a/tests/controls/dataviewctrltest.cpp b/tests/controls/dataviewctrltest.cpp new file mode 100644 index 0000000000..60d1a38270 --- /dev/null +++ b/tests/controls/dataviewctrltest.cpp @@ -0,0 +1,140 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/controls/treectrltest.cpp +// Purpose: wxDataViewCtrl unit test +// Author: Vaclav Slavik +// Created: 2011-08-08 +// RCS-ID: $Id$ +// Copyright: (c) 2011 Vaclav Slavik +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" + +#if wxUSE_DATAVIEWCTRL + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#include "wx/app.h" +#include "wx/dataview.h" + +#include "testableframe.h" + +// ---------------------------------------------------------------------------- +// test class +// ---------------------------------------------------------------------------- + +class DataViewCtrlTestCase : public CppUnit::TestCase +{ +public: + DataViewCtrlTestCase() { } + + virtual void setUp(); + virtual void tearDown(); + +private: + CPPUNIT_TEST_SUITE( DataViewCtrlTestCase ); + CPPUNIT_TEST( DeleteSelected ); + CPPUNIT_TEST( DeleteNotSelected ); + CPPUNIT_TEST_SUITE_END(); + + void DeleteSelected(); + void DeleteNotSelected(); + + // the dataview control itself + wxDataViewTreeCtrl *m_dvc; + + // and some of its items + wxDataViewItem m_root, + m_child1, + m_child2, + m_grandchild; + + DECLARE_NO_COPY_CLASS(DataViewCtrlTestCase) +}; + +// register in the unnamed registry so that these tests are run by default +CPPUNIT_TEST_SUITE_REGISTRATION( DataViewCtrlTestCase ); + +// also include in its own registry so that these tests can be run alone +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DataViewCtrlTestCase, "DataViewCtrlTestCase" ); + +// ---------------------------------------------------------------------------- +// test initialization +// ---------------------------------------------------------------------------- + +void DataViewCtrlTestCase::setUp() +{ + m_dvc = new wxDataViewTreeCtrl(wxTheApp->GetTopWindow(), + wxID_ANY, + wxDefaultPosition, + wxSize(400, 200), + wxDV_MULTIPLE); + + m_root = m_dvc->AppendContainer(wxDataViewItem(), "The root"); + m_child1 = m_dvc->AppendContainer(m_root, "child1"); + m_grandchild = m_dvc->AppendItem(m_child1, "grandchild"); + m_child2 = m_dvc->AppendItem(m_root, "child2"); + + m_dvc->SetSize(400, 200); + m_dvc->ExpandAncestors(m_root); + m_dvc->Refresh(); + m_dvc->Update(); +} + +void DataViewCtrlTestCase::tearDown() +{ + delete m_dvc; + m_dvc = NULL; + + m_root = + m_child1 = + m_child2 = + m_grandchild = wxDataViewItem(); +} + +// ---------------------------------------------------------------------------- +// the tests themselves +// ---------------------------------------------------------------------------- + +void DataViewCtrlTestCase::DeleteSelected() +{ + wxDataViewItemArray sel; + sel.push_back(m_child1); + sel.push_back(m_grandchild); + sel.push_back(m_child2); + m_dvc->SetSelections(sel); + + // delete a selected item + m_dvc->DeleteItem(m_child1); + + m_dvc->GetSelections(sel); + + // m_child1 and its children should be removed from the selection now + CPPUNIT_ASSERT( sel.size() == 1 ); + CPPUNIT_ASSERT( sel[0] == m_child2 ); +} + +void DataViewCtrlTestCase::DeleteNotSelected() +{ + wxDataViewItemArray sel; + sel.push_back(m_child1); + sel.push_back(m_grandchild); + m_dvc->SetSelections(sel); + + // delete unselected item + m_dvc->DeleteItem(m_child2); + + m_dvc->GetSelections(sel); + + // m_child1 and its children should be removed from the selection now + CPPUNIT_ASSERT( sel.size() == 2 ); + CPPUNIT_ASSERT( sel[0] == m_child1 ); + CPPUNIT_ASSERT( sel[1] == m_grandchild ); +} + +#endif //wxUSE_TREECTRL diff --git a/tests/makefile.bcc b/tests/makefile.bcc index 3f816730c2..812e939fae 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -151,7 +151,8 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_choicebooktest.obj \ $(OBJS)\test_gui_choicetest.obj \ $(OBJS)\test_gui_comboboxtest.obj \ - $(OBJS)\test_gui_datepickerctrltest.obj \ + $(OBJS)\test_gui_dataviewctrltest.obj \ + $(OBJS)\test_gui_datepickerctrltest.obj \ $(OBJS)\test_gui_frametest.obj \ $(OBJS)\test_gui_gaugetest.obj \ $(OBJS)\test_gui_gridtest.obj \ @@ -780,9 +781,12 @@ $(OBJS)\test_gui_choicetest.obj: .\controls\choicetest.cpp $(OBJS)\test_gui_comboboxtest.obj: .\controls\comboboxtest.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\comboboxtest.cpp -$(OBJS)\test_gui_datepickerctrltest.obj: .\controls\datepickerctrltest.cpp - $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\datepickerctrltest.cpp - +$(OBJS)\test_gui_dataviewctrltest.obj: .\controls\dataviewctrltest.cpp + $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\dataviewctrltest.cpp + +$(OBJS)\test_gui_datepickerctrltest.obj: .\controls\datepickerctrltest.cpp + $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\datepickerctrltest.cpp + $(OBJS)\test_gui_frametest.obj: .\controls\frametest.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\frametest.cpp diff --git a/tests/makefile.gcc b/tests/makefile.gcc index 652df038ca..49ea23cddd 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -144,7 +144,8 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_choicebooktest.o \ $(OBJS)\test_gui_choicetest.o \ $(OBJS)\test_gui_comboboxtest.o \ - $(OBJS)\test_gui_datepickerctrltest.o \ + $(OBJS)\test_gui_dataviewctrltest.o \ + $(OBJS)\test_gui_datepickerctrltest.o \ $(OBJS)\test_gui_frametest.o \ $(OBJS)\test_gui_gaugetest.o \ $(OBJS)\test_gui_gridtest.o \ @@ -761,9 +762,12 @@ $(OBJS)\test_gui_choicetest.o: ./controls/choicetest.cpp $(OBJS)\test_gui_comboboxtest.o: ./controls/comboboxtest.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< -$(OBJS)\test_gui_datepickerctrltest.o: ./controls/datepickerctrltest.cpp - $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< - +$(OBJS)\test_gui_dataviewctrltest.o: ./controls/dataviewctrltest.cpp + $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< + +$(OBJS)\test_gui_datepickerctrltest.o: ./controls/datepickerctrltest.cpp + $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_gui_frametest.o: ./controls/frametest.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index a509e659ee..91f4734924 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -146,7 +146,8 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_choicebooktest.obj \ $(OBJS)\test_gui_choicetest.obj \ $(OBJS)\test_gui_comboboxtest.obj \ - $(OBJS)\test_gui_datepickerctrltest.obj \ + $(OBJS)\test_gui_dataviewctrltest.obj \ + $(OBJS)\test_gui_datepickerctrltest.obj \ $(OBJS)\test_gui_frametest.obj \ $(OBJS)\test_gui_gaugetest.obj \ $(OBJS)\test_gui_gridtest.obj \ @@ -906,9 +907,12 @@ $(OBJS)\test_gui_choicetest.obj: .\controls\choicetest.cpp $(OBJS)\test_gui_comboboxtest.obj: .\controls\comboboxtest.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\comboboxtest.cpp -$(OBJS)\test_gui_datepickerctrltest.obj: .\controls\datepickerctrltest.cpp - $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\datepickerctrltest.cpp - +$(OBJS)\test_gui_dataviewctrltest.obj: .\controls\dataviewctrltest.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\dataviewctrltest.cpp + +$(OBJS)\test_gui_datepickerctrltest.obj: .\controls\datepickerctrltest.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\datepickerctrltest.cpp + $(OBJS)\test_gui_frametest.obj: .\controls\frametest.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\frametest.cpp diff --git a/tests/makefile.wat b/tests/makefile.wat index 12fca8172a..e566570d79 100644 --- a/tests/makefile.wat +++ b/tests/makefile.wat @@ -390,7 +390,8 @@ TEST_GUI_OBJECTS = & $(OBJS)\test_gui_choicebooktest.obj & $(OBJS)\test_gui_choicetest.obj & $(OBJS)\test_gui_comboboxtest.obj & - $(OBJS)\test_gui_datepickerctrltest.obj & + $(OBJS)\test_gui_dataviewctrltest.obj & + $(OBJS)\test_gui_datepickerctrltest.obj & $(OBJS)\test_gui_frametest.obj & $(OBJS)\test_gui_gaugetest.obj & $(OBJS)\test_gui_gridtest.obj & @@ -820,9 +821,12 @@ $(OBJS)\test_gui_choicetest.obj : .AUTODEPEND .\controls\choicetest.cpp $(OBJS)\test_gui_comboboxtest.obj : .AUTODEPEND .\controls\comboboxtest.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< -$(OBJS)\test_gui_datepickerctrltest.obj : .AUTODEPEND .\controls\datepickerctrltest.cpp - $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< - +$(OBJS)\test_gui_dataviewctrltest.obj : .AUTODEPEND .\controls\dataviewctrltest.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< + +$(OBJS)\test_gui_datepickerctrltest.obj : .AUTODEPEND .\controls\datepickerctrltest.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< + $(OBJS)\test_gui_frametest.obj : .AUTODEPEND .\controls\frametest.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< diff --git a/tests/test.bkl b/tests/test.bkl index 6530babbb1..344abee419 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -147,6 +147,7 @@ controls/choicebooktest.cpp controls/choicetest.cpp controls/comboboxtest.cpp + controls/dataviewctrltest.cpp controls/datepickerctrltest.cpp controls/frametest.cpp controls/gaugetest.cpp diff --git a/tests/test_test_gui.dsp b/tests/test_test_gui.dsp index 4ebfd62727..cd06b3663e 100644 --- a/tests/test_test_gui.dsp +++ b/tests/test_test_gui.dsp @@ -307,10 +307,14 @@ SOURCE=.\config\config.cpp # End Source File # Begin Source File -SOURCE=.\controls\datepickerctrltest.cpp -# End Source File -# Begin Source File - +SOURCE=.\controls\dataviewctrltest.cpp +# End Source File +# Begin Source File + +SOURCE=.\controls\datepickerctrltest.cpp +# End Source File +# Begin Source File + SOURCE=.\dummy.cpp # ADD BASE CPP /Yc"testprec.h" # ADD CPP /Yc"testprec.h" diff --git a/tests/test_vc7_test_gui.vcproj b/tests/test_vc7_test_gui.vcproj index 344e7b1059..7bffd2876b 100644 --- a/tests/test_vc7_test_gui.vcproj +++ b/tests/test_vc7_test_gui.vcproj @@ -620,9 +620,12 @@ RelativePath=".\config\config.cpp"> - - + + + + diff --git a/tests/test_vc8_test_gui.vcproj b/tests/test_vc8_test_gui.vcproj index 978c1aa733..bdcc44289b 100644 --- a/tests/test_vc8_test_gui.vcproj +++ b/tests/test_vc8_test_gui.vcproj @@ -900,10 +900,14 @@ > - - + + + + - - + + + +