]>
git.saurik.com Git - wxWidgets.git/blob - tests/misc/selstoretest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/misc/selstoretest.cpp
3 // Purpose: wxSelectionStore unit test
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2008 Vadim Zeitlin
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
19 #include "wx/selstore.h"
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 class SelStoreTestCase
: public CppUnit::TestCase
28 SelStoreTestCase() { m_store
= NULL
; }
32 m_store
= new wxSelectionStore
;
33 m_store
->SetItemCount(NUM_ITEMS
);
36 virtual void tearDown()
43 CPPUNIT_TEST_SUITE( SelStoreTestCase
);
44 CPPUNIT_TEST( SelectItem
);
45 CPPUNIT_TEST( SelectRange
);
46 CPPUNIT_TEST( SetItemCount
);
47 CPPUNIT_TEST( Clear
);
48 CPPUNIT_TEST_SUITE_END();
56 static const unsigned NUM_ITEMS
;
58 wxSelectionStore
*m_store
;
60 DECLARE_NO_COPY_CLASS(SelStoreTestCase
)
63 // register in the unnamed registry so that these tests are run by default
64 CPPUNIT_TEST_SUITE_REGISTRATION( SelStoreTestCase
);
66 // also include in its own registry so that these tests can be run alone
67 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SelStoreTestCase
, "SelStoreTestCase" );
69 const unsigned SelStoreTestCase::NUM_ITEMS
= 10; // NB: must be even
71 void SelStoreTestCase::SelectItem()
73 m_store
->SelectItem(0);
74 CPPUNIT_ASSERT_EQUAL( 1u, m_store
->GetSelectedCount() );
75 CPPUNIT_ASSERT( m_store
->IsSelected(0) );
77 m_store
->SelectItem(NUM_ITEMS
- 1);
78 CPPUNIT_ASSERT_EQUAL( 2u, m_store
->GetSelectedCount() );
79 CPPUNIT_ASSERT( m_store
->IsSelected(NUM_ITEMS
- 1) );
81 m_store
->SelectItem(0, false);
82 CPPUNIT_ASSERT_EQUAL( 1u, m_store
->GetSelectedCount() );
83 CPPUNIT_ASSERT( !m_store
->IsSelected(0) );
86 void SelStoreTestCase::SelectRange()
88 m_store
->SelectRange(0, NUM_ITEMS
/2);
89 CPPUNIT_ASSERT_EQUAL( NUM_ITEMS
/2 + 1, m_store
->GetSelectedCount() );
90 CPPUNIT_ASSERT( m_store
->IsSelected(0) );
91 CPPUNIT_ASSERT( !m_store
->IsSelected(NUM_ITEMS
- 1) );
93 m_store
->SelectRange(NUM_ITEMS
/2, NUM_ITEMS
- 1);
94 CPPUNIT_ASSERT_EQUAL( NUM_ITEMS
, m_store
->GetSelectedCount() );
95 CPPUNIT_ASSERT( m_store
->IsSelected(0) );
96 CPPUNIT_ASSERT( m_store
->IsSelected(NUM_ITEMS
- 1) );
98 m_store
->SelectRange(1, NUM_ITEMS
- 2, false);
99 CPPUNIT_ASSERT_EQUAL( 2u, m_store
->GetSelectedCount() );
100 CPPUNIT_ASSERT( m_store
->IsSelected(0) );
101 CPPUNIT_ASSERT( !m_store
->IsSelected(NUM_ITEMS
/2) );
102 CPPUNIT_ASSERT( m_store
->IsSelected(NUM_ITEMS
- 1) );
105 void SelStoreTestCase::SetItemCount()
107 m_store
->SelectRange(1, NUM_ITEMS
- 2);
108 CPPUNIT_ASSERT_EQUAL( NUM_ITEMS
- 2, m_store
->GetSelectedCount() );
110 m_store
->SetItemCount(NUM_ITEMS
/2);
111 CPPUNIT_ASSERT_EQUAL( NUM_ITEMS
/2 - 1, m_store
->GetSelectedCount() );
115 m_store
->SetItemCount(NUM_ITEMS
);
118 m_store
->SelectItem(NUM_ITEMS
/2 - 1);
119 m_store
->SelectItem(NUM_ITEMS
/2 + 1);
120 m_store
->SetItemCount(NUM_ITEMS
/2);
121 CPPUNIT_ASSERT_EQUAL( 1u, m_store
->GetSelectedCount() );
124 void SelStoreTestCase::Clear()
126 CPPUNIT_ASSERT_EQUAL( 0u, m_store
->GetSelectedCount() );
128 m_store
->SelectItem(0);
131 CPPUNIT_ASSERT_EQUAL( 0u, m_store
->GetSelectedCount() );