Moved wxPGChoices m_choices member from various property classes to base wxPGProperty...
[wxWidgets.git] / samples / propgrid / tests.cpp
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
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
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();
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
886 //
887 // This updates children as well
888 wxString nvs = "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002";
889 pgman->SetPropertyValue("Car", nvs);
890
891 if ( pgman->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
892 {
893 wxLogDebug("Did not match: Car.Model=%s", pgman->GetPropertyValueAsString("Car.Model").c_str());
894 RT_FAILURE();
895 }
896
897 if ( pgman->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
898 {
899 wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
900 RT_FAILURE();
901 }
902
903 if ( pgman->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
904 {
905 wxLogDebug("Did not match: Car.Price ($)=%s", pgman->GetPropertyValueAsString("Car.Price ($)").c_str());
906 RT_FAILURE();
907 }
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 {
1027 RT_START_TEST(Choice_Manipulation)
1028
1029 wxPGProperty* enumProp = pgman->GetProperty(wxT("EnumProperty"));
1030
1031 pgman->SelectPage(2);
1032 pgman->SelectProperty(enumProp);
1033 wxASSERT(pgman->GetGrid()->GetSelection() == enumProp);
1034
1035 const wxPGChoices& choices = enumProp->GetChoices();
1036 int ind = enumProp->InsertChoice(wxT("New Choice"), choices.GetCount()/2);
1037 enumProp->DeleteChoice(ind);
1038
1039 // Recreate the original grid
1040 CreateGrid( -1, -1 );
1041 pgman = m_pPropGridManager;
1042 }
1043
1044 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
1045 {
1046 RT_START_TEST(RandomCollapse)
1047
1048 // Select the most error prone page as visible.
1049 pgman->SelectPage(1);
1050
1051 for ( i=0; i<3; i++ )
1052 {
1053 wxArrayPtrVoid arr;
1054
1055 wxPropertyGridPage* page = pgman->GetPage(i);
1056
1057 wxPropertyGridIterator it;
1058
1059 for ( it = page->GetIterator( wxPG_ITERATE_CATEGORIES );
1060 !it.AtEnd();
1061 it++ )
1062 {
1063 arr.Add((void*)*it);
1064 }
1065
1066 if ( arr.GetCount() )
1067 {
1068 size_t n;
1069
1070 pgman->Collapse( (wxPGProperty*)arr.Item(0) );
1071
1072 for ( n=arr.GetCount()-1; n>0; n-- )
1073 {
1074 pgman->Collapse( (wxPGProperty*)arr.Item(n) );
1075 }
1076 }
1077
1078 }
1079 }
1080
1081 {
1082 RT_START_TEST(EnsureVisible)
1083 pgman->EnsureVisible(wxT("Cell Colour"));
1084 }
1085
1086 {
1087 RT_START_TEST(SetPropertyBackgroundColour)
1088 wxCommandEvent evt;
1089 evt.SetInt(1); // IsChecked() will return TRUE.
1090 evt.SetId(ID_COLOURSCHEME4);
1091 OnCatColours(evt);
1092 OnColourScheme(evt);
1093 }
1094
1095 {
1096 // Test ClearPropertyValue
1097 RT_START_TEST(ClearPropertyValue)
1098
1099 for ( i=0; i<3; i++ )
1100 {
1101 wxPropertyGridPage* page = pgman->GetPage(i);
1102
1103 // Iterate over all properties.
1104 wxPropertyGridIterator it;
1105
1106 for ( it = page->GetIterator();
1107 !it.AtEnd();
1108 it++ )
1109 {
1110 wxLogDebug((*it)->GetLabel());
1111 pgman->ClearPropertyValue( *it );
1112 }
1113 }
1114
1115 }
1116
1117 {
1118 RT_START_TEST(ManagerClear)
1119 pgman->Clear();
1120
1121 if ( pgman->GetPageCount() )
1122 RT_FAILURE();
1123
1124 // Recreate the original grid
1125 CreateGrid( -1, -1 );
1126 pgman = m_pPropGridManager;
1127 }
1128
1129 /*
1130 {
1131 // TODO: This test fails.
1132 RT_START_TEST(SetSplitterPosition)
1133
1134 InitPanel();
1135
1136 const int trySplitterPos = 50;
1137
1138 int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
1139 pgman = m_pPropGridManager =
1140 new wxPropertyGridManager(m_panel, wxID_ANY,
1141 wxDefaultPosition,
1142 wxDefaultSize,
1143 style );
1144
1145 PopulateGrid();
1146 pgman->SetSplitterPosition(trySplitterPos);
1147
1148 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1149 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1150
1151 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
1152 FinalizePanel();
1153
1154 wxSize sz = GetSize();
1155 wxSize origSz = sz;
1156 sz.x += 5;
1157 sz.y += 5;
1158
1159 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1160 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1161
1162 SetSize(origSz);
1163
1164 // Recreate the original grid
1165 CreateGrid( -1, -1 );
1166 pgman = m_pPropGridManager;
1167 }
1168 */
1169
1170 {
1171 RT_START_TEST(HideProperty)
1172
1173 wxPropertyGridPage* page = pgman->GetPage(0);
1174
1175 srand(0x1234);
1176
1177 wxArrayPGProperty arr1;
1178
1179 arr1 = GetPropertiesInRandomOrder(page);
1180
1181 if ( !_failed_ )
1182 {
1183 for ( i=0; i<arr1.size(); i++ )
1184 {
1185 wxPGProperty* p = arr1[i];
1186 page->HideProperty(p, true);
1187
1188 wxString s = wxString::Format(wxT("HideProperty(%i, %s)"), i, p->GetLabel().c_str());
1189 RT_VALIDATE_VIRTUAL_HEIGHT(page, s)
1190 if ( _failed_ )
1191 break;
1192 }
1193 }
1194
1195 if ( !_failed_ )
1196 {
1197 wxArrayPGProperty arr2 = GetPropertiesInRandomOrder(page);
1198
1199 for ( i=0; i<arr2.size(); i++ )
1200 {
1201 wxPGProperty* p = arr2[i];
1202 page->HideProperty(p, false);
1203
1204 wxString s = wxString::Format(wxT("ShowProperty(%i, %s)"), i, p->GetLabel().c_str());
1205 RT_VALIDATE_VIRTUAL_HEIGHT(page, s)
1206 if ( _failed_ )
1207 break;
1208 }
1209 }
1210
1211 //
1212 // Let's do some more, for better consistency
1213 arr1 = GetPropertiesInRandomOrder(page);
1214
1215 if ( !_failed_ )
1216 {
1217 for ( i=0; i<arr1.size(); i++ )
1218 {
1219 wxPGProperty* p = arr1[i];
1220 page->HideProperty(p, true);
1221
1222 wxString s = wxString::Format(wxT("HideProperty(%i, %s)"), i, p->GetLabel().c_str());
1223 RT_VALIDATE_VIRTUAL_HEIGHT(page, s)
1224 if ( _failed_ )
1225 break;
1226 }
1227 }
1228
1229 if ( !_failed_ )
1230 {
1231 wxArrayPGProperty arr2 = GetPropertiesInRandomOrder(page);
1232
1233 for ( i=0; i<arr2.size(); i++ )
1234 {
1235 wxPGProperty* p = arr2[i];
1236 page->HideProperty(p, false);
1237
1238 wxString s = wxString::Format(wxT("ShowProperty(%i, %s)"), i, p->GetLabel().c_str());
1239 RT_VALIDATE_VIRTUAL_HEIGHT(page, s)
1240 if ( _failed_ )
1241 break;
1242 }
1243 }
1244
1245 //
1246 // Ok, this time only hide half of them
1247 arr1 = GetPropertiesInRandomOrder(page);
1248 arr1.resize(arr1.size()/2);
1249
1250 if ( !_failed_ )
1251 {
1252 for ( i=0; i<arr1.size(); i++ )
1253 {
1254 wxPGProperty* p = arr1[i];
1255 page->HideProperty(p, true);
1256
1257 wxString s = wxString::Format(wxT("HideProperty(%i, %s)"), i, p->GetLabel().c_str());
1258 RT_VALIDATE_VIRTUAL_HEIGHT(page, s)
1259 if ( _failed_ )
1260 break;
1261 }
1262 }
1263
1264 if ( !_failed_ )
1265 {
1266 wxArrayPGProperty arr2 = GetPropertiesInRandomOrder(page);
1267
1268 for ( i=0; i<arr2.size(); i++ )
1269 {
1270 wxPGProperty* p = arr2[i];
1271 page->HideProperty(p, false);
1272
1273 wxString s = wxString::Format(wxT("ShowProperty(%i, %s)"), i, p->GetLabel().c_str());
1274 RT_VALIDATE_VIRTUAL_HEIGHT(page, s)
1275 if ( _failed_ )
1276 break;
1277 }
1278 }
1279
1280 // Recreate the original grid
1281 CreateGrid( -1, -1 );
1282 pgman = m_pPropGridManager;
1283 }
1284
1285 if ( fullTest )
1286 {
1287 RT_START_TEST(MultipleColumns)
1288
1289 // Test with multiple columns
1290 // FIXME: Does not display changes.
1291 for ( i=3; i<12; i+=2 )
1292 {
1293 RT_MSG(wxString::Format(wxT("%i columns"),i));
1294 CreateGrid( -1, -1 );
1295 pgman = m_pPropGridManager;
1296 pgman->SetColumnCount(i);
1297 Refresh();
1298 Update();
1299 wxMilliSleep(500);
1300 }
1301 }
1302
1303 if ( fullTest )
1304 {
1305 RT_START_TEST(WindowStyles)
1306
1307 // Recreate grid with all possible (single) flags
1308 wxASSERT(wxPG_AUTO_SORT == 0x000000010);
1309
1310 for ( i=4; i<16; i++ )
1311 {
1312 int flag = 1<<i;
1313 RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag));
1314 CreateGrid( flag, -1 );
1315 pgman = m_pPropGridManager;
1316 Update();
1317 wxMilliSleep(500);
1318 }
1319
1320 wxASSERT(wxPG_EX_INIT_NOCAT == 0x00001000);
1321
1322 for ( i=12; i<24; i++ )
1323 {
1324 int flag = 1<<i;
1325 RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag));
1326 CreateGrid( -1, flag );
1327 pgman = m_pPropGridManager;
1328 Update();
1329 wxMilliSleep(500);
1330 }
1331
1332 // Recreate the original grid
1333 CreateGrid( -1, -1 );
1334 pgman = m_pPropGridManager;
1335 }
1336
1337 RT_START_TEST(none)
1338
1339 bool retVal;
1340
1341 if ( failures || errorMessages.size() )
1342 {
1343 retVal = false;
1344
1345 wxString s;
1346 #ifdef __WXDEBUG__
1347 if ( failures )
1348 #endif
1349 s = wxString::Format(wxT("%i tests failed!!!"), failures);
1350 #ifdef __WXDEBUG__
1351 else
1352 s = wxString::Format(wxT("All tests were succesfull, but there were %i warnings!"), wxPGGlobalVars->m_warnings);
1353 #endif
1354 RT_MSG(s)
1355 for ( i=0; i<errorMessages.size(); i++ )
1356 RT_MSG(errorMessages[i])
1357 wxMessageBox(s, wxT("Some Tests Failed"));
1358 }
1359 else
1360 {
1361 RT_MSG(wxT("All tests succesfull"))
1362 retVal = true;
1363
1364 if ( !interactive )
1365 dlg->Close();
1366 }
1367
1368 pgman->SelectPage(0);
1369
1370 // Test may screw up the toolbar, so we need to refresh it.
1371 wxToolBar* toolBar = pgman->GetToolBar();
1372 if ( toolBar )
1373 toolBar->Refresh();
1374
1375 return retVal;
1376 }
1377
1378 // -----------------------------------------------------------------------