1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/propgrid/tests.cpp
3 // Purpose: wxPropertyGrid tests
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
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"))->SetAutoUnspecified(true);
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
,
168 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
169 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
170 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
171 const int butSzFlags
=
172 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
173 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
174 0, butSzFlags
, spacing
);
175 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
177 dlg
->SetSizer( topsizer
);
178 topsizer
->SetSizeHints( dlg
);
180 dlg
->SetSize(400,300);
185 // -----------------------------------------------------------------------
191 TestRunner( const wxString
& name
, wxPropertyGridManager
* man
, wxTextCtrl
* ed
, wxArrayString
* errorMessages
)
196 m_errorMessages
= errorMessages
;
198 m_preWarnings
= wxPGGlobalVars
->m_warnings
;
201 if ( name
!= wxT("none") )
208 int warningsOccurred
= wxPGGlobalVars
->m_warnings
- m_preWarnings
;
209 if ( warningsOccurred
)
211 wxString s
= wxString::Format(wxT("%i warnings occurred during test '%s'"), warningsOccurred
, m_name
.c_str());
212 m_errorMessages
->push_back(s
);
218 void Msg( const wxString
& text
)
222 m_ed
->AppendText(text
);
223 m_ed
->AppendText(wxT("\n"));
229 wxPropertyGridManager
* m_man
;
231 wxArrayString
* m_errorMessages
;
239 #define RT_START_TEST(TESTNAME) \
240 TestRunner tr(wxT(#TESTNAME), pgman, ed, &errorMessages);
245 #define RT_FAILURE() \
247 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
248 errorMessages.push_back(s1); \
253 #define RT_ASSERT(COND) \
257 #define RT_FAILURE_MSG(MSG) \
259 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
260 errorMessages.push_back(s1); \
262 wxString s2 = wxString::Format(wxT("Message: %s"),MSG); \
263 errorMessages.push_back(s2); \
268 #define RT_VALIDATE_VIRTUAL_HEIGHT(PROPS, EXTRATEXT) \
270 unsigned int h1_ = PROPS->GetVirtualHeight(); \
271 unsigned int h2_ = PROPS->GetActualVirtualHeight(); \
274 wxString s_ = wxString::Format(wxT("VirtualHeight = %i, should be %i (%s)"), h1_, h2_, EXTRATEXT.c_str()); \
275 RT_FAILURE_MSG(s_.c_str()); \
285 int gpiro_cmpfunc(const void* a
, const void* b
)
287 const wxPGProperty
* p1
= (const wxPGProperty
*) a
;
288 const wxPGProperty
* p2
= (const wxPGProperty
*) b
;
289 return (int) (((size_t)p1
->GetClientData()) - ((size_t)p2
->GetClientData()));
292 wxArrayPGProperty
GetPropertiesInRandomOrder( wxPropertyGridInterface
* props
, int iterationFlags
= wxPG_ITERATE_ALL
)
294 wxArrayPGProperty arr
;
296 wxPropertyGridIterator it
;
298 for ( it
= props
->GetIterator(iterationFlags
);
302 wxPGProperty
* p
= *it
;
303 size_t randomNumber
= rand();
304 p
->SetClientData(reinterpret_cast<void*>(randomNumber
));
308 wxPGProperty
** firstEntry
= &arr
[0];
309 qsort(firstEntry
, arr
.size(), sizeof(wxPGProperty
*), gpiro_cmpfunc
);
314 // Callback for testing property sorting
315 int MyPropertySortFunction(wxPropertyGrid
* WXUNUSED(propGrid
),
319 // Reverse alphabetical order
320 return p2
->GetLabel().CmpNoCase( p1
->GetBaseName() );
323 bool FormMain::RunTests( bool fullTest
, bool interactive
)
327 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
332 pgman
->ClearSelection();
335 bool _failed_
= false;
336 wxArrayString errorMessages
;
337 wxDialog
* dlg
= NULL
;
339 dlg
= new wxDialog(this,-1,wxT("wxPropertyGrid Regression Tests"),
340 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
342 // multi-line text editor dialog
343 const int spacing
= 8;
344 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
345 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
346 wxTextCtrl
* ed
= new wxTextCtrl(dlg
, 11, wxEmptyString
,
347 wxDefaultPosition
, wxDefaultSize
,
349 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
350 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
351 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
352 const int butSzFlags
=
353 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
354 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
355 0, butSzFlags
, spacing
);
356 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
358 dlg
->SetSizer( topsizer
);
359 topsizer
->SetSizeHints( dlg
);
361 dlg
->SetSize(400,300);
362 dlg
->Move(wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)-dlg
->GetSize().x
,
363 wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)-dlg
->GetSize().y
);
368 // Basic iterator tests
369 RT_START_TEST(GetIterator
)
375 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
379 wxPGProperty
* p
= it
.GetProperty();
380 if ( p
->IsCategory() )
381 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a category (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
382 else if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
383 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
387 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES) -> %i entries"), count
));
390 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_CATEGORIES
);
394 wxPGProperty
* p
= it
.GetProperty();
395 if ( !p
->IsCategory() )
396 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is not a category (only category was expected)"),p
->GetLabel().c_str()).c_str())
400 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
403 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
|wxPG_ITERATE_CATEGORIES
);
407 wxPGProperty
* p
= it
.GetProperty();
408 if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
409 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property or category expected)"),p
->GetLabel().c_str()).c_str())
413 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
416 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_VISIBLE
);
420 wxPGProperty
* p
= it
.GetProperty();
421 if ( (p
->GetParent() != p
->GetParentState()->DoGetRoot() && !p
->GetParent()->IsExpanded()) )
422 RT_FAILURE_MSG(wxString::Format(wxT("'%s' had collapsed parent (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
423 else if ( p
->HasFlag(wxPG_PROP_HIDDEN
) )
424 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was hidden (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
428 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_VISIBLE) -> %i entries"), count
));
433 // Test that setting focus to properties does not crash things
434 RT_START_TEST(SelectProperty
)
436 wxPropertyGridIterator it
;
439 for ( ind
=0; ind
<pgman
->GetPageCount(); ind
++ )
441 wxPropertyGridPage
* page
= pgman
->GetPage(ind
);
442 pgman
->SelectPage(page
);
444 for ( it
= page
->GetIterator(wxPG_ITERATE_VISIBLE
);
448 wxPGProperty
* p
= *it
;
449 RT_MSG(p
->GetLabel());
450 pgman
->GetGrid()->SelectProperty(p
, true);
459 // Delete everything in reverse order
460 RT_START_TEST(DeleteProperty
)
463 wxArrayPGProperty array
;
465 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_ALL
&~(wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
)));
468 array
.push_back(it
.GetProperty());
470 wxArrayPGProperty::reverse_iterator it2
;
472 for ( it2
= array
.rbegin(); it2
!= array
.rend(); it2
++ )
474 wxPGProperty
* p
= (wxPGProperty
*)*it2
;
475 RT_MSG(wxString::Format(wxT("Deleting '%s' ('%s')"),p
->GetLabel().c_str(),p
->GetName().c_str()));
476 pgman
->DeleteProperty(p
);
480 CreateGrid( -1, -1 );
481 pgman
= m_pPropGridManager
;
486 // Test property default values
487 RT_START_TEST(Default_Values
)
491 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
495 wxPGProperty
* p
= it
.GetProperty();
496 pgman
->SetPropertyValue(p
, p
->GetDefaultValue());
500 CreateGrid( -1, -1 );
501 pgman
= m_pPropGridManager
;
506 // Test wxAny<->wxVariant conversion
507 RT_START_TEST(WXVARIANT_TO_WXANY_CONVERSION
)
513 prop
= pgman
->GetProperty("DateProperty");
514 wxDateTime testTime
= wxDateTime::Now();
517 if ( wxANY_AS(prop
->GetValue().GetAny(), wxDateTime
) != testTime
)
521 prop
= pgman
->GetProperty("IntProperty");
522 int testInt
= 25537983;
525 if ( wxANY_AS(prop
->GetValue().GetAny(), int) != testInt
)
528 if ( wxANY_AS(prop
->GetValue().GetAny(), wxLongLong_t
) != testInt
)
532 prop
= pgman
->GetProperty("StringProperty");
533 wxString testString
= "asd934jfyn3";
536 if ( wxANY_AS(prop
->GetValue().GetAny(), wxString
) != testString
)
539 // Test with a type generated with IMPLEMENT_VARIANT_OBJECT()
540 prop
= pgman
->GetProperty("ColourProperty");
541 wxColour testCol
= *wxCYAN
;
544 if ( wxANY_AS(prop
->GetValue().GetAny(), wxColour
) != testCol
)
547 // Test with a type with custom wxVariantData defined by
549 prop
= pgman
->GetProperty("Position");
550 wxPoint
testPoint(199, 199);
553 if ( wxANY_AS(prop
->GetValue().GetAny(), wxPoint
) != testPoint
)
558 RT_START_TEST(GetPropertyValues
)
560 for ( i
=0; i
<3; i
++ )
564 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
566 wxVariant values
= page
->GetPropertyValues();
569 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
571 wxVariant
& v
= values
[i
];
573 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\"\n"),(int)i
,
574 v
.GetName().c_str(),v
.GetType().c_str());
578 ed
->AppendText(text
);
583 RT_START_TEST(SetPropertyValue_and_GetPropertyValue
)
585 // In this section, mixed up usage of wxT("propname") and "propname"
586 // in wxPropertyGridInterface functions is intentional.
587 // Purpose is to test wxPGPropArgCls ctors.
589 //pg = (wxPropertyGrid*) NULL;
591 wxArrayString test_arrstr_1
;
592 test_arrstr_1
.Add(wxT("Apple"));
593 test_arrstr_1
.Add(wxT("Orange"));
594 test_arrstr_1
.Add(wxT("Lemon"));
596 wxArrayString test_arrstr_2
;
597 test_arrstr_2
.Add(wxT("Potato"));
598 test_arrstr_2
.Add(wxT("Cabbage"));
599 test_arrstr_2
.Add(wxT("Cucumber"));
601 wxArrayInt test_arrint_1
;
602 test_arrint_1
.Add(1);
603 test_arrint_1
.Add(2);
604 test_arrint_1
.Add(3);
606 wxArrayInt test_arrint_2
;
607 test_arrint_2
.Add(0);
608 test_arrint_2
.Add(1);
609 test_arrint_2
.Add(4);
612 wxDateTime dt1
= wxDateTime::Now();
613 dt1
.SetYear(dt1
.GetYear()-1);
615 wxDateTime dt2
= wxDateTime::Now();
616 dt2
.SetYear(dt2
.GetYear()-10);
619 wxColour
colWithAlpha(1, 128, 254, 100);
620 wxString
colWithAlphaStr(colWithAlpha
.GetAsString(wxC2S_CSS_SYNTAX
));
622 #define FLAG_TEST_SET1 (wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER)
623 #define FLAG_TEST_SET2 (wxSTAY_ON_TOP|wxCAPTION|wxICONIZE|wxSYSTEM_MENU)
625 pgman
->SetPropertyValue(wxT("StringProperty"),wxT("Text1"));
626 pgman
->SetPropertyValue(wxT("IntProperty"),1024);
627 pgman
->SetPropertyValue(wxT("FloatProperty"),1024.0000000001);
628 pgman
->SetPropertyValue(wxT("BoolProperty"),FALSE
);
629 pgman
->SetPropertyValue(wxT("EnumProperty"),120);
630 pgman
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_1
);
632 pgman
->SetPropertyValue(wxT("ColourProperty"),emptyCol
);
633 pgman
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxBLACK
);
634 pgman
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(150,150)));
635 pgman
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(150,150)));
636 pgman
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_1
);
638 pgman
->SetPropertyValue(wxT("DateProperty"),dt1
);
641 pgman
->SelectPage(2);
642 pg
= pgman
->GetGrid();
644 if ( pg
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text1") )
646 if ( pg
->GetPropertyValueAsInt(wxT("IntProperty")) != 1024 )
648 if ( pg
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 1024.0000000001 )
650 if ( pg
->GetPropertyValueAsBool(wxT("BoolProperty")) != FALSE
)
652 if ( pg
->GetPropertyValueAsLong(wxT("EnumProperty")) != 120 )
654 if ( pg
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_1
)
657 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
658 if ( col
!= *wxBLACK
)
660 wxVariant
varSize(pg
->GetPropertyValue(wxT("Size")));
661 if ( wxSizeRefFromVariant(varSize
) != wxSize(150,150) )
663 wxVariant
varPos(pg
->GetPropertyValue(wxT("Position")));
664 if ( wxPointRefFromVariant(varPos
) != wxPoint(150,150) )
666 if ( !(pg
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_1
) )
669 if ( !(pg
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt1
) )
673 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(10000000000));
674 if ( pg
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(10000000000) )
677 pg
->SetPropertyValue(wxT("StringProperty"),wxT("Text2"));
678 pg
->SetPropertyValue(wxT("IntProperty"),512);
679 pg
->SetPropertyValue(wxT("FloatProperty"),512.0);
680 pg
->SetPropertyValue(wxT("BoolProperty"),TRUE
);
681 pg
->SetPropertyValue(wxT("EnumProperty"),80);
682 pg
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_2
);
683 pg
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxWHITE
);
684 pg
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(300,300)));
685 pg
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(300,300)));
686 pg
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_2
);
688 pg
->SetPropertyValue(wxT("DateProperty"),dt2
);
691 //pg = (wxPropertyGrid*) NULL;
693 pgman
->SelectPage(0);
695 if ( pgman
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text2") )
697 if ( pgman
->GetPropertyValueAsInt(wxT("IntProperty")) != 512 )
699 if ( pgman
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 512.0 )
701 if ( pgman
->GetPropertyValueAsBool(wxT("BoolProperty")) != TRUE
)
703 if ( pgman
->GetPropertyValueAsLong(wxT("EnumProperty")) != 80 )
705 if ( pgman
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_2
)
707 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
708 if ( col
!= *wxWHITE
)
710 varSize
= pgman
->GetPropertyValue(wxT("Size"));
711 if ( wxSizeRefFromVariant(varSize
) != wxSize(300,300) )
713 varPos
= pgman
->GetPropertyValue(wxT("Position"));
714 if ( wxPointRefFromVariant(varPos
) != wxPoint(300,300) )
716 if ( !(pgman
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_2
) )
719 if ( !(pgman
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt2
) )
723 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000));
724 if ( pgman
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) )
727 // Make sure children of composite parent get updated as well
728 // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000; Not Convertible"
731 // This updates children as well
732 wxString nvs
= "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002; Convertible";
733 pgman
->SetPropertyValue("Car", nvs
);
735 if ( pgman
->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
737 wxLogDebug("Did not match: Car.Model=%s", pgman
->GetPropertyValueAsString("Car.Model").c_str());
741 if ( pgman
->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
743 wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman
->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
747 if ( pgman
->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
749 wxLogDebug("Did not match: Car.Price ($)=%s", pgman
->GetPropertyValueAsString("Car.Price ($)").c_str());
753 if ( !pgman
->GetPropertyValueAsBool("Car.Convertible") )
755 wxLogDebug("Did not match: Car.Convertible=%s", pgman
->GetPropertyValueAsString("Car.Convertible").c_str());
759 // SetPropertyValueString for special cases such as wxColour
760 pgman
->SetPropertyValueString("ColourProperty", "(123,4,255)");
761 col
<< pgman
->GetPropertyValue("ColourProperty");
762 if ( col
!= wxColour(123, 4, 255) )
764 pgman
->SetPropertyValueString("ColourProperty", "#FE860B");
765 col
<< pgman
->GetPropertyValue("ColourProperty");
766 if ( col
!= wxColour(254, 134, 11) )
769 pgman
->SetPropertyValueString("ColourPropertyWithAlpha",
770 "(10, 20, 30, 128)");
771 col
<< pgman
->GetPropertyValue("ColourPropertyWithAlpha");
772 if ( col
!= wxColour(10, 20, 30, 128) )
774 if ( pgman
->GetPropertyValueAsString("ColourPropertyWithAlpha")
775 != "(10,20,30,128)" )
780 RT_START_TEST(SetPropertyValueUnspecified
)
782 // Null variant setter tests
783 pgman
->SetPropertyValueUnspecified(wxT("StringProperty"));
784 pgman
->SetPropertyValueUnspecified(wxT("IntProperty"));
785 pgman
->SetPropertyValueUnspecified(wxT("FloatProperty"));
786 pgman
->SetPropertyValueUnspecified(wxT("BoolProperty"));
787 pgman
->SetPropertyValueUnspecified(wxT("EnumProperty"));
788 pgman
->SetPropertyValueUnspecified(wxT("ArrayStringProperty"));
789 pgman
->SetPropertyValueUnspecified(wxT("ColourProperty"));
790 pgman
->SetPropertyValueUnspecified(wxT("Size"));
791 pgman
->SetPropertyValueUnspecified(wxT("Position"));
792 pgman
->SetPropertyValueUnspecified(wxT("MultiChoiceProperty"));
794 pgman
->SetPropertyValueUnspecified(wxT("DateProperty"));
800 // Test multiple selection
801 RT_START_TEST(MULTIPLE_SELECTION
)
802 if ( !(pgman
->GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
803 CreateGrid( -1, wxPG_EX_MULTIPLE_SELECTION
);
804 pgman
= m_pPropGridManager
;
806 wxPropertyGrid
* pg
= pgman
->GetGrid();
808 wxPGProperty
* prop1
= pg
->GetProperty(wxT("Label"));
809 wxPGProperty
* prop2
= pg
->GetProperty(wxT("Cell Text Colour"));
810 wxPGProperty
* prop3
= pg
->GetProperty(wxT("Height"));
811 wxPGProperty
* catProp
= pg
->GetProperty(wxT("Appearance"));
813 RT_ASSERT( prop1
&& prop2
&& prop3
);
815 pg
->ClearSelection();
816 pg
->AddToSelection(prop1
);
817 pg
->AddToSelection(prop2
);
818 pg
->AddToSelection(prop3
);
820 // Adding category to selection should fail silently
821 pg
->AddToSelection(catProp
);
823 wxArrayPGProperty selectedProperties
= pg
->GetSelectedProperties();
825 RT_ASSERT( selectedProperties
.size() == 3 )
826 RT_ASSERT( pg
->IsPropertySelected(prop1
) )
827 RT_ASSERT( pg
->IsPropertySelected(prop2
) )
828 RT_ASSERT( pg
->IsPropertySelected(prop3
) )
829 RT_ASSERT( !pg
->IsPropertySelected(catProp
) )
831 pg
->RemoveFromSelection(prop1
);
832 wxArrayPGProperty selectedProperties2
= pg
->GetSelectedProperties();
834 RT_ASSERT( selectedProperties2
.size() == 2 )
835 RT_ASSERT( !pg
->IsPropertySelected(prop1
) )
836 RT_ASSERT( pg
->IsPropertySelected(prop2
) )
837 RT_ASSERT( pg
->IsPropertySelected(prop3
) )
839 pg
->ClearSelection();
841 wxArrayPGProperty selectedProperties3
= pg
->GetSelectedProperties();
843 RT_ASSERT( selectedProperties3
.size() == 0 )
844 RT_ASSERT( !pg
->IsPropertySelected(prop1
) )
845 RT_ASSERT( !pg
->IsPropertySelected(prop2
) )
846 RT_ASSERT( !pg
->IsPropertySelected(prop3
) )
848 pg
->SelectProperty(prop2
);
850 RT_ASSERT( !pg
->IsPropertySelected(prop1
) )
851 RT_ASSERT( pg
->IsPropertySelected(prop2
) )
852 RT_ASSERT( !pg
->IsPropertySelected(prop3
) )
857 // Test label editing
858 RT_START_TEST(LABEL_EDITING
)
860 wxPropertyGrid
* pg
= pgman
->GetGrid();
862 // Just mostly test that these won't crash
863 pg
->MakeColumnEditable(0, true);
864 pg
->MakeColumnEditable(2, true);
865 pg
->MakeColumnEditable(0, false);
866 pg
->MakeColumnEditable(2, false);
867 pg
->SelectProperty(wxT("Height"));
868 pg
->BeginLabelEdit(0);
869 pg
->BeginLabelEdit(0);
874 CreateGrid( -1, -1 );
875 pgman
= m_pPropGridManager
;
879 RT_START_TEST(Attributes
)
881 wxPGProperty
* prop
= pgman
->GetProperty(wxT("StringProperty"));
882 prop
->SetAttribute(wxT("Dummy Attribute"), (long)15);
884 if ( prop
->GetAttribute(wxT("Dummy Attribute")).GetLong() != 15 )
887 prop
->SetAttribute(wxT("Dummy Attribute"), wxVariant());
889 if ( !prop
->GetAttribute(wxT("Dummy Attribute")).IsNull() )
894 RT_START_TEST(DoubleToString
)
896 // Locale-specific decimal separator
897 wxString sep
= wxString::Format("%g", 1.1)[1];
901 if ( wxPropertyGrid::DoubleToString(s
, 123.123, 2, true) !=
902 wxString::Format("123%s12", sep
.c_str()) )
904 if ( wxPropertyGrid::DoubleToString(s
, -123.123, 4, false) !=
905 wxString::Format("-123%s1230", sep
.c_str()) )
907 if ( wxPropertyGrid::DoubleToString(s
, -0.02, 1, false) !=
908 wxString::Format("0%s0", sep
) )
910 if ( wxPropertyGrid::DoubleToString(s
, -0.000123, 3, true) != "0" )
915 wxPropertyGridPage
* page1
;
916 wxPropertyGridPage
* page2
;
917 wxPropertyGridPage
* page3
;
918 wxVariant pg1_values
;
919 wxVariant pg2_values
;
920 wxVariant pg3_values
;
923 RT_START_TEST(GetPropertyValues
)
925 page1
= pgman
->GetPage(0);
926 pg1_values
= page1
->GetPropertyValues(wxT("Page1"),NULL
,wxPG_KEEP_STRUCTURE
);
927 page2
= pgman
->GetPage(1);
928 pg2_values
= page2
->GetPropertyValues(wxT("Page2"),NULL
,wxPG_KEEP_STRUCTURE
);
929 page3
= pgman
->GetPage(2);
930 pg3_values
= page3
->GetPropertyValues(wxT("Page3"),NULL
,wxPG_KEEP_STRUCTURE
);
934 RT_START_TEST(SetPropertyValues
)
936 page1
->SetPropertyValues(pg3_values
);
937 page2
->SetPropertyValues(pg1_values
);
938 page3
->SetPropertyValues(pg2_values
);
942 if ( !(pgman
->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES
) )
944 RT_START_TEST(Collapse_and_GetFirstCategory_and_GetNextCategory
)
946 for ( i
=0; i
<3; i
++ )
948 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
950 wxPropertyGridIterator it
;
952 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
956 wxPGProperty
* p
= *it
;
958 if ( !page
->IsPropertyCategory(p
) )
963 t
.Printf(wxT("Collapsing: %s\n"),page
->GetPropertyLabel(p
).c_str());
970 RT_START_TEST(Save_And_RestoreEditableState
)
972 for ( i
=0; i
<3; i
++ )
974 pgman
->SelectPage(i
);
976 wxString stringState
= pgman
->SaveEditableState();
977 bool res
= pgman
->RestoreEditableState(stringState
);
983 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
985 RT_START_TEST(Expand_and_GetFirstCategory_and_GetNextCategory
)
987 for ( i
=0; i
<3; i
++ )
989 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
991 wxPropertyGridIterator it
;
993 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
997 wxPGProperty
* p
= *it
;
999 if ( !page
->IsPropertyCategory(p
) )
1004 t
.Printf(wxT("Expand: %s\n"),page
->GetPropertyLabel(p
).c_str());
1011 RT_START_TEST(Choice_Manipulation
)
1013 wxPGProperty
* enumProp
= pgman
->GetProperty(wxT("EnumProperty"));
1015 pgman
->SelectPage(2);
1016 pgman
->SelectProperty(enumProp
);
1017 wxASSERT(pgman
->GetGrid()->GetSelection() == enumProp
);
1019 const wxPGChoices
& choices
= enumProp
->GetChoices();
1020 int ind
= enumProp
->InsertChoice(wxT("New Choice"), choices
.GetCount()/2);
1021 enumProp
->DeleteChoice(ind
);
1023 // Recreate the original grid
1024 CreateGrid( -1, -1 );
1025 pgman
= m_pPropGridManager
;
1028 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
1030 RT_START_TEST(RandomCollapse
)
1032 // Select the most error prone page as visible.
1033 pgman
->SelectPage(1);
1035 for ( i
=0; i
<3; i
++ )
1039 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
1041 wxPropertyGridIterator it
;
1043 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
1047 arr
.Add((void*)*it
);
1050 if ( arr
.GetCount() )
1054 pgman
->Collapse( (wxPGProperty
*)arr
.Item(0) );
1056 for ( n
=arr
.GetCount()-1; n
>0; n
-- )
1058 pgman
->Collapse( (wxPGProperty
*)arr
.Item(n
) );
1066 RT_START_TEST(EnsureVisible
)
1067 pgman
->EnsureVisible(wxT("Cell Colour"));
1071 RT_START_TEST(RemoveProperty
)
1075 wxPGProperty
* origParent
=
1076 pgman
->GetProperty("Window Styles")->GetParent();
1078 // For testing purposes, let's set some custom cell colours
1079 p
= pgman
->GetProperty("Window Styles");
1080 p
->SetCell(2, wxPGCell("style"));
1081 p
= pgman
->RemoveProperty("Window Styles");
1085 pgman
->AppendIn(origParent
, p
);
1086 wxASSERT( p
->GetCell(2).GetText() == "style");
1092 RT_START_TEST(SortFunction
)
1096 // Make sure indexes are as supposed
1098 p
= pgman
->GetProperty(wxT("User Name"));
1099 if ( p
->GetIndexInParent() != 3 )
1102 p
= pgman
->GetProperty(wxT("User Id"));
1103 if ( p
->GetIndexInParent() != 2 )
1106 p
= pgman
->GetProperty(wxT("User Home"));
1107 if ( p
->GetIndexInParent() != 1 )
1110 p
= pgman
->GetProperty(wxT("Operating System"));
1111 if ( p
->GetIndexInParent() != 0 )
1114 pgman
->GetGrid()->SetSortFunction(MyPropertySortFunction
);
1116 pgman
->GetGrid()->SortChildren(wxT("Environment"));
1118 // Make sure indexes have been reversed
1119 p
= pgman
->GetProperty(wxT("User Name"));
1120 if ( p
->GetIndexInParent() != 0 )
1123 p
= pgman
->GetProperty(wxT("User Id"));
1124 if ( p
->GetIndexInParent() != 1 )
1127 p
= pgman
->GetProperty(wxT("User Home"));
1128 if ( p
->GetIndexInParent() != 2 )
1131 p
= pgman
->GetProperty(wxT("Operating System"));
1132 if ( p
->GetIndexInParent() != 3 )
1137 RT_START_TEST(SetPropertyBackgroundColour
)
1139 evt
.SetInt(1); // IsChecked() will return TRUE.
1140 evt
.SetId(ID_COLOURSCHEME4
);
1142 OnColourScheme(evt
);
1146 RT_START_TEST(Clear
)
1149 pgman
->SelectProperty("Label");
1152 if ( pgman
->GetPageCount() )
1155 if ( pgman
->GetGrid()->GetRoot()->GetChildCount() )
1158 // Recreate the original grid
1159 CreateGrid( -1, -1 );
1160 pgman
= m_pPropGridManager
;
1163 pgman
->SelectProperty("Label");
1164 pgman
->GetGrid()->Clear();
1166 if ( pgman
->GetGrid()->GetRoot()->GetChildCount() )
1169 // Recreate the original grid
1170 CreateGrid( -1, -1 );
1171 pgman
= m_pPropGridManager
;
1175 // TODO: This test fails.
1176 RT_START_TEST(SetSplitterPosition)
1180 const int trySplitterPos = 50;
1182 int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
1183 pgman = m_pPropGridManager =
1184 new wxPropertyGridManager(m_panel, wxID_ANY,
1190 pgman->SetSplitterPosition(trySplitterPos);
1192 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1193 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1195 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
1198 wxSize sz = GetSize();
1203 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1204 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1208 // Recreate the original grid
1209 CreateGrid( -1, -1 );
1210 pgman = m_pPropGridManager;
1214 RT_START_TEST(HideProperty
)
1216 wxPropertyGridPage
* page
= pgman
->GetPage(0);
1220 wxArrayPGProperty arr1
;
1222 arr1
= GetPropertiesInRandomOrder(page
);
1226 for ( i
=0; i
<arr1
.size(); i
++ )
1228 wxPGProperty
* p
= arr1
[i
];
1229 page
->HideProperty(p
, true);
1231 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1232 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1240 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1242 for ( i
=0; i
<arr2
.size(); i
++ )
1244 wxPGProperty
* p
= arr2
[i
];
1245 page
->HideProperty(p
, false);
1247 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1248 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1255 // Let's do some more, for better consistency
1256 arr1
= GetPropertiesInRandomOrder(page
);
1260 for ( i
=0; i
<arr1
.size(); i
++ )
1262 wxPGProperty
* p
= arr1
[i
];
1263 page
->HideProperty(p
, true);
1265 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1266 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1274 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1276 for ( i
=0; i
<arr2
.size(); i
++ )
1278 wxPGProperty
* p
= arr2
[i
];
1279 page
->HideProperty(p
, false);
1281 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1282 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1289 // Ok, this time only hide half of them
1290 arr1
= GetPropertiesInRandomOrder(page
);
1291 arr1
.resize(arr1
.size()/2);
1295 for ( i
=0; i
<arr1
.size(); i
++ )
1297 wxPGProperty
* p
= arr1
[i
];
1298 page
->HideProperty(p
, true);
1300 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1301 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1309 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1311 for ( i
=0; i
<arr2
.size(); i
++ )
1313 wxPGProperty
* p
= arr2
[i
];
1314 page
->HideProperty(p
, false);
1316 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1317 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1323 // Recreate the original grid
1324 CreateGrid( -1, -1 );
1325 pgman
= m_pPropGridManager
;
1330 RT_START_TEST(MultipleColumns
)
1332 // Test with multiple columns
1333 // FIXME: Does not display changes.
1334 for ( i
=3; i
<12; i
+=2 )
1336 RT_MSG(wxString::Format(wxT("%i columns"),i
));
1337 CreateGrid( -1, -1 );
1338 pgman
= m_pPropGridManager
;
1339 pgman
->SetColumnCount(i
);
1348 RT_START_TEST(WindowStyles
)
1350 // Recreate grid with all possible (single) flags
1351 wxASSERT(wxPG_AUTO_SORT
== 0x000000010);
1353 for ( i
=4; i
<16; i
++ )
1356 RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag
));
1357 CreateGrid( flag
, -1 );
1358 pgman
= m_pPropGridManager
;
1363 wxASSERT(wxPG_EX_INIT_NOCAT
== 0x00001000);
1365 for ( i
=12; i
<27; i
++ )
1368 RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag
));
1369 CreateGrid( -1, flag
);
1370 pgman
= m_pPropGridManager
;
1375 // Recreate the original grid
1376 CreateGrid( -1, -1 );
1377 pgman
= m_pPropGridManager
;
1384 if ( failures
|| errorMessages
.size() )
1392 s
= wxString::Format(wxT("%i tests failed!!!"), failures
);
1395 s
= wxString::Format(wxT("All tests were succesfull, but there were %i warnings!"), wxPGGlobalVars
->m_warnings
);
1398 for ( i
=0; i
<errorMessages
.size(); i
++ )
1399 RT_MSG(errorMessages
[i
])
1400 wxMessageBox(s
, wxT("Some Tests Failed"));
1404 RT_MSG(wxT("All tests succesfull"))
1411 pgman
->SelectPage(0);
1413 // Test may screw up the toolbar, so we need to refresh it.
1414 wxToolBar
* toolBar
= pgman
->GetToolBar();
1421 // -----------------------------------------------------------------------