1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/propgrid/tests.cpp
3 // Purpose: wxPropertyGrid tests
4 // Author: Jaakko Salli
7 // Copyright: (c) Jaakko Salli
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
21 #include <wx/propgrid/propgrid.h>
22 #include <wx/propgrid/advprops.h>
23 #include <wx/propgrid/manager.h>
26 #include "sampleprops.h"
29 // -----------------------------------------------------------------------
30 // wxTestCustomFlagsProperty
31 // -----------------------------------------------------------------------
34 // Test customizing wxColourProperty via subclassing
36 // * Includes custom colour entry.
37 // * Includes extra custom entry.
39 class MyColourProperty
: public wxColourProperty
42 MyColourProperty( const wxString
& label
= wxPG_LABEL
,
43 const wxString
& name
= wxPG_LABEL
,
44 const wxColour
& value
= *wxWHITE
)
45 : wxColourProperty(label
, name
, value
)
48 colours
.Add(wxT("White"));
49 colours
.Add(wxT("Black"));
50 colours
.Add(wxT("Red"));
51 colours
.Add(wxT("Green"));
52 colours
.Add(wxT("Blue"));
53 colours
.Add(wxT("Custom"));
54 colours
.Add(wxT("None"));
62 virtual ~MyColourProperty()
66 virtual wxColour
GetColour( int index
) const
70 case 0: return *wxWHITE
;
71 case 1: return *wxBLACK
;
72 case 2: return *wxRED
;
73 case 3: return *wxGREEN
;
74 case 4: return *wxBLUE
;
76 // Return current colour for the custom entry
78 if ( GetIndex() == GetCustomColourIndex() )
80 if ( m_value
.IsNull() )
90 virtual wxString
ColourToString( const wxColour
& col
,
92 int argFlags
= 0 ) const
94 if ( index
== (int)(m_choices
.GetCount()-1) )
97 return wxColourProperty::ColourToString(col
, index
, argFlags
);
100 virtual int GetCustomColourIndex() const
102 return m_choices
.GetCount()-2;
107 void FormMain::AddTestProperties( wxPropertyGridPage
* pg
)
109 pg
->Append( new MyColourProperty(wxT("CustomColourProperty"), wxPG_LABEL
, *wxGREEN
) );
110 pg
->GetProperty(wxT("CustomColourProperty"))->SetAutoUnspecified(true);
111 pg
->SetPropertyEditor( wxT("CustomColourProperty"), wxPGEditor_ComboBox
);
113 pg
->SetPropertyHelpString(wxT("CustomColourProperty"),
114 wxT("This is a MyColourProperty from the sample app. ")
115 wxT("It is built by subclassing wxColourProperty."));
118 // -----------------------------------------------------------------------
120 void FormMain::OnDumpList( wxCommandEvent
& WXUNUSED(event
) )
122 wxVariant values
= m_pPropGridManager
->GetPropertyValues(wxT("list"), wxNullProperty
, wxPG_INC_ATTRIBUTES
);
123 wxString text
= wxT("This only tests that wxVariant related routines do not crash.");
126 wxDialog
* dlg
= new wxDialog(this,-1,wxT("wxVariant Test"),
127 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
130 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
132 wxVariant
& v
= values
[i
];
134 wxString strValue
= v
.GetString();
136 #if wxCHECK_VERSION(2,8,0)
137 if ( v
.GetName().EndsWith(wxT("@attr")) )
139 if ( v
.GetName().Right(5) == wxT("@attr") )
142 text
+= wxString::Format(wxT("Attributes:\n"));
145 for ( n
= 0; n
< (unsigned int)v
.GetCount(); n
++ )
149 t
.Printf(wxT(" atribute %i: name=\"%s\" (type=\"%s\" value=\"%s\")\n"),(int)n
,
150 a
.GetName().c_str(),a
.GetType().c_str(),a
.GetString().c_str());
156 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\" value=\"%s\"\n"),(int)i
,
157 v
.GetName().c_str(),v
.GetType().c_str(),strValue
.c_str());
162 // multi-line text editor dialog
163 const int spacing
= 8;
164 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
165 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
166 wxTextCtrl
* ed
= new wxTextCtrl(dlg
, 11, text
,
167 wxDefaultPosition
, wxDefaultSize
,
169 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
170 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
171 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
172 const int butSzFlags
=
173 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
174 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
175 0, butSzFlags
, spacing
);
176 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
178 dlg
->SetSizer( topsizer
);
179 topsizer
->SetSizeHints( dlg
);
181 dlg
->SetSize(400,300);
186 // -----------------------------------------------------------------------
192 TestRunner( const wxString
& name
, wxPropertyGridManager
* man
, wxTextCtrl
* ed
, wxArrayString
* errorMessages
)
197 m_errorMessages
= errorMessages
;
199 m_preWarnings
= wxPGGlobalVars
->m_warnings
;
202 if ( name
!= wxT("none") )
209 int warningsOccurred
= wxPGGlobalVars
->m_warnings
- m_preWarnings
;
210 if ( warningsOccurred
)
212 wxString s
= wxString::Format(wxT("%i warnings occurred during test '%s'"), warningsOccurred
, m_name
.c_str());
213 m_errorMessages
->push_back(s
);
219 void Msg( const wxString
& text
)
223 m_ed
->AppendText(text
);
224 m_ed
->AppendText(wxT("\n"));
230 wxPropertyGridManager
* m_man
;
232 wxArrayString
* m_errorMessages
;
240 #define RT_START_TEST(TESTNAME) \
241 TestRunner tr(wxT(#TESTNAME), pgman, ed, &errorMessages);
246 #define RT_FAILURE() \
248 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
249 errorMessages.push_back(s1); \
254 #define RT_ASSERT(COND) \
258 #define RT_FAILURE_MSG(MSG) \
260 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
261 errorMessages.push_back(s1); \
263 wxString s2 = wxString::Format(wxT("Message: %s"),MSG); \
264 errorMessages.push_back(s2); \
269 #define RT_VALIDATE_VIRTUAL_HEIGHT(PROPS, EXTRATEXT) \
271 unsigned int h1_ = PROPS->GetVirtualHeight(); \
272 unsigned int h2_ = PROPS->GetActualVirtualHeight(); \
275 wxString s_ = wxString::Format(wxT("VirtualHeight = %i, should be %i (%s)"), h1_, h2_, EXTRATEXT.c_str()); \
276 RT_FAILURE_MSG(s_.c_str()); \
286 int gpiro_cmpfunc(const void* a
, const void* b
)
288 const wxPGProperty
* p1
= (const wxPGProperty
*) a
;
289 const wxPGProperty
* p2
= (const wxPGProperty
*) b
;
290 return (int) (((size_t)p1
->GetClientData()) - ((size_t)p2
->GetClientData()));
293 wxArrayPGProperty
GetPropertiesInRandomOrder( wxPropertyGridInterface
* props
, int iterationFlags
= wxPG_ITERATE_ALL
)
295 wxArrayPGProperty arr
;
297 wxPropertyGridIterator it
;
299 for ( it
= props
->GetIterator(iterationFlags
);
303 wxPGProperty
* p
= *it
;
304 size_t randomNumber
= rand();
305 p
->SetClientData(reinterpret_cast<void*>(randomNumber
));
309 wxPGProperty
** firstEntry
= &arr
[0];
310 qsort(firstEntry
, arr
.size(), sizeof(wxPGProperty
*), gpiro_cmpfunc
);
315 // Callback for testing property sorting
316 int MyPropertySortFunction(wxPropertyGrid
* WXUNUSED(propGrid
),
320 // Reverse alphabetical order
321 return p2
->GetLabel().CmpNoCase( p1
->GetBaseName() );
324 bool FormMain::RunTests( bool fullTest
, bool interactive
)
328 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
333 pgman
->ClearSelection();
336 bool _failed_
= false;
337 wxArrayString errorMessages
;
338 wxDialog
* dlg
= NULL
;
340 dlg
= new wxDialog(this,-1,wxT("wxPropertyGrid Regression Tests"),
341 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
343 // multi-line text editor dialog
344 const int spacing
= 8;
345 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
346 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
347 wxTextCtrl
* ed
= new wxTextCtrl(dlg
, 11, wxEmptyString
,
348 wxDefaultPosition
, wxDefaultSize
,
350 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
351 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
352 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
353 const int butSzFlags
=
354 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
355 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
356 0, butSzFlags
, spacing
);
357 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
359 dlg
->SetSizer( topsizer
);
360 topsizer
->SetSizeHints( dlg
);
362 dlg
->SetSize(400,300);
363 dlg
->Move(wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)-dlg
->GetSize().x
,
364 wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)-dlg
->GetSize().y
);
369 // Basic iterator tests
370 RT_START_TEST(GetIterator
)
376 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
380 wxPGProperty
* p
= it
.GetProperty();
381 if ( p
->IsCategory() )
382 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a category (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
383 else if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
384 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
388 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES) -> %i entries"), count
));
391 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_CATEGORIES
);
395 wxPGProperty
* p
= it
.GetProperty();
396 if ( !p
->IsCategory() )
397 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is not a category (only category was expected)"),p
->GetLabel().c_str()).c_str())
401 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
404 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
|wxPG_ITERATE_CATEGORIES
);
408 wxPGProperty
* p
= it
.GetProperty();
409 if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
410 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property or category expected)"),p
->GetLabel().c_str()).c_str())
414 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
417 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_VISIBLE
);
421 wxPGProperty
* p
= it
.GetProperty();
422 if ( (p
->GetParent() != p
->GetParentState()->DoGetRoot() && !p
->GetParent()->IsExpanded()) )
423 RT_FAILURE_MSG(wxString::Format(wxT("'%s' had collapsed parent (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
424 else if ( p
->HasFlag(wxPG_PROP_HIDDEN
) )
425 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was hidden (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
429 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_VISIBLE) -> %i entries"), count
));
434 // Test that setting focus to properties does not crash things
435 RT_START_TEST(SelectProperty
)
437 wxPropertyGridIterator it
;
440 for ( ind
=0; ind
<pgman
->GetPageCount(); ind
++ )
442 wxPropertyGridPage
* page
= pgman
->GetPage(ind
);
443 pgman
->SelectPage(page
);
445 for ( it
= page
->GetIterator(wxPG_ITERATE_VISIBLE
);
449 wxPGProperty
* p
= *it
;
450 RT_MSG(p
->GetLabel());
451 pgman
->GetGrid()->SelectProperty(p
, true);
460 // Delete everything in reverse order
461 RT_START_TEST(DeleteProperty
)
464 wxArrayPGProperty array
;
466 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_ALL
&~(wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
)));
469 array
.push_back(it
.GetProperty());
471 wxArrayPGProperty::reverse_iterator it2
;
473 for ( it2
= array
.rbegin(); it2
!= array
.rend(); it2
++ )
475 wxPGProperty
* p
= (wxPGProperty
*)*it2
;
476 RT_MSG(wxString::Format(wxT("Deleting '%s' ('%s')"),p
->GetLabel().c_str(),p
->GetName().c_str()));
477 pgman
->DeleteProperty(p
);
481 CreateGrid( -1, -1 );
482 pgman
= m_pPropGridManager
;
487 // Test property default values
488 RT_START_TEST(Default_Values
)
492 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
496 wxPGProperty
* p
= it
.GetProperty();
497 pgman
->SetPropertyValue(p
, p
->GetDefaultValue());
501 CreateGrid( -1, -1 );
502 pgman
= m_pPropGridManager
;
507 // Test wxAny<->wxVariant conversion
508 RT_START_TEST(WXVARIANT_TO_WXANY_CONVERSION
)
514 prop
= pgman
->GetProperty("DateProperty");
515 wxDateTime testTime
= wxDateTime::Now();
518 if ( wxANY_AS(prop
->GetValue().GetAny(), wxDateTime
) != testTime
)
522 prop
= pgman
->GetProperty("IntProperty");
523 int testInt
= 25537983;
526 if ( wxANY_AS(prop
->GetValue().GetAny(), int) != testInt
)
529 if ( wxANY_AS(prop
->GetValue().GetAny(), wxLongLong_t
) != testInt
)
533 prop
= pgman
->GetProperty("StringProperty");
534 wxString testString
= "asd934jfyn3";
537 if ( wxANY_AS(prop
->GetValue().GetAny(), wxString
) != testString
)
540 // Test with a type generated with IMPLEMENT_VARIANT_OBJECT()
541 prop
= pgman
->GetProperty("ColourProperty");
542 wxColour testCol
= *wxCYAN
;
545 if ( wxANY_AS(prop
->GetValue().GetAny(), wxColour
) != testCol
)
548 // Test with a type with custom wxVariantData defined by
550 prop
= pgman
->GetProperty("Position");
551 wxPoint
testPoint(199, 199);
554 if ( wxANY_AS(prop
->GetValue().GetAny(), wxPoint
) != testPoint
)
559 RT_START_TEST(GetPropertyValues
)
561 for ( i
=0; i
<3; i
++ )
565 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
567 wxVariant values
= page
->GetPropertyValues();
570 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
572 wxVariant
& v
= values
[i
];
574 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\"\n"),(int)i
,
575 v
.GetName().c_str(),v
.GetType().c_str());
579 ed
->AppendText(text
);
584 RT_START_TEST(SetPropertyValue_and_GetPropertyValue
)
586 // In this section, mixed up usage of wxT("propname") and "propname"
587 // in wxPropertyGridInterface functions is intentional.
588 // Purpose is to test wxPGPropArgCls ctors.
590 //pg = (wxPropertyGrid*) NULL;
592 wxArrayString test_arrstr_1
;
593 test_arrstr_1
.Add(wxT("Apple"));
594 test_arrstr_1
.Add(wxT("Orange"));
595 test_arrstr_1
.Add(wxT("Lemon"));
597 wxArrayString test_arrstr_2
;
598 test_arrstr_2
.Add(wxT("Potato"));
599 test_arrstr_2
.Add(wxT("Cabbage"));
600 test_arrstr_2
.Add(wxT("Cucumber"));
602 wxArrayInt test_arrint_1
;
603 test_arrint_1
.Add(1);
604 test_arrint_1
.Add(2);
605 test_arrint_1
.Add(3);
607 wxArrayInt test_arrint_2
;
608 test_arrint_2
.Add(0);
609 test_arrint_2
.Add(1);
610 test_arrint_2
.Add(4);
613 wxDateTime dt1
= wxDateTime::Now();
614 dt1
.SetYear(dt1
.GetYear()-1);
616 wxDateTime dt2
= wxDateTime::Now();
617 dt2
.SetYear(dt2
.GetYear()-10);
620 wxColour
colWithAlpha(1, 128, 254, 100);
621 wxString
colWithAlphaStr(colWithAlpha
.GetAsString(wxC2S_CSS_SYNTAX
));
623 #define FLAG_TEST_SET1 (wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER)
624 #define FLAG_TEST_SET2 (wxSTAY_ON_TOP|wxCAPTION|wxICONIZE|wxSYSTEM_MENU)
626 pgman
->SetPropertyValue(wxT("StringProperty"),wxT("Text1"));
627 pgman
->SetPropertyValue(wxT("IntProperty"),1024);
628 pgman
->SetPropertyValue(wxT("FloatProperty"),1024.0000000001);
629 pgman
->SetPropertyValue(wxT("BoolProperty"),FALSE
);
630 pgman
->SetPropertyValue(wxT("EnumProperty"),120);
631 pgman
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_1
);
633 pgman
->SetPropertyValue(wxT("ColourProperty"),emptyCol
);
634 pgman
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxBLACK
);
635 pgman
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(150,150)));
636 pgman
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(150,150)));
637 pgman
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_1
);
639 pgman
->SetPropertyValue(wxT("DateProperty"),dt1
);
642 pgman
->SelectPage(2);
643 pg
= pgman
->GetGrid();
645 if ( pg
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text1") )
647 if ( pg
->GetPropertyValueAsInt(wxT("IntProperty")) != 1024 )
649 if ( pg
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 1024.0000000001 )
651 if ( pg
->GetPropertyValueAsBool(wxT("BoolProperty")) != FALSE
)
653 if ( pg
->GetPropertyValueAsLong(wxT("EnumProperty")) != 120 )
655 if ( pg
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_1
)
658 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
659 if ( col
!= *wxBLACK
)
661 wxVariant
varSize(pg
->GetPropertyValue(wxT("Size")));
662 if ( wxSizeRefFromVariant(varSize
) != wxSize(150,150) )
664 wxVariant
varPos(pg
->GetPropertyValue(wxT("Position")));
665 if ( wxPointRefFromVariant(varPos
) != wxPoint(150,150) )
667 if ( !(pg
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_1
) )
670 if ( !(pg
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt1
) )
674 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(10000000000));
675 if ( pg
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(10000000000) )
678 pg
->SetPropertyValue(wxT("StringProperty"),wxT("Text2"));
679 pg
->SetPropertyValue(wxT("IntProperty"),512);
680 pg
->SetPropertyValue(wxT("FloatProperty"),512.0);
681 pg
->SetPropertyValue(wxT("BoolProperty"),TRUE
);
682 pg
->SetPropertyValue(wxT("EnumProperty"),80);
683 pg
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_2
);
684 pg
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxWHITE
);
685 pg
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(300,300)));
686 pg
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(300,300)));
687 pg
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_2
);
689 pg
->SetPropertyValue(wxT("DateProperty"),dt2
);
692 //pg = (wxPropertyGrid*) NULL;
694 pgman
->SelectPage(0);
696 if ( pgman
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text2") )
698 if ( pgman
->GetPropertyValueAsInt(wxT("IntProperty")) != 512 )
700 if ( pgman
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 512.0 )
702 if ( pgman
->GetPropertyValueAsBool(wxT("BoolProperty")) != TRUE
)
704 if ( pgman
->GetPropertyValueAsLong(wxT("EnumProperty")) != 80 )
706 if ( pgman
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_2
)
708 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
709 if ( col
!= *wxWHITE
)
711 varSize
= pgman
->GetPropertyValue(wxT("Size"));
712 if ( wxSizeRefFromVariant(varSize
) != wxSize(300,300) )
714 varPos
= pgman
->GetPropertyValue(wxT("Position"));
715 if ( wxPointRefFromVariant(varPos
) != wxPoint(300,300) )
717 if ( !(pgman
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_2
) )
720 if ( !(pgman
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt2
) )
724 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000));
725 if ( pgman
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) )
728 // Make sure children of composite parent get updated as well
729 // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000; Not Convertible"
732 // This updates children as well
733 wxString nvs
= "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002; Convertible";
734 pgman
->SetPropertyValue("Car", nvs
);
736 if ( pgman
->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
738 wxLogDebug("Did not match: Car.Model=%s", pgman
->GetPropertyValueAsString("Car.Model").c_str());
742 if ( pgman
->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
744 wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman
->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
748 if ( pgman
->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
750 wxLogDebug("Did not match: Car.Price ($)=%s", pgman
->GetPropertyValueAsString("Car.Price ($)").c_str());
754 if ( !pgman
->GetPropertyValueAsBool("Car.Convertible") )
756 wxLogDebug("Did not match: Car.Convertible=%s", pgman
->GetPropertyValueAsString("Car.Convertible").c_str());
760 // SetPropertyValueString for special cases such as wxColour
761 pgman
->SetPropertyValueString("ColourProperty", "(123,4,255)");
762 col
<< pgman
->GetPropertyValue("ColourProperty");
763 if ( col
!= wxColour(123, 4, 255) )
765 pgman
->SetPropertyValueString("ColourProperty", "#FE860B");
766 col
<< pgman
->GetPropertyValue("ColourProperty");
767 if ( col
!= wxColour(254, 134, 11) )
770 pgman
->SetPropertyValueString("ColourPropertyWithAlpha",
771 "(10, 20, 30, 128)");
772 col
<< pgman
->GetPropertyValue("ColourPropertyWithAlpha");
773 if ( col
!= wxColour(10, 20, 30, 128) )
775 if ( pgman
->GetPropertyValueAsString("ColourPropertyWithAlpha")
776 != "(10,20,30,128)" )
781 RT_START_TEST(SetPropertyValueUnspecified
)
783 // Null variant setter tests
784 pgman
->SetPropertyValueUnspecified(wxT("StringProperty"));
785 pgman
->SetPropertyValueUnspecified(wxT("IntProperty"));
786 pgman
->SetPropertyValueUnspecified(wxT("FloatProperty"));
787 pgman
->SetPropertyValueUnspecified(wxT("BoolProperty"));
788 pgman
->SetPropertyValueUnspecified(wxT("EnumProperty"));
789 pgman
->SetPropertyValueUnspecified(wxT("ArrayStringProperty"));
790 pgman
->SetPropertyValueUnspecified(wxT("ColourProperty"));
791 pgman
->SetPropertyValueUnspecified(wxT("Size"));
792 pgman
->SetPropertyValueUnspecified(wxT("Position"));
793 pgman
->SetPropertyValueUnspecified(wxT("MultiChoiceProperty"));
795 pgman
->SetPropertyValueUnspecified(wxT("DateProperty"));
801 // Test multiple selection
802 RT_START_TEST(MULTIPLE_SELECTION
)
803 if ( !(pgman
->GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
804 CreateGrid( -1, wxPG_EX_MULTIPLE_SELECTION
);
805 pgman
= m_pPropGridManager
;
807 wxPropertyGrid
* pg
= pgman
->GetGrid();
809 wxPGProperty
* prop1
= pg
->GetProperty(wxT("Label"));
810 wxPGProperty
* prop2
= pg
->GetProperty(wxT("Cell Text Colour"));
811 wxPGProperty
* prop3
= pg
->GetProperty(wxT("Height"));
812 wxPGProperty
* catProp
= pg
->GetProperty(wxT("Appearance"));
814 RT_ASSERT( prop1
&& prop2
&& prop3
);
816 pg
->ClearSelection();
817 pg
->AddToSelection(prop1
);
818 pg
->AddToSelection(prop2
);
819 pg
->AddToSelection(prop3
);
821 // Adding category to selection should fail silently
822 pg
->AddToSelection(catProp
);
824 wxArrayPGProperty selectedProperties
= pg
->GetSelectedProperties();
826 RT_ASSERT( selectedProperties
.size() == 3 )
827 RT_ASSERT( pg
->IsPropertySelected(prop1
) )
828 RT_ASSERT( pg
->IsPropertySelected(prop2
) )
829 RT_ASSERT( pg
->IsPropertySelected(prop3
) )
830 RT_ASSERT( !pg
->IsPropertySelected(catProp
) )
832 pg
->RemoveFromSelection(prop1
);
833 wxArrayPGProperty selectedProperties2
= pg
->GetSelectedProperties();
835 RT_ASSERT( selectedProperties2
.size() == 2 )
836 RT_ASSERT( !pg
->IsPropertySelected(prop1
) )
837 RT_ASSERT( pg
->IsPropertySelected(prop2
) )
838 RT_ASSERT( pg
->IsPropertySelected(prop3
) )
840 pg
->ClearSelection();
842 wxArrayPGProperty selectedProperties3
= pg
->GetSelectedProperties();
844 RT_ASSERT( selectedProperties3
.size() == 0 )
845 RT_ASSERT( !pg
->IsPropertySelected(prop1
) )
846 RT_ASSERT( !pg
->IsPropertySelected(prop2
) )
847 RT_ASSERT( !pg
->IsPropertySelected(prop3
) )
849 pg
->SelectProperty(prop2
);
851 RT_ASSERT( !pg
->IsPropertySelected(prop1
) )
852 RT_ASSERT( pg
->IsPropertySelected(prop2
) )
853 RT_ASSERT( !pg
->IsPropertySelected(prop3
) )
858 // Test label editing
859 RT_START_TEST(LABEL_EDITING
)
861 wxPropertyGrid
* pg
= pgman
->GetGrid();
863 // Just mostly test that these won't crash
864 pg
->MakeColumnEditable(0, true);
865 pg
->MakeColumnEditable(2, true);
866 pg
->MakeColumnEditable(0, false);
867 pg
->MakeColumnEditable(2, false);
868 pg
->SelectProperty(wxT("Height"));
869 pg
->BeginLabelEdit(0);
870 pg
->BeginLabelEdit(0);
875 CreateGrid( -1, -1 );
876 pgman
= m_pPropGridManager
;
880 RT_START_TEST(Attributes
)
882 wxPGProperty
* prop
= pgman
->GetProperty(wxT("StringProperty"));
883 prop
->SetAttribute(wxT("Dummy Attribute"), (long)15);
885 if ( prop
->GetAttribute(wxT("Dummy Attribute")).GetLong() != 15 )
888 prop
->SetAttribute(wxT("Dummy Attribute"), wxVariant());
890 if ( !prop
->GetAttribute(wxT("Dummy Attribute")).IsNull() )
895 RT_START_TEST(DoubleToString
)
897 // Locale-specific decimal separator
898 wxString sep
= wxString::Format("%g", 1.1)[1];
902 if ( wxPropertyGrid::DoubleToString(s
, 123.123, 2, true) !=
903 wxString::Format("123%s12", sep
.c_str()) )
905 if ( wxPropertyGrid::DoubleToString(s
, -123.123, 4, false) !=
906 wxString::Format("-123%s1230", sep
.c_str()) )
908 if ( wxPropertyGrid::DoubleToString(s
, -0.02, 1, false) !=
909 wxString::Format("0%s0", sep
) )
911 if ( wxPropertyGrid::DoubleToString(s
, -0.000123, 3, true) != "0" )
916 wxPropertyGridPage
* page1
;
917 wxPropertyGridPage
* page2
;
918 wxPropertyGridPage
* page3
;
919 wxVariant pg1_values
;
920 wxVariant pg2_values
;
921 wxVariant pg3_values
;
924 RT_START_TEST(GetPropertyValues
)
926 page1
= pgman
->GetPage(0);
927 pg1_values
= page1
->GetPropertyValues(wxT("Page1"),NULL
,wxPG_KEEP_STRUCTURE
);
928 page2
= pgman
->GetPage(1);
929 pg2_values
= page2
->GetPropertyValues(wxT("Page2"),NULL
,wxPG_KEEP_STRUCTURE
);
930 page3
= pgman
->GetPage(2);
931 pg3_values
= page3
->GetPropertyValues(wxT("Page3"),NULL
,wxPG_KEEP_STRUCTURE
);
935 RT_START_TEST(SetPropertyValues
)
937 page1
->SetPropertyValues(pg3_values
);
938 page2
->SetPropertyValues(pg1_values
);
939 page3
->SetPropertyValues(pg2_values
);
943 if ( !(pgman
->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES
) )
945 RT_START_TEST(Collapse_and_GetFirstCategory_and_GetNextCategory
)
947 for ( i
=0; i
<3; i
++ )
949 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
951 wxPropertyGridIterator it
;
953 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
957 wxPGProperty
* p
= *it
;
959 if ( !page
->IsPropertyCategory(p
) )
964 t
.Printf(wxT("Collapsing: %s\n"),page
->GetPropertyLabel(p
).c_str());
971 RT_START_TEST(Save_And_RestoreEditableState
)
973 for ( i
=0; i
<3; i
++ )
975 pgman
->SelectPage(i
);
977 wxString stringState
= pgman
->SaveEditableState();
978 bool res
= pgman
->RestoreEditableState(stringState
);
984 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
986 RT_START_TEST(Expand_and_GetFirstCategory_and_GetNextCategory
)
988 for ( i
=0; i
<3; i
++ )
990 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
992 wxPropertyGridIterator it
;
994 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
998 wxPGProperty
* p
= *it
;
1000 if ( !page
->IsPropertyCategory(p
) )
1005 t
.Printf(wxT("Expand: %s\n"),page
->GetPropertyLabel(p
).c_str());
1012 RT_START_TEST(Choice_Manipulation
)
1014 wxPGProperty
* enumProp
= pgman
->GetProperty(wxT("EnumProperty"));
1016 pgman
->SelectPage(2);
1017 pgman
->SelectProperty(enumProp
);
1018 wxASSERT(pgman
->GetGrid()->GetSelection() == enumProp
);
1020 const wxPGChoices
& choices
= enumProp
->GetChoices();
1021 int ind
= enumProp
->InsertChoice(wxT("New Choice"), choices
.GetCount()/2);
1022 enumProp
->DeleteChoice(ind
);
1024 // Recreate the original grid
1025 CreateGrid( -1, -1 );
1026 pgman
= m_pPropGridManager
;
1029 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
1031 RT_START_TEST(RandomCollapse
)
1033 // Select the most error prone page as visible.
1034 pgman
->SelectPage(1);
1036 for ( i
=0; i
<3; i
++ )
1040 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
1042 wxPropertyGridIterator it
;
1044 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
1048 arr
.Add((void*)*it
);
1051 if ( arr
.GetCount() )
1055 pgman
->Collapse( (wxPGProperty
*)arr
.Item(0) );
1057 for ( n
=arr
.GetCount()-1; n
>0; n
-- )
1059 pgman
->Collapse( (wxPGProperty
*)arr
.Item(n
) );
1067 RT_START_TEST(EnsureVisible
)
1068 pgman
->EnsureVisible(wxT("Cell Colour"));
1072 RT_START_TEST(RemoveProperty
)
1076 wxPGProperty
* origParent
=
1077 pgman
->GetProperty("Window Styles")->GetParent();
1079 // For testing purposes, let's set some custom cell colours
1080 p
= pgman
->GetProperty("Window Styles");
1081 p
->SetCell(2, wxPGCell("style"));
1082 p
= pgman
->RemoveProperty("Window Styles");
1086 pgman
->AppendIn(origParent
, p
);
1087 wxASSERT( p
->GetCell(2).GetText() == "style");
1093 RT_START_TEST(SortFunction
)
1097 // Make sure indexes are as supposed
1099 p
= pgman
->GetProperty(wxT("User Name"));
1100 if ( p
->GetIndexInParent() != 3 )
1103 p
= pgman
->GetProperty(wxT("User Id"));
1104 if ( p
->GetIndexInParent() != 2 )
1107 p
= pgman
->GetProperty(wxT("User Home"));
1108 if ( p
->GetIndexInParent() != 1 )
1111 p
= pgman
->GetProperty(wxT("Operating System"));
1112 if ( p
->GetIndexInParent() != 0 )
1115 pgman
->GetGrid()->SetSortFunction(MyPropertySortFunction
);
1117 pgman
->GetGrid()->SortChildren(wxT("Environment"));
1119 // Make sure indexes have been reversed
1120 p
= pgman
->GetProperty(wxT("User Name"));
1121 if ( p
->GetIndexInParent() != 0 )
1124 p
= pgman
->GetProperty(wxT("User Id"));
1125 if ( p
->GetIndexInParent() != 1 )
1128 p
= pgman
->GetProperty(wxT("User Home"));
1129 if ( p
->GetIndexInParent() != 2 )
1132 p
= pgman
->GetProperty(wxT("Operating System"));
1133 if ( p
->GetIndexInParent() != 3 )
1138 RT_START_TEST(SetPropertyBackgroundColour
)
1140 evt
.SetInt(1); // IsChecked() will return TRUE.
1141 evt
.SetId(ID_COLOURSCHEME4
);
1143 OnColourScheme(evt
);
1147 RT_START_TEST(Clear
)
1150 pgman
->SelectProperty("Label");
1153 if ( pgman
->GetPageCount() )
1156 if ( pgman
->GetGrid()->GetRoot()->GetChildCount() )
1159 // Recreate the original grid
1160 CreateGrid( -1, -1 );
1161 pgman
= m_pPropGridManager
;
1164 pgman
->SelectProperty("Label");
1165 pgman
->GetGrid()->Clear();
1167 if ( pgman
->GetGrid()->GetRoot()->GetChildCount() )
1170 // Recreate the original grid
1171 CreateGrid( -1, -1 );
1172 pgman
= m_pPropGridManager
;
1176 // TODO: This test fails.
1177 RT_START_TEST(SetSplitterPosition)
1181 const int trySplitterPos = 50;
1183 int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
1184 pgman = m_pPropGridManager =
1185 new wxPropertyGridManager(m_panel, wxID_ANY,
1191 pgman->SetSplitterPosition(trySplitterPos);
1193 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1194 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1196 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
1199 wxSize sz = GetSize();
1204 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1205 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1209 // Recreate the original grid
1210 CreateGrid( -1, -1 );
1211 pgman = m_pPropGridManager;
1215 RT_START_TEST(HideProperty
)
1217 wxPropertyGridPage
* page
= pgman
->GetPage(0);
1221 wxArrayPGProperty arr1
;
1223 arr1
= GetPropertiesInRandomOrder(page
);
1227 for ( i
=0; i
<arr1
.size(); i
++ )
1229 wxPGProperty
* p
= arr1
[i
];
1230 page
->HideProperty(p
, true);
1232 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1233 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1241 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1243 for ( i
=0; i
<arr2
.size(); i
++ )
1245 wxPGProperty
* p
= arr2
[i
];
1246 page
->HideProperty(p
, false);
1248 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1249 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1256 // Let's do some more, for better consistency
1257 arr1
= GetPropertiesInRandomOrder(page
);
1261 for ( i
=0; i
<arr1
.size(); i
++ )
1263 wxPGProperty
* p
= arr1
[i
];
1264 page
->HideProperty(p
, true);
1266 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1267 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1275 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1277 for ( i
=0; i
<arr2
.size(); i
++ )
1279 wxPGProperty
* p
= arr2
[i
];
1280 page
->HideProperty(p
, false);
1282 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1283 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1290 // Ok, this time only hide half of them
1291 arr1
= GetPropertiesInRandomOrder(page
);
1292 arr1
.resize(arr1
.size()/2);
1296 for ( i
=0; i
<arr1
.size(); i
++ )
1298 wxPGProperty
* p
= arr1
[i
];
1299 page
->HideProperty(p
, true);
1301 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1302 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1310 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1312 for ( i
=0; i
<arr2
.size(); i
++ )
1314 wxPGProperty
* p
= arr2
[i
];
1315 page
->HideProperty(p
, false);
1317 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1318 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1324 // Recreate the original grid
1325 CreateGrid( -1, -1 );
1326 pgman
= m_pPropGridManager
;
1331 RT_START_TEST(MultipleColumns
)
1333 // Test with multiple columns
1334 // FIXME: Does not display changes.
1335 for ( i
=3; i
<12; i
+=2 )
1337 RT_MSG(wxString::Format(wxT("%i columns"),i
));
1338 CreateGrid( -1, -1 );
1339 pgman
= m_pPropGridManager
;
1340 pgman
->SetColumnCount(i
);
1349 RT_START_TEST(WindowStyles
)
1351 // Recreate grid with all possible (single) flags
1352 wxASSERT(wxPG_AUTO_SORT
== 0x000000010);
1354 for ( i
=4; i
<16; i
++ )
1357 RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag
));
1358 CreateGrid( flag
, -1 );
1359 pgman
= m_pPropGridManager
;
1364 wxASSERT(wxPG_EX_INIT_NOCAT
== 0x00001000);
1366 for ( i
=12; i
<27; i
++ )
1369 RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag
));
1370 CreateGrid( -1, flag
);
1371 pgman
= m_pPropGridManager
;
1376 // Recreate the original grid
1377 CreateGrid( -1, -1 );
1378 pgman
= m_pPropGridManager
;
1385 if ( failures
|| errorMessages
.size() )
1393 s
= wxString::Format(wxT("%i tests failed!!!"), failures
);
1396 s
= wxString::Format(wxT("All tests were successful, but there were %i warnings!"), wxPGGlobalVars
->m_warnings
);
1399 for ( i
=0; i
<errorMessages
.size(); i
++ )
1400 RT_MSG(errorMessages
[i
])
1401 wxMessageBox(s
, wxT("Some Tests Failed"));
1405 RT_MSG(wxT("All tests successfull"))
1412 pgman
->SelectPage(0);
1414 // Test may screw up the toolbar, so we need to refresh it.
1415 wxToolBar
* toolBar
= pgman
->GetToolBar();
1422 // -----------------------------------------------------------------------