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