]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/itemcontainertest.cpp
Include wx_presets.py in the distribution made by "make dist".
[wxWidgets.git] / tests / controls / itemcontainertest.cpp
CommitLineData
232fdc63
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/controls/itemcontainertest.cpp
3// Purpose: wxItemContainer unit test
4// Author: Steven Lamerton
5// Created: 2010-06-29
6// RCS-ID: $Id$
7// Copyright: (c) 2010 Steven Lamerton
8///////////////////////////////////////////////////////////////////////////////
9
10#include "testprec.h"
11
12#ifndef WX_PRECOMP
13 #include "wx/app.h"
14 #include "wx/ctrlsub.h"
15#endif // WX_PRECOMP
16
17#include "itemcontainertest.h"
18
19void ItemContainerTestCase::Append()
20{
21 wxItemContainer * const container = GetContainer();
22
23 container->Append("item 0");
24
25 CPPUNIT_ASSERT_EQUAL("item 0", container->GetString(0));
26
27 wxArrayString testitems;
28 testitems.Add("item 1");
29 testitems.Add("item 2");
30
31 container->Append(testitems);
32
33 CPPUNIT_ASSERT_EQUAL("item 1", container->GetString(1));
34 CPPUNIT_ASSERT_EQUAL("item 2", container->GetString(2));
35
36 wxString arritems[] = { "item 3", "item 4" };
37
38 container->Append(2, arritems);
39
40 CPPUNIT_ASSERT_EQUAL("item 3", container->GetString(3));
41 CPPUNIT_ASSERT_EQUAL("item 4", container->GetString(4));
42}
43
44void ItemContainerTestCase::Insert()
45{
46 wxItemContainer * const container = GetContainer();
47
48 container->Insert("item 0", 0);
49
50 CPPUNIT_ASSERT_EQUAL("item 0", container->GetString(0));
51
52 wxArrayString testitems;
53 testitems.Add("item 1");
54 testitems.Add("item 2");
55
56 container->Insert(testitems, 0);
57
58 CPPUNIT_ASSERT_EQUAL("item 1", container->GetString(0));
59 CPPUNIT_ASSERT_EQUAL("item 2", container->GetString(1));
60
61 wxString arritems[] = { "item 3", "item 4" };
62
63 container->Insert(2, arritems, 1);
64
65 CPPUNIT_ASSERT_EQUAL("item 3", container->GetString(1));
66 CPPUNIT_ASSERT_EQUAL("item 4", container->GetString(2));
67}
68
69void ItemContainerTestCase::Count()
70{
71 wxItemContainer * const container = GetContainer();
72
73 CPPUNIT_ASSERT(container->IsEmpty());
74
75 wxArrayString testitems;
76 testitems.Add("item 0");
77 testitems.Add("item 1");
78 testitems.Add("item 2");
79 testitems.Add("item 3");
80
81 container->Append(testitems);
82
83 CPPUNIT_ASSERT(!container->IsEmpty());
84 CPPUNIT_ASSERT_EQUAL(4, container->GetCount());
85
86 container->Delete(0);
87
88 CPPUNIT_ASSERT_EQUAL(3, container->GetCount());
89
90 container->Delete(0);
91 container->Delete(0);
92
93 CPPUNIT_ASSERT_EQUAL(1, container->GetCount());
94
95 container->Insert(testitems, 1);
96
97 CPPUNIT_ASSERT_EQUAL(5, container->GetCount());
98}
99
100void ItemContainerTestCase::ItemSelection()
101{
102 wxItemContainer * const container = GetContainer();
103
104 wxArrayString testitems;
105 testitems.Add("item 0");
106 testitems.Add("item 1");
107 testitems.Add("item 2");
108 testitems.Add("item 3");
109
110 container->Append(testitems);
111
112 container->SetSelection(wxNOT_FOUND);
113
114 CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, container->GetSelection());
115 CPPUNIT_ASSERT_EQUAL("", container->GetStringSelection());
116
117 container->SetSelection(1);
118
119 CPPUNIT_ASSERT_EQUAL(1, container->GetSelection());
120 CPPUNIT_ASSERT_EQUAL("item 1", container->GetStringSelection());
121
122 container->SetStringSelection("item 2");
123
124 CPPUNIT_ASSERT_EQUAL(2, container->GetSelection());
125 CPPUNIT_ASSERT_EQUAL("item 2", container->GetStringSelection());
126}
127
128void ItemContainerTestCase::FindString()
129{
130 wxItemContainer * const container = GetContainer();
131
132 wxArrayString testitems;
133 testitems.Add("item 0");
134 testitems.Add("item 1");
135 testitems.Add("item 2");
136 testitems.Add("item 3");
137
138 container->Append(testitems);
139
140 CPPUNIT_ASSERT_EQUAL(1, container->FindString("item 1"));
141 CPPUNIT_ASSERT_EQUAL(1, container->FindString("ITEM 1"));
142 CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, container->FindString("ITEM 1", true));
143}
144
145void ItemContainerTestCase::ClientData()
146{
147 wxItemContainer * const container = GetContainer();
148
149 wxStringClientData* item0data = new wxStringClientData("item0data");
150 wxStringClientData* item1data = new wxStringClientData("item1data");
151 wxStringClientData* item2data = new wxStringClientData("item2data");
152
153 container->Append("item 0", item0data);
154
155 CPPUNIT_ASSERT_EQUAL(static_cast<wxClientData*>(item0data),
156 container->GetClientObject(0));
157
158 container->Append("item 1");
159 container->SetClientObject(1, item1data);
160
161 CPPUNIT_ASSERT_EQUAL(static_cast<wxClientData*>(item1data),
162 container->GetClientObject(1));
163
164 container->Insert("item 2", 2, item2data);
165
166 CPPUNIT_ASSERT_EQUAL(static_cast<wxClientData*>(item2data),
167 container->GetClientObject(2));
168}
169
170void ItemContainerTestCase::VoidData()
171{
172 wxItemContainer * const container = GetContainer();
173
174 wxString item0data("item0data"), item1data("item0data"),
175 item2data("item0data");
176
177 void* item0 = &item0data;
178 void* item1 = &item1data;
179 void* item2 = &item2data;
180
181 container->Append("item 0", item0);
182
183 CPPUNIT_ASSERT_EQUAL(item0, container->GetClientData(0));
184
185 container->Append("item 1");
186 container->SetClientData(1, item1);
187
188 CPPUNIT_ASSERT_EQUAL(item1, container->GetClientData(1));
189
190 container->Insert("item 2", 2, item2);
191
192 CPPUNIT_ASSERT_EQUAL(item2, container->GetClientData(2));
193}
194
195void ItemContainerTestCase::Set()
196{
197 wxItemContainer * const container = GetContainer();
198
199 wxArrayString testitems;
200 testitems.Add("item 0");
201 testitems.Add("item 1");
202
203 container->Append(testitems);
204
205 wxArrayString newtestitems;
206 newtestitems.Add("new item 0");
207 newtestitems.Add("new item 1");
208 newtestitems.Add("new item 2");
209 newtestitems.Add("new item 3");
210
211 container->Set(newtestitems);
212
213 CPPUNIT_ASSERT_EQUAL(4, container->GetCount());
214 CPPUNIT_ASSERT_EQUAL("new item 1", container->GetString(1));
215
216 wxString arrnewitems[] = { "even newer 0", "event newer 1" };
217
218 container->Set(2, arrnewitems);
219
220 CPPUNIT_ASSERT_EQUAL(2, container->GetCount());
221 CPPUNIT_ASSERT_EQUAL("even newer 0", container->GetString(0));
222}
223
224void ItemContainerTestCase::SetString()
225{
226 wxItemContainer * const container = GetContainer();
227
228 wxArrayString testitems;
229 testitems.Add("item 0");
230 testitems.Add("item 1");
231 testitems.Add("item 2");
232 testitems.Add("item 3");
233
234 container->Append(testitems);
235
236 container->SetString(0, "new item 0");
237#ifndef __WXOSX__
238 container->SetString(2, "");
239#endif
240
241 CPPUNIT_ASSERT_EQUAL("new item 0", container->GetString(0));
242#ifndef __WXOSX__
243 CPPUNIT_ASSERT_EQUAL("", container->GetString(2));
244#endif
245}