1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/itemcontainertest.cpp
3 // Purpose: wxItemContainer unit test
4 // Author: Steven Lamerton
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
14 #include "wx/ctrlsub.h"
17 #include "itemcontainertest.h"
19 void ItemContainerTestCase::Append()
21 wxItemContainer
* const container
= GetContainer();
23 container
->Append("item 0");
25 CPPUNIT_ASSERT_EQUAL("item 0", container
->GetString(0));
27 wxArrayString testitems
;
28 testitems
.Add("item 1");
29 testitems
.Add("item 2");
31 container
->Append(testitems
);
33 CPPUNIT_ASSERT_EQUAL("item 1", container
->GetString(1));
34 CPPUNIT_ASSERT_EQUAL("item 2", container
->GetString(2));
36 wxString arritems
[] = { "item 3", "item 4" };
38 container
->Append(2, arritems
);
40 CPPUNIT_ASSERT_EQUAL("item 3", container
->GetString(3));
41 CPPUNIT_ASSERT_EQUAL("item 4", container
->GetString(4));
44 void ItemContainerTestCase::Insert()
46 wxItemContainer
* const container
= GetContainer();
48 container
->Insert("item 0", 0);
50 CPPUNIT_ASSERT_EQUAL("item 0", container
->GetString(0));
52 wxArrayString testitems
;
53 testitems
.Add("item 1");
54 testitems
.Add("item 2");
56 container
->Insert(testitems
, 0);
58 CPPUNIT_ASSERT_EQUAL("item 1", container
->GetString(0));
59 CPPUNIT_ASSERT_EQUAL("item 2", container
->GetString(1));
61 wxString arritems
[] = { "item 3", "item 4" };
63 container
->Insert(2, arritems
, 1);
65 CPPUNIT_ASSERT_EQUAL("item 3", container
->GetString(1));
66 CPPUNIT_ASSERT_EQUAL("item 4", container
->GetString(2));
69 void ItemContainerTestCase::Count()
71 wxItemContainer
* const container
= GetContainer();
73 CPPUNIT_ASSERT(container
->IsEmpty());
75 wxArrayString testitems
;
76 testitems
.Add("item 0");
77 testitems
.Add("item 1");
78 testitems
.Add("item 2");
79 testitems
.Add("item 3");
81 container
->Append(testitems
);
83 CPPUNIT_ASSERT(!container
->IsEmpty());
84 CPPUNIT_ASSERT_EQUAL(4, container
->GetCount());
88 CPPUNIT_ASSERT_EQUAL(3, container
->GetCount());
93 CPPUNIT_ASSERT_EQUAL(1, container
->GetCount());
95 container
->Insert(testitems
, 1);
97 CPPUNIT_ASSERT_EQUAL(5, container
->GetCount());
100 void ItemContainerTestCase::ItemSelection()
102 wxItemContainer
* const container
= GetContainer();
104 wxArrayString testitems
;
105 testitems
.Add("item 0");
106 testitems
.Add("item 1");
107 testitems
.Add("item 2");
108 testitems
.Add("item 3");
110 container
->Append(testitems
);
112 container
->SetSelection(wxNOT_FOUND
);
114 CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND
, container
->GetSelection());
115 CPPUNIT_ASSERT_EQUAL("", container
->GetStringSelection());
117 container
->SetSelection(1);
119 CPPUNIT_ASSERT_EQUAL(1, container
->GetSelection());
120 CPPUNIT_ASSERT_EQUAL("item 1", container
->GetStringSelection());
122 container
->SetStringSelection("item 2");
124 CPPUNIT_ASSERT_EQUAL(2, container
->GetSelection());
125 CPPUNIT_ASSERT_EQUAL("item 2", container
->GetStringSelection());
128 void ItemContainerTestCase::FindString()
130 wxItemContainer
* const container
= GetContainer();
132 wxArrayString testitems
;
133 testitems
.Add("item 0");
134 testitems
.Add("item 1");
135 testitems
.Add("item 2");
136 testitems
.Add("item 3");
138 container
->Append(testitems
);
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));
145 void ItemContainerTestCase::ClientData()
147 wxItemContainer
* const container
= GetContainer();
149 wxStringClientData
* item0data
= new wxStringClientData("item0data");
150 wxStringClientData
* item1data
= new wxStringClientData("item1data");
151 wxStringClientData
* item2data
= new wxStringClientData("item2data");
153 container
->Append("item 0", item0data
);
155 CPPUNIT_ASSERT_EQUAL(static_cast<wxClientData
*>(item0data
),
156 container
->GetClientObject(0));
158 container
->Append("item 1");
159 container
->SetClientObject(1, item1data
);
161 CPPUNIT_ASSERT_EQUAL(static_cast<wxClientData
*>(item1data
),
162 container
->GetClientObject(1));
164 container
->Insert("item 2", 2, item2data
);
166 CPPUNIT_ASSERT_EQUAL(static_cast<wxClientData
*>(item2data
),
167 container
->GetClientObject(2));
170 void ItemContainerTestCase::VoidData()
172 wxItemContainer
* const container
= GetContainer();
174 wxString
item0data("item0data"), item1data("item0data"),
175 item2data("item0data");
177 void* item0
= &item0data
;
178 void* item1
= &item1data
;
179 void* item2
= &item2data
;
181 container
->Append("item 0", item0
);
183 CPPUNIT_ASSERT_EQUAL(item0
, container
->GetClientData(0));
185 container
->Append("item 1");
186 container
->SetClientData(1, item1
);
188 CPPUNIT_ASSERT_EQUAL(item1
, container
->GetClientData(1));
190 container
->Insert("item 2", 2, item2
);
192 CPPUNIT_ASSERT_EQUAL(item2
, container
->GetClientData(2));
195 void ItemContainerTestCase::Set()
197 wxItemContainer
* const container
= GetContainer();
199 wxArrayString testitems
;
200 testitems
.Add("item 0");
201 testitems
.Add("item 1");
203 container
->Append(testitems
);
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");
211 container
->Set(newtestitems
);
213 CPPUNIT_ASSERT_EQUAL(4, container
->GetCount());
214 CPPUNIT_ASSERT_EQUAL("new item 1", container
->GetString(1));
216 wxString arrnewitems
[] = { "even newer 0", "event newer 1" };
218 container
->Set(2, arrnewitems
);
220 CPPUNIT_ASSERT_EQUAL(2, container
->GetCount());
221 CPPUNIT_ASSERT_EQUAL("even newer 0", container
->GetString(0));
224 void ItemContainerTestCase::SetString()
226 wxItemContainer
* const container
= GetContainer();
228 wxArrayString testitems
;
229 testitems
.Add("item 0");
230 testitems
.Add("item 1");
231 testitems
.Add("item 2");
232 testitems
.Add("item 3");
234 container
->Append(testitems
);
236 container
->SetString(0, "new item 0");
238 container
->SetString(2, "");
241 CPPUNIT_ASSERT_EQUAL("new item 0", container
->GetString(0));
243 CPPUNIT_ASSERT_EQUAL("", container
->GetString(2));