]>
Commit | Line | Data |
---|---|---|
1c4293cb VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: samples/propgrid/tests.cpp | |
3 | // Purpose: wxPropertyGrid tests | |
4 | // Author: Jaakko Salli | |
5 | // Modified by: | |
6 | // Created: 2007-05-16 | |
7 | // RCS-ID: $Id: | |
8 | // Copyright: (c) Jaakko Salli | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/wx.h" | |
20 | #endif | |
21 | ||
22 | #include <wx/propgrid/propgrid.h> | |
23 | #include <wx/propgrid/advprops.h> | |
24 | #include <wx/propgrid/manager.h> | |
25 | ||
26 | #include "propgrid.h" | |
27 | #include "sampleprops.h" | |
28 | ||
29 | ||
30 | // ----------------------------------------------------------------------- | |
31 | // Declare custom test properties | |
32 | // ----------------------------------------------------------------------- | |
33 | ||
34 | WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY(wxTestCustomFlagsProperty) | |
35 | ||
36 | WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY(wxTestCustomEnumProperty) | |
37 | ||
38 | ||
39 | // ----------------------------------------------------------------------- | |
40 | // wxTestCustomFlagsProperty | |
41 | // ----------------------------------------------------------------------- | |
42 | ||
43 | // | |
44 | // Constant definitions required by wxFlagsProperty examples. | |
45 | // | |
46 | ||
47 | static const wxChar* _fs_framestyle_labels[] = { | |
48 | wxT("wxCAPTION"), | |
49 | wxT("wxMINIMIZE"), | |
50 | wxT("wxMAXIMIZE"), | |
51 | wxT("wxCLOSE_BOX"), | |
52 | wxT("wxSTAY_ON_TOP"), | |
53 | wxT("wxSYSTEM_MENU"), | |
54 | wxT("wxRESIZE_BORDER"), | |
55 | wxT("wxFRAME_TOOL_WINDOW"), | |
56 | wxT("wxFRAME_NO_TASKBAR"), | |
57 | wxT("wxFRAME_FLOAT_ON_PARENT"), | |
58 | wxT("wxFRAME_SHAPED"), | |
59 | (const wxChar*) NULL | |
60 | }; | |
61 | ||
62 | static const long _fs_framestyle_values[] = { | |
63 | wxCAPTION, | |
64 | wxMINIMIZE, | |
65 | wxMAXIMIZE, | |
66 | wxCLOSE_BOX, | |
67 | wxSTAY_ON_TOP, | |
68 | wxSYSTEM_MENU, | |
69 | wxRESIZE_BORDER, | |
70 | wxFRAME_TOOL_WINDOW, | |
71 | wxFRAME_NO_TASKBAR, | |
72 | wxFRAME_FLOAT_ON_PARENT, | |
73 | wxFRAME_SHAPED | |
74 | }; | |
75 | ||
76 | ||
77 | WX_PG_IMPLEMENT_CUSTOM_FLAGS_PROPERTY(wxTestCustomFlagsProperty, | |
78 | _fs_framestyle_labels, | |
79 | _fs_framestyle_values, | |
80 | wxDEFAULT_FRAME_STYLE) | |
81 | ||
82 | WX_PG_IMPLEMENT_CUSTOM_ENUM_PROPERTY(wxTestCustomEnumProperty, | |
83 | _fs_framestyle_labels, | |
84 | _fs_framestyle_values, | |
85 | wxCAPTION) | |
86 | ||
87 | ||
88 | // Colour labels. Last (before NULL, if any) must be Custom. | |
89 | static const wxChar* mycolprop_labels[] = { | |
90 | wxT("Black"), | |
91 | wxT("Blue"), | |
92 | wxT("Brown"), | |
93 | wxT("Custom"), | |
94 | (const wxChar*) NULL | |
95 | }; | |
96 | ||
97 | // Relevant colour values as unsigned longs. | |
98 | static unsigned long mycolprop_colours[] = { | |
99 | wxPG_COLOUR(0,0,0), | |
100 | wxPG_COLOUR(0,0,255), | |
101 | wxPG_COLOUR(166,124,81), | |
102 | wxPG_COLOUR(0,0,0) | |
103 | }; | |
104 | ||
105 | // Implement property class. Third argument is optional values array, | |
106 | // but in this example we are only interested in creating a shortcut | |
107 | // for user to access the colour values. Last arg is itemcount, but | |
108 | // it will be deprecated in the future. | |
109 | WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(wxMyColourProperty) | |
110 | WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(wxMyColourProperty, | |
111 | mycolprop_labels, | |
112 | (long*)NULL, | |
113 | mycolprop_colours) | |
114 | ||
115 | ||
116 | WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY(wxMyColour2Property) | |
117 | WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(wxMyColour2Property, | |
118 | mycolprop_labels, | |
119 | (long*)NULL, | |
120 | mycolprop_colours) | |
121 | ||
122 | ||
123 | ||
124 | // Just testing the macros | |
125 | WX_PG_DECLARE_STRING_PROPERTY(wxTestStringProperty) | |
126 | WX_PG_IMPLEMENT_STRING_PROPERTY(wxTestStringProperty,wxPG_NO_ESCAPE) | |
127 | bool wxTestStringProperty::OnButtonClick( wxPropertyGrid*, | |
128 | wxString& ) | |
129 | { | |
130 | ::wxMessageBox(wxT("Button Clicked")); | |
131 | return true; | |
132 | } | |
133 | ||
134 | WX_PG_DECLARE_STRING_PROPERTY(wxTextStringPropertyWithValidator) | |
135 | WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(wxTextStringPropertyWithValidator, | |
136 | wxPG_NO_ESCAPE) | |
137 | ||
138 | bool wxTextStringPropertyWithValidator::OnButtonClick( wxPropertyGrid* WXUNUSED(propgrid), | |
139 | wxString& WXUNUSED(value) ) | |
140 | { | |
141 | ::wxMessageBox(wxT("Button Clicked")); | |
142 | return true; | |
143 | } | |
144 | ||
145 | wxValidator* wxTextStringPropertyWithValidator::DoGetValidator() const | |
146 | { | |
147 | #if wxUSE_VALIDATORS | |
148 | WX_PG_DOGETVALIDATOR_ENTRY() | |
149 | wxTextValidator* validator = new | |
150 | wxTextValidator(wxFILTER_INCLUDE_CHAR_LIST); | |
151 | wxArrayString oValid; | |
152 | oValid.Add(wxT("0")); | |
153 | oValid.Add(wxT("1")); | |
154 | oValid.Add(wxT("2")); | |
155 | oValid.Add(wxT("3")); | |
156 | oValid.Add(wxT("4")); | |
157 | oValid.Add(wxT("5")); | |
158 | oValid.Add(wxT("6")); | |
159 | oValid.Add(wxT("7")); | |
160 | oValid.Add(wxT("8")); | |
161 | oValid.Add(wxT("9")); | |
162 | oValid.Add(wxT("$")); | |
163 | validator->SetIncludes(oValid); | |
164 | WX_PG_DOGETVALIDATOR_EXIT(validator) | |
165 | #else | |
166 | return NULL; | |
167 | #endif | |
168 | } | |
169 | ||
170 | // ----------------------------------------------------------------------- | |
171 | ||
172 | // | |
173 | // Test customizing wxColourProperty via subclassing | |
174 | // | |
175 | // * Includes custom colour entry. | |
176 | // * Includes extra custom entry. | |
177 | // | |
178 | class MyColourProperty3 : public wxColourProperty | |
179 | { | |
180 | public: | |
181 | MyColourProperty3( const wxString& label = wxPG_LABEL, | |
182 | const wxString& name = wxPG_LABEL, | |
183 | const wxColour& value = *wxWHITE ) | |
184 | : wxColourProperty(label, name, value) | |
185 | { | |
186 | wxPGChoices colours; | |
187 | colours.Add(wxT("White")); | |
188 | colours.Add(wxT("Black")); | |
189 | colours.Add(wxT("Red")); | |
190 | colours.Add(wxT("Green")); | |
191 | colours.Add(wxT("Blue")); | |
192 | colours.Add(wxT("Custom")); | |
193 | colours.Add(wxT("None")); | |
194 | m_choices = colours; | |
195 | SetIndex(0); | |
196 | wxVariant variant; | |
197 | variant << value; | |
198 | SetValue(variant); | |
199 | } | |
200 | ||
201 | virtual ~MyColourProperty3() | |
202 | { | |
203 | } | |
204 | ||
205 | virtual wxColour GetColour( int index ) const | |
206 | { | |
207 | switch (index) | |
208 | { | |
209 | case 0: return *wxWHITE; | |
210 | case 1: return *wxBLACK; | |
211 | case 2: return *wxRED; | |
212 | case 3: return *wxGREEN; | |
213 | case 4: return *wxBLUE; | |
214 | case 5: | |
215 | // Return current colour for the custom entry | |
216 | wxColour col; | |
217 | if ( GetIndex() == GetCustomColourIndex() ) | |
218 | { | |
219 | if ( m_value.IsNull() ) | |
220 | return col; | |
221 | col << m_value; | |
222 | return col; | |
223 | } | |
224 | return *wxWHITE; | |
225 | }; | |
226 | return wxColour(); | |
227 | } | |
228 | ||
229 | virtual wxString ColourToString( const wxColour& col, int index ) const | |
230 | { | |
231 | if ( index == (int)(m_choices.GetCount()-1) ) | |
232 | return wxT(""); | |
233 | ||
234 | return wxColourProperty::ColourToString(col, index); | |
235 | } | |
236 | ||
237 | virtual int GetCustomColourIndex() const | |
238 | { | |
239 | return m_choices.GetCount()-2; | |
240 | } | |
241 | }; | |
242 | ||
243 | ||
244 | void FormMain::AddTestProperties( wxPropertyGridPage* pg ) | |
245 | { | |
246 | pg->Append( new wxTestCustomFlagsProperty(wxT("Custom FlagsProperty"), wxPG_LABEL ) ); | |
247 | pg->SetPropertyEditor( wxT("Custom FlagsProperty"), wxPG_EDITOR(TextCtrlAndButton) ); | |
248 | ||
249 | pg->Append( new wxTestCustomEnumProperty(wxT("Custom EnumProperty"), wxPG_LABEL ) ); | |
250 | ||
251 | pg->Append( new wxMyColourProperty(wxT("CustomColourProperty1")) ); | |
252 | ||
253 | pg->SetPropertyHelpString(wxT("CustomColourProperty1"), | |
254 | wxT("This is a wxMyColourProperty from the sample app. ") | |
255 | wxT("It is built with WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR macro ") | |
256 | wxT("and has wxColour as its data type")); | |
257 | ||
258 | pg->Append( new wxMyColour2Property(wxT("CustomColourProperty2")) ); | |
259 | ||
260 | pg->SetPropertyHelpString(wxT("CustomColourProperty2"), | |
261 | wxT("This is a wxMyColour2Property from the sample app. ") | |
262 | wxT("It is built with WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY macro ") | |
263 | wxT("and has wxColourPropertyValue as its data type")); | |
264 | ||
265 | pg->Append( new MyColourProperty3(wxT("CustomColourProperty3"), wxPG_LABEL, *wxGREEN) ); | |
266 | pg->GetProperty(wxT("CustomColourProperty3"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED); | |
267 | pg->SetPropertyEditor( wxT("CustomColourProperty3"), wxPG_EDITOR(ComboBox) ); | |
268 | ||
269 | pg->SetPropertyHelpString(wxT("CustomColourProperty3"), | |
270 | wxT("This is a MyColourProperty3 from the sample app. ") | |
271 | wxT("It is built by subclassing wxColourProperty.")); | |
272 | ||
273 | pg->Append( new wxTextStringPropertyWithValidator(wxT("TestProp1"), wxPG_LABEL) ); | |
274 | } | |
275 | ||
276 | // ----------------------------------------------------------------------- | |
277 | ||
278 | void FormMain::OnDumpList( wxCommandEvent& WXUNUSED(event) ) | |
279 | { | |
280 | wxVariant values = m_pPropGridManager->GetPropertyValues(wxT("list"), wxNullProperty, wxPG_INC_ATTRIBUTES); | |
281 | wxString text = wxT("This only tests that wxVariant related routines do not crash."); | |
282 | wxString t; | |
283 | ||
284 | wxDialog* dlg = new wxDialog(this,-1,wxT("wxVariant Test"), | |
285 | wxDefaultPosition,wxDefaultSize,wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER); | |
286 | ||
287 | unsigned int i; | |
288 | for ( i = 0; i < (unsigned int)values.GetCount(); i++ ) | |
289 | { | |
290 | wxVariant& v = values[i]; | |
291 | ||
292 | wxString strValue = v.GetString(); | |
293 | ||
294 | #if wxCHECK_VERSION(2,8,0) | |
295 | if ( v.GetName().EndsWith(wxT("@attr")) ) | |
296 | #else | |
297 | if ( v.GetName().Right(5) == wxT("@attr") ) | |
298 | #endif | |
299 | { | |
300 | text += wxString::Format(wxT("Attributes:\n")); | |
301 | ||
302 | unsigned int n; | |
303 | for ( n = 0; n < (unsigned int)v.GetCount(); n++ ) | |
304 | { | |
305 | wxVariant& a = v[n]; | |
306 | ||
307 | t.Printf(wxT(" atribute %i: name=\"%s\" (type=\"%s\" value=\"%s\")\n"),(int)n, | |
308 | a.GetName().c_str(),a.GetType().c_str(),a.GetString().c_str()); | |
309 | text += t; | |
310 | } | |
311 | } | |
312 | else | |
313 | { | |
314 | t.Printf(wxT("%i: name=\"%s\" type=\"%s\" value=\"%s\"\n"),(int)i, | |
315 | v.GetName().c_str(),v.GetType().c_str(),strValue.c_str()); | |
316 | text += t; | |
317 | } | |
318 | } | |
319 | ||
320 | // multi-line text editor dialog | |
321 | const int spacing = 8; | |
322 | wxBoxSizer* topsizer = new wxBoxSizer( wxVERTICAL ); | |
323 | wxBoxSizer* rowsizer = new wxBoxSizer( wxHORIZONTAL ); | |
324 | wxTextCtrl* ed = new wxTextCtrl(dlg,11,text, | |
325 | wxDefaultPosition,wxDefaultSize,wxTE_MULTILINE|wxTE_READONLY); | |
326 | rowsizer->Add( ed, 1, wxEXPAND|wxALL, spacing ); | |
327 | topsizer->Add( rowsizer, 1, wxEXPAND, 0 ); | |
328 | rowsizer = new wxBoxSizer( wxHORIZONTAL ); | |
329 | const int butSzFlags = | |
330 | wxALIGN_CENTRE_HORIZONTAL|wxALIGN_CENTRE_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT; | |
331 | rowsizer->Add( new wxButton(dlg,wxID_OK,wxT("Ok")), | |
332 | 0, butSzFlags, spacing ); | |
333 | topsizer->Add( rowsizer, 0, wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL, 0 ); | |
334 | ||
335 | dlg->SetSizer( topsizer ); | |
336 | topsizer->SetSizeHints( dlg ); | |
337 | ||
338 | dlg->SetSize(400,300); | |
339 | dlg->Centre(); | |
340 | dlg->ShowModal(); | |
341 | } | |
342 | ||
343 | // ----------------------------------------------------------------------- | |
344 | ||
345 | class TestRunner | |
346 | { | |
347 | public: | |
348 | ||
349 | TestRunner( const wxString& name, wxPropertyGridManager* man, wxTextCtrl* ed, wxArrayString* errorMessages ) | |
350 | { | |
351 | m_name = name; | |
352 | m_man = man; | |
353 | m_ed = ed; | |
354 | m_errorMessages = errorMessages; | |
355 | #ifdef __WXDEBUG__ | |
356 | m_preWarnings = wxPGGlobalVars->m_warnings; | |
357 | #endif | |
358 | ||
359 | if ( name != wxT("none") ) | |
360 | Msg(name+wxT("\n")); | |
361 | } | |
362 | ||
363 | ~TestRunner() | |
364 | { | |
365 | #ifdef __WXDEBUG__ | |
366 | int warningsOccurred = wxPGGlobalVars->m_warnings - m_preWarnings; | |
367 | if ( warningsOccurred ) | |
368 | { | |
369 | wxString s = wxString::Format(wxT("%i warnings occurred during test '%s'"), warningsOccurred, m_name.c_str()); | |
370 | m_errorMessages->push_back(s); | |
371 | Msg(s); | |
372 | } | |
373 | #endif | |
374 | } | |
375 | ||
376 | void Msg( const wxString& text ) | |
377 | { | |
378 | if ( m_ed ) | |
379 | { | |
380 | m_ed->AppendText(text); | |
381 | m_ed->AppendText(wxT("\n")); | |
382 | } | |
383 | wxLogDebug(text); | |
384 | } | |
385 | ||
386 | protected: | |
387 | wxPropertyGridManager* m_man; | |
388 | wxTextCtrl* m_ed; | |
389 | wxArrayString* m_errorMessages; | |
390 | wxString m_name; | |
391 | #ifdef __WXDEBUG__ | |
392 | int m_preWarnings; | |
393 | #endif | |
394 | }; | |
395 | ||
396 | ||
397 | #define RT_START_TEST(TESTNAME) \ | |
398 | TestRunner tr(wxT(#TESTNAME), pgman, ed, &errorMessages); | |
399 | ||
400 | #define RT_MSG(S) \ | |
401 | tr.Msg(S); | |
402 | ||
403 | #define RT_FAILURE() \ | |
404 | { \ | |
405 | wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \ | |
406 | errorMessages.push_back(s1); \ | |
407 | wxLogDebug(s1); \ | |
408 | failures++; \ | |
409 | } | |
410 | ||
411 | #define RT_FAILURE_MSG(MSG) \ | |
412 | { \ | |
413 | wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \ | |
414 | errorMessages.push_back(s1); \ | |
415 | wxLogDebug(s1); \ | |
416 | wxString s2 = wxString::Format(wxT("Message: %s"),MSG); \ | |
417 | errorMessages.push_back(s2); \ | |
418 | wxLogDebug(s2); \ | |
419 | failures++; \ | |
420 | } | |
421 | ||
422 | #define RT_VALIDATE_VIRTUAL_HEIGHT(PROPS, EXTRATEXT) \ | |
423 | { \ | |
424 | unsigned int h1_ = PROPS->GetVirtualHeight(); \ | |
425 | unsigned int h2_ = PROPS->GetActualVirtualHeight(); \ | |
426 | if ( h1_ != h2_ ) \ | |
427 | { \ | |
428 | wxString s_ = wxString::Format(wxT("VirtualHeight = %i, should be %i (%s)"), h1_, h2_, EXTRATEXT.c_str()); \ | |
429 | RT_FAILURE_MSG(s_.c_str()); \ | |
430 | _failed_ = true; \ | |
431 | } \ | |
432 | else \ | |
433 | { \ | |
434 | _failed_ = false; \ | |
435 | } \ | |
436 | } | |
437 | ||
438 | ||
439 | int gpiro_cmpfunc(const void* a, const void* b) | |
440 | { | |
441 | const wxPGProperty* p1 = (const wxPGProperty*) a; | |
442 | const wxPGProperty* p2 = (const wxPGProperty*) b; | |
443 | return (int) (((size_t)p1->GetClientData()) - ((size_t)p2->GetClientData())); | |
444 | } | |
445 | ||
446 | wxArrayPGProperty GetPropertiesInRandomOrder( wxPropertyGridInterface* props, int iterationFlags = wxPG_ITERATE_ALL ) | |
447 | { | |
448 | wxArrayPGProperty arr; | |
449 | ||
450 | wxPropertyGridIterator it; | |
451 | ||
452 | for ( it = props->GetIterator(iterationFlags); | |
453 | !it.AtEnd(); | |
454 | it++ ) | |
455 | { | |
456 | wxPGProperty* p = *it; | |
457 | size_t randomNumber = rand(); | |
458 | p->SetClientData(reinterpret_cast<void*>(randomNumber)); | |
459 | arr.push_back(p); | |
460 | } | |
461 | ||
462 | wxPGProperty** firstEntry = &arr[0]; | |
463 | qsort(firstEntry, arr.size(), sizeof(wxPGProperty*), gpiro_cmpfunc); | |
464 | ||
465 | return arr; | |
466 | } | |
467 | ||
468 | static void PropertiesToNames( wxPropertyGridInterface* WXUNUSED(iface), | |
469 | wxArrayString* names, | |
470 | const wxArrayPGProperty& properties ) | |
471 | { | |
472 | unsigned int i; | |
473 | for ( i=0; i<properties.size(); i++ ) | |
474 | names->Add( properties[i]->GetName() ); | |
475 | } | |
476 | ||
477 | static void NamesToProperties( wxPropertyGridInterface* iface, | |
478 | wxArrayPGProperty* properties, | |
479 | const wxArrayString& names ) | |
480 | { | |
481 | unsigned int i; | |
482 | for ( i=0; i<names.size(); i++ ) | |
483 | { | |
484 | wxPGProperty* p = iface->GetPropertyByName(names[i]); | |
485 | if ( p ) | |
486 | properties->push_back(p); | |
487 | } | |
488 | } | |
489 | ||
490 | bool FormMain::RunTests( bool fullTest, bool interactive ) | |
491 | { | |
492 | wxString t; | |
493 | ||
494 | wxPropertyGridManager* pgman = m_pPropGridManager; | |
495 | wxPropertyGrid* pg; | |
496 | ||
497 | size_t i; | |
498 | ||
499 | pgman->ClearSelection(); | |
500 | ||
501 | int failures = 0; | |
502 | bool _failed_ = false; | |
503 | wxArrayString errorMessages; | |
504 | wxDialog* dlg = NULL; | |
505 | ||
506 | dlg = new wxDialog(this,-1,wxT("wxPropertyGrid Regression Tests"), | |
507 | wxDefaultPosition,wxDefaultSize,wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER); | |
508 | ||
509 | // multi-line text editor dialog | |
510 | const int spacing = 8; | |
511 | wxBoxSizer* topsizer = new wxBoxSizer( wxVERTICAL ); | |
512 | wxBoxSizer* rowsizer = new wxBoxSizer( wxHORIZONTAL ); | |
513 | wxTextCtrl* ed = new wxTextCtrl(dlg,11,wxEmptyString, | |
514 | wxDefaultPosition,wxDefaultSize,wxTE_MULTILINE|wxTE_READONLY); | |
515 | rowsizer->Add( ed, 1, wxEXPAND|wxALL, spacing ); | |
516 | topsizer->Add( rowsizer, 1, wxEXPAND, 0 ); | |
517 | rowsizer = new wxBoxSizer( wxHORIZONTAL ); | |
518 | const int butSzFlags = | |
519 | wxALIGN_CENTRE_HORIZONTAL|wxALIGN_CENTRE_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT; | |
520 | rowsizer->Add( new wxButton(dlg,wxID_OK,wxT("Ok")), | |
521 | 0, butSzFlags, spacing ); | |
522 | topsizer->Add( rowsizer, 0, wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL, 0 ); | |
523 | ||
524 | dlg->SetSizer( topsizer ); | |
525 | topsizer->SetSizeHints( dlg ); | |
526 | ||
527 | dlg->SetSize(400,300); | |
528 | dlg->Move(wxSystemSettings::GetMetric(wxSYS_SCREEN_X)-dlg->GetSize().x, | |
529 | wxSystemSettings::GetMetric(wxSYS_SCREEN_Y)-dlg->GetSize().y); | |
530 | dlg->Show(); | |
531 | ||
532 | { | |
533 | // | |
534 | // Basic iterator tests | |
535 | RT_START_TEST(GetIterator) | |
536 | ||
537 | wxPGVIterator it; | |
538 | int count; | |
539 | ||
540 | count = 0; | |
541 | for ( it = pgman->GetVIterator(wxPG_ITERATE_PROPERTIES); | |
542 | !it.AtEnd(); | |
543 | it.Next() ) | |
544 | { | |
545 | wxPGProperty* p = it.GetProperty(); | |
546 | if ( p->IsCategory() ) | |
547 | RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a category (non-private child property expected)"),p->GetLabel().c_str()).c_str()) | |
548 | else if ( p->GetParent()->HasFlag(wxPG_PROP_AGGREGATE) ) | |
549 | RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property expected)"),p->GetLabel().c_str()).c_str()) | |
550 | count++; | |
551 | } | |
552 | ||
553 | RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES) -> %i entries"), count)); | |
554 | ||
555 | count = 0; | |
556 | for ( it = pgman->GetVIterator(wxPG_ITERATE_CATEGORIES); | |
557 | !it.AtEnd(); | |
558 | it.Next() ) | |
559 | { | |
560 | wxPGProperty* p = it.GetProperty(); | |
561 | if ( !p->IsCategory() ) | |
562 | RT_FAILURE_MSG(wxString::Format(wxT("'%s' is not a category (only category was expected)"),p->GetLabel().c_str()).c_str()) | |
563 | count++; | |
564 | } | |
565 | ||
566 | RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_CATEGORIES) -> %i entries"), count)); | |
567 | ||
568 | count = 0; | |
569 | for ( it = pgman->GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES); | |
570 | !it.AtEnd(); | |
571 | it.Next() ) | |
572 | { | |
573 | wxPGProperty* p = it.GetProperty(); | |
574 | if ( p->GetParent()->HasFlag(wxPG_PROP_AGGREGATE) ) | |
575 | RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property or category expected)"),p->GetLabel().c_str()).c_str()) | |
576 | count++; | |
577 | } | |
578 | ||
579 | RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES) -> %i entries"), count)); | |
580 | ||
581 | count = 0; | |
582 | for ( it = pgman->GetVIterator(wxPG_ITERATE_VISIBLE); | |
583 | !it.AtEnd(); | |
584 | it.Next() ) | |
585 | { | |
586 | wxPGProperty* p = it.GetProperty(); | |
587 | if ( (p->GetParent() != p->GetParentState()->DoGetRoot() && !p->GetParent()->IsExpanded()) ) | |
588 | RT_FAILURE_MSG(wxString::Format(wxT("'%s' had collapsed parent (only visible properties expected)"),p->GetLabel().c_str()).c_str()) | |
589 | else if ( p->HasFlag(wxPG_PROP_HIDDEN) ) | |
590 | RT_FAILURE_MSG(wxString::Format(wxT("'%s' was hidden (only visible properties expected)"),p->GetLabel().c_str()).c_str()) | |
591 | count++; | |
592 | } | |
593 | ||
594 | RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_VISIBLE) -> %i entries"), count)); | |
595 | } | |
596 | ||
597 | if ( fullTest ) | |
598 | { | |
599 | // Test that setting focus to properties does not crash things | |
600 | RT_START_TEST(SelectProperty) | |
601 | ||
602 | wxPropertyGridIterator it; | |
603 | size_t ind; | |
604 | ||
605 | for ( ind=0; ind<pgman->GetPageCount(); ind++ ) | |
606 | { | |
607 | wxPropertyGridPage* page = pgman->GetPage(ind); | |
608 | pgman->SelectPage(page); | |
609 | ||
610 | for ( it = page->GetIterator(wxPG_ITERATE_VISIBLE); | |
611 | !it.AtEnd(); | |
612 | it++ ) | |
613 | { | |
614 | wxPGProperty* p = *it; | |
615 | RT_MSG(p->GetLabel()); | |
616 | pgman->GetGrid()->SelectProperty(p, true); | |
617 | ::wxMilliSleep(150); | |
618 | Update(); | |
619 | } | |
620 | } | |
621 | } | |
622 | ||
623 | { | |
624 | RT_START_TEST(GetPropertiesWithFlag) | |
625 | ||
626 | // | |
627 | // Get list of expanded properties | |
628 | wxArrayPGProperty array = pgman->GetExpandedProperties(); | |
629 | ||
630 | // Make sure list only has items with children | |
631 | for ( i=0; i<array.size(); i++ ) | |
632 | { | |
633 | wxPGProperty* p = array[i]; | |
634 | if ( !p->IsKindOf(CLASSINFO(wxPGProperty)) ) | |
635 | RT_FAILURE_MSG(wxString::Format(wxT("'%s' was returned by GetExpandedProperties(), but was not a parent"),p->GetName().c_str()).c_str()); | |
636 | } | |
637 | ||
638 | wxArrayString names; | |
639 | PropertiesToNames( pgman, &names, array ); | |
640 | ||
641 | // | |
642 | // ... and then collapse them | |
643 | wxArrayPGProperty array2; | |
644 | NamesToProperties( pgman, &array2, names ); | |
645 | ||
646 | for ( i=0; i<array2.size(); i++ ) | |
647 | { | |
648 | wxPGProperty* p = array[i]; | |
649 | p->SetExpanded(false); | |
650 | } | |
651 | ||
652 | // Make sure everything is collapsed | |
653 | wxPGVIterator it; | |
654 | ||
655 | for ( it = pgman->GetVIterator(wxPG_ITERATE_ALL); | |
656 | !it.AtEnd(); | |
657 | it.Next() ) | |
658 | { | |
659 | wxPGProperty* p = it.GetProperty(); | |
660 | if ( p->IsExpanded() ) | |
661 | RT_FAILURE_MSG(wxString::Format(wxT("'%s.%s' was expanded"),p->GetParent()->GetName().c_str(),p->GetName().c_str()).c_str()); | |
662 | } | |
663 | ||
664 | pgman->Refresh(); | |
665 | } | |
666 | ||
667 | { | |
668 | // | |
669 | // Delete everything in reverse order | |
670 | RT_START_TEST(DeleteProperty) | |
671 | ||
672 | wxPGVIterator it; | |
673 | wxArrayPGProperty array; | |
674 | ||
675 | for ( it = pgman->GetVIterator(wxPG_ITERATE_ALL&~(wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE))); | |
676 | !it.AtEnd(); | |
677 | it.Next() ) | |
678 | array.push_back(it.GetProperty()); | |
679 | ||
680 | wxArrayPGProperty::reverse_iterator it2; | |
681 | ||
682 | for ( it2 = array.rbegin(); it2 != array.rend(); it2++ ) | |
683 | { | |
684 | wxPGProperty* p = (wxPGProperty*)*it2; | |
685 | RT_MSG(wxString::Format(wxT("Deleting '%s' ('%s')"),p->GetLabel().c_str(),p->GetName().c_str())); | |
686 | pgman->DeleteProperty(p); | |
687 | } | |
688 | ||
689 | // Recreate grid | |
690 | CreateGrid( -1, -1 ); | |
691 | pgman = m_pPropGridManager; | |
692 | } | |
693 | ||
694 | { | |
695 | // | |
696 | // Clear property value | |
697 | RT_START_TEST(ClearPropertyValue) | |
698 | ||
699 | wxPGVIterator it; | |
700 | ||
701 | for ( it = pgman->GetVIterator(wxPG_ITERATE_PROPERTIES); | |
702 | !it.AtEnd(); | |
703 | it.Next() ) | |
704 | { | |
705 | RT_MSG(wxString::Format(wxT("Clearing value of '%s'"),it.GetProperty()->GetLabel().c_str())); | |
706 | pgman->ClearPropertyValue(it.GetProperty()); | |
707 | } | |
708 | ||
709 | // Recreate grid | |
710 | CreateGrid( -1, -1 ); | |
711 | pgman = m_pPropGridManager; | |
712 | } | |
713 | ||
714 | { | |
715 | RT_START_TEST(GetPropertyValues) | |
716 | ||
717 | for ( i=0; i<3; i++ ) | |
718 | { | |
719 | wxString text; | |
720 | ||
721 | wxPropertyGridPage* page = pgman->GetPage(i); | |
722 | ||
723 | wxVariant values = page->GetPropertyValues(); | |
724 | ||
725 | unsigned int i; | |
726 | for ( i = 0; i < (unsigned int)values.GetCount(); i++ ) | |
727 | { | |
728 | wxVariant& v = values[i]; | |
729 | ||
730 | t.Printf(wxT("%i: name=\"%s\" type=\"%s\"\n"),(int)i, | |
731 | v.GetName().c_str(),v.GetType().c_str()); | |
732 | ||
733 | text += t; | |
734 | } | |
735 | ed->AppendText(text); | |
736 | } | |
737 | } | |
738 | ||
739 | { | |
740 | RT_START_TEST(SetPropertyValue_and_GetPropertyValue) | |
741 | ||
f3793429 JS |
742 | // In this section, mixed up usage of wxT("propname") and "propname" |
743 | // in wxPropertyGridInterface functions is intentional. | |
744 | // Purpose is to test wxPGPropArgCls ctors. | |
745 | ||
1c4293cb VZ |
746 | //pg = (wxPropertyGrid*) NULL; |
747 | ||
748 | wxArrayString test_arrstr_1; | |
749 | test_arrstr_1.Add(wxT("Apple")); | |
750 | test_arrstr_1.Add(wxT("Orange")); | |
751 | test_arrstr_1.Add(wxT("Lemon")); | |
752 | ||
753 | wxArrayString test_arrstr_2; | |
754 | test_arrstr_2.Add(wxT("Potato")); | |
755 | test_arrstr_2.Add(wxT("Cabbage")); | |
756 | test_arrstr_2.Add(wxT("Cucumber")); | |
757 | ||
758 | wxArrayInt test_arrint_1; | |
759 | test_arrint_1.Add(1); | |
760 | test_arrint_1.Add(2); | |
761 | test_arrint_1.Add(3); | |
762 | ||
763 | wxArrayInt test_arrint_2; | |
764 | test_arrint_2.Add(0); | |
765 | test_arrint_2.Add(1); | |
766 | test_arrint_2.Add(4); | |
767 | ||
768 | #if wxUSE_DATETIME | |
769 | wxDateTime dt1 = wxDateTime::Now(); | |
770 | dt1.SetYear(dt1.GetYear()-1); | |
771 | ||
772 | wxDateTime dt2 = wxDateTime::Now(); | |
773 | dt2.SetYear(dt2.GetYear()-10); | |
774 | #endif | |
775 | ||
776 | #define FLAG_TEST_SET1 (wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER) | |
777 | #define FLAG_TEST_SET2 (wxSTAY_ON_TOP|wxCAPTION|wxICONIZE|wxSYSTEM_MENU) | |
778 | ||
779 | pgman->SetPropertyValue(wxT("StringProperty"),wxT("Text1")); | |
780 | pgman->SetPropertyValue(wxT("IntProperty"),1024); | |
781 | pgman->SetPropertyValue(wxT("FloatProperty"),1024.0000000001); | |
782 | pgman->SetPropertyValue(wxT("BoolProperty"),FALSE); | |
783 | pgman->SetPropertyValue(wxT("EnumProperty"),120); | |
784 | pgman->SetPropertyValue(wxT("Custom FlagsProperty"),FLAG_TEST_SET1); | |
785 | pgman->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_1); | |
786 | wxColour emptyCol; | |
787 | pgman->SetPropertyValue(wxT("ColourProperty"),emptyCol); | |
788 | pgman->SetPropertyValue(wxT("ColourProperty"),(wxObject*)wxBLACK); | |
789 | pgman->SetPropertyValue(wxT("Size"),wxSize(150,150)); | |
790 | pgman->SetPropertyValue(wxT("Position"),wxPoint(150,150)); | |
791 | pgman->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_1); | |
792 | #if wxUSE_DATETIME | |
793 | pgman->SetPropertyValue(wxT("DateProperty"),dt1); | |
794 | #endif | |
795 | ||
796 | pgman->SelectPage(2); | |
797 | pg = pgman->GetGrid(); | |
798 | ||
799 | if ( pg->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text1") ) | |
800 | RT_FAILURE(); | |
801 | if ( pg->GetPropertyValueAsInt(wxT("IntProperty")) != 1024 ) | |
802 | RT_FAILURE(); | |
803 | if ( pg->GetPropertyValueAsDouble(wxT("FloatProperty")) != 1024.0000000001 ) | |
804 | RT_FAILURE(); | |
805 | if ( pg->GetPropertyValueAsBool(wxT("BoolProperty")) != FALSE ) | |
806 | RT_FAILURE(); | |
807 | if ( pg->GetPropertyValueAsLong(wxT("EnumProperty")) != 120 ) | |
808 | RT_FAILURE(); | |
809 | if ( pg->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_1 ) | |
810 | RT_FAILURE(); | |
811 | if ( pg->GetPropertyValueAsLong(wxT("Custom FlagsProperty")) != FLAG_TEST_SET1 ) | |
812 | RT_FAILURE(); | |
813 | wxColour col; | |
814 | col << pgman->GetPropertyValue(wxT("ColourProperty")); | |
815 | if ( col != *wxBLACK ) | |
816 | RT_FAILURE(); | |
817 | if ( pg->GetPropertyValueAsSize(wxT("Size")) != wxSize(150,150) ) | |
818 | RT_FAILURE(); | |
819 | if ( pg->GetPropertyValueAsPoint(wxT("Position")) != wxPoint(150,150) ) | |
820 | RT_FAILURE(); | |
821 | if ( !(pg->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_1) ) | |
822 | RT_FAILURE(); | |
823 | #if wxUSE_DATETIME | |
824 | if ( !(pg->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt1) ) | |
825 | RT_FAILURE(); | |
826 | #endif | |
827 | ||
828 | pgman->SetPropertyValue(wxT("IntProperty"),wxLL(10000000000)); | |
829 | if ( pg->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(10000000000) ) | |
830 | RT_FAILURE(); | |
831 | ||
832 | pg->SetPropertyValue(wxT("StringProperty"),wxT("Text2")); | |
833 | pg->SetPropertyValue(wxT("IntProperty"),512); | |
834 | pg->SetPropertyValue(wxT("FloatProperty"),512.0); | |
835 | pg->SetPropertyValue(wxT("BoolProperty"),TRUE); | |
836 | pg->SetPropertyValue(wxT("EnumProperty"),80); | |
837 | pg->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_2); | |
838 | pg->SetPropertyValue(wxT("Custom FlagsProperty"),FLAG_TEST_SET2); | |
839 | pg->SetPropertyValue(wxT("ColourProperty"),(wxObject*)wxWHITE); | |
840 | pg->SetPropertyValue(wxT("Size"),wxSize(300,300)); | |
841 | pg->SetPropertyValue(wxT("Position"),wxPoint(300,300)); | |
842 | pg->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_2); | |
843 | #if wxUSE_DATETIME | |
844 | pg->SetPropertyValue(wxT("DateProperty"),dt2); | |
845 | #endif | |
846 | ||
847 | //pg = (wxPropertyGrid*) NULL; | |
848 | ||
849 | pgman->SelectPage(0); | |
850 | ||
851 | if ( pgman->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text2") ) | |
852 | RT_FAILURE(); | |
853 | if ( pgman->GetPropertyValueAsInt(wxT("IntProperty")) != 512 ) | |
854 | RT_FAILURE(); | |
855 | if ( pgman->GetPropertyValueAsDouble(wxT("FloatProperty")) != 512.0 ) | |
856 | RT_FAILURE(); | |
857 | if ( pgman->GetPropertyValueAsBool(wxT("BoolProperty")) != TRUE ) | |
858 | RT_FAILURE(); | |
859 | if ( pgman->GetPropertyValueAsLong(wxT("EnumProperty")) != 80 ) | |
860 | RT_FAILURE(); | |
861 | if ( pgman->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_2 ) | |
862 | RT_FAILURE(); | |
863 | if ( pgman->GetPropertyValueAsLong(wxT("Custom FlagsProperty")) != FLAG_TEST_SET2 ) | |
864 | RT_FAILURE(); | |
865 | col << pgman->GetPropertyValue(wxT("ColourProperty")); | |
866 | if ( col != *wxWHITE ) | |
867 | RT_FAILURE(); | |
868 | if ( pgman->GetPropertyValueAsSize(wxT("Size")) != wxSize(300,300) ) | |
869 | RT_FAILURE(); | |
870 | if ( pgman->GetPropertyValueAsPoint(wxT("Position")) != wxPoint(300,300) ) | |
871 | RT_FAILURE(); | |
872 | if ( !(pgman->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_2) ) | |
873 | RT_FAILURE(); | |
874 | #if wxUSE_DATETIME | |
875 | if ( !(pgman->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt2) ) | |
876 | RT_FAILURE(); | |
877 | #endif | |
878 | ||
879 | pgman->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000)); | |
880 | if ( pgman->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) ) | |
881 | RT_FAILURE(); | |
8f18b252 JS |
882 | |
883 | // Make sure children of composite parent get updated as well | |
884 | // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000" | |
885 | ||
f3793429 | 886 | // |
8f18b252 JS |
887 | // This updates children as well |
888 | wxString nvs = "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002"; | |
f3793429 | 889 | pgman->SetPropertyValue("Car", nvs); |
8f18b252 | 890 | |
f3793429 | 891 | if ( pgman->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" ) |
8f18b252 | 892 | { |
f3793429 | 893 | wxLogDebug("Did not match: Car.Model=%s", pgman->GetPropertyValueAsString("Car.Model").c_str()); |
8f18b252 JS |
894 | RT_FAILURE(); |
895 | } | |
896 | ||
f3793429 | 897 | if ( pgman->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 ) |
8f18b252 | 898 | { |
f3793429 | 899 | wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str()); |
8f18b252 JS |
900 | RT_FAILURE(); |
901 | } | |
902 | ||
f3793429 | 903 | if ( pgman->GetPropertyValueAsInt("Car.Price ($)") != 3000002 ) |
8f18b252 | 904 | { |
f3793429 | 905 | wxLogDebug("Did not match: Car.Price ($)=%s", pgman->GetPropertyValueAsString("Car.Price ($)").c_str()); |
8f18b252 JS |
906 | RT_FAILURE(); |
907 | } | |
1c4293cb VZ |
908 | } |
909 | ||
910 | { | |
911 | RT_START_TEST(SetPropertyValueUnspecified) | |
912 | ||
913 | // Null variant setter tests | |
914 | pgman->SetPropertyValueUnspecified(wxT("StringProperty")); | |
915 | pgman->SetPropertyValueUnspecified(wxT("IntProperty")); | |
916 | pgman->SetPropertyValueUnspecified(wxT("FloatProperty")); | |
917 | pgman->SetPropertyValueUnspecified(wxT("BoolProperty")); | |
918 | pgman->SetPropertyValueUnspecified(wxT("EnumProperty")); | |
919 | pgman->SetPropertyValueUnspecified(wxT("ArrayStringProperty")); | |
920 | pgman->SetPropertyValueUnspecified(wxT("Custom FlagsProperty")); | |
921 | pgman->SetPropertyValueUnspecified(wxT("ColourProperty")); | |
922 | pgman->SetPropertyValueUnspecified(wxT("Size")); | |
923 | pgman->SetPropertyValueUnspecified(wxT("Position")); | |
924 | pgman->SetPropertyValueUnspecified(wxT("MultiChoiceProperty")); | |
925 | #if wxUSE_DATETIME | |
926 | pgman->SetPropertyValueUnspecified(wxT("DateProperty")); | |
927 | #endif | |
928 | } | |
929 | ||
930 | { | |
931 | wxPropertyGridPage* page1; | |
932 | wxPropertyGridPage* page2; | |
933 | wxPropertyGridPage* page3; | |
934 | wxVariant pg1_values; | |
935 | wxVariant pg2_values; | |
936 | wxVariant pg3_values; | |
937 | ||
938 | { | |
939 | RT_START_TEST(GetPropertyValues) | |
940 | ||
941 | page1 = pgman->GetPage(0); | |
942 | pg1_values = page1->GetPropertyValues(wxT("Page1"),NULL,wxPG_KEEP_STRUCTURE); | |
943 | page2 = pgman->GetPage(1); | |
944 | pg2_values = page2->GetPropertyValues(wxT("Page2"),NULL,wxPG_KEEP_STRUCTURE); | |
945 | page3 = pgman->GetPage(2); | |
946 | pg3_values = page3->GetPropertyValues(wxT("Page3"),NULL,wxPG_KEEP_STRUCTURE); | |
947 | } | |
948 | ||
949 | { | |
950 | RT_START_TEST(SetPropertyValues) | |
951 | ||
952 | page1->SetPropertyValues(pg3_values); | |
953 | page2->SetPropertyValues(pg1_values); | |
954 | page3->SetPropertyValues(pg2_values); | |
955 | } | |
956 | } | |
957 | ||
958 | if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) ) | |
959 | { | |
960 | RT_START_TEST(Collapse_and_GetFirstCategory_and_GetNextCategory) | |
961 | ||
962 | for ( i=0; i<3; i++ ) | |
963 | { | |
964 | wxPropertyGridPage* page = pgman->GetPage(i); | |
965 | ||
966 | wxPropertyGridIterator it; | |
967 | ||
968 | for ( it = page->GetIterator( wxPG_ITERATE_CATEGORIES ); | |
969 | !it.AtEnd(); | |
970 | it++ ) | |
971 | { | |
972 | wxPGProperty* p = *it; | |
973 | ||
974 | if ( !page->IsPropertyCategory(p) ) | |
975 | RT_FAILURE(); | |
976 | ||
977 | page->Collapse( p ); | |
978 | ||
979 | t.Printf(wxT("Collapsing: %s\n"),page->GetPropertyLabel(p).c_str()); | |
980 | ed->AppendText(t); | |
981 | } | |
982 | } | |
983 | } | |
984 | ||
985 | { | |
986 | RT_START_TEST(Save_And_RestoreEditableState) | |
987 | ||
988 | for ( i=0; i<3; i++ ) | |
989 | { | |
990 | pgman->SelectPage(i); | |
991 | ||
992 | wxString stringState = pgman->SaveEditableState(); | |
993 | bool res = pgman->RestoreEditableState(stringState); | |
994 | if ( !res ) | |
995 | RT_FAILURE(); | |
996 | } | |
997 | } | |
998 | ||
999 | //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) ) | |
1000 | { | |
1001 | RT_START_TEST(Expand_and_GetFirstCategory_and_GetNextCategory) | |
1002 | ||
1003 | for ( i=0; i<3; i++ ) | |
1004 | { | |
1005 | wxPropertyGridPage* page = pgman->GetPage(i); | |
1006 | ||
1007 | wxPropertyGridIterator it; | |
1008 | ||
1009 | for ( it = page->GetIterator( wxPG_ITERATE_CATEGORIES ); | |
1010 | !it.AtEnd(); | |
1011 | it++ ) | |
1012 | { | |
1013 | wxPGProperty* p = *it; | |
1014 | ||
1015 | if ( !page->IsPropertyCategory(p) ) | |
1016 | RT_FAILURE(); | |
1017 | ||
1018 | page->Expand( p ); | |
1019 | ||
1020 | t.Printf(wxT("Expand: %s\n"),page->GetPropertyLabel(p).c_str()); | |
1021 | ed->AppendText(t); | |
1022 | } | |
1023 | } | |
1024 | } | |
1025 | ||
1026 | //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) ) | |
1027 | { | |
1028 | RT_START_TEST(RandomCollapse) | |
1029 | ||
1030 | // Select the most error prone page as visible. | |
1031 | pgman->SelectPage(1); | |
1032 | ||
1033 | for ( i=0; i<3; i++ ) | |
1034 | { | |
1035 | wxArrayPtrVoid arr; | |
1036 | ||
1037 | wxPropertyGridPage* page = pgman->GetPage(i); | |
1038 | ||
1039 | wxPropertyGridIterator it; | |
1040 | ||
1041 | for ( it = page->GetIterator( wxPG_ITERATE_CATEGORIES ); | |
1042 | !it.AtEnd(); | |
1043 | it++ ) | |
1044 | { | |
1045 | arr.Add((void*)*it); | |
1046 | } | |
1047 | ||
1048 | if ( arr.GetCount() ) | |
1049 | { | |
1050 | size_t n; | |
1051 | ||
1052 | pgman->Collapse( (wxPGProperty*)arr.Item(0) ); | |
1053 | ||
1054 | for ( n=arr.GetCount()-1; n>0; n-- ) | |
1055 | { | |
1056 | pgman->Collapse( (wxPGProperty*)arr.Item(n) ); | |
1057 | } | |
1058 | } | |
1059 | ||
1060 | } | |
1061 | } | |
1062 | ||
1063 | { | |
1064 | RT_START_TEST(EnsureVisible) | |
1065 | pgman->EnsureVisible(wxT("Cell Colour")); | |
1066 | } | |
1067 | ||
1068 | { | |
1069 | RT_START_TEST(SetPropertyBackgroundColour) | |
1070 | wxCommandEvent evt; | |
1071 | evt.SetInt(1); // IsChecked() will return TRUE. | |
1072 | evt.SetId(ID_COLOURSCHEME4); | |
1073 | OnCatColours(evt); | |
1074 | OnColourScheme(evt); | |
1075 | } | |
1076 | ||
1077 | { | |
1078 | // Test ClearPropertyValue | |
1079 | RT_START_TEST(ClearPropertyValue) | |
1080 | ||
1081 | for ( i=0; i<3; i++ ) | |
1082 | { | |
1083 | wxPropertyGridPage* page = pgman->GetPage(i); | |
1084 | ||
1085 | // Iterate over all properties. | |
1086 | wxPropertyGridIterator it; | |
1087 | ||
1088 | for ( it = page->GetIterator(); | |
1089 | !it.AtEnd(); | |
1090 | it++ ) | |
1091 | { | |
1092 | wxLogDebug((*it)->GetLabel()); | |
1093 | pgman->ClearPropertyValue( *it ); | |
1094 | } | |
1095 | } | |
1096 | ||
1097 | } | |
1098 | ||
1099 | { | |
1100 | RT_START_TEST(ManagerClear) | |
1101 | pgman->Clear(); | |
1102 | ||
1103 | if ( pgman->GetPageCount() ) | |
1104 | RT_FAILURE(); | |
1105 | ||
1106 | // Recreate the original grid | |
1107 | CreateGrid( -1, -1 ); | |
1108 | pgman = m_pPropGridManager; | |
1109 | } | |
1110 | ||
1111 | /* | |
1112 | { | |
1113 | // TODO: This test fails. | |
1114 | RT_START_TEST(SetSplitterPosition) | |
1115 | ||
1116 | InitPanel(); | |
1117 | ||
1118 | const int trySplitterPos = 50; | |
1119 | ||
1120 | int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER; | |
1121 | pgman = m_pPropGridManager = | |
1122 | new wxPropertyGridManager(m_panel, wxID_ANY, | |
1123 | wxDefaultPosition, | |
1124 | wxDefaultSize, | |
1125 | style ); | |
1126 | ||
1127 | PopulateGrid(); | |
1128 | pgman->SetSplitterPosition(trySplitterPos); | |
1129 | ||
1130 | if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos ) | |
1131 | RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str()); | |
1132 | ||
1133 | m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND ); | |
1134 | FinalizePanel(); | |
1135 | ||
1136 | wxSize sz = GetSize(); | |
1137 | wxSize origSz = sz; | |
1138 | sz.x += 5; | |
1139 | sz.y += 5; | |
1140 | ||
1141 | if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos ) | |
1142 | RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str()); | |
1143 | ||
1144 | SetSize(origSz); | |
1145 | ||
1146 | // Recreate the original grid | |
1147 | CreateGrid( -1, -1 ); | |
1148 | pgman = m_pPropGridManager; | |
1149 | } | |
1150 | */ | |
1151 | ||
1152 | { | |
1153 | RT_START_TEST(HideProperty) | |
1154 | ||
1155 | wxPropertyGridPage* page = pgman->GetPage(0); | |
1156 | ||
1157 | srand(0x1234); | |
1158 | ||
1159 | wxArrayPGProperty arr1; | |
1160 | ||
1161 | arr1 = GetPropertiesInRandomOrder(page); | |
1162 | ||
1163 | if ( !_failed_ ) | |
1164 | { | |
1165 | for ( i=0; i<arr1.size(); i++ ) | |
1166 | { | |
1167 | wxPGProperty* p = arr1[i]; | |
1168 | page->HideProperty(p, true); | |
1169 | ||
1170 | wxString s = wxString::Format(wxT("HideProperty(%i, %s)"), i, p->GetLabel().c_str()); | |
1171 | RT_VALIDATE_VIRTUAL_HEIGHT(page, s) | |
1172 | if ( _failed_ ) | |
1173 | break; | |
1174 | } | |
1175 | } | |
1176 | ||
1177 | if ( !_failed_ ) | |
1178 | { | |
1179 | wxArrayPGProperty arr2 = GetPropertiesInRandomOrder(page); | |
1180 | ||
1181 | for ( i=0; i<arr2.size(); i++ ) | |
1182 | { | |
1183 | wxPGProperty* p = arr2[i]; | |
1184 | page->HideProperty(p, false); | |
1185 | ||
1186 | wxString s = wxString::Format(wxT("ShowProperty(%i, %s)"), i, p->GetLabel().c_str()); | |
1187 | RT_VALIDATE_VIRTUAL_HEIGHT(page, s) | |
1188 | if ( _failed_ ) | |
1189 | break; | |
1190 | } | |
1191 | } | |
1192 | ||
1193 | // | |
1194 | // Let's do some more, for better consistency | |
1195 | arr1 = GetPropertiesInRandomOrder(page); | |
1196 | ||
1197 | if ( !_failed_ ) | |
1198 | { | |
1199 | for ( i=0; i<arr1.size(); i++ ) | |
1200 | { | |
1201 | wxPGProperty* p = arr1[i]; | |
1202 | page->HideProperty(p, true); | |
1203 | ||
1204 | wxString s = wxString::Format(wxT("HideProperty(%i, %s)"), i, p->GetLabel().c_str()); | |
1205 | RT_VALIDATE_VIRTUAL_HEIGHT(page, s) | |
1206 | if ( _failed_ ) | |
1207 | break; | |
1208 | } | |
1209 | } | |
1210 | ||
1211 | if ( !_failed_ ) | |
1212 | { | |
1213 | wxArrayPGProperty arr2 = GetPropertiesInRandomOrder(page); | |
1214 | ||
1215 | for ( i=0; i<arr2.size(); i++ ) | |
1216 | { | |
1217 | wxPGProperty* p = arr2[i]; | |
1218 | page->HideProperty(p, false); | |
1219 | ||
1220 | wxString s = wxString::Format(wxT("ShowProperty(%i, %s)"), i, p->GetLabel().c_str()); | |
1221 | RT_VALIDATE_VIRTUAL_HEIGHT(page, s) | |
1222 | if ( _failed_ ) | |
1223 | break; | |
1224 | } | |
1225 | } | |
1226 | ||
1227 | // | |
1228 | // Ok, this time only hide half of them | |
1229 | arr1 = GetPropertiesInRandomOrder(page); | |
1c4293cb | 1230 | arr1.resize(arr1.size()/2); |
1c4293cb VZ |
1231 | |
1232 | if ( !_failed_ ) | |
1233 | { | |
1234 | for ( i=0; i<arr1.size(); i++ ) | |
1235 | { | |
1236 | wxPGProperty* p = arr1[i]; | |
1237 | page->HideProperty(p, true); | |
1238 | ||
1239 | wxString s = wxString::Format(wxT("HideProperty(%i, %s)"), i, p->GetLabel().c_str()); | |
1240 | RT_VALIDATE_VIRTUAL_HEIGHT(page, s) | |
1241 | if ( _failed_ ) | |
1242 | break; | |
1243 | } | |
1244 | } | |
1245 | ||
1246 | if ( !_failed_ ) | |
1247 | { | |
1248 | wxArrayPGProperty arr2 = GetPropertiesInRandomOrder(page); | |
1249 | ||
1250 | for ( i=0; i<arr2.size(); i++ ) | |
1251 | { | |
1252 | wxPGProperty* p = arr2[i]; | |
1253 | page->HideProperty(p, false); | |
1254 | ||
1255 | wxString s = wxString::Format(wxT("ShowProperty(%i, %s)"), i, p->GetLabel().c_str()); | |
1256 | RT_VALIDATE_VIRTUAL_HEIGHT(page, s) | |
1257 | if ( _failed_ ) | |
1258 | break; | |
1259 | } | |
1260 | } | |
1261 | ||
1262 | // Recreate the original grid | |
1263 | CreateGrid( -1, -1 ); | |
1264 | pgman = m_pPropGridManager; | |
1265 | } | |
1266 | ||
1267 | if ( fullTest ) | |
1268 | { | |
1269 | RT_START_TEST(MultipleColumns) | |
1270 | ||
1271 | // Test with multiple columns | |
1272 | // FIXME: Does not display changes. | |
1273 | for ( i=3; i<12; i+=2 ) | |
1274 | { | |
1275 | RT_MSG(wxString::Format(wxT("%i columns"),i)); | |
1276 | CreateGrid( -1, -1 ); | |
1277 | pgman = m_pPropGridManager; | |
1278 | pgman->SetColumnCount(i); | |
1279 | Refresh(); | |
1280 | Update(); | |
1281 | wxMilliSleep(500); | |
1282 | } | |
1283 | } | |
1284 | ||
1285 | if ( fullTest ) | |
1286 | { | |
1287 | RT_START_TEST(WindowStyles) | |
1288 | ||
1289 | // Recreate grid with all possible (single) flags | |
1290 | wxASSERT(wxPG_AUTO_SORT == 0x000000010); | |
1291 | ||
1292 | for ( i=4; i<16; i++ ) | |
1293 | { | |
1294 | int flag = 1<<i; | |
1295 | RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag)); | |
1296 | CreateGrid( flag, -1 ); | |
1297 | pgman = m_pPropGridManager; | |
1298 | Update(); | |
1299 | wxMilliSleep(500); | |
1300 | } | |
1301 | ||
1302 | wxASSERT(wxPG_EX_INIT_NOCAT == 0x00001000); | |
1303 | ||
1304 | for ( i=12; i<24; i++ ) | |
1305 | { | |
1306 | int flag = 1<<i; | |
1307 | RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag)); | |
1308 | CreateGrid( -1, flag ); | |
1309 | pgman = m_pPropGridManager; | |
1310 | Update(); | |
1311 | wxMilliSleep(500); | |
1312 | } | |
1313 | ||
1314 | // Recreate the original grid | |
1315 | CreateGrid( -1, -1 ); | |
1316 | pgman = m_pPropGridManager; | |
1317 | } | |
1318 | ||
1319 | RT_START_TEST(none) | |
1320 | ||
1321 | bool retVal; | |
1322 | ||
1323 | if ( failures || errorMessages.size() ) | |
1324 | { | |
1325 | retVal = false; | |
1326 | ||
1327 | wxString s; | |
1328 | #ifdef __WXDEBUG__ | |
1329 | if ( failures ) | |
1330 | #endif | |
1331 | s = wxString::Format(wxT("%i tests failed!!!"), failures); | |
1332 | #ifdef __WXDEBUG__ | |
1333 | else | |
1334 | s = wxString::Format(wxT("All tests were succesfull, but there were %i warnings!"), wxPGGlobalVars->m_warnings); | |
1335 | #endif | |
1336 | RT_MSG(s) | |
1337 | for ( i=0; i<errorMessages.size(); i++ ) | |
1338 | RT_MSG(errorMessages[i]) | |
1339 | wxMessageBox(s, wxT("Some Tests Failed")); | |
1340 | } | |
1341 | else | |
1342 | { | |
1343 | RT_MSG(wxT("All tests succesfull")) | |
1344 | retVal = true; | |
1345 | ||
1346 | if ( !interactive ) | |
1347 | dlg->Close(); | |
1348 | } | |
1349 | ||
1350 | pgman->SelectPage(0); | |
1351 | ||
1352 | // Test may screw up the toolbar, so we need to refresh it. | |
1353 | wxToolBar* toolBar = pgman->GetToolBar(); | |
1354 | if ( toolBar ) | |
1355 | toolBar->Refresh(); | |
1356 | ||
1357 | return retVal; | |
1358 | } | |
1359 | ||
1360 | // ----------------------------------------------------------------------- |