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