]>
git.saurik.com Git - wxWidgets.git/blob - tests/misc/selstoretest.cpp
65b6e38642ac9fe67398aff487330979d9c8f4b6
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/misc/selstoretest.cpp
3 // Purpose: wxSelectionStore unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
20 #include "wx/selstore.h"
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
26 class SelStoreTestCase
: public CppUnit::TestCase
29 SelStoreTestCase() { m_store
= NULL
; }
33 m_store
= new wxSelectionStore
;
34 m_store
->SetItemCount(NUM_ITEMS
);
37 virtual void tearDown()
44 CPPUNIT_TEST_SUITE( SelStoreTestCase
);
45 CPPUNIT_TEST( SelectItem
);
46 CPPUNIT_TEST( SelectRange
);
47 CPPUNIT_TEST( SetItemCount
);
48 CPPUNIT_TEST( Clear
);
49 CPPUNIT_TEST_SUITE_END();
57 static const unsigned NUM_ITEMS
;
59 wxSelectionStore
*m_store
;
61 DECLARE_NO_COPY_CLASS(SelStoreTestCase
)
64 // register in the unnamed registry so that these tests are run by default
65 CPPUNIT_TEST_SUITE_REGISTRATION( SelStoreTestCase
);
67 // also include in its own registry so that these tests can be run alone
68 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SelStoreTestCase
, "SelStoreTestCase" );
70 const unsigned SelStoreTestCase::NUM_ITEMS
= 10; // NB: must be even
72 void SelStoreTestCase::SelectItem()
74 m_store
->SelectItem(0);
75 CPPUNIT_ASSERT_EQUAL( 1u, m_store
->GetSelectedCount() );
76 CPPUNIT_ASSERT( m_store
->IsSelected(0) );
78 m_store
->SelectItem(NUM_ITEMS
- 1);
79 CPPUNIT_ASSERT_EQUAL( 2u, m_store
->GetSelectedCount() );
80 CPPUNIT_ASSERT( m_store
->IsSelected(NUM_ITEMS
- 1) );
82 m_store
->SelectItem(0, false);
83 CPPUNIT_ASSERT_EQUAL( 1u, m_store
->GetSelectedCount() );
84 CPPUNIT_ASSERT( !m_store
->IsSelected(0) );
87 void SelStoreTestCase::SelectRange()
89 m_store
->SelectRange(0, NUM_ITEMS
/2);
90 CPPUNIT_ASSERT_EQUAL( NUM_ITEMS
/2 + 1, m_store
->GetSelectedCount() );
91 CPPUNIT_ASSERT( m_store
->IsSelected(0) );
92 CPPUNIT_ASSERT( !m_store
->IsSelected(NUM_ITEMS
- 1) );
94 m_store
->SelectRange(NUM_ITEMS
/2, NUM_ITEMS
- 1);
95 CPPUNIT_ASSERT_EQUAL( NUM_ITEMS
, m_store
->GetSelectedCount() );
96 CPPUNIT_ASSERT( m_store
->IsSelected(0) );
97 CPPUNIT_ASSERT( m_store
->IsSelected(NUM_ITEMS
- 1) );
99 m_store
->SelectRange(1, NUM_ITEMS
- 2, false);
100 CPPUNIT_ASSERT_EQUAL( 2u, m_store
->GetSelectedCount() );
101 CPPUNIT_ASSERT( m_store
->IsSelected(0) );
102 CPPUNIT_ASSERT( !m_store
->IsSelected(NUM_ITEMS
/2) );
103 CPPUNIT_ASSERT( m_store
->IsSelected(NUM_ITEMS
- 1) );
106 void SelStoreTestCase::SetItemCount()
108 m_store
->SelectRange(1, NUM_ITEMS
- 2);
109 CPPUNIT_ASSERT_EQUAL( NUM_ITEMS
- 2, m_store
->GetSelectedCount() );
111 m_store
->SetItemCount(NUM_ITEMS
/2);
112 CPPUNIT_ASSERT_EQUAL( NUM_ITEMS
/2 - 1, m_store
->GetSelectedCount() );
116 m_store
->SetItemCount(NUM_ITEMS
);
119 m_store
->SelectItem(NUM_ITEMS
/2 - 1);
120 m_store
->SelectItem(NUM_ITEMS
/2 + 1);
121 m_store
->SetItemCount(NUM_ITEMS
/2);
122 CPPUNIT_ASSERT_EQUAL( 1u, m_store
->GetSelectedCount() );
125 void SelStoreTestCase::Clear()
127 CPPUNIT_ASSERT_EQUAL( 0u, m_store
->GetSelectedCount() );
129 m_store
->SelectItem(0);
132 CPPUNIT_ASSERT_EQUAL( 0u, m_store
->GetSelectedCount() );