]> git.saurik.com Git - wxWidgets.git/blob - tests/misc/selstoretest.cpp
Fix install_name_tool calls in OS X "make install".
[wxWidgets.git] / tests / misc / selstoretest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/misc/selstoretest.cpp
3 // Purpose: wxSelectionStore unit test
4 // Author: Vadim Zeitlin
5 // Created: 2008-03-31
6 // Copyright: (c) 2008 Vadim Zeitlin
7 ///////////////////////////////////////////////////////////////////////////////
8
9 // ----------------------------------------------------------------------------
10 // headers
11 // ----------------------------------------------------------------------------
12
13 #include "testprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #include "wx/selstore.h"
20
21 // ----------------------------------------------------------------------------
22 // test class
23 // ----------------------------------------------------------------------------
24
25 class SelStoreTestCase : public CppUnit::TestCase
26 {
27 public:
28 SelStoreTestCase() { m_store = NULL; }
29
30 virtual void setUp()
31 {
32 m_store = new wxSelectionStore;
33 m_store->SetItemCount(NUM_ITEMS);
34 }
35
36 virtual void tearDown()
37 {
38 delete m_store;
39 m_store = NULL;
40 }
41
42 private:
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();
49
50 void SelectItem();
51 void SelectRange();
52 void SetItemCount();
53 void Clear();
54
55 // NB: must be even
56 static const unsigned NUM_ITEMS;
57
58 wxSelectionStore *m_store;
59
60 DECLARE_NO_COPY_CLASS(SelStoreTestCase)
61 };
62
63 // register in the unnamed registry so that these tests are run by default
64 CPPUNIT_TEST_SUITE_REGISTRATION( SelStoreTestCase );
65
66 // also include in its own registry so that these tests can be run alone
67 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SelStoreTestCase, "SelStoreTestCase" );
68
69 const unsigned SelStoreTestCase::NUM_ITEMS = 10; // NB: must be even
70
71 void SelStoreTestCase::SelectItem()
72 {
73 m_store->SelectItem(0);
74 CPPUNIT_ASSERT_EQUAL( 1u, m_store->GetSelectedCount() );
75 CPPUNIT_ASSERT( m_store->IsSelected(0) );
76
77 m_store->SelectItem(NUM_ITEMS - 1);
78 CPPUNIT_ASSERT_EQUAL( 2u, m_store->GetSelectedCount() );
79 CPPUNIT_ASSERT( m_store->IsSelected(NUM_ITEMS - 1) );
80
81 m_store->SelectItem(0, false);
82 CPPUNIT_ASSERT_EQUAL( 1u, m_store->GetSelectedCount() );
83 CPPUNIT_ASSERT( !m_store->IsSelected(0) );
84 }
85
86 void SelStoreTestCase::SelectRange()
87 {
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) );
92
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) );
97
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) );
103 }
104
105 void SelStoreTestCase::SetItemCount()
106 {
107 m_store->SelectRange(1, NUM_ITEMS - 2);
108 CPPUNIT_ASSERT_EQUAL( NUM_ITEMS - 2, m_store->GetSelectedCount() );
109
110 m_store->SetItemCount(NUM_ITEMS/2);
111 CPPUNIT_ASSERT_EQUAL( NUM_ITEMS/2 - 1, m_store->GetSelectedCount() );
112
113
114 m_store->Clear();
115 m_store->SetItemCount(NUM_ITEMS);
116
117
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() );
122 }
123
124 void SelStoreTestCase::Clear()
125 {
126 CPPUNIT_ASSERT_EQUAL( 0u, m_store->GetSelectedCount() );
127
128 m_store->SelectItem(0);
129 m_store->Clear();
130
131 CPPUNIT_ASSERT_EQUAL( 0u, m_store->GetSelectedCount() );
132 }
133