1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/propgrid/tests.cpp
3 // Purpose: wxPropertyGrid tests
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
22 #include <wx/propgrid/propgrid.h>
23 #include <wx/propgrid/advprops.h>
24 #include <wx/propgrid/manager.h>
27 #include "sampleprops.h"
30 // -----------------------------------------------------------------------
31 // wxTestCustomFlagsProperty
32 // -----------------------------------------------------------------------
35 // Test customizing wxColourProperty via subclassing
37 // * Includes custom colour entry.
38 // * Includes extra custom entry.
40 class MyColourProperty
: public wxColourProperty
43 MyColourProperty( const wxString
& label
= wxPG_LABEL
,
44 const wxString
& name
= wxPG_LABEL
,
45 const wxColour
& value
= *wxWHITE
)
46 : wxColourProperty(label
, name
, value
)
49 colours
.Add(wxT("White"));
50 colours
.Add(wxT("Black"));
51 colours
.Add(wxT("Red"));
52 colours
.Add(wxT("Green"));
53 colours
.Add(wxT("Blue"));
54 colours
.Add(wxT("Custom"));
55 colours
.Add(wxT("None"));
63 virtual ~MyColourProperty()
67 virtual wxColour
GetColour( int index
) const
71 case 0: return *wxWHITE
;
72 case 1: return *wxBLACK
;
73 case 2: return *wxRED
;
74 case 3: return *wxGREEN
;
75 case 4: return *wxBLUE
;
77 // Return current colour for the custom entry
79 if ( GetIndex() == GetCustomColourIndex() )
81 if ( m_value
.IsNull() )
91 virtual wxString
ColourToString( const wxColour
& col
, int index
) const
93 if ( index
== (int)(m_choices
.GetCount()-1) )
96 return wxColourProperty::ColourToString(col
, index
);
99 virtual int GetCustomColourIndex() const
101 return m_choices
.GetCount()-2;
106 void FormMain::AddTestProperties( wxPropertyGridPage
* pg
)
108 pg
->Append( new MyColourProperty(wxT("CustomColourProperty"), wxPG_LABEL
, *wxGREEN
) );
109 pg
->GetProperty(wxT("CustomColourProperty"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
110 pg
->SetPropertyEditor( wxT("CustomColourProperty"), wxPGEditor_ComboBox
);
112 pg
->SetPropertyHelpString(wxT("CustomColourProperty"),
113 wxT("This is a MyColourProperty from the sample app. ")
114 wxT("It is built by subclassing wxColourProperty."));
117 // -----------------------------------------------------------------------
119 void FormMain::OnDumpList( wxCommandEvent
& WXUNUSED(event
) )
121 wxVariant values
= m_pPropGridManager
->GetPropertyValues(wxT("list"), wxNullProperty
, wxPG_INC_ATTRIBUTES
);
122 wxString text
= wxT("This only tests that wxVariant related routines do not crash.");
125 wxDialog
* dlg
= new wxDialog(this,-1,wxT("wxVariant Test"),
126 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
129 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
131 wxVariant
& v
= values
[i
];
133 wxString strValue
= v
.GetString();
135 #if wxCHECK_VERSION(2,8,0)
136 if ( v
.GetName().EndsWith(wxT("@attr")) )
138 if ( v
.GetName().Right(5) == wxT("@attr") )
141 text
+= wxString::Format(wxT("Attributes:\n"));
144 for ( n
= 0; n
< (unsigned int)v
.GetCount(); n
++ )
148 t
.Printf(wxT(" atribute %i: name=\"%s\" (type=\"%s\" value=\"%s\")\n"),(int)n
,
149 a
.GetName().c_str(),a
.GetType().c_str(),a
.GetString().c_str());
155 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\" value=\"%s\"\n"),(int)i
,
156 v
.GetName().c_str(),v
.GetType().c_str(),strValue
.c_str());
161 // multi-line text editor dialog
162 const int spacing
= 8;
163 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
164 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
165 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,text
,
166 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
167 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
168 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
169 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
170 const int butSzFlags
=
171 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
172 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
173 0, butSzFlags
, spacing
);
174 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
176 dlg
->SetSizer( topsizer
);
177 topsizer
->SetSizeHints( dlg
);
179 dlg
->SetSize(400,300);
184 // -----------------------------------------------------------------------
190 TestRunner( const wxString
& name
, wxPropertyGridManager
* man
, wxTextCtrl
* ed
, wxArrayString
* errorMessages
)
195 m_errorMessages
= errorMessages
;
197 m_preWarnings
= wxPGGlobalVars
->m_warnings
;
200 if ( name
!= wxT("none") )
207 int warningsOccurred
= wxPGGlobalVars
->m_warnings
- m_preWarnings
;
208 if ( warningsOccurred
)
210 wxString s
= wxString::Format(wxT("%i warnings occurred during test '%s'"), warningsOccurred
, m_name
.c_str());
211 m_errorMessages
->push_back(s
);
217 void Msg( const wxString
& text
)
221 m_ed
->AppendText(text
);
222 m_ed
->AppendText(wxT("\n"));
228 wxPropertyGridManager
* m_man
;
230 wxArrayString
* m_errorMessages
;
238 #define RT_START_TEST(TESTNAME) \
239 TestRunner tr(wxT(#TESTNAME), pgman, ed, &errorMessages);
244 #define RT_FAILURE() \
246 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
247 errorMessages.push_back(s1); \
252 #define RT_FAILURE_MSG(MSG) \
254 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
255 errorMessages.push_back(s1); \
257 wxString s2 = wxString::Format(wxT("Message: %s"),MSG); \
258 errorMessages.push_back(s2); \
263 #define RT_VALIDATE_VIRTUAL_HEIGHT(PROPS, EXTRATEXT) \
265 unsigned int h1_ = PROPS->GetVirtualHeight(); \
266 unsigned int h2_ = PROPS->GetActualVirtualHeight(); \
269 wxString s_ = wxString::Format(wxT("VirtualHeight = %i, should be %i (%s)"), h1_, h2_, EXTRATEXT.c_str()); \
270 RT_FAILURE_MSG(s_.c_str()); \
280 int gpiro_cmpfunc(const void* a
, const void* b
)
282 const wxPGProperty
* p1
= (const wxPGProperty
*) a
;
283 const wxPGProperty
* p2
= (const wxPGProperty
*) b
;
284 return (int) (((size_t)p1
->GetClientData()) - ((size_t)p2
->GetClientData()));
287 wxArrayPGProperty
GetPropertiesInRandomOrder( wxPropertyGridInterface
* props
, int iterationFlags
= wxPG_ITERATE_ALL
)
289 wxArrayPGProperty arr
;
291 wxPropertyGridIterator it
;
293 for ( it
= props
->GetIterator(iterationFlags
);
297 wxPGProperty
* p
= *it
;
298 size_t randomNumber
= rand();
299 p
->SetClientData(reinterpret_cast<void*>(randomNumber
));
303 wxPGProperty
** firstEntry
= &arr
[0];
304 qsort(firstEntry
, arr
.size(), sizeof(wxPGProperty
*), gpiro_cmpfunc
);
309 bool FormMain::RunTests( bool fullTest
, bool interactive
)
313 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
318 pgman
->ClearSelection();
321 bool _failed_
= false;
322 wxArrayString errorMessages
;
323 wxDialog
* dlg
= NULL
;
325 dlg
= new wxDialog(this,-1,wxT("wxPropertyGrid Regression Tests"),
326 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
328 // multi-line text editor dialog
329 const int spacing
= 8;
330 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
331 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
332 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,wxEmptyString
,
333 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
334 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
335 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
336 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
337 const int butSzFlags
=
338 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
339 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
340 0, butSzFlags
, spacing
);
341 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
343 dlg
->SetSizer( topsizer
);
344 topsizer
->SetSizeHints( dlg
);
346 dlg
->SetSize(400,300);
347 dlg
->Move(wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)-dlg
->GetSize().x
,
348 wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)-dlg
->GetSize().y
);
353 // Basic iterator tests
354 RT_START_TEST(GetIterator
)
360 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
364 wxPGProperty
* p
= it
.GetProperty();
365 if ( p
->IsCategory() )
366 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a category (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
367 else if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
368 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
372 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES) -> %i entries"), count
));
375 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_CATEGORIES
);
379 wxPGProperty
* p
= it
.GetProperty();
380 if ( !p
->IsCategory() )
381 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is not a category (only category was expected)"),p
->GetLabel().c_str()).c_str())
385 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
388 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
|wxPG_ITERATE_CATEGORIES
);
392 wxPGProperty
* p
= it
.GetProperty();
393 if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
394 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property or category expected)"),p
->GetLabel().c_str()).c_str())
398 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
401 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_VISIBLE
);
405 wxPGProperty
* p
= it
.GetProperty();
406 if ( (p
->GetParent() != p
->GetParentState()->DoGetRoot() && !p
->GetParent()->IsExpanded()) )
407 RT_FAILURE_MSG(wxString::Format(wxT("'%s' had collapsed parent (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
408 else if ( p
->HasFlag(wxPG_PROP_HIDDEN
) )
409 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was hidden (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
413 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_VISIBLE) -> %i entries"), count
));
418 // Test that setting focus to properties does not crash things
419 RT_START_TEST(SelectProperty
)
421 wxPropertyGridIterator it
;
424 for ( ind
=0; ind
<pgman
->GetPageCount(); ind
++ )
426 wxPropertyGridPage
* page
= pgman
->GetPage(ind
);
427 pgman
->SelectPage(page
);
429 for ( it
= page
->GetIterator(wxPG_ITERATE_VISIBLE
);
433 wxPGProperty
* p
= *it
;
434 RT_MSG(p
->GetLabel());
435 pgman
->GetGrid()->SelectProperty(p
, true);
444 // Delete everything in reverse order
445 RT_START_TEST(DeleteProperty
)
448 wxArrayPGProperty array
;
450 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_ALL
&~(wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
)));
453 array
.push_back(it
.GetProperty());
455 wxArrayPGProperty::reverse_iterator it2
;
457 for ( it2
= array
.rbegin(); it2
!= array
.rend(); it2
++ )
459 wxPGProperty
* p
= (wxPGProperty
*)*it2
;
460 RT_MSG(wxString::Format(wxT("Deleting '%s' ('%s')"),p
->GetLabel().c_str(),p
->GetName().c_str()));
461 pgman
->DeleteProperty(p
);
465 CreateGrid( -1, -1 );
466 pgman
= m_pPropGridManager
;
471 // Test property default values
472 RT_START_TEST(Default_Values
)
476 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
480 wxPGProperty
* p
= it
.GetProperty();
481 pgman
->SetPropertyValue(p
, p
->GetDefaultValue());
485 CreateGrid( -1, -1 );
486 pgman
= m_pPropGridManager
;
490 RT_START_TEST(GetPropertyValues
)
492 for ( i
=0; i
<3; i
++ )
496 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
498 wxVariant values
= page
->GetPropertyValues();
501 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
503 wxVariant
& v
= values
[i
];
505 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\"\n"),(int)i
,
506 v
.GetName().c_str(),v
.GetType().c_str());
510 ed
->AppendText(text
);
515 RT_START_TEST(SetPropertyValue_and_GetPropertyValue
)
517 // In this section, mixed up usage of wxT("propname") and "propname"
518 // in wxPropertyGridInterface functions is intentional.
519 // Purpose is to test wxPGPropArgCls ctors.
521 //pg = (wxPropertyGrid*) NULL;
523 wxArrayString test_arrstr_1
;
524 test_arrstr_1
.Add(wxT("Apple"));
525 test_arrstr_1
.Add(wxT("Orange"));
526 test_arrstr_1
.Add(wxT("Lemon"));
528 wxArrayString test_arrstr_2
;
529 test_arrstr_2
.Add(wxT("Potato"));
530 test_arrstr_2
.Add(wxT("Cabbage"));
531 test_arrstr_2
.Add(wxT("Cucumber"));
533 wxArrayInt test_arrint_1
;
534 test_arrint_1
.Add(1);
535 test_arrint_1
.Add(2);
536 test_arrint_1
.Add(3);
538 wxArrayInt test_arrint_2
;
539 test_arrint_2
.Add(0);
540 test_arrint_2
.Add(1);
541 test_arrint_2
.Add(4);
544 wxDateTime dt1
= wxDateTime::Now();
545 dt1
.SetYear(dt1
.GetYear()-1);
547 wxDateTime dt2
= wxDateTime::Now();
548 dt2
.SetYear(dt2
.GetYear()-10);
551 #define FLAG_TEST_SET1 (wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER)
552 #define FLAG_TEST_SET2 (wxSTAY_ON_TOP|wxCAPTION|wxICONIZE|wxSYSTEM_MENU)
554 pgman
->SetPropertyValue(wxT("StringProperty"),wxT("Text1"));
555 pgman
->SetPropertyValue(wxT("IntProperty"),1024);
556 pgman
->SetPropertyValue(wxT("FloatProperty"),1024.0000000001);
557 pgman
->SetPropertyValue(wxT("BoolProperty"),FALSE
);
558 pgman
->SetPropertyValue(wxT("EnumProperty"),120);
559 pgman
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_1
);
561 pgman
->SetPropertyValue(wxT("ColourProperty"),emptyCol
);
562 pgman
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxBLACK
);
563 pgman
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(150,150)));
564 pgman
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(150,150)));
565 pgman
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_1
);
567 pgman
->SetPropertyValue(wxT("DateProperty"),dt1
);
570 pgman
->SelectPage(2);
571 pg
= pgman
->GetGrid();
573 if ( pg
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text1") )
575 if ( pg
->GetPropertyValueAsInt(wxT("IntProperty")) != 1024 )
577 if ( pg
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 1024.0000000001 )
579 if ( pg
->GetPropertyValueAsBool(wxT("BoolProperty")) != FALSE
)
581 if ( pg
->GetPropertyValueAsLong(wxT("EnumProperty")) != 120 )
583 if ( pg
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_1
)
586 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
587 if ( col
!= *wxBLACK
)
589 if ( wxSizeRefFromVariant(pg
->GetPropertyValue(wxT("Size"))) != wxSize(150,150) )
591 if ( wxPointRefFromVariant(pg
->GetPropertyValue(wxT("Position"))) != wxPoint(150,150) )
593 if ( !(pg
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_1
) )
596 if ( !(pg
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt1
) )
600 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(10000000000));
601 if ( pg
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(10000000000) )
604 pg
->SetPropertyValue(wxT("StringProperty"),wxT("Text2"));
605 pg
->SetPropertyValue(wxT("IntProperty"),512);
606 pg
->SetPropertyValue(wxT("FloatProperty"),512.0);
607 pg
->SetPropertyValue(wxT("BoolProperty"),TRUE
);
608 pg
->SetPropertyValue(wxT("EnumProperty"),80);
609 pg
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_2
);
610 pg
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxWHITE
);
611 pg
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(300,300)));
612 pg
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(300,300)));
613 pg
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_2
);
615 pg
->SetPropertyValue(wxT("DateProperty"),dt2
);
618 //pg = (wxPropertyGrid*) NULL;
620 pgman
->SelectPage(0);
622 if ( pgman
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text2") )
624 if ( pgman
->GetPropertyValueAsInt(wxT("IntProperty")) != 512 )
626 if ( pgman
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 512.0 )
628 if ( pgman
->GetPropertyValueAsBool(wxT("BoolProperty")) != TRUE
)
630 if ( pgman
->GetPropertyValueAsLong(wxT("EnumProperty")) != 80 )
632 if ( pgman
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_2
)
634 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
635 if ( col
!= *wxWHITE
)
637 if ( wxSizeRefFromVariant(pgman
->GetPropertyValue(wxT("Size"))) != wxSize(300,300) )
639 if ( wxPointRefFromVariant(pgman
->GetPropertyValue(wxT("Position"))) != wxPoint(300,300) )
641 if ( !(pgman
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_2
) )
644 if ( !(pgman
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt2
) )
648 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000));
649 if ( pgman
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) )
653 // Flexible wx(U)LongLong << operator safety conformance tests
658 prop
= pgman
->GetProperty(wxT("IntProperty"));
660 ll
<< prop
->GetValue();
664 prop
->SetValue(WXVARIANT(wxLL(68719476736)));
665 ll
<< prop
->GetValue();
666 if ( ll
.GetValue() != wxLL(68719476736) )
669 #if wxUSE_LONGLONG_NATIVE
671 ll_t
<< prop
->GetValue();
672 if ( ll_t
!= wxLL(68719476736) )
677 ll
<< prop
->GetValue();
681 prop
= pgman
->GetProperty(wxT("UIntProperty"));
683 ull
<< prop
->GetValue();
687 prop
->SetValue(WXVARIANT(wxULL(68719476739)));
688 ull
<< prop
->GetValue();
689 if ( ull
.GetValue() != wxULL(68719476739) )
692 #if wxUSE_LONGLONG_NATIVE
694 ull_t
<< prop
->GetValue();
695 if ( ull_t
!= wxLL(68719476739) )
700 ull
<< prop
->GetValue();
704 // Make sure children of composite parent get updated as well
705 // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000"
708 // This updates children as well
709 wxString nvs
= "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002";
710 pgman
->SetPropertyValue("Car", nvs
);
712 if ( pgman
->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
714 wxLogDebug("Did not match: Car.Model=%s", pgman
->GetPropertyValueAsString("Car.Model").c_str());
718 if ( pgman
->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
720 wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman
->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
724 if ( pgman
->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
726 wxLogDebug("Did not match: Car.Price ($)=%s", pgman
->GetPropertyValueAsString("Car.Price ($)").c_str());
732 RT_START_TEST(SetPropertyValueUnspecified
)
734 // Null variant setter tests
735 pgman
->SetPropertyValueUnspecified(wxT("StringProperty"));
736 pgman
->SetPropertyValueUnspecified(wxT("IntProperty"));
737 pgman
->SetPropertyValueUnspecified(wxT("FloatProperty"));
738 pgman
->SetPropertyValueUnspecified(wxT("BoolProperty"));
739 pgman
->SetPropertyValueUnspecified(wxT("EnumProperty"));
740 pgman
->SetPropertyValueUnspecified(wxT("ArrayStringProperty"));
741 pgman
->SetPropertyValueUnspecified(wxT("ColourProperty"));
742 pgman
->SetPropertyValueUnspecified(wxT("Size"));
743 pgman
->SetPropertyValueUnspecified(wxT("Position"));
744 pgman
->SetPropertyValueUnspecified(wxT("MultiChoiceProperty"));
746 pgman
->SetPropertyValueUnspecified(wxT("DateProperty"));
751 RT_START_TEST(Attributes
)
753 wxPGProperty
* prop
= pgman
->GetProperty(wxT("StringProperty"));
754 prop
->SetAttribute(wxT("Dummy Attribute"), (long)15);
756 if ( prop
->GetAttribute(wxT("Dummy Attribute")).GetLong() != 15 )
759 prop
->SetAttribute(wxT("Dummy Attribute"), wxVariant());
761 if ( !prop
->GetAttribute(wxT("Dummy Attribute")).IsNull() )
766 wxPropertyGridPage
* page1
;
767 wxPropertyGridPage
* page2
;
768 wxPropertyGridPage
* page3
;
769 wxVariant pg1_values
;
770 wxVariant pg2_values
;
771 wxVariant pg3_values
;
774 RT_START_TEST(GetPropertyValues
)
776 page1
= pgman
->GetPage(0);
777 pg1_values
= page1
->GetPropertyValues(wxT("Page1"),NULL
,wxPG_KEEP_STRUCTURE
);
778 page2
= pgman
->GetPage(1);
779 pg2_values
= page2
->GetPropertyValues(wxT("Page2"),NULL
,wxPG_KEEP_STRUCTURE
);
780 page3
= pgman
->GetPage(2);
781 pg3_values
= page3
->GetPropertyValues(wxT("Page3"),NULL
,wxPG_KEEP_STRUCTURE
);
785 RT_START_TEST(SetPropertyValues
)
787 page1
->SetPropertyValues(pg3_values
);
788 page2
->SetPropertyValues(pg1_values
);
789 page3
->SetPropertyValues(pg2_values
);
793 if ( !(pgman
->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES
) )
795 RT_START_TEST(Collapse_and_GetFirstCategory_and_GetNextCategory
)
797 for ( i
=0; i
<3; i
++ )
799 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
801 wxPropertyGridIterator it
;
803 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
807 wxPGProperty
* p
= *it
;
809 if ( !page
->IsPropertyCategory(p
) )
814 t
.Printf(wxT("Collapsing: %s\n"),page
->GetPropertyLabel(p
).c_str());
821 RT_START_TEST(Save_And_RestoreEditableState
)
823 for ( i
=0; i
<3; i
++ )
825 pgman
->SelectPage(i
);
827 wxString stringState
= pgman
->SaveEditableState();
828 bool res
= pgman
->RestoreEditableState(stringState
);
834 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
836 RT_START_TEST(Expand_and_GetFirstCategory_and_GetNextCategory
)
838 for ( i
=0; i
<3; i
++ )
840 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
842 wxPropertyGridIterator it
;
844 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
848 wxPGProperty
* p
= *it
;
850 if ( !page
->IsPropertyCategory(p
) )
855 t
.Printf(wxT("Expand: %s\n"),page
->GetPropertyLabel(p
).c_str());
862 RT_START_TEST(Choice_Manipulation
)
864 wxPGProperty
* enumProp
= pgman
->GetProperty(wxT("EnumProperty"));
866 pgman
->SelectPage(2);
867 pgman
->SelectProperty(enumProp
);
868 wxASSERT(pgman
->GetGrid()->GetSelection() == enumProp
);
870 const wxPGChoices
& choices
= enumProp
->GetChoices();
871 int ind
= enumProp
->InsertChoice(wxT("New Choice"), choices
.GetCount()/2);
872 enumProp
->DeleteChoice(ind
);
874 // Recreate the original grid
875 CreateGrid( -1, -1 );
876 pgman
= m_pPropGridManager
;
879 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
881 RT_START_TEST(RandomCollapse
)
883 // Select the most error prone page as visible.
884 pgman
->SelectPage(1);
886 for ( i
=0; i
<3; i
++ )
890 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
892 wxPropertyGridIterator it
;
894 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
901 if ( arr
.GetCount() )
905 pgman
->Collapse( (wxPGProperty
*)arr
.Item(0) );
907 for ( n
=arr
.GetCount()-1; n
>0; n
-- )
909 pgman
->Collapse( (wxPGProperty
*)arr
.Item(n
) );
917 RT_START_TEST(EnsureVisible
)
918 pgman
->EnsureVisible(wxT("Cell Colour"));
922 RT_START_TEST(SetPropertyBackgroundColour
)
924 evt
.SetInt(1); // IsChecked() will return TRUE.
925 evt
.SetId(ID_COLOURSCHEME4
);
931 RT_START_TEST(ManagerClear
)
934 if ( pgman
->GetPageCount() )
937 // Recreate the original grid
938 CreateGrid( -1, -1 );
939 pgman
= m_pPropGridManager
;
944 // TODO: This test fails.
945 RT_START_TEST(SetSplitterPosition)
949 const int trySplitterPos = 50;
951 int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
952 pgman = m_pPropGridManager =
953 new wxPropertyGridManager(m_panel, wxID_ANY,
959 pgman->SetSplitterPosition(trySplitterPos);
961 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
962 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
964 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
967 wxSize sz = GetSize();
972 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
973 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
977 // Recreate the original grid
978 CreateGrid( -1, -1 );
979 pgman = m_pPropGridManager;
984 RT_START_TEST(HideProperty
)
986 wxPropertyGridPage
* page
= pgman
->GetPage(0);
990 wxArrayPGProperty arr1
;
992 arr1
= GetPropertiesInRandomOrder(page
);
996 for ( i
=0; i
<arr1
.size(); i
++ )
998 wxPGProperty
* p
= arr1
[i
];
999 page
->HideProperty(p
, true);
1001 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1002 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1010 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1012 for ( i
=0; i
<arr2
.size(); i
++ )
1014 wxPGProperty
* p
= arr2
[i
];
1015 page
->HideProperty(p
, false);
1017 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1018 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1025 // Let's do some more, for better consistency
1026 arr1
= GetPropertiesInRandomOrder(page
);
1030 for ( i
=0; i
<arr1
.size(); i
++ )
1032 wxPGProperty
* p
= arr1
[i
];
1033 page
->HideProperty(p
, true);
1035 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1036 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1044 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1046 for ( i
=0; i
<arr2
.size(); i
++ )
1048 wxPGProperty
* p
= arr2
[i
];
1049 page
->HideProperty(p
, false);
1051 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1052 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1059 // Ok, this time only hide half of them
1060 arr1
= GetPropertiesInRandomOrder(page
);
1061 arr1
.resize(arr1
.size()/2);
1065 for ( i
=0; i
<arr1
.size(); i
++ )
1067 wxPGProperty
* p
= arr1
[i
];
1068 page
->HideProperty(p
, true);
1070 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1071 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1079 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1081 for ( i
=0; i
<arr2
.size(); i
++ )
1083 wxPGProperty
* p
= arr2
[i
];
1084 page
->HideProperty(p
, false);
1086 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1087 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1093 // Recreate the original grid
1094 CreateGrid( -1, -1 );
1095 pgman
= m_pPropGridManager
;
1100 RT_START_TEST(MultipleColumns
)
1102 // Test with multiple columns
1103 // FIXME: Does not display changes.
1104 for ( i
=3; i
<12; i
+=2 )
1106 RT_MSG(wxString::Format(wxT("%i columns"),i
));
1107 CreateGrid( -1, -1 );
1108 pgman
= m_pPropGridManager
;
1109 pgman
->SetColumnCount(i
);
1118 RT_START_TEST(WindowStyles
)
1120 // Recreate grid with all possible (single) flags
1121 wxASSERT(wxPG_AUTO_SORT
== 0x000000010);
1123 for ( i
=4; i
<16; i
++ )
1126 RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag
));
1127 CreateGrid( flag
, -1 );
1128 pgman
= m_pPropGridManager
;
1133 wxASSERT(wxPG_EX_INIT_NOCAT
== 0x00001000);
1135 for ( i
=12; i
<24; i
++ )
1138 RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag
));
1139 CreateGrid( -1, flag
);
1140 pgman
= m_pPropGridManager
;
1145 // Recreate the original grid
1146 CreateGrid( -1, -1 );
1147 pgman
= m_pPropGridManager
;
1154 if ( failures
|| errorMessages
.size() )
1162 s
= wxString::Format(wxT("%i tests failed!!!"), failures
);
1165 s
= wxString::Format(wxT("All tests were succesfull, but there were %i warnings!"), wxPGGlobalVars
->m_warnings
);
1168 for ( i
=0; i
<errorMessages
.size(); i
++ )
1169 RT_MSG(errorMessages
[i
])
1170 wxMessageBox(s
, wxT("Some Tests Failed"));
1174 RT_MSG(wxT("All tests succesfull"))
1181 pgman
->SelectPage(0);
1183 // Test may screw up the toolbar, so we need to refresh it.
1184 wxToolBar
* toolBar
= pgman
->GetToolBar();
1191 // -----------------------------------------------------------------------