1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/propgrid/tests.cpp
3 // Purpose: wxPropertyGrid tests
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
22 #include <wx/propgrid/propgrid.h>
23 #include <wx/propgrid/advprops.h>
24 #include <wx/propgrid/manager.h>
27 #include "sampleprops.h"
30 // -----------------------------------------------------------------------
31 // wxTestCustomFlagsProperty
32 // -----------------------------------------------------------------------
35 // Constant definitions required by wxFlagsProperty examples.
38 static const wxChar
* _fs_framestyle_labels
[] = {
45 wxT("wxRESIZE_BORDER"),
46 wxT("wxFRAME_TOOL_WINDOW"),
47 wxT("wxFRAME_NO_TASKBAR"),
48 wxT("wxFRAME_FLOAT_ON_PARENT"),
49 wxT("wxFRAME_SHAPED"),
53 static const long _fs_framestyle_values
[] = {
63 wxFRAME_FLOAT_ON_PARENT
,
67 // Colour labels. Last (before NULL, if any) must be Custom.
68 static const wxChar
* mycolprop_labels
[] = {
76 // Relevant colour values as unsigned longs.
77 static unsigned long mycolprop_colours
[] = {
80 wxPG_COLOUR(166,124,81),
84 // Implement property class. Third argument is optional values array,
85 // but in this example we are only interested in creating a shortcut
86 // for user to access the colour values. Last arg is itemcount, but
87 // it will be deprecated in the future.
88 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(wxMyColourProperty
)
89 WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(wxMyColourProperty
,
95 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY(wxMyColour2Property
)
96 WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(wxMyColour2Property
,
101 // -----------------------------------------------------------------------
104 // Test customizing wxColourProperty via subclassing
106 // * Includes custom colour entry.
107 // * Includes extra custom entry.
109 class MyColourProperty3
: public wxColourProperty
112 MyColourProperty3( const wxString
& label
= wxPG_LABEL
,
113 const wxString
& name
= wxPG_LABEL
,
114 const wxColour
& value
= *wxWHITE
)
115 : wxColourProperty(label
, name
, value
)
118 colours
.Add(wxT("White"));
119 colours
.Add(wxT("Black"));
120 colours
.Add(wxT("Red"));
121 colours
.Add(wxT("Green"));
122 colours
.Add(wxT("Blue"));
123 colours
.Add(wxT("Custom"));
124 colours
.Add(wxT("None"));
132 virtual ~MyColourProperty3()
136 virtual wxColour
GetColour( int index
) const
140 case 0: return *wxWHITE
;
141 case 1: return *wxBLACK
;
142 case 2: return *wxRED
;
143 case 3: return *wxGREEN
;
144 case 4: return *wxBLUE
;
146 // Return current colour for the custom entry
148 if ( GetIndex() == GetCustomColourIndex() )
150 if ( m_value
.IsNull() )
160 virtual wxString
ColourToString( const wxColour
& col
, int index
) const
162 if ( index
== (int)(m_choices
.GetCount()-1) )
165 return wxColourProperty::ColourToString(col
, index
);
168 virtual int GetCustomColourIndex() const
170 return m_choices
.GetCount()-2;
175 void FormMain::AddTestProperties( wxPropertyGridPage
* pg
)
177 pg
->Append( new wxMyColourProperty(wxT("CustomColourProperty1")) );
179 pg
->SetPropertyHelpString(wxT("CustomColourProperty1"),
180 wxT("This is a wxMyColourProperty from the sample app. ")
181 wxT("It is built with WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR macro ")
182 wxT("and has wxColour as its data type"));
184 pg
->Append( new wxMyColour2Property(wxT("CustomColourProperty2")) );
186 pg
->SetPropertyHelpString(wxT("CustomColourProperty2"),
187 wxT("This is a wxMyColour2Property from the sample app. ")
188 wxT("It is built with WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY macro ")
189 wxT("and has wxColourPropertyValue as its data type"));
191 pg
->Append( new MyColourProperty3(wxT("CustomColourProperty3"), wxPG_LABEL
, *wxGREEN
) );
192 pg
->GetProperty(wxT("CustomColourProperty3"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
193 pg
->SetPropertyEditor( wxT("CustomColourProperty3"), wxPGEditor_ComboBox
);
195 pg
->SetPropertyHelpString(wxT("CustomColourProperty3"),
196 wxT("This is a MyColourProperty3 from the sample app. ")
197 wxT("It is built by subclassing wxColourProperty."));
200 // -----------------------------------------------------------------------
202 void FormMain::OnDumpList( wxCommandEvent
& WXUNUSED(event
) )
204 wxVariant values
= m_pPropGridManager
->GetPropertyValues(wxT("list"), wxNullProperty
, wxPG_INC_ATTRIBUTES
);
205 wxString text
= wxT("This only tests that wxVariant related routines do not crash.");
208 wxDialog
* dlg
= new wxDialog(this,-1,wxT("wxVariant Test"),
209 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
212 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
214 wxVariant
& v
= values
[i
];
216 wxString strValue
= v
.GetString();
218 #if wxCHECK_VERSION(2,8,0)
219 if ( v
.GetName().EndsWith(wxT("@attr")) )
221 if ( v
.GetName().Right(5) == wxT("@attr") )
224 text
+= wxString::Format(wxT("Attributes:\n"));
227 for ( n
= 0; n
< (unsigned int)v
.GetCount(); n
++ )
231 t
.Printf(wxT(" atribute %i: name=\"%s\" (type=\"%s\" value=\"%s\")\n"),(int)n
,
232 a
.GetName().c_str(),a
.GetType().c_str(),a
.GetString().c_str());
238 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\" value=\"%s\"\n"),(int)i
,
239 v
.GetName().c_str(),v
.GetType().c_str(),strValue
.c_str());
244 // multi-line text editor dialog
245 const int spacing
= 8;
246 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
247 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
248 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,text
,
249 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
250 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
251 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
252 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
253 const int butSzFlags
=
254 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
255 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
256 0, butSzFlags
, spacing
);
257 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
259 dlg
->SetSizer( topsizer
);
260 topsizer
->SetSizeHints( dlg
);
262 dlg
->SetSize(400,300);
267 // -----------------------------------------------------------------------
273 TestRunner( const wxString
& name
, wxPropertyGridManager
* man
, wxTextCtrl
* ed
, wxArrayString
* errorMessages
)
278 m_errorMessages
= errorMessages
;
280 m_preWarnings
= wxPGGlobalVars
->m_warnings
;
283 if ( name
!= wxT("none") )
290 int warningsOccurred
= wxPGGlobalVars
->m_warnings
- m_preWarnings
;
291 if ( warningsOccurred
)
293 wxString s
= wxString::Format(wxT("%i warnings occurred during test '%s'"), warningsOccurred
, m_name
.c_str());
294 m_errorMessages
->push_back(s
);
300 void Msg( const wxString
& text
)
304 m_ed
->AppendText(text
);
305 m_ed
->AppendText(wxT("\n"));
311 wxPropertyGridManager
* m_man
;
313 wxArrayString
* m_errorMessages
;
321 #define RT_START_TEST(TESTNAME) \
322 TestRunner tr(wxT(#TESTNAME), pgman, ed, &errorMessages);
327 #define RT_FAILURE() \
329 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
330 errorMessages.push_back(s1); \
335 #define RT_FAILURE_MSG(MSG) \
337 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
338 errorMessages.push_back(s1); \
340 wxString s2 = wxString::Format(wxT("Message: %s"),MSG); \
341 errorMessages.push_back(s2); \
346 #define RT_VALIDATE_VIRTUAL_HEIGHT(PROPS, EXTRATEXT) \
348 unsigned int h1_ = PROPS->GetVirtualHeight(); \
349 unsigned int h2_ = PROPS->GetActualVirtualHeight(); \
352 wxString s_ = wxString::Format(wxT("VirtualHeight = %i, should be %i (%s)"), h1_, h2_, EXTRATEXT.c_str()); \
353 RT_FAILURE_MSG(s_.c_str()); \
363 int gpiro_cmpfunc(const void* a
, const void* b
)
365 const wxPGProperty
* p1
= (const wxPGProperty
*) a
;
366 const wxPGProperty
* p2
= (const wxPGProperty
*) b
;
367 return (int) (((size_t)p1
->GetClientData()) - ((size_t)p2
->GetClientData()));
370 wxArrayPGProperty
GetPropertiesInRandomOrder( wxPropertyGridInterface
* props
, int iterationFlags
= wxPG_ITERATE_ALL
)
372 wxArrayPGProperty arr
;
374 wxPropertyGridIterator it
;
376 for ( it
= props
->GetIterator(iterationFlags
);
380 wxPGProperty
* p
= *it
;
381 size_t randomNumber
= rand();
382 p
->SetClientData(reinterpret_cast<void*>(randomNumber
));
386 wxPGProperty
** firstEntry
= &arr
[0];
387 qsort(firstEntry
, arr
.size(), sizeof(wxPGProperty
*), gpiro_cmpfunc
);
392 bool FormMain::RunTests( bool fullTest
, bool interactive
)
396 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
401 pgman
->ClearSelection();
404 bool _failed_
= false;
405 wxArrayString errorMessages
;
406 wxDialog
* dlg
= NULL
;
408 dlg
= new wxDialog(this,-1,wxT("wxPropertyGrid Regression Tests"),
409 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
411 // multi-line text editor dialog
412 const int spacing
= 8;
413 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
414 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
415 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,wxEmptyString
,
416 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
417 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
418 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
419 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
420 const int butSzFlags
=
421 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
422 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
423 0, butSzFlags
, spacing
);
424 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
426 dlg
->SetSizer( topsizer
);
427 topsizer
->SetSizeHints( dlg
);
429 dlg
->SetSize(400,300);
430 dlg
->Move(wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)-dlg
->GetSize().x
,
431 wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)-dlg
->GetSize().y
);
436 // Basic iterator tests
437 RT_START_TEST(GetIterator
)
443 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
447 wxPGProperty
* p
= it
.GetProperty();
448 if ( p
->IsCategory() )
449 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a category (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
450 else if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
451 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
455 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES) -> %i entries"), count
));
458 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_CATEGORIES
);
462 wxPGProperty
* p
= it
.GetProperty();
463 if ( !p
->IsCategory() )
464 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is not a category (only category was expected)"),p
->GetLabel().c_str()).c_str())
468 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
471 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
|wxPG_ITERATE_CATEGORIES
);
475 wxPGProperty
* p
= it
.GetProperty();
476 if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
477 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property or category expected)"),p
->GetLabel().c_str()).c_str())
481 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
484 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_VISIBLE
);
488 wxPGProperty
* p
= it
.GetProperty();
489 if ( (p
->GetParent() != p
->GetParentState()->DoGetRoot() && !p
->GetParent()->IsExpanded()) )
490 RT_FAILURE_MSG(wxString::Format(wxT("'%s' had collapsed parent (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
491 else if ( p
->HasFlag(wxPG_PROP_HIDDEN
) )
492 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was hidden (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
496 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_VISIBLE) -> %i entries"), count
));
501 // Test that setting focus to properties does not crash things
502 RT_START_TEST(SelectProperty
)
504 wxPropertyGridIterator it
;
507 for ( ind
=0; ind
<pgman
->GetPageCount(); ind
++ )
509 wxPropertyGridPage
* page
= pgman
->GetPage(ind
);
510 pgman
->SelectPage(page
);
512 for ( it
= page
->GetIterator(wxPG_ITERATE_VISIBLE
);
516 wxPGProperty
* p
= *it
;
517 RT_MSG(p
->GetLabel());
518 pgman
->GetGrid()->SelectProperty(p
, true);
527 // Delete everything in reverse order
528 RT_START_TEST(DeleteProperty
)
531 wxArrayPGProperty array
;
533 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_ALL
&~(wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
)));
536 array
.push_back(it
.GetProperty());
538 wxArrayPGProperty::reverse_iterator it2
;
540 for ( it2
= array
.rbegin(); it2
!= array
.rend(); it2
++ )
542 wxPGProperty
* p
= (wxPGProperty
*)*it2
;
543 RT_MSG(wxString::Format(wxT("Deleting '%s' ('%s')"),p
->GetLabel().c_str(),p
->GetName().c_str()));
544 pgman
->DeleteProperty(p
);
548 CreateGrid( -1, -1 );
549 pgman
= m_pPropGridManager
;
554 // Test property default values
555 RT_START_TEST(Default_Values
)
559 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
563 wxPGProperty
* p
= it
.GetProperty();
564 pgman
->SetPropertyValue(p
, p
->GetDefaultValue());
568 CreateGrid( -1, -1 );
569 pgman
= m_pPropGridManager
;
573 RT_START_TEST(GetPropertyValues
)
575 for ( i
=0; i
<3; i
++ )
579 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
581 wxVariant values
= page
->GetPropertyValues();
584 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
586 wxVariant
& v
= values
[i
];
588 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\"\n"),(int)i
,
589 v
.GetName().c_str(),v
.GetType().c_str());
593 ed
->AppendText(text
);
598 RT_START_TEST(SetPropertyValue_and_GetPropertyValue
)
600 // In this section, mixed up usage of wxT("propname") and "propname"
601 // in wxPropertyGridInterface functions is intentional.
602 // Purpose is to test wxPGPropArgCls ctors.
604 //pg = (wxPropertyGrid*) NULL;
606 wxArrayString test_arrstr_1
;
607 test_arrstr_1
.Add(wxT("Apple"));
608 test_arrstr_1
.Add(wxT("Orange"));
609 test_arrstr_1
.Add(wxT("Lemon"));
611 wxArrayString test_arrstr_2
;
612 test_arrstr_2
.Add(wxT("Potato"));
613 test_arrstr_2
.Add(wxT("Cabbage"));
614 test_arrstr_2
.Add(wxT("Cucumber"));
616 wxArrayInt test_arrint_1
;
617 test_arrint_1
.Add(1);
618 test_arrint_1
.Add(2);
619 test_arrint_1
.Add(3);
621 wxArrayInt test_arrint_2
;
622 test_arrint_2
.Add(0);
623 test_arrint_2
.Add(1);
624 test_arrint_2
.Add(4);
627 wxDateTime dt1
= wxDateTime::Now();
628 dt1
.SetYear(dt1
.GetYear()-1);
630 wxDateTime dt2
= wxDateTime::Now();
631 dt2
.SetYear(dt2
.GetYear()-10);
634 #define FLAG_TEST_SET1 (wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER)
635 #define FLAG_TEST_SET2 (wxSTAY_ON_TOP|wxCAPTION|wxICONIZE|wxSYSTEM_MENU)
637 pgman
->SetPropertyValue(wxT("StringProperty"),wxT("Text1"));
638 pgman
->SetPropertyValue(wxT("IntProperty"),1024);
639 pgman
->SetPropertyValue(wxT("FloatProperty"),1024.0000000001);
640 pgman
->SetPropertyValue(wxT("BoolProperty"),FALSE
);
641 pgman
->SetPropertyValue(wxT("EnumProperty"),120);
642 pgman
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_1
);
644 pgman
->SetPropertyValue(wxT("ColourProperty"),emptyCol
);
645 pgman
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxBLACK
);
646 pgman
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(150,150)));
647 pgman
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(150,150)));
648 pgman
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_1
);
650 pgman
->SetPropertyValue(wxT("DateProperty"),dt1
);
653 pgman
->SelectPage(2);
654 pg
= pgman
->GetGrid();
656 if ( pg
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text1") )
658 if ( pg
->GetPropertyValueAsInt(wxT("IntProperty")) != 1024 )
660 if ( pg
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 1024.0000000001 )
662 if ( pg
->GetPropertyValueAsBool(wxT("BoolProperty")) != FALSE
)
664 if ( pg
->GetPropertyValueAsLong(wxT("EnumProperty")) != 120 )
666 if ( pg
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_1
)
669 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
670 if ( col
!= *wxBLACK
)
672 if ( wxSizeRefFromVariant(pg
->GetPropertyValue(wxT("Size"))) != wxSize(150,150) )
674 if ( wxPointRefFromVariant(pg
->GetPropertyValue(wxT("Position"))) != wxPoint(150,150) )
676 if ( !(pg
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_1
) )
679 if ( !(pg
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt1
) )
683 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(10000000000));
684 if ( pg
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(10000000000) )
687 pg
->SetPropertyValue(wxT("StringProperty"),wxT("Text2"));
688 pg
->SetPropertyValue(wxT("IntProperty"),512);
689 pg
->SetPropertyValue(wxT("FloatProperty"),512.0);
690 pg
->SetPropertyValue(wxT("BoolProperty"),TRUE
);
691 pg
->SetPropertyValue(wxT("EnumProperty"),80);
692 pg
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_2
);
693 pg
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxWHITE
);
694 pg
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(300,300)));
695 pg
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(300,300)));
696 pg
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_2
);
698 pg
->SetPropertyValue(wxT("DateProperty"),dt2
);
701 //pg = (wxPropertyGrid*) NULL;
703 pgman
->SelectPage(0);
705 if ( pgman
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text2") )
707 if ( pgman
->GetPropertyValueAsInt(wxT("IntProperty")) != 512 )
709 if ( pgman
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 512.0 )
711 if ( pgman
->GetPropertyValueAsBool(wxT("BoolProperty")) != TRUE
)
713 if ( pgman
->GetPropertyValueAsLong(wxT("EnumProperty")) != 80 )
715 if ( pgman
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_2
)
717 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
718 if ( col
!= *wxWHITE
)
720 if ( wxSizeRefFromVariant(pgman
->GetPropertyValue(wxT("Size"))) != wxSize(300,300) )
722 if ( wxPointRefFromVariant(pgman
->GetPropertyValue(wxT("Position"))) != wxPoint(300,300) )
724 if ( !(pgman
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_2
) )
727 if ( !(pgman
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt2
) )
731 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000));
732 if ( pgman
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) )
736 // Flexible wx(U)LongLong << operator safety conformance tests
741 prop
= pgman
->GetProperty(wxT("IntProperty"));
743 ll
<< prop
->GetValue();
747 prop
->SetValue(WXVARIANT(wxLL(68719476736)));
748 ll
<< prop
->GetValue();
749 if ( ll
.GetValue() != wxLL(68719476736) )
752 #if wxUSE_LONGLONG_NATIVE
754 ll_t
<< prop
->GetValue();
755 if ( ll_t
!= wxLL(68719476736) )
760 ll
<< prop
->GetValue();
764 prop
= pgman
->GetProperty(wxT("UIntProperty"));
766 ull
<< prop
->GetValue();
770 prop
->SetValue(WXVARIANT(wxULL(68719476739)));
771 ull
<< prop
->GetValue();
772 if ( ull
.GetValue() != wxULL(68719476739) )
775 #if wxUSE_LONGLONG_NATIVE
777 ull_t
<< prop
->GetValue();
778 if ( ull_t
!= wxLL(68719476739) )
783 ull
<< prop
->GetValue();
787 // Make sure children of composite parent get updated as well
788 // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000"
791 // This updates children as well
792 wxString nvs
= "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002";
793 pgman
->SetPropertyValue("Car", nvs
);
795 if ( pgman
->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
797 wxLogDebug("Did not match: Car.Model=%s", pgman
->GetPropertyValueAsString("Car.Model").c_str());
801 if ( pgman
->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
803 wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman
->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
807 if ( pgman
->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
809 wxLogDebug("Did not match: Car.Price ($)=%s", pgman
->GetPropertyValueAsString("Car.Price ($)").c_str());
815 RT_START_TEST(SetPropertyValueUnspecified
)
817 // Null variant setter tests
818 pgman
->SetPropertyValueUnspecified(wxT("StringProperty"));
819 pgman
->SetPropertyValueUnspecified(wxT("IntProperty"));
820 pgman
->SetPropertyValueUnspecified(wxT("FloatProperty"));
821 pgman
->SetPropertyValueUnspecified(wxT("BoolProperty"));
822 pgman
->SetPropertyValueUnspecified(wxT("EnumProperty"));
823 pgman
->SetPropertyValueUnspecified(wxT("ArrayStringProperty"));
824 pgman
->SetPropertyValueUnspecified(wxT("ColourProperty"));
825 pgman
->SetPropertyValueUnspecified(wxT("Size"));
826 pgman
->SetPropertyValueUnspecified(wxT("Position"));
827 pgman
->SetPropertyValueUnspecified(wxT("MultiChoiceProperty"));
829 pgman
->SetPropertyValueUnspecified(wxT("DateProperty"));
834 RT_START_TEST(Attributes
)
836 wxPGProperty
* prop
= pgman
->GetProperty(wxT("StringProperty"));
837 prop
->SetAttribute(wxT("Dummy Attribute"), (long)15);
839 if ( prop
->GetAttribute(wxT("Dummy Attribute")).GetLong() != 15 )
842 prop
->SetAttribute(wxT("Dummy Attribute"), wxVariant());
844 if ( !prop
->GetAttribute(wxT("Dummy Attribute")).IsNull() )
849 wxPropertyGridPage
* page1
;
850 wxPropertyGridPage
* page2
;
851 wxPropertyGridPage
* page3
;
852 wxVariant pg1_values
;
853 wxVariant pg2_values
;
854 wxVariant pg3_values
;
857 RT_START_TEST(GetPropertyValues
)
859 page1
= pgman
->GetPage(0);
860 pg1_values
= page1
->GetPropertyValues(wxT("Page1"),NULL
,wxPG_KEEP_STRUCTURE
);
861 page2
= pgman
->GetPage(1);
862 pg2_values
= page2
->GetPropertyValues(wxT("Page2"),NULL
,wxPG_KEEP_STRUCTURE
);
863 page3
= pgman
->GetPage(2);
864 pg3_values
= page3
->GetPropertyValues(wxT("Page3"),NULL
,wxPG_KEEP_STRUCTURE
);
868 RT_START_TEST(SetPropertyValues
)
870 page1
->SetPropertyValues(pg3_values
);
871 page2
->SetPropertyValues(pg1_values
);
872 page3
->SetPropertyValues(pg2_values
);
876 if ( !(pgman
->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES
) )
878 RT_START_TEST(Collapse_and_GetFirstCategory_and_GetNextCategory
)
880 for ( i
=0; i
<3; i
++ )
882 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
884 wxPropertyGridIterator it
;
886 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
890 wxPGProperty
* p
= *it
;
892 if ( !page
->IsPropertyCategory(p
) )
897 t
.Printf(wxT("Collapsing: %s\n"),page
->GetPropertyLabel(p
).c_str());
904 RT_START_TEST(Save_And_RestoreEditableState
)
906 for ( i
=0; i
<3; i
++ )
908 pgman
->SelectPage(i
);
910 wxString stringState
= pgman
->SaveEditableState();
911 bool res
= pgman
->RestoreEditableState(stringState
);
917 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
919 RT_START_TEST(Expand_and_GetFirstCategory_and_GetNextCategory
)
921 for ( i
=0; i
<3; i
++ )
923 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
925 wxPropertyGridIterator it
;
927 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
931 wxPGProperty
* p
= *it
;
933 if ( !page
->IsPropertyCategory(p
) )
938 t
.Printf(wxT("Expand: %s\n"),page
->GetPropertyLabel(p
).c_str());
945 RT_START_TEST(Choice_Manipulation
)
947 wxPGProperty
* enumProp
= pgman
->GetProperty(wxT("EnumProperty"));
949 pgman
->SelectPage(2);
950 pgman
->SelectProperty(enumProp
);
951 wxASSERT(pgman
->GetGrid()->GetSelection() == enumProp
);
953 const wxPGChoices
& choices
= enumProp
->GetChoices();
954 int ind
= enumProp
->InsertChoice(wxT("New Choice"), choices
.GetCount()/2);
955 enumProp
->DeleteChoice(ind
);
957 // Recreate the original grid
958 CreateGrid( -1, -1 );
959 pgman
= m_pPropGridManager
;
962 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
964 RT_START_TEST(RandomCollapse
)
966 // Select the most error prone page as visible.
967 pgman
->SelectPage(1);
969 for ( i
=0; i
<3; i
++ )
973 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
975 wxPropertyGridIterator it
;
977 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
984 if ( arr
.GetCount() )
988 pgman
->Collapse( (wxPGProperty
*)arr
.Item(0) );
990 for ( n
=arr
.GetCount()-1; n
>0; n
-- )
992 pgman
->Collapse( (wxPGProperty
*)arr
.Item(n
) );
1000 RT_START_TEST(EnsureVisible
)
1001 pgman
->EnsureVisible(wxT("Cell Colour"));
1005 RT_START_TEST(SetPropertyBackgroundColour
)
1007 evt
.SetInt(1); // IsChecked() will return TRUE.
1008 evt
.SetId(ID_COLOURSCHEME4
);
1010 OnColourScheme(evt
);
1014 RT_START_TEST(ManagerClear
)
1017 if ( pgman
->GetPageCount() )
1020 // Recreate the original grid
1021 CreateGrid( -1, -1 );
1022 pgman
= m_pPropGridManager
;
1027 // TODO: This test fails.
1028 RT_START_TEST(SetSplitterPosition)
1032 const int trySplitterPos = 50;
1034 int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
1035 pgman = m_pPropGridManager =
1036 new wxPropertyGridManager(m_panel, wxID_ANY,
1042 pgman->SetSplitterPosition(trySplitterPos);
1044 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1045 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1047 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
1050 wxSize sz = GetSize();
1055 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1056 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1060 // Recreate the original grid
1061 CreateGrid( -1, -1 );
1062 pgman = m_pPropGridManager;
1067 RT_START_TEST(HideProperty
)
1069 wxPropertyGridPage
* page
= pgman
->GetPage(0);
1073 wxArrayPGProperty arr1
;
1075 arr1
= GetPropertiesInRandomOrder(page
);
1079 for ( i
=0; i
<arr1
.size(); i
++ )
1081 wxPGProperty
* p
= arr1
[i
];
1082 page
->HideProperty(p
, true);
1084 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1085 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1093 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1095 for ( i
=0; i
<arr2
.size(); i
++ )
1097 wxPGProperty
* p
= arr2
[i
];
1098 page
->HideProperty(p
, false);
1100 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1101 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1108 // Let's do some more, for better consistency
1109 arr1
= GetPropertiesInRandomOrder(page
);
1113 for ( i
=0; i
<arr1
.size(); i
++ )
1115 wxPGProperty
* p
= arr1
[i
];
1116 page
->HideProperty(p
, true);
1118 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1119 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1127 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1129 for ( i
=0; i
<arr2
.size(); i
++ )
1131 wxPGProperty
* p
= arr2
[i
];
1132 page
->HideProperty(p
, false);
1134 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1135 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1142 // Ok, this time only hide half of them
1143 arr1
= GetPropertiesInRandomOrder(page
);
1144 arr1
.resize(arr1
.size()/2);
1148 for ( i
=0; i
<arr1
.size(); i
++ )
1150 wxPGProperty
* p
= arr1
[i
];
1151 page
->HideProperty(p
, true);
1153 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1154 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1162 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1164 for ( i
=0; i
<arr2
.size(); i
++ )
1166 wxPGProperty
* p
= arr2
[i
];
1167 page
->HideProperty(p
, false);
1169 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1170 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1176 // Recreate the original grid
1177 CreateGrid( -1, -1 );
1178 pgman
= m_pPropGridManager
;
1183 RT_START_TEST(MultipleColumns
)
1185 // Test with multiple columns
1186 // FIXME: Does not display changes.
1187 for ( i
=3; i
<12; i
+=2 )
1189 RT_MSG(wxString::Format(wxT("%i columns"),i
));
1190 CreateGrid( -1, -1 );
1191 pgman
= m_pPropGridManager
;
1192 pgman
->SetColumnCount(i
);
1201 RT_START_TEST(WindowStyles
)
1203 // Recreate grid with all possible (single) flags
1204 wxASSERT(wxPG_AUTO_SORT
== 0x000000010);
1206 for ( i
=4; i
<16; i
++ )
1209 RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag
));
1210 CreateGrid( flag
, -1 );
1211 pgman
= m_pPropGridManager
;
1216 wxASSERT(wxPG_EX_INIT_NOCAT
== 0x00001000);
1218 for ( i
=12; i
<24; i
++ )
1221 RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag
));
1222 CreateGrid( -1, flag
);
1223 pgman
= m_pPropGridManager
;
1228 // Recreate the original grid
1229 CreateGrid( -1, -1 );
1230 pgman
= m_pPropGridManager
;
1237 if ( failures
|| errorMessages
.size() )
1245 s
= wxString::Format(wxT("%i tests failed!!!"), failures
);
1248 s
= wxString::Format(wxT("All tests were succesfull, but there were %i warnings!"), wxPGGlobalVars
->m_warnings
);
1251 for ( i
=0; i
<errorMessages
.size(); i
++ )
1252 RT_MSG(errorMessages
[i
])
1253 wxMessageBox(s
, wxT("Some Tests Failed"));
1257 RT_MSG(wxT("All tests succesfull"))
1264 pgman
->SelectPage(0);
1266 // Test may screw up the toolbar, so we need to refresh it.
1267 wxToolBar
* toolBar
= pgman
->GetToolBar();
1274 // -----------------------------------------------------------------------