wxSelectionStore() : m_itemsSel(wxUIntCmp) { Init(); }
// set the total number of items we handle
- void SetItemCount(unsigned count) { m_count = count; }
+ void SetItemCount(unsigned count);
// special case of SetItemCount(0)
void Clear() { m_itemsSel.Clear(); m_count = 0; m_defaultState = false; }
// returns true if the items selection really changed
bool SelectItem(unsigned item, bool select = true);
- // select the range of items
+ // select the range of items (inclusive)
//
// return true and fill the itemsChanged array with the indices of items
// which have changed state if "few" of them did, otherwise return false
}
}
+void wxSelectionStore::SetItemCount(unsigned count)
+{
+ // forget about all items whose indices are now invalid if the size
+ // decreased
+ if ( count < m_count )
+ {
+ for ( size_t i = m_itemsSel.GetCount(); i > 0; i-- )
+ {
+ if ( m_itemsSel[i - 1] >= count )
+ m_itemsSel.RemoveAt(i - 1);
+ }
+ }
+
+ // remember the new number of items
+ m_count = count;
+}
test_gui_point.o \
test_gui_config.o \
test_gui_clientsize.o \
- test_gui_textctrltest.o
+ test_gui_textctrltest.o \
+ test_gui_selstoretest.o
TEST_GUI_ODEP = $(___pch_testprec_test_gui_testprec_h_gch___depname)
PRINTFBENCH_CXXFLAGS = $(__printfbench_PCH_INC) -D__WX$(TOOLKIT)__ \
$(__WXUNIV_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) \
test_gui_textctrltest.o: $(srcdir)/controls/textctrltest.cpp $(TEST_GUI_ODEP)
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/textctrltest.cpp
+test_gui_selstoretest.o: $(srcdir)/misc/selstoretest.cpp $(TEST_GUI_ODEP)
+ $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/misc/selstoretest.cpp
+
printfbench_printfbench.o: $(srcdir)/benchmarks/printfbench.cpp $(PRINTFBENCH_ODEP)
$(CXXC) -c -o $@ $(PRINTFBENCH_CXXFLAGS) $(srcdir)/benchmarks/printfbench.cpp
$(OBJS)\test_gui_point.obj \
$(OBJS)\test_gui_config.obj \
$(OBJS)\test_gui_clientsize.obj \
- $(OBJS)\test_gui_textctrltest.obj
+ $(OBJS)\test_gui_textctrltest.obj \
+ $(OBJS)\test_gui_selstoretest.obj
PRINTFBENCH_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \
$(__OPTIMIZEFLAG) $(__THREADSFLAG_1) -D__WXMSW__ $(__WXUNIV_DEFINE_p) \
$(__DEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) \
$(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\textctrltest.cpp
+$(OBJS)\test_gui_selstoretest.obj: .\misc\selstoretest.cpp
+ $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\misc\selstoretest.cpp
+
$(OBJS)\printfbench_dummy.obj: .\dummy.cpp
$(CXX) -q -c -P -o$@ $(PRINTFBENCH_CXXFLAGS) -H .\dummy.cpp
$(OBJS)\test_gui_point.o \
$(OBJS)\test_gui_config.o \
$(OBJS)\test_gui_clientsize.o \
- $(OBJS)\test_gui_textctrltest.o
+ $(OBJS)\test_gui_textctrltest.o \
+ $(OBJS)\test_gui_selstoretest.o
PRINTFBENCH_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) \
$(GCCFLAGS) -DHAVE_W32API_H -D__WXMSW__ $(__WXUNIV_DEFINE_p) \
$(__DEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) \
$(OBJS)\test_gui_textctrltest.o: ./controls/textctrltest.cpp
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
+$(OBJS)\test_gui_selstoretest.o: ./misc/selstoretest.cpp
+ $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
+
$(OBJS)\printfbench_dummy.o: ./dummy.cpp
$(CXX) -c -o $@ $(PRINTFBENCH_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\test_gui_point.obj \
$(OBJS)\test_gui_config.obj \
$(OBJS)\test_gui_clientsize.obj \
- $(OBJS)\test_gui_textctrltest.obj
+ $(OBJS)\test_gui_textctrltest.obj \
+ $(OBJS)\test_gui_selstoretest.obj
PRINTFBENCH_CXXFLAGS = /M$(__RUNTIME_LIBS_38)$(__DEBUGRUNTIME) /DWIN32 \
$(__DEBUGINFO) /Fd$(OBJS)\printfbench.pdb $(____DEBUGRUNTIME) \
$(__OPTIMIZEFLAG) $(__NO_VC_CRTDBG_p) /D__WXMSW__ $(__WXUNIV_DEFINE_p) \
$(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\textctrltest.cpp
+$(OBJS)\test_gui_selstoretest.obj: .\misc\selstoretest.cpp
+ $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\misc\selstoretest.cpp
+
$(OBJS)\printfbench_dummy.obj: .\dummy.cpp
$(CXX) /c /nologo /TP /Fo$@ $(PRINTFBENCH_CXXFLAGS) /Yctestprec.h .\dummy.cpp
$(OBJS)\test_gui_point.obj &
$(OBJS)\test_gui_config.obj &
$(OBJS)\test_gui_clientsize.obj &
- $(OBJS)\test_gui_textctrltest.obj
+ $(OBJS)\test_gui_textctrltest.obj &
+ $(OBJS)\test_gui_selstoretest.obj
PRINTFBENCH_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) &
$(__RUNTIME_LIBS) -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) &
$(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) &
$(OBJS)\test_gui_textctrltest.obj : .AUTODEPEND .\controls\textctrltest.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
+$(OBJS)\test_gui_selstoretest.obj : .AUTODEPEND .\misc\selstoretest.cpp
+ $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
+
$(OBJS)\printfbench_dummy.obj : .AUTODEPEND .\dummy.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(PRINTFBENCH_CXXFLAGS) $<
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: tests/misc/selstoretest.cpp
+// Purpose: wxSelectionStore unit test
+// Author: Vadim Zeitlin
+// Created: 2008-03-31
+// RCS-ID: $Id$
+// Copyright: (c) 2008 Vadim Zeitlin
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#include "wx/selstore.h"
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class SelStoreTestCase : public CppUnit::TestCase
+{
+public:
+ SelStoreTestCase() { m_store = NULL; }
+
+ virtual void setUp()
+ {
+ m_store = new wxSelectionStore;
+ m_store->SetItemCount(NUM_ITEMS);
+ }
+
+ virtual void tearDown()
+ {
+ delete m_store;
+ m_store = NULL;
+ }
+
+private:
+ CPPUNIT_TEST_SUITE( SelStoreTestCase );
+ CPPUNIT_TEST( SelectItem );
+ CPPUNIT_TEST( SelectRange );
+ CPPUNIT_TEST( SetItemCount );
+ CPPUNIT_TEST( Clear );
+ CPPUNIT_TEST_SUITE_END();
+
+ void SelectItem();
+ void SelectRange();
+ void SetItemCount();
+ void Clear();
+
+ // NB: must be even
+ static const unsigned NUM_ITEMS;
+
+ wxSelectionStore *m_store;
+
+ DECLARE_NO_COPY_CLASS(SelStoreTestCase)
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( SelStoreTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SelStoreTestCase, "SelStoreTestCase" );
+
+const unsigned SelStoreTestCase::NUM_ITEMS = 10; // NB: must be even
+
+void SelStoreTestCase::SelectItem()
+{
+ m_store->SelectItem(0);
+ CPPUNIT_ASSERT_EQUAL( 1u, m_store->GetSelectedCount() );
+ CPPUNIT_ASSERT( m_store->IsSelected(0) );
+
+ m_store->SelectItem(NUM_ITEMS - 1);
+ CPPUNIT_ASSERT_EQUAL( 2u, m_store->GetSelectedCount() );
+ CPPUNIT_ASSERT( m_store->IsSelected(NUM_ITEMS - 1) );
+
+ m_store->SelectItem(0, false);
+ CPPUNIT_ASSERT_EQUAL( 1u, m_store->GetSelectedCount() );
+ CPPUNIT_ASSERT( !m_store->IsSelected(0) );
+}
+
+void SelStoreTestCase::SelectRange()
+{
+ m_store->SelectRange(0, NUM_ITEMS/2);
+ CPPUNIT_ASSERT_EQUAL( NUM_ITEMS/2 + 1, m_store->GetSelectedCount() );
+ CPPUNIT_ASSERT( m_store->IsSelected(0) );
+ CPPUNIT_ASSERT( !m_store->IsSelected(NUM_ITEMS - 1) );
+
+ m_store->SelectRange(NUM_ITEMS/2, NUM_ITEMS - 1);
+ CPPUNIT_ASSERT_EQUAL( NUM_ITEMS, m_store->GetSelectedCount() );
+ CPPUNIT_ASSERT( m_store->IsSelected(0) );
+ CPPUNIT_ASSERT( m_store->IsSelected(NUM_ITEMS - 1) );
+
+ m_store->SelectRange(1, NUM_ITEMS - 2, false);
+ CPPUNIT_ASSERT_EQUAL( 2u, m_store->GetSelectedCount() );
+ CPPUNIT_ASSERT( m_store->IsSelected(0) );
+ CPPUNIT_ASSERT( !m_store->IsSelected(NUM_ITEMS/2) );
+ CPPUNIT_ASSERT( m_store->IsSelected(NUM_ITEMS - 1) );
+}
+
+void SelStoreTestCase::SetItemCount()
+{
+ m_store->SelectRange(1, NUM_ITEMS - 2);
+ CPPUNIT_ASSERT_EQUAL( NUM_ITEMS - 2, m_store->GetSelectedCount() );
+
+ m_store->SetItemCount(NUM_ITEMS/2);
+ CPPUNIT_ASSERT_EQUAL( NUM_ITEMS/2 - 1, m_store->GetSelectedCount() );
+
+
+ m_store->Clear();
+ m_store->SetItemCount(NUM_ITEMS);
+
+
+ m_store->SelectItem(NUM_ITEMS/2 - 1);
+ m_store->SelectItem(NUM_ITEMS/2 + 1);
+ m_store->SetItemCount(NUM_ITEMS/2);
+ CPPUNIT_ASSERT_EQUAL( 1u, m_store->GetSelectedCount() );
+}
+
+void SelStoreTestCase::Clear()
+{
+ CPPUNIT_ASSERT_EQUAL( 0u, m_store->GetSelectedCount() );
+
+ m_store->SelectItem(0);
+ m_store->Clear();
+
+ CPPUNIT_ASSERT_EQUAL( 0u, m_store->GetSelectedCount() );
+}
+
config/config.cpp
controls/clientsize.cpp
controls/textctrltest.cpp
+ misc/selstoretest.cpp
</sources>
<wx-lib>core</wx-lib>
<wx-lib>base</wx-lib>
# End Source File\r
# Begin Source File\r
\r
+SOURCE=.\misc\selstoretest.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\geometry\size.cpp\r
# End Source File\r
# Begin Source File\r
RelativePath=".\geometry\point.cpp"/>\r
<File\r
RelativePath=".\geometry\rect.cpp"/>\r
+ <File\r
+ RelativePath=".\misc\selstoretest.cpp"/>\r
<File\r
RelativePath=".\geometry\size.cpp"/>\r
<File\r
<File\r
RelativePath=".\geometry\rect.cpp"\r
/>\r
+ <File\r
+ RelativePath=".\misc\selstoretest.cpp"\r
+ />\r
<File\r
RelativePath=".\geometry\size.cpp"\r
/>\r