From 681694bca959aa25670a22ee70833f5a71e39fca Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 13 Nov 2010 15:03:20 +0000 Subject: [PATCH] Add a unit test checking selection updating in virtual wxListCtrl. Verify that the selection is updated correctly after the number of items in the control is decreased. See #12378. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66141 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- tests/Makefile.in | 4 ++ tests/controls/virtlistctrltest.cpp | 92 +++++++++++++++++++++++++++++ tests/makefile.bcc | 4 ++ tests/makefile.gcc | 4 ++ tests/makefile.vc | 4 ++ tests/makefile.wat | 4 ++ tests/test.bkl | 1 + tests/test_test_gui.dsp | 4 ++ tests/test_vc7_test_gui.vcproj | 3 + tests/test_vc8_test_gui.vcproj | 4 ++ tests/test_vc9_test_gui.vcproj | 4 ++ 11 files changed, 128 insertions(+) create mode 100644 tests/controls/virtlistctrltest.cpp diff --git a/tests/Makefile.in b/tests/Makefile.in index 3c0ec97cc2..64b4e3ee6b 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -192,6 +192,7 @@ TEST_GUI_OBJECTS = \ test_gui_toolbooktest.o \ test_gui_treebooktest.o \ test_gui_treectrltest.o \ + test_gui_virtlistctrltest.o \ test_gui_windowtest.o \ test_gui_clone.o \ test_gui_propagation.o \ @@ -797,6 +798,9 @@ test_gui_treebooktest.o: $(srcdir)/controls/treebooktest.cpp $(TEST_GUI_ODEP) test_gui_treectrltest.o: $(srcdir)/controls/treectrltest.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/treectrltest.cpp +test_gui_virtlistctrltest.o: $(srcdir)/controls/virtlistctrltest.cpp $(TEST_GUI_ODEP) + $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/virtlistctrltest.cpp + test_gui_windowtest.o: $(srcdir)/controls/windowtest.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/windowtest.cpp diff --git a/tests/controls/virtlistctrltest.cpp b/tests/controls/virtlistctrltest.cpp new file mode 100644 index 0000000000..ea049042f4 --- /dev/null +++ b/tests/controls/virtlistctrltest.cpp @@ -0,0 +1,92 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/controls/virtlistctrltest.cpp +// Purpose: wxListCtrl unit tests for virtual mode +// Author: Vadim Zeitlin +// Created: 2010-11-13 +// RCS-ID: $Id$ +// Copyright: (c) 2010 Vadim Zeitlin +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" + +#if wxUSE_LISTCTRL + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/app.h" +#endif // WX_PRECOMP + +#include "wx/listctrl.h" + +// ---------------------------------------------------------------------------- +// test class +// ---------------------------------------------------------------------------- + +class VirtListCtrlTestCase : public CppUnit::TestCase +{ +public: + VirtListCtrlTestCase() { } + + virtual void setUp(); + virtual void tearDown(); + +private: + CPPUNIT_TEST_SUITE( VirtListCtrlTestCase ); + CPPUNIT_TEST( UpdateSelection ); + CPPUNIT_TEST_SUITE_END(); + + void UpdateSelection(); + + wxListCtrl *m_list; + + wxDECLARE_NO_COPY_CLASS(VirtListCtrlTestCase); +}; + +// register in the unnamed registry so that these tests are run by default +CPPUNIT_TEST_SUITE_REGISTRATION( VirtListCtrlTestCase ); + +// also include in it's own registry so that these tests can be run alone +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VirtListCtrlTestCase, "VirtListCtrlTestCase" ); + +// ---------------------------------------------------------------------------- +// test initialization +// ---------------------------------------------------------------------------- + +void VirtListCtrlTestCase::setUp() +{ + m_list = new wxListCtrl(wxTheApp->GetTopWindow(), wxID_ANY, + wxPoint(0, 0), wxSize(400, 200), + wxLC_REPORT | wxLC_VIRTUAL); +} + +void VirtListCtrlTestCase::tearDown() +{ + delete m_list; + m_list = NULL; +} + +void VirtListCtrlTestCase::UpdateSelection() +{ + m_list->SetItemCount(10); + CPPUNIT_ASSERT_EQUAL( 0, m_list->GetSelectedItemCount() ); + + m_list->SetItemState(7, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() ); + + m_list->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + CPPUNIT_ASSERT_EQUAL( 2, m_list->GetSelectedItemCount() ); + + // The item 7 is now invalid and so shouldn't be counted as selected any + // more. + m_list->SetItemCount(5); + CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() ); +} + +#endif // wxUSE_LISTCTRL diff --git a/tests/makefile.bcc b/tests/makefile.bcc index a373da303d..c7f9b74cb0 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -177,6 +177,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_toolbooktest.obj \ $(OBJS)\test_gui_treebooktest.obj \ $(OBJS)\test_gui_treectrltest.obj \ + $(OBJS)\test_gui_virtlistctrltest.obj \ $(OBJS)\test_gui_windowtest.obj \ $(OBJS)\test_gui_clone.obj \ $(OBJS)\test_gui_propagation.obj \ @@ -843,6 +844,9 @@ $(OBJS)\test_gui_treebooktest.obj: .\controls\treebooktest.cpp $(OBJS)\test_gui_treectrltest.obj: .\controls\treectrltest.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\treectrltest.cpp +$(OBJS)\test_gui_virtlistctrltest.obj: .\controls\virtlistctrltest.cpp + $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\virtlistctrltest.cpp + $(OBJS)\test_gui_windowtest.obj: .\controls\windowtest.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\windowtest.cpp diff --git a/tests/makefile.gcc b/tests/makefile.gcc index 9d0b1550d3..d5c284bff5 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -170,6 +170,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_toolbooktest.o \ $(OBJS)\test_gui_treebooktest.o \ $(OBJS)\test_gui_treectrltest.o \ + $(OBJS)\test_gui_virtlistctrltest.o \ $(OBJS)\test_gui_windowtest.o \ $(OBJS)\test_gui_clone.o \ $(OBJS)\test_gui_propagation.o \ @@ -824,6 +825,9 @@ $(OBJS)\test_gui_treebooktest.o: ./controls/treebooktest.cpp $(OBJS)\test_gui_treectrltest.o: ./controls/treectrltest.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_gui_virtlistctrltest.o: ./controls/virtlistctrltest.cpp + $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_gui_windowtest.o: ./controls/windowtest.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index f4aa014d92..8552144003 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -172,6 +172,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_toolbooktest.obj \ $(OBJS)\test_gui_treebooktest.obj \ $(OBJS)\test_gui_treectrltest.obj \ + $(OBJS)\test_gui_virtlistctrltest.obj \ $(OBJS)\test_gui_windowtest.obj \ $(OBJS)\test_gui_clone.obj \ $(OBJS)\test_gui_propagation.obj \ @@ -969,6 +970,9 @@ $(OBJS)\test_gui_treebooktest.obj: .\controls\treebooktest.cpp $(OBJS)\test_gui_treectrltest.obj: .\controls\treectrltest.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\treectrltest.cpp +$(OBJS)\test_gui_virtlistctrltest.obj: .\controls\virtlistctrltest.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\virtlistctrltest.cpp + $(OBJS)\test_gui_windowtest.obj: .\controls\windowtest.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\windowtest.cpp diff --git a/tests/makefile.wat b/tests/makefile.wat index 891c461586..b3eb973032 100644 --- a/tests/makefile.wat +++ b/tests/makefile.wat @@ -412,6 +412,7 @@ TEST_GUI_OBJECTS = & $(OBJS)\test_gui_toolbooktest.obj & $(OBJS)\test_gui_treebooktest.obj & $(OBJS)\test_gui_treectrltest.obj & + $(OBJS)\test_gui_virtlistctrltest.obj & $(OBJS)\test_gui_windowtest.obj & $(OBJS)\test_gui_clone.obj & $(OBJS)\test_gui_propagation.obj & @@ -882,6 +883,9 @@ $(OBJS)\test_gui_treebooktest.obj : .AUTODEPEND .\controls\treebooktest.cpp $(OBJS)\test_gui_treectrltest.obj : .AUTODEPEND .\controls\treectrltest.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< +$(OBJS)\test_gui_virtlistctrltest.obj : .AUTODEPEND .\controls\virtlistctrltest.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< + $(OBJS)\test_gui_windowtest.obj : .AUTODEPEND .\controls\windowtest.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< diff --git a/tests/test.bkl b/tests/test.bkl index bd04f82ab5..9b8f76833d 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -173,6 +173,7 @@ controls/toolbooktest.cpp controls/treebooktest.cpp controls/treectrltest.cpp + controls/virtlistctrltest.cpp controls/windowtest.cpp events/clone.cpp events/propagation.cpp diff --git a/tests/test_test_gui.dsp b/tests/test_test_gui.dsp index b53a63b20d..6b6b845b56 100644 --- a/tests/test_test_gui.dsp +++ b/tests/test_test_gui.dsp @@ -501,6 +501,10 @@ SOURCE=.\controls\treectrltest.cpp # End Source File # Begin Source File +SOURCE=.\controls\virtlistctrltest.cpp +# End Source File +# Begin Source File + SOURCE=.\controls\windowtest.cpp # End Source File # Begin Source File diff --git a/tests/test_vc7_test_gui.vcproj b/tests/test_vc7_test_gui.vcproj index 7e26320eb4..4b506325a8 100644 --- a/tests/test_vc7_test_gui.vcproj +++ b/tests/test_vc7_test_gui.vcproj @@ -808,6 +808,9 @@ + + diff --git a/tests/test_vc8_test_gui.vcproj b/tests/test_vc8_test_gui.vcproj index 47043a7260..687e5e7e01 100644 --- a/tests/test_vc8_test_gui.vcproj +++ b/tests/test_vc8_test_gui.vcproj @@ -1151,6 +1151,10 @@ RelativePath=".\controls\treectrltest.cpp" > + + diff --git a/tests/test_vc9_test_gui.vcproj b/tests/test_vc9_test_gui.vcproj index 205cd7c09f..939d0453af 100644 --- a/tests/test_vc9_test_gui.vcproj +++ b/tests/test_vc9_test_gui.vcproj @@ -1123,6 +1123,10 @@ RelativePath=".\controls\treectrltest.cpp" > + + -- 2.47.2