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
,
93 int argFlags
= 0 ) const
95 if ( index
== (int)(m_choices
.GetCount()-1) )
98 return wxColourProperty::ColourToString(col
, index
, argFlags
);
101 virtual int GetCustomColourIndex() const
103 return m_choices
.GetCount()-2;
108 void FormMain::AddTestProperties( wxPropertyGridPage
* pg
)
110 pg
->Append( new MyColourProperty(wxT("CustomColourProperty"), wxPG_LABEL
, *wxGREEN
) );
111 pg
->GetProperty(wxT("CustomColourProperty"))->SetAutoUnspecified(true);
112 pg
->SetPropertyEditor( wxT("CustomColourProperty"), wxPGEditor_ComboBox
);
114 pg
->SetPropertyHelpString(wxT("CustomColourProperty"),
115 wxT("This is a MyColourProperty from the sample app. ")
116 wxT("It is built by subclassing wxColourProperty."));
119 // -----------------------------------------------------------------------
121 void FormMain::OnDumpList( wxCommandEvent
& WXUNUSED(event
) )
123 wxVariant values
= m_pPropGridManager
->GetPropertyValues(wxT("list"), wxNullProperty
, wxPG_INC_ATTRIBUTES
);
124 wxString text
= wxT("This only tests that wxVariant related routines do not crash.");
127 wxDialog
* dlg
= new wxDialog(this,-1,wxT("wxVariant Test"),
128 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
131 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
133 wxVariant
& v
= values
[i
];
135 wxString strValue
= v
.GetString();
137 #if wxCHECK_VERSION(2,8,0)
138 if ( v
.GetName().EndsWith(wxT("@attr")) )
140 if ( v
.GetName().Right(5) == wxT("@attr") )
143 text
+= wxString::Format(wxT("Attributes:\n"));
146 for ( n
= 0; n
< (unsigned int)v
.GetCount(); n
++ )
150 t
.Printf(wxT(" atribute %i: name=\"%s\" (type=\"%s\" value=\"%s\")\n"),(int)n
,
151 a
.GetName().c_str(),a
.GetType().c_str(),a
.GetString().c_str());
157 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\" value=\"%s\"\n"),(int)i
,
158 v
.GetName().c_str(),v
.GetType().c_str(),strValue
.c_str());
163 // multi-line text editor dialog
164 const int spacing
= 8;
165 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
166 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
167 wxTextCtrl
* ed
= new wxTextCtrl(dlg
, 11, text
,
168 wxDefaultPosition
, wxDefaultSize
,
170 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
171 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
172 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
173 const int butSzFlags
=
174 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
175 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
176 0, butSzFlags
, spacing
);
177 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
179 dlg
->SetSizer( topsizer
);
180 topsizer
->SetSizeHints( dlg
);
182 dlg
->SetSize(400,300);
187 // -----------------------------------------------------------------------
193 TestRunner( const wxString
& name
, wxPropertyGridManager
* man
, wxTextCtrl
* ed
, wxArrayString
* errorMessages
)
198 m_errorMessages
= errorMessages
;
200 m_preWarnings
= wxPGGlobalVars
->m_warnings
;
203 if ( name
!= wxT("none") )
210 int warningsOccurred
= wxPGGlobalVars
->m_warnings
- m_preWarnings
;
211 if ( warningsOccurred
)
213 wxString s
= wxString::Format(wxT("%i warnings occurred during test '%s'"), warningsOccurred
, m_name
.c_str());
214 m_errorMessages
->push_back(s
);
220 void Msg( const wxString
& text
)
224 m_ed
->AppendText(text
);
225 m_ed
->AppendText(wxT("\n"));
231 wxPropertyGridManager
* m_man
;
233 wxArrayString
* m_errorMessages
;
241 #define RT_START_TEST(TESTNAME) \
242 TestRunner tr(wxT(#TESTNAME), pgman, ed, &errorMessages);
247 #define RT_FAILURE() \
249 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
250 errorMessages.push_back(s1); \
255 #define RT_ASSERT(COND) \
259 #define RT_FAILURE_MSG(MSG) \
261 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
262 errorMessages.push_back(s1); \
264 wxString s2 = wxString::Format(wxT("Message: %s"),MSG); \
265 errorMessages.push_back(s2); \
270 #define RT_VALIDATE_VIRTUAL_HEIGHT(PROPS, EXTRATEXT) \
272 unsigned int h1_ = PROPS->GetVirtualHeight(); \
273 unsigned int h2_ = PROPS->GetActualVirtualHeight(); \
276 wxString s_ = wxString::Format(wxT("VirtualHeight = %i, should be %i (%s)"), h1_, h2_, EXTRATEXT.c_str()); \
277 RT_FAILURE_MSG(s_.c_str()); \
287 int gpiro_cmpfunc(const void* a
, const void* b
)
289 const wxPGProperty
* p1
= (const wxPGProperty
*) a
;
290 const wxPGProperty
* p2
= (const wxPGProperty
*) b
;
291 return (int) (((size_t)p1
->GetClientData()) - ((size_t)p2
->GetClientData()));
294 wxArrayPGProperty
GetPropertiesInRandomOrder( wxPropertyGridInterface
* props
, int iterationFlags
= wxPG_ITERATE_ALL
)
296 wxArrayPGProperty arr
;
298 wxPropertyGridIterator it
;
300 for ( it
= props
->GetIterator(iterationFlags
);
304 wxPGProperty
* p
= *it
;
305 size_t randomNumber
= rand();
306 p
->SetClientData(reinterpret_cast<void*>(randomNumber
));
310 wxPGProperty
** firstEntry
= &arr
[0];
311 qsort(firstEntry
, arr
.size(), sizeof(wxPGProperty
*), gpiro_cmpfunc
);
316 // Callback for testing property sorting
317 int MyPropertySortFunction(wxPropertyGrid
* WXUNUSED(propGrid
),
321 // Reverse alphabetical order
322 return p2
->GetLabel().CmpNoCase( p1
->GetBaseName() );
325 bool FormMain::RunTests( bool fullTest
, bool interactive
)
329 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
334 pgman
->ClearSelection();
337 bool _failed_
= false;
338 wxArrayString errorMessages
;
339 wxDialog
* dlg
= NULL
;
341 dlg
= new wxDialog(this,-1,wxT("wxPropertyGrid Regression Tests"),
342 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
344 // multi-line text editor dialog
345 const int spacing
= 8;
346 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
347 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
348 wxTextCtrl
* ed
= new wxTextCtrl(dlg
, 11, wxEmptyString
,
349 wxDefaultPosition
, wxDefaultSize
,
351 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
352 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
353 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
354 const int butSzFlags
=
355 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
356 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
357 0, butSzFlags
, spacing
);
358 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
360 dlg
->SetSizer( topsizer
);
361 topsizer
->SetSizeHints( dlg
);
363 dlg
->SetSize(400,300);
364 dlg
->Move(wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)-dlg
->GetSize().x
,
365 wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)-dlg
->GetSize().y
);
370 // Basic iterator tests
371 RT_START_TEST(GetIterator
)
377 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
381 wxPGProperty
* p
= it
.GetProperty();
382 if ( p
->IsCategory() )
383 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a category (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
384 else if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
385 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
389 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES) -> %i entries"), count
));
392 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_CATEGORIES
);
396 wxPGProperty
* p
= it
.GetProperty();
397 if ( !p
->IsCategory() )
398 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is not a category (only category was expected)"),p
->GetLabel().c_str()).c_str())
402 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
405 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
|wxPG_ITERATE_CATEGORIES
);
409 wxPGProperty
* p
= it
.GetProperty();
410 if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
411 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property or category expected)"),p
->GetLabel().c_str()).c_str())
415 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
418 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_VISIBLE
);
422 wxPGProperty
* p
= it
.GetProperty();
423 if ( (p
->GetParent() != p
->GetParentState()->DoGetRoot() && !p
->GetParent()->IsExpanded()) )
424 RT_FAILURE_MSG(wxString::Format(wxT("'%s' had collapsed parent (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
425 else if ( p
->HasFlag(wxPG_PROP_HIDDEN
) )
426 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was hidden (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
430 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_VISIBLE) -> %i entries"), count
));
435 // Test that setting focus to properties does not crash things
436 RT_START_TEST(SelectProperty
)
438 wxPropertyGridIterator it
;
441 for ( ind
=0; ind
<pgman
->GetPageCount(); ind
++ )
443 wxPropertyGridPage
* page
= pgman
->GetPage(ind
);
444 pgman
->SelectPage(page
);
446 for ( it
= page
->GetIterator(wxPG_ITERATE_VISIBLE
);
450 wxPGProperty
* p
= *it
;
451 RT_MSG(p
->GetLabel());
452 pgman
->GetGrid()->SelectProperty(p
, true);
461 // Delete everything in reverse order
462 RT_START_TEST(DeleteProperty
)
465 wxArrayPGProperty array
;
467 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_ALL
&~(wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
)));
470 array
.push_back(it
.GetProperty());
472 wxArrayPGProperty::reverse_iterator it2
;
474 for ( it2
= array
.rbegin(); it2
!= array
.rend(); it2
++ )
476 wxPGProperty
* p
= (wxPGProperty
*)*it2
;
477 RT_MSG(wxString::Format(wxT("Deleting '%s' ('%s')"),p
->GetLabel().c_str(),p
->GetName().c_str()));
478 pgman
->DeleteProperty(p
);
482 CreateGrid( -1, -1 );
483 pgman
= m_pPropGridManager
;
488 // Test property default values
489 RT_START_TEST(Default_Values
)
493 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
497 wxPGProperty
* p
= it
.GetProperty();
498 pgman
->SetPropertyValue(p
, p
->GetDefaultValue());
502 CreateGrid( -1, -1 );
503 pgman
= m_pPropGridManager
;
508 // Test wxAny<->wxVariant conversion
509 RT_START_TEST(WXVARIANT_TO_WXANY_CONVERSION
)
515 prop
= pgman
->GetProperty("DateProperty");
516 wxDateTime testTime
= wxDateTime::Now();
519 if ( wxANY_AS(prop
->GetValue().GetAny(), wxDateTime
) != testTime
)
523 prop
= pgman
->GetProperty("IntProperty");
524 int testInt
= 25537983;
527 if ( wxANY_AS(prop
->GetValue().GetAny(), int) != testInt
)
530 if ( wxANY_AS(prop
->GetValue().GetAny(), wxLongLong_t
) != testInt
)
534 prop
= pgman
->GetProperty("StringProperty");
535 wxString testString
= "asd934jfyn3";
538 if ( wxANY_AS(prop
->GetValue().GetAny(), wxString
) != testString
)
541 // Test with a type generated with IMPLEMENT_VARIANT_OBJECT()
542 prop
= pgman
->GetProperty("ColourProperty");
543 wxColour testCol
= *wxCYAN
;
546 if ( wxANY_AS(prop
->GetValue().GetAny(), wxColour
) != testCol
)
549 // Test with a type with custom wxVariantData defined by
551 prop
= pgman
->GetProperty("Position");
552 wxPoint
testPoint(199, 199);
555 if ( wxANY_AS(prop
->GetValue().GetAny(), wxPoint
) != testPoint
)
560 RT_START_TEST(GetPropertyValues
)
562 for ( i
=0; i
<3; i
++ )
566 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
568 wxVariant values
= page
->GetPropertyValues();
571 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
573 wxVariant
& v
= values
[i
];
575 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\"\n"),(int)i
,
576 v
.GetName().c_str(),v
.GetType().c_str());
580 ed
->AppendText(text
);
585 RT_START_TEST(SetPropertyValue_and_GetPropertyValue
)
587 // In this section, mixed up usage of wxT("propname") and "propname"
588 // in wxPropertyGridInterface functions is intentional.
589 // Purpose is to test wxPGPropArgCls ctors.
591 //pg = (wxPropertyGrid*) NULL;
593 wxArrayString test_arrstr_1
;
594 test_arrstr_1
.Add(wxT("Apple"));
595 test_arrstr_1
.Add(wxT("Orange"));
596 test_arrstr_1
.Add(wxT("Lemon"));
598 wxArrayString test_arrstr_2
;
599 test_arrstr_2
.Add(wxT("Potato"));
600 test_arrstr_2
.Add(wxT("Cabbage"));
601 test_arrstr_2
.Add(wxT("Cucumber"));
603 wxArrayInt test_arrint_1
;
604 test_arrint_1
.Add(1);
605 test_arrint_1
.Add(2);
606 test_arrint_1
.Add(3);
608 wxArrayInt test_arrint_2
;
609 test_arrint_2
.Add(0);
610 test_arrint_2
.Add(1);
611 test_arrint_2
.Add(4);
614 wxDateTime dt1
= wxDateTime::Now();
615 dt1
.SetYear(dt1
.GetYear()-1);
617 wxDateTime dt2
= wxDateTime::Now();
618 dt2
.SetYear(dt2
.GetYear()-10);
621 wxColour
colWithAlpha(1, 128, 254, 100);
622 wxString
colWithAlphaStr(colWithAlpha
.GetAsString(wxC2S_CSS_SYNTAX
));
624 #define FLAG_TEST_SET1 (wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER)
625 #define FLAG_TEST_SET2 (wxSTAY_ON_TOP|wxCAPTION|wxICONIZE|wxSYSTEM_MENU)
627 pgman
->SetPropertyValue(wxT("StringProperty"),wxT("Text1"));
628 pgman
->SetPropertyValue(wxT("IntProperty"),1024);
629 pgman
->SetPropertyValue(wxT("FloatProperty"),1024.0000000001);
630 pgman
->SetPropertyValue(wxT("BoolProperty"),FALSE
);
631 pgman
->SetPropertyValue(wxT("EnumProperty"),120);
632 pgman
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_1
);
634 pgman
->SetPropertyValue(wxT("ColourProperty"),emptyCol
);
635 pgman
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxBLACK
);
636 pgman
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(150,150)));
637 pgman
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(150,150)));
638 pgman
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_1
);
640 pgman
->SetPropertyValue(wxT("DateProperty"),dt1
);
643 pgman
->SelectPage(2);
644 pg
= pgman
->GetGrid();
646 if ( pg
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text1") )
648 if ( pg
->GetPropertyValueAsInt(wxT("IntProperty")) != 1024 )
650 if ( pg
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 1024.0000000001 )
652 if ( pg
->GetPropertyValueAsBool(wxT("BoolProperty")) != FALSE
)
654 if ( pg
->GetPropertyValueAsLong(wxT("EnumProperty")) != 120 )
656 if ( pg
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_1
)
659 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
660 if ( col
!= *wxBLACK
)
662 wxVariant
varSize(pg
->GetPropertyValue(wxT("Size")));
663 if ( wxSizeRefFromVariant(varSize
) != wxSize(150,150) )
665 wxVariant
varPos(pg
->GetPropertyValue(wxT("Position")));
666 if ( wxPointRefFromVariant(varPos
) != wxPoint(150,150) )
668 if ( !(pg
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_1
) )
671 if ( !(pg
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt1
) )
675 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(10000000000));
676 if ( pg
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(10000000000) )
679 pg
->SetPropertyValue(wxT("StringProperty"),wxT("Text2"));
680 pg
->SetPropertyValue(wxT("IntProperty"),512);
681 pg
->SetPropertyValue(wxT("FloatProperty"),512.0);
682 pg
->SetPropertyValue(wxT("BoolProperty"),TRUE
);
683 pg
->SetPropertyValue(wxT("EnumProperty"),80);
684 pg
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_2
);
685 pg
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxWHITE
);
686 pg
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(300,300)));
687 pg
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(300,300)));
688 pg
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_2
);
690 pg
->SetPropertyValue(wxT("DateProperty"),dt2
);
693 //pg = (wxPropertyGrid*) NULL;
695 pgman
->SelectPage(0);
697 if ( pgman
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text2") )
699 if ( pgman
->GetPropertyValueAsInt(wxT("IntProperty")) != 512 )
701 if ( pgman
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 512.0 )
703 if ( pgman
->GetPropertyValueAsBool(wxT("BoolProperty")) != TRUE
)
705 if ( pgman
->GetPropertyValueAsLong(wxT("EnumProperty")) != 80 )
707 if ( pgman
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_2
)
709 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
710 if ( col
!= *wxWHITE
)
712 varSize
= pgman
->GetPropertyValue(wxT("Size"));
713 if ( wxSizeRefFromVariant(varSize
) != wxSize(300,300) )
715 varPos
= pgman
->GetPropertyValue(wxT("Position"));
716 if ( wxPointRefFromVariant(varPos
) != wxPoint(300,300) )
718 if ( !(pgman
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_2
) )
721 if ( !(pgman
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt2
) )
725 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000));
726 if ( pgman
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) )
729 // Make sure children of composite parent get updated as well
730 // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000; Not Convertible"
733 // This updates children as well
734 wxString nvs
= "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002; Convertible";
735 pgman
->SetPropertyValue("Car", nvs
);
737 if ( pgman
->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
739 wxLogDebug("Did not match: Car.Model=%s", pgman
->GetPropertyValueAsString("Car.Model").c_str());
743 if ( pgman
->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
745 wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman
->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
749 if ( pgman
->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
751 wxLogDebug("Did not match: Car.Price ($)=%s", pgman
->GetPropertyValueAsString("Car.Price ($)").c_str());
755 if ( !pgman
->GetPropertyValueAsBool("Car.Convertible") )
757 wxLogDebug("Did not match: Car.Convertible=%s", pgman
->GetPropertyValueAsString("Car.Convertible").c_str());
761 // SetPropertyValueString for special cases such as wxColour
762 pgman
->SetPropertyValueString("ColourProperty", "(123,4,255)");
763 col
<< pgman
->GetPropertyValue("ColourProperty");
764 if ( col
!= wxColour(123, 4, 255) )
766 pgman
->SetPropertyValueString("ColourProperty", "#FE860B");
767 col
<< pgman
->GetPropertyValue("ColourProperty");
768 if ( col
!= wxColour(254, 134, 11) )
771 pgman
->SetPropertyValueString("ColourPropertyWithAlpha",
772 "(10, 20, 30, 128)");
773 col
<< pgman
->GetPropertyValue("ColourPropertyWithAlpha");
774 if ( col
!= wxColour(10, 20, 30, 128) )
776 if ( pgman
->GetPropertyValueAsString("ColourPropertyWithAlpha")
777 != "(10,20,30,128)" )
782 RT_START_TEST(SetPropertyValueUnspecified
)
784 // Null variant setter tests
785 pgman
->SetPropertyValueUnspecified(wxT("StringProperty"));
786 pgman
->SetPropertyValueUnspecified(wxT("IntProperty"));
787 pgman
->SetPropertyValueUnspecified(wxT("FloatProperty"));
788 pgman
->SetPropertyValueUnspecified(wxT("BoolProperty"));
789 pgman
->SetPropertyValueUnspecified(wxT("EnumProperty"));
790 pgman
->SetPropertyValueUnspecified(wxT("ArrayStringProperty"));
791 pgman
->SetPropertyValueUnspecified(wxT("ColourProperty"));
792 pgman
->SetPropertyValueUnspecified(wxT("Size"));
793 pgman
->SetPropertyValueUnspecified(wxT("Position"));
794 pgman
->SetPropertyValueUnspecified(wxT("MultiChoiceProperty"));
796 pgman
->SetPropertyValueUnspecified(wxT("DateProperty"));
802 // Test multiple selection
803 RT_START_TEST(MULTIPLE_SELECTION
)
804 if ( !(pgman
->GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
805 CreateGrid( -1, wxPG_EX_MULTIPLE_SELECTION
);
806 pgman
= m_pPropGridManager
;
808 wxPropertyGrid
* pg
= pgman
->GetGrid();
810 wxPGProperty
* prop1
= pg
->GetProperty(wxT("Label"));
811 wxPGProperty
* prop2
= pg
->GetProperty(wxT("Cell Text Colour"));
812 wxPGProperty
* prop3
= pg
->GetProperty(wxT("Height"));
813 wxPGProperty
* catProp
= pg
->GetProperty(wxT("Appearance"));
815 RT_ASSERT( prop1
&& prop2
&& prop3
);
817 pg
->ClearSelection();
818 pg
->AddToSelection(prop1
);
819 pg
->AddToSelection(prop2
);
820 pg
->AddToSelection(prop3
);
822 // Adding category to selection should fail silently
823 pg
->AddToSelection(catProp
);
825 wxArrayPGProperty selectedProperties
= pg
->GetSelectedProperties();
827 RT_ASSERT( selectedProperties
.size() == 3 )
828 RT_ASSERT( pg
->IsPropertySelected(prop1
) )
829 RT_ASSERT( pg
->IsPropertySelected(prop2
) )
830 RT_ASSERT( pg
->IsPropertySelected(prop3
) )
831 RT_ASSERT( !pg
->IsPropertySelected(catProp
) )
833 pg
->RemoveFromSelection(prop1
);
834 wxArrayPGProperty selectedProperties2
= pg
->GetSelectedProperties();
836 RT_ASSERT( selectedProperties2
.size() == 2 )
837 RT_ASSERT( !pg
->IsPropertySelected(prop1
) )
838 RT_ASSERT( pg
->IsPropertySelected(prop2
) )
839 RT_ASSERT( pg
->IsPropertySelected(prop3
) )
841 pg
->ClearSelection();
843 wxArrayPGProperty selectedProperties3
= pg
->GetSelectedProperties();
845 RT_ASSERT( selectedProperties3
.size() == 0 )
846 RT_ASSERT( !pg
->IsPropertySelected(prop1
) )
847 RT_ASSERT( !pg
->IsPropertySelected(prop2
) )
848 RT_ASSERT( !pg
->IsPropertySelected(prop3
) )
850 pg
->SelectProperty(prop2
);
852 RT_ASSERT( !pg
->IsPropertySelected(prop1
) )
853 RT_ASSERT( pg
->IsPropertySelected(prop2
) )
854 RT_ASSERT( !pg
->IsPropertySelected(prop3
) )
859 // Test label editing
860 RT_START_TEST(LABEL_EDITING
)
862 wxPropertyGrid
* pg
= pgman
->GetGrid();
864 // Just mostly test that these won't crash
865 pg
->MakeColumnEditable(0, true);
866 pg
->MakeColumnEditable(2, true);
867 pg
->MakeColumnEditable(0, false);
868 pg
->MakeColumnEditable(2, false);
869 pg
->SelectProperty(wxT("Height"));
870 pg
->BeginLabelEdit(0);
871 pg
->BeginLabelEdit(0);
876 CreateGrid( -1, -1 );
877 pgman
= m_pPropGridManager
;
881 RT_START_TEST(Attributes
)
883 wxPGProperty
* prop
= pgman
->GetProperty(wxT("StringProperty"));
884 prop
->SetAttribute(wxT("Dummy Attribute"), (long)15);
886 if ( prop
->GetAttribute(wxT("Dummy Attribute")).GetLong() != 15 )
889 prop
->SetAttribute(wxT("Dummy Attribute"), wxVariant());
891 if ( !prop
->GetAttribute(wxT("Dummy Attribute")).IsNull() )
896 RT_START_TEST(DoubleToString
)
898 // Locale-specific decimal separator
899 wxString sep
= wxString::Format("%g", 1.1)[1];
903 if ( wxPropertyGrid::DoubleToString(s
, 123.123, 2, true) !=
904 wxString::Format("123%s12", sep
.c_str()) )
906 if ( wxPropertyGrid::DoubleToString(s
, -123.123, 4, false) !=
907 wxString::Format("-123%s1230", sep
.c_str()) )
909 if ( wxPropertyGrid::DoubleToString(s
, -0.02, 1, false) !=
910 wxString::Format("0%s0", sep
) )
912 if ( wxPropertyGrid::DoubleToString(s
, -0.000123, 3, true) != "0" )
917 wxPropertyGridPage
* page1
;
918 wxPropertyGridPage
* page2
;
919 wxPropertyGridPage
* page3
;
920 wxVariant pg1_values
;
921 wxVariant pg2_values
;
922 wxVariant pg3_values
;
925 RT_START_TEST(GetPropertyValues
)
927 page1
= pgman
->GetPage(0);
928 pg1_values
= page1
->GetPropertyValues(wxT("Page1"),NULL
,wxPG_KEEP_STRUCTURE
);
929 page2
= pgman
->GetPage(1);
930 pg2_values
= page2
->GetPropertyValues(wxT("Page2"),NULL
,wxPG_KEEP_STRUCTURE
);
931 page3
= pgman
->GetPage(2);
932 pg3_values
= page3
->GetPropertyValues(wxT("Page3"),NULL
,wxPG_KEEP_STRUCTURE
);
936 RT_START_TEST(SetPropertyValues
)
938 page1
->SetPropertyValues(pg3_values
);
939 page2
->SetPropertyValues(pg1_values
);
940 page3
->SetPropertyValues(pg2_values
);
944 if ( !(pgman
->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES
) )
946 RT_START_TEST(Collapse_and_GetFirstCategory_and_GetNextCategory
)
948 for ( i
=0; i
<3; i
++ )
950 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
952 wxPropertyGridIterator it
;
954 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
958 wxPGProperty
* p
= *it
;
960 if ( !page
->IsPropertyCategory(p
) )
965 t
.Printf(wxT("Collapsing: %s\n"),page
->GetPropertyLabel(p
).c_str());
972 RT_START_TEST(Save_And_RestoreEditableState
)
974 for ( i
=0; i
<3; i
++ )
976 pgman
->SelectPage(i
);
978 wxString stringState
= pgman
->SaveEditableState();
979 bool res
= pgman
->RestoreEditableState(stringState
);
985 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
987 RT_START_TEST(Expand_and_GetFirstCategory_and_GetNextCategory
)
989 for ( i
=0; i
<3; i
++ )
991 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
993 wxPropertyGridIterator it
;
995 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
999 wxPGProperty
* p
= *it
;
1001 if ( !page
->IsPropertyCategory(p
) )
1006 t
.Printf(wxT("Expand: %s\n"),page
->GetPropertyLabel(p
).c_str());
1013 RT_START_TEST(Choice_Manipulation
)
1015 wxPGProperty
* enumProp
= pgman
->GetProperty(wxT("EnumProperty"));
1017 pgman
->SelectPage(2);
1018 pgman
->SelectProperty(enumProp
);
1019 wxASSERT(pgman
->GetGrid()->GetSelection() == enumProp
);
1021 const wxPGChoices
& choices
= enumProp
->GetChoices();
1022 int ind
= enumProp
->InsertChoice(wxT("New Choice"), choices
.GetCount()/2);
1023 enumProp
->DeleteChoice(ind
);
1025 // Recreate the original grid
1026 CreateGrid( -1, -1 );
1027 pgman
= m_pPropGridManager
;
1030 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
1032 RT_START_TEST(RandomCollapse
)
1034 // Select the most error prone page as visible.
1035 pgman
->SelectPage(1);
1037 for ( i
=0; i
<3; i
++ )
1041 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
1043 wxPropertyGridIterator it
;
1045 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
1049 arr
.Add((void*)*it
);
1052 if ( arr
.GetCount() )
1056 pgman
->Collapse( (wxPGProperty
*)arr
.Item(0) );
1058 for ( n
=arr
.GetCount()-1; n
>0; n
-- )
1060 pgman
->Collapse( (wxPGProperty
*)arr
.Item(n
) );
1068 RT_START_TEST(EnsureVisible
)
1069 pgman
->EnsureVisible(wxT("Cell Colour"));
1073 RT_START_TEST(RemoveProperty
)
1077 wxPGProperty
* origParent
=
1078 pgman
->GetProperty("Window Styles")->GetParent();
1080 // For testing purposes, let's set some custom cell colours
1081 p
= pgman
->GetProperty("Window Styles");
1082 p
->SetCell(2, wxPGCell("style"));
1083 p
= pgman
->RemoveProperty("Window Styles");
1087 pgman
->AppendIn(origParent
, p
);
1088 wxASSERT( p
->GetCell(2).GetText() == "style");
1094 RT_START_TEST(SortFunction
)
1098 // Make sure indexes are as supposed
1100 p
= pgman
->GetProperty(wxT("User Name"));
1101 if ( p
->GetIndexInParent() != 3 )
1104 p
= pgman
->GetProperty(wxT("User Id"));
1105 if ( p
->GetIndexInParent() != 2 )
1108 p
= pgman
->GetProperty(wxT("User Home"));
1109 if ( p
->GetIndexInParent() != 1 )
1112 p
= pgman
->GetProperty(wxT("Operating System"));
1113 if ( p
->GetIndexInParent() != 0 )
1116 pgman
->GetGrid()->SetSortFunction(MyPropertySortFunction
);
1118 pgman
->GetGrid()->SortChildren(wxT("Environment"));
1120 // Make sure indexes have been reversed
1121 p
= pgman
->GetProperty(wxT("User Name"));
1122 if ( p
->GetIndexInParent() != 0 )
1125 p
= pgman
->GetProperty(wxT("User Id"));
1126 if ( p
->GetIndexInParent() != 1 )
1129 p
= pgman
->GetProperty(wxT("User Home"));
1130 if ( p
->GetIndexInParent() != 2 )
1133 p
= pgman
->GetProperty(wxT("Operating System"));
1134 if ( p
->GetIndexInParent() != 3 )
1139 RT_START_TEST(SetPropertyBackgroundColour
)
1141 evt
.SetInt(1); // IsChecked() will return TRUE.
1142 evt
.SetId(ID_COLOURSCHEME4
);
1144 OnColourScheme(evt
);
1148 RT_START_TEST(Clear
)
1151 pgman
->SelectProperty("Label");
1154 if ( pgman
->GetPageCount() )
1157 if ( pgman
->GetGrid()->GetRoot()->GetChildCount() )
1160 // Recreate the original grid
1161 CreateGrid( -1, -1 );
1162 pgman
= m_pPropGridManager
;
1165 pgman
->SelectProperty("Label");
1166 pgman
->GetGrid()->Clear();
1168 if ( pgman
->GetGrid()->GetRoot()->GetChildCount() )
1171 // Recreate the original grid
1172 CreateGrid( -1, -1 );
1173 pgman
= m_pPropGridManager
;
1177 // TODO: This test fails.
1178 RT_START_TEST(SetSplitterPosition)
1182 const int trySplitterPos = 50;
1184 int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
1185 pgman = m_pPropGridManager =
1186 new wxPropertyGridManager(m_panel, wxID_ANY,
1192 pgman->SetSplitterPosition(trySplitterPos);
1194 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1195 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1197 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
1200 wxSize sz = GetSize();
1205 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1206 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1210 // Recreate the original grid
1211 CreateGrid( -1, -1 );
1212 pgman = m_pPropGridManager;
1216 RT_START_TEST(HideProperty
)
1218 wxPropertyGridPage
* page
= pgman
->GetPage(0);
1222 wxArrayPGProperty arr1
;
1224 arr1
= GetPropertiesInRandomOrder(page
);
1228 for ( i
=0; i
<arr1
.size(); i
++ )
1230 wxPGProperty
* p
= arr1
[i
];
1231 page
->HideProperty(p
, true);
1233 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1234 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1242 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1244 for ( i
=0; i
<arr2
.size(); i
++ )
1246 wxPGProperty
* p
= arr2
[i
];
1247 page
->HideProperty(p
, false);
1249 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1250 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1257 // Let's do some more, for better consistency
1258 arr1
= GetPropertiesInRandomOrder(page
);
1262 for ( i
=0; i
<arr1
.size(); i
++ )
1264 wxPGProperty
* p
= arr1
[i
];
1265 page
->HideProperty(p
, true);
1267 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1268 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1276 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1278 for ( i
=0; i
<arr2
.size(); i
++ )
1280 wxPGProperty
* p
= arr2
[i
];
1281 page
->HideProperty(p
, false);
1283 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1284 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1291 // Ok, this time only hide half of them
1292 arr1
= GetPropertiesInRandomOrder(page
);
1293 arr1
.resize(arr1
.size()/2);
1297 for ( i
=0; i
<arr1
.size(); i
++ )
1299 wxPGProperty
* p
= arr1
[i
];
1300 page
->HideProperty(p
, true);
1302 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1303 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1311 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1313 for ( i
=0; i
<arr2
.size(); i
++ )
1315 wxPGProperty
* p
= arr2
[i
];
1316 page
->HideProperty(p
, false);
1318 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1319 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1325 // Recreate the original grid
1326 CreateGrid( -1, -1 );
1327 pgman
= m_pPropGridManager
;
1332 RT_START_TEST(MultipleColumns
)
1334 // Test with multiple columns
1335 // FIXME: Does not display changes.
1336 for ( i
=3; i
<12; i
+=2 )
1338 RT_MSG(wxString::Format(wxT("%i columns"),i
));
1339 CreateGrid( -1, -1 );
1340 pgman
= m_pPropGridManager
;
1341 pgman
->SetColumnCount(i
);
1350 RT_START_TEST(WindowStyles
)
1352 // Recreate grid with all possible (single) flags
1353 wxASSERT(wxPG_AUTO_SORT
== 0x000000010);
1355 for ( i
=4; i
<16; i
++ )
1358 RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag
));
1359 CreateGrid( flag
, -1 );
1360 pgman
= m_pPropGridManager
;
1365 wxASSERT(wxPG_EX_INIT_NOCAT
== 0x00001000);
1367 for ( i
=12; i
<27; i
++ )
1370 RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag
));
1371 CreateGrid( -1, flag
);
1372 pgman
= m_pPropGridManager
;
1377 // Recreate the original grid
1378 CreateGrid( -1, -1 );
1379 pgman
= m_pPropGridManager
;
1386 if ( failures
|| errorMessages
.size() )
1394 s
= wxString::Format(wxT("%i tests failed!!!"), failures
);
1397 s
= wxString::Format(wxT("All tests were successful, but there were %i warnings!"), wxPGGlobalVars
->m_warnings
);
1400 for ( i
=0; i
<errorMessages
.size(); i
++ )
1401 RT_MSG(errorMessages
[i
])
1402 wxMessageBox(s
, wxT("Some Tests Failed"));
1406 RT_MSG(wxT("All tests successfull"))
1413 pgman
->SelectPage(0);
1415 // Test may screw up the toolbar, so we need to refresh it.
1416 wxToolBar
* toolBar
= pgman
->GetToolBar();
1423 // -----------------------------------------------------------------------