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
,
103 // Just testing the macros
104 WX_PG_DECLARE_STRING_PROPERTY(wxTestStringProperty
)
105 WX_PG_IMPLEMENT_STRING_PROPERTY(wxTestStringProperty
,wxPG_NO_ESCAPE
)
106 bool wxTestStringProperty::OnButtonClick( wxPropertyGrid
*,
109 ::wxMessageBox(wxT("Button Clicked"));
113 WX_PG_DECLARE_STRING_PROPERTY(wxTextStringPropertyWithValidator
)
114 WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(wxTextStringPropertyWithValidator
,
117 bool wxTextStringPropertyWithValidator::OnButtonClick( wxPropertyGrid
* WXUNUSED(propgrid
),
118 wxString
& WXUNUSED(value
) )
120 ::wxMessageBox(wxT("Button Clicked"));
124 wxValidator
* wxTextStringPropertyWithValidator::DoGetValidator() const
127 WX_PG_DOGETVALIDATOR_ENTRY()
128 wxTextValidator
* validator
= new
129 wxTextValidator(wxFILTER_INCLUDE_CHAR_LIST
);
130 wxArrayString oValid
;
131 oValid
.Add(wxT("0"));
132 oValid
.Add(wxT("1"));
133 oValid
.Add(wxT("2"));
134 oValid
.Add(wxT("3"));
135 oValid
.Add(wxT("4"));
136 oValid
.Add(wxT("5"));
137 oValid
.Add(wxT("6"));
138 oValid
.Add(wxT("7"));
139 oValid
.Add(wxT("8"));
140 oValid
.Add(wxT("9"));
141 oValid
.Add(wxT("$"));
142 validator
->SetIncludes(oValid
);
143 WX_PG_DOGETVALIDATOR_EXIT(validator
)
149 // -----------------------------------------------------------------------
152 // Test customizing wxColourProperty via subclassing
154 // * Includes custom colour entry.
155 // * Includes extra custom entry.
157 class MyColourProperty3
: public wxColourProperty
160 MyColourProperty3( const wxString
& label
= wxPG_LABEL
,
161 const wxString
& name
= wxPG_LABEL
,
162 const wxColour
& value
= *wxWHITE
)
163 : wxColourProperty(label
, name
, value
)
166 colours
.Add(wxT("White"));
167 colours
.Add(wxT("Black"));
168 colours
.Add(wxT("Red"));
169 colours
.Add(wxT("Green"));
170 colours
.Add(wxT("Blue"));
171 colours
.Add(wxT("Custom"));
172 colours
.Add(wxT("None"));
180 virtual ~MyColourProperty3()
184 virtual wxColour
GetColour( int index
) const
188 case 0: return *wxWHITE
;
189 case 1: return *wxBLACK
;
190 case 2: return *wxRED
;
191 case 3: return *wxGREEN
;
192 case 4: return *wxBLUE
;
194 // Return current colour for the custom entry
196 if ( GetIndex() == GetCustomColourIndex() )
198 if ( m_value
.IsNull() )
208 virtual wxString
ColourToString( const wxColour
& col
, int index
) const
210 if ( index
== (int)(m_choices
.GetCount()-1) )
213 return wxColourProperty::ColourToString(col
, index
);
216 virtual int GetCustomColourIndex() const
218 return m_choices
.GetCount()-2;
223 void FormMain::AddTestProperties( wxPropertyGridPage
* pg
)
225 pg
->Append( new wxMyColourProperty(wxT("CustomColourProperty1")) );
227 pg
->SetPropertyHelpString(wxT("CustomColourProperty1"),
228 wxT("This is a wxMyColourProperty from the sample app. ")
229 wxT("It is built with WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR macro ")
230 wxT("and has wxColour as its data type"));
232 pg
->Append( new wxMyColour2Property(wxT("CustomColourProperty2")) );
234 pg
->SetPropertyHelpString(wxT("CustomColourProperty2"),
235 wxT("This is a wxMyColour2Property from the sample app. ")
236 wxT("It is built with WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY macro ")
237 wxT("and has wxColourPropertyValue as its data type"));
239 pg
->Append( new MyColourProperty3(wxT("CustomColourProperty3"), wxPG_LABEL
, *wxGREEN
) );
240 pg
->GetProperty(wxT("CustomColourProperty3"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
241 pg
->SetPropertyEditor( wxT("CustomColourProperty3"), wxPGEditor_ComboBox
);
243 pg
->SetPropertyHelpString(wxT("CustomColourProperty3"),
244 wxT("This is a MyColourProperty3 from the sample app. ")
245 wxT("It is built by subclassing wxColourProperty."));
247 pg
->Append( new wxTextStringPropertyWithValidator(wxT("TestProp1"), wxPG_LABEL
) );
250 // -----------------------------------------------------------------------
252 void FormMain::OnDumpList( wxCommandEvent
& WXUNUSED(event
) )
254 wxVariant values
= m_pPropGridManager
->GetPropertyValues(wxT("list"), wxNullProperty
, wxPG_INC_ATTRIBUTES
);
255 wxString text
= wxT("This only tests that wxVariant related routines do not crash.");
258 wxDialog
* dlg
= new wxDialog(this,-1,wxT("wxVariant Test"),
259 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
262 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
264 wxVariant
& v
= values
[i
];
266 wxString strValue
= v
.GetString();
268 #if wxCHECK_VERSION(2,8,0)
269 if ( v
.GetName().EndsWith(wxT("@attr")) )
271 if ( v
.GetName().Right(5) == wxT("@attr") )
274 text
+= wxString::Format(wxT("Attributes:\n"));
277 for ( n
= 0; n
< (unsigned int)v
.GetCount(); n
++ )
281 t
.Printf(wxT(" atribute %i: name=\"%s\" (type=\"%s\" value=\"%s\")\n"),(int)n
,
282 a
.GetName().c_str(),a
.GetType().c_str(),a
.GetString().c_str());
288 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\" value=\"%s\"\n"),(int)i
,
289 v
.GetName().c_str(),v
.GetType().c_str(),strValue
.c_str());
294 // multi-line text editor dialog
295 const int spacing
= 8;
296 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
297 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
298 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,text
,
299 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
300 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
301 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
302 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
303 const int butSzFlags
=
304 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
305 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
306 0, butSzFlags
, spacing
);
307 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
309 dlg
->SetSizer( topsizer
);
310 topsizer
->SetSizeHints( dlg
);
312 dlg
->SetSize(400,300);
317 // -----------------------------------------------------------------------
323 TestRunner( const wxString
& name
, wxPropertyGridManager
* man
, wxTextCtrl
* ed
, wxArrayString
* errorMessages
)
328 m_errorMessages
= errorMessages
;
330 m_preWarnings
= wxPGGlobalVars
->m_warnings
;
333 if ( name
!= wxT("none") )
340 int warningsOccurred
= wxPGGlobalVars
->m_warnings
- m_preWarnings
;
341 if ( warningsOccurred
)
343 wxString s
= wxString::Format(wxT("%i warnings occurred during test '%s'"), warningsOccurred
, m_name
.c_str());
344 m_errorMessages
->push_back(s
);
350 void Msg( const wxString
& text
)
354 m_ed
->AppendText(text
);
355 m_ed
->AppendText(wxT("\n"));
361 wxPropertyGridManager
* m_man
;
363 wxArrayString
* m_errorMessages
;
371 #define RT_START_TEST(TESTNAME) \
372 TestRunner tr(wxT(#TESTNAME), pgman, ed, &errorMessages);
377 #define RT_FAILURE() \
379 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
380 errorMessages.push_back(s1); \
385 #define RT_FAILURE_MSG(MSG) \
387 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
388 errorMessages.push_back(s1); \
390 wxString s2 = wxString::Format(wxT("Message: %s"),MSG); \
391 errorMessages.push_back(s2); \
396 #define RT_VALIDATE_VIRTUAL_HEIGHT(PROPS, EXTRATEXT) \
398 unsigned int h1_ = PROPS->GetVirtualHeight(); \
399 unsigned int h2_ = PROPS->GetActualVirtualHeight(); \
402 wxString s_ = wxString::Format(wxT("VirtualHeight = %i, should be %i (%s)"), h1_, h2_, EXTRATEXT.c_str()); \
403 RT_FAILURE_MSG(s_.c_str()); \
413 int gpiro_cmpfunc(const void* a
, const void* b
)
415 const wxPGProperty
* p1
= (const wxPGProperty
*) a
;
416 const wxPGProperty
* p2
= (const wxPGProperty
*) b
;
417 return (int) (((size_t)p1
->GetClientData()) - ((size_t)p2
->GetClientData()));
420 wxArrayPGProperty
GetPropertiesInRandomOrder( wxPropertyGridInterface
* props
, int iterationFlags
= wxPG_ITERATE_ALL
)
422 wxArrayPGProperty arr
;
424 wxPropertyGridIterator it
;
426 for ( it
= props
->GetIterator(iterationFlags
);
430 wxPGProperty
* p
= *it
;
431 size_t randomNumber
= rand();
432 p
->SetClientData(reinterpret_cast<void*>(randomNumber
));
436 wxPGProperty
** firstEntry
= &arr
[0];
437 qsort(firstEntry
, arr
.size(), sizeof(wxPGProperty
*), gpiro_cmpfunc
);
442 bool FormMain::RunTests( bool fullTest
, bool interactive
)
446 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
451 pgman
->ClearSelection();
454 bool _failed_
= false;
455 wxArrayString errorMessages
;
456 wxDialog
* dlg
= NULL
;
458 dlg
= new wxDialog(this,-1,wxT("wxPropertyGrid Regression Tests"),
459 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
461 // multi-line text editor dialog
462 const int spacing
= 8;
463 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
464 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
465 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,wxEmptyString
,
466 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
467 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
468 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
469 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
470 const int butSzFlags
=
471 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
472 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
473 0, butSzFlags
, spacing
);
474 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
476 dlg
->SetSizer( topsizer
);
477 topsizer
->SetSizeHints( dlg
);
479 dlg
->SetSize(400,300);
480 dlg
->Move(wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)-dlg
->GetSize().x
,
481 wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)-dlg
->GetSize().y
);
486 // Basic iterator tests
487 RT_START_TEST(GetIterator
)
493 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
497 wxPGProperty
* p
= it
.GetProperty();
498 if ( p
->IsCategory() )
499 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a category (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
500 else if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
501 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
505 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES) -> %i entries"), count
));
508 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_CATEGORIES
);
512 wxPGProperty
* p
= it
.GetProperty();
513 if ( !p
->IsCategory() )
514 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is not a category (only category was expected)"),p
->GetLabel().c_str()).c_str())
518 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
521 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
|wxPG_ITERATE_CATEGORIES
);
525 wxPGProperty
* p
= it
.GetProperty();
526 if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
527 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property or category expected)"),p
->GetLabel().c_str()).c_str())
531 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
534 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_VISIBLE
);
538 wxPGProperty
* p
= it
.GetProperty();
539 if ( (p
->GetParent() != p
->GetParentState()->DoGetRoot() && !p
->GetParent()->IsExpanded()) )
540 RT_FAILURE_MSG(wxString::Format(wxT("'%s' had collapsed parent (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
541 else if ( p
->HasFlag(wxPG_PROP_HIDDEN
) )
542 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was hidden (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
546 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_VISIBLE) -> %i entries"), count
));
551 // Test that setting focus to properties does not crash things
552 RT_START_TEST(SelectProperty
)
554 wxPropertyGridIterator it
;
557 for ( ind
=0; ind
<pgman
->GetPageCount(); ind
++ )
559 wxPropertyGridPage
* page
= pgman
->GetPage(ind
);
560 pgman
->SelectPage(page
);
562 for ( it
= page
->GetIterator(wxPG_ITERATE_VISIBLE
);
566 wxPGProperty
* p
= *it
;
567 RT_MSG(p
->GetLabel());
568 pgman
->GetGrid()->SelectProperty(p
, true);
577 // Delete everything in reverse order
578 RT_START_TEST(DeleteProperty
)
581 wxArrayPGProperty array
;
583 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_ALL
&~(wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
)));
586 array
.push_back(it
.GetProperty());
588 wxArrayPGProperty::reverse_iterator it2
;
590 for ( it2
= array
.rbegin(); it2
!= array
.rend(); it2
++ )
592 wxPGProperty
* p
= (wxPGProperty
*)*it2
;
593 RT_MSG(wxString::Format(wxT("Deleting '%s' ('%s')"),p
->GetLabel().c_str(),p
->GetName().c_str()));
594 pgman
->DeleteProperty(p
);
598 CreateGrid( -1, -1 );
599 pgman
= m_pPropGridManager
;
604 // Test property default values
605 RT_START_TEST(Default_Values
)
609 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
613 wxPGProperty
* p
= it
.GetProperty();
614 pgman
->SetPropertyValue(p
, p
->GetDefaultValue());
618 CreateGrid( -1, -1 );
619 pgman
= m_pPropGridManager
;
623 RT_START_TEST(GetPropertyValues
)
625 for ( i
=0; i
<3; i
++ )
629 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
631 wxVariant values
= page
->GetPropertyValues();
634 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
636 wxVariant
& v
= values
[i
];
638 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\"\n"),(int)i
,
639 v
.GetName().c_str(),v
.GetType().c_str());
643 ed
->AppendText(text
);
648 RT_START_TEST(SetPropertyValue_and_GetPropertyValue
)
650 // In this section, mixed up usage of wxT("propname") and "propname"
651 // in wxPropertyGridInterface functions is intentional.
652 // Purpose is to test wxPGPropArgCls ctors.
654 //pg = (wxPropertyGrid*) NULL;
656 wxArrayString test_arrstr_1
;
657 test_arrstr_1
.Add(wxT("Apple"));
658 test_arrstr_1
.Add(wxT("Orange"));
659 test_arrstr_1
.Add(wxT("Lemon"));
661 wxArrayString test_arrstr_2
;
662 test_arrstr_2
.Add(wxT("Potato"));
663 test_arrstr_2
.Add(wxT("Cabbage"));
664 test_arrstr_2
.Add(wxT("Cucumber"));
666 wxArrayInt test_arrint_1
;
667 test_arrint_1
.Add(1);
668 test_arrint_1
.Add(2);
669 test_arrint_1
.Add(3);
671 wxArrayInt test_arrint_2
;
672 test_arrint_2
.Add(0);
673 test_arrint_2
.Add(1);
674 test_arrint_2
.Add(4);
677 wxDateTime dt1
= wxDateTime::Now();
678 dt1
.SetYear(dt1
.GetYear()-1);
680 wxDateTime dt2
= wxDateTime::Now();
681 dt2
.SetYear(dt2
.GetYear()-10);
684 #define FLAG_TEST_SET1 (wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER)
685 #define FLAG_TEST_SET2 (wxSTAY_ON_TOP|wxCAPTION|wxICONIZE|wxSYSTEM_MENU)
687 pgman
->SetPropertyValue(wxT("StringProperty"),wxT("Text1"));
688 pgman
->SetPropertyValue(wxT("IntProperty"),1024);
689 pgman
->SetPropertyValue(wxT("FloatProperty"),1024.0000000001);
690 pgman
->SetPropertyValue(wxT("BoolProperty"),FALSE
);
691 pgman
->SetPropertyValue(wxT("EnumProperty"),120);
692 pgman
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_1
);
694 pgman
->SetPropertyValue(wxT("ColourProperty"),emptyCol
);
695 pgman
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxBLACK
);
696 pgman
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(150,150)));
697 pgman
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(150,150)));
698 pgman
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_1
);
700 pgman
->SetPropertyValue(wxT("DateProperty"),dt1
);
703 pgman
->SelectPage(2);
704 pg
= pgman
->GetGrid();
706 if ( pg
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text1") )
708 if ( pg
->GetPropertyValueAsInt(wxT("IntProperty")) != 1024 )
710 if ( pg
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 1024.0000000001 )
712 if ( pg
->GetPropertyValueAsBool(wxT("BoolProperty")) != FALSE
)
714 if ( pg
->GetPropertyValueAsLong(wxT("EnumProperty")) != 120 )
716 if ( pg
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_1
)
719 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
720 if ( col
!= *wxBLACK
)
722 if ( wxSizeRefFromVariant(pg
->GetPropertyValue(wxT("Size"))) != wxSize(150,150) )
724 if ( wxPointRefFromVariant(pg
->GetPropertyValue(wxT("Position"))) != wxPoint(150,150) )
726 if ( !(pg
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_1
) )
729 if ( !(pg
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt1
) )
733 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(10000000000));
734 if ( pg
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(10000000000) )
737 pg
->SetPropertyValue(wxT("StringProperty"),wxT("Text2"));
738 pg
->SetPropertyValue(wxT("IntProperty"),512);
739 pg
->SetPropertyValue(wxT("FloatProperty"),512.0);
740 pg
->SetPropertyValue(wxT("BoolProperty"),TRUE
);
741 pg
->SetPropertyValue(wxT("EnumProperty"),80);
742 pg
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_2
);
743 pg
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxWHITE
);
744 pg
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(300,300)));
745 pg
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(300,300)));
746 pg
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_2
);
748 pg
->SetPropertyValue(wxT("DateProperty"),dt2
);
751 //pg = (wxPropertyGrid*) NULL;
753 pgman
->SelectPage(0);
755 if ( pgman
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text2") )
757 if ( pgman
->GetPropertyValueAsInt(wxT("IntProperty")) != 512 )
759 if ( pgman
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 512.0 )
761 if ( pgman
->GetPropertyValueAsBool(wxT("BoolProperty")) != TRUE
)
763 if ( pgman
->GetPropertyValueAsLong(wxT("EnumProperty")) != 80 )
765 if ( pgman
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_2
)
767 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
768 if ( col
!= *wxWHITE
)
770 if ( wxSizeRefFromVariant(pgman
->GetPropertyValue(wxT("Size"))) != wxSize(300,300) )
772 if ( wxPointRefFromVariant(pgman
->GetPropertyValue(wxT("Position"))) != wxPoint(300,300) )
774 if ( !(pgman
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_2
) )
777 if ( !(pgman
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt2
) )
781 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000));
782 if ( pgman
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) )
786 // Flexible wx(U)LongLong << operator safety conformance tests
791 prop
= pgman
->GetProperty(wxT("IntProperty"));
793 ll
<< prop
->GetValue();
797 prop
->SetValue(WXVARIANT(wxLL(68719476736)));
798 ll
<< prop
->GetValue();
799 if ( ll
.GetValue() != wxLL(68719476736) )
802 #if wxUSE_LONGLONG_NATIVE
804 ll_t
<< prop
->GetValue();
805 if ( ll_t
!= wxLL(68719476736) )
810 ll
<< prop
->GetValue();
814 prop
= pgman
->GetProperty(wxT("UIntProperty"));
816 ull
<< prop
->GetValue();
820 prop
->SetValue(WXVARIANT(wxULL(68719476739)));
821 ull
<< prop
->GetValue();
822 if ( ull
.GetValue() != wxULL(68719476739) )
825 #if wxUSE_LONGLONG_NATIVE
827 ull_t
<< prop
->GetValue();
828 if ( ull_t
!= wxLL(68719476739) )
833 ull
<< prop
->GetValue();
837 // Make sure children of composite parent get updated as well
838 // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000"
841 // This updates children as well
842 wxString nvs
= "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002";
843 pgman
->SetPropertyValue("Car", nvs
);
845 if ( pgman
->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
847 wxLogDebug("Did not match: Car.Model=%s", pgman
->GetPropertyValueAsString("Car.Model").c_str());
851 if ( pgman
->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
853 wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman
->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
857 if ( pgman
->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
859 wxLogDebug("Did not match: Car.Price ($)=%s", pgman
->GetPropertyValueAsString("Car.Price ($)").c_str());
865 RT_START_TEST(SetPropertyValueUnspecified
)
867 // Null variant setter tests
868 pgman
->SetPropertyValueUnspecified(wxT("StringProperty"));
869 pgman
->SetPropertyValueUnspecified(wxT("IntProperty"));
870 pgman
->SetPropertyValueUnspecified(wxT("FloatProperty"));
871 pgman
->SetPropertyValueUnspecified(wxT("BoolProperty"));
872 pgman
->SetPropertyValueUnspecified(wxT("EnumProperty"));
873 pgman
->SetPropertyValueUnspecified(wxT("ArrayStringProperty"));
874 pgman
->SetPropertyValueUnspecified(wxT("ColourProperty"));
875 pgman
->SetPropertyValueUnspecified(wxT("Size"));
876 pgman
->SetPropertyValueUnspecified(wxT("Position"));
877 pgman
->SetPropertyValueUnspecified(wxT("MultiChoiceProperty"));
879 pgman
->SetPropertyValueUnspecified(wxT("DateProperty"));
884 RT_START_TEST(Attributes
)
886 wxPGProperty
* prop
= pgman
->GetProperty(wxT("StringProperty"));
887 prop
->SetAttribute(wxT("Dummy Attribute"), (long)15);
889 if ( prop
->GetAttribute(wxT("Dummy Attribute")).GetLong() != 15 )
892 prop
->SetAttribute(wxT("Dummy Attribute"), wxVariant());
894 if ( !prop
->GetAttribute(wxT("Dummy Attribute")).IsNull() )
899 wxPropertyGridPage
* page1
;
900 wxPropertyGridPage
* page2
;
901 wxPropertyGridPage
* page3
;
902 wxVariant pg1_values
;
903 wxVariant pg2_values
;
904 wxVariant pg3_values
;
907 RT_START_TEST(GetPropertyValues
)
909 page1
= pgman
->GetPage(0);
910 pg1_values
= page1
->GetPropertyValues(wxT("Page1"),NULL
,wxPG_KEEP_STRUCTURE
);
911 page2
= pgman
->GetPage(1);
912 pg2_values
= page2
->GetPropertyValues(wxT("Page2"),NULL
,wxPG_KEEP_STRUCTURE
);
913 page3
= pgman
->GetPage(2);
914 pg3_values
= page3
->GetPropertyValues(wxT("Page3"),NULL
,wxPG_KEEP_STRUCTURE
);
918 RT_START_TEST(SetPropertyValues
)
920 page1
->SetPropertyValues(pg3_values
);
921 page2
->SetPropertyValues(pg1_values
);
922 page3
->SetPropertyValues(pg2_values
);
926 if ( !(pgman
->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES
) )
928 RT_START_TEST(Collapse_and_GetFirstCategory_and_GetNextCategory
)
930 for ( i
=0; i
<3; i
++ )
932 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
934 wxPropertyGridIterator it
;
936 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
940 wxPGProperty
* p
= *it
;
942 if ( !page
->IsPropertyCategory(p
) )
947 t
.Printf(wxT("Collapsing: %s\n"),page
->GetPropertyLabel(p
).c_str());
954 RT_START_TEST(Save_And_RestoreEditableState
)
956 for ( i
=0; i
<3; i
++ )
958 pgman
->SelectPage(i
);
960 wxString stringState
= pgman
->SaveEditableState();
961 bool res
= pgman
->RestoreEditableState(stringState
);
967 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
969 RT_START_TEST(Expand_and_GetFirstCategory_and_GetNextCategory
)
971 for ( i
=0; i
<3; i
++ )
973 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
975 wxPropertyGridIterator it
;
977 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
981 wxPGProperty
* p
= *it
;
983 if ( !page
->IsPropertyCategory(p
) )
988 t
.Printf(wxT("Expand: %s\n"),page
->GetPropertyLabel(p
).c_str());
995 RT_START_TEST(Choice_Manipulation
)
997 wxPGProperty
* enumProp
= pgman
->GetProperty(wxT("EnumProperty"));
999 pgman
->SelectPage(2);
1000 pgman
->SelectProperty(enumProp
);
1001 wxASSERT(pgman
->GetGrid()->GetSelection() == enumProp
);
1003 const wxPGChoices
& choices
= enumProp
->GetChoices();
1004 int ind
= enumProp
->InsertChoice(wxT("New Choice"), choices
.GetCount()/2);
1005 enumProp
->DeleteChoice(ind
);
1007 // Recreate the original grid
1008 CreateGrid( -1, -1 );
1009 pgman
= m_pPropGridManager
;
1012 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
1014 RT_START_TEST(RandomCollapse
)
1016 // Select the most error prone page as visible.
1017 pgman
->SelectPage(1);
1019 for ( i
=0; i
<3; i
++ )
1023 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
1025 wxPropertyGridIterator it
;
1027 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
1031 arr
.Add((void*)*it
);
1034 if ( arr
.GetCount() )
1038 pgman
->Collapse( (wxPGProperty
*)arr
.Item(0) );
1040 for ( n
=arr
.GetCount()-1; n
>0; n
-- )
1042 pgman
->Collapse( (wxPGProperty
*)arr
.Item(n
) );
1050 RT_START_TEST(EnsureVisible
)
1051 pgman
->EnsureVisible(wxT("Cell Colour"));
1055 RT_START_TEST(SetPropertyBackgroundColour
)
1057 evt
.SetInt(1); // IsChecked() will return TRUE.
1058 evt
.SetId(ID_COLOURSCHEME4
);
1060 OnColourScheme(evt
);
1064 RT_START_TEST(ManagerClear
)
1067 if ( pgman
->GetPageCount() )
1070 // Recreate the original grid
1071 CreateGrid( -1, -1 );
1072 pgman
= m_pPropGridManager
;
1077 // TODO: This test fails.
1078 RT_START_TEST(SetSplitterPosition)
1082 const int trySplitterPos = 50;
1084 int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
1085 pgman = m_pPropGridManager =
1086 new wxPropertyGridManager(m_panel, wxID_ANY,
1092 pgman->SetSplitterPosition(trySplitterPos);
1094 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1095 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1097 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
1100 wxSize sz = GetSize();
1105 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1106 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1110 // Recreate the original grid
1111 CreateGrid( -1, -1 );
1112 pgman = m_pPropGridManager;
1117 RT_START_TEST(HideProperty
)
1119 wxPropertyGridPage
* page
= pgman
->GetPage(0);
1123 wxArrayPGProperty arr1
;
1125 arr1
= GetPropertiesInRandomOrder(page
);
1129 for ( i
=0; i
<arr1
.size(); i
++ )
1131 wxPGProperty
* p
= arr1
[i
];
1132 page
->HideProperty(p
, true);
1134 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1135 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1143 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1145 for ( i
=0; i
<arr2
.size(); i
++ )
1147 wxPGProperty
* p
= arr2
[i
];
1148 page
->HideProperty(p
, false);
1150 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1151 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1158 // Let's do some more, for better consistency
1159 arr1
= GetPropertiesInRandomOrder(page
);
1163 for ( i
=0; i
<arr1
.size(); i
++ )
1165 wxPGProperty
* p
= arr1
[i
];
1166 page
->HideProperty(p
, true);
1168 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1169 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1177 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1179 for ( i
=0; i
<arr2
.size(); i
++ )
1181 wxPGProperty
* p
= arr2
[i
];
1182 page
->HideProperty(p
, false);
1184 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1185 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1192 // Ok, this time only hide half of them
1193 arr1
= GetPropertiesInRandomOrder(page
);
1194 arr1
.resize(arr1
.size()/2);
1198 for ( i
=0; i
<arr1
.size(); i
++ )
1200 wxPGProperty
* p
= arr1
[i
];
1201 page
->HideProperty(p
, true);
1203 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1204 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1212 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1214 for ( i
=0; i
<arr2
.size(); i
++ )
1216 wxPGProperty
* p
= arr2
[i
];
1217 page
->HideProperty(p
, false);
1219 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1220 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1226 // Recreate the original grid
1227 CreateGrid( -1, -1 );
1228 pgman
= m_pPropGridManager
;
1233 RT_START_TEST(MultipleColumns
)
1235 // Test with multiple columns
1236 // FIXME: Does not display changes.
1237 for ( i
=3; i
<12; i
+=2 )
1239 RT_MSG(wxString::Format(wxT("%i columns"),i
));
1240 CreateGrid( -1, -1 );
1241 pgman
= m_pPropGridManager
;
1242 pgman
->SetColumnCount(i
);
1251 RT_START_TEST(WindowStyles
)
1253 // Recreate grid with all possible (single) flags
1254 wxASSERT(wxPG_AUTO_SORT
== 0x000000010);
1256 for ( i
=4; i
<16; i
++ )
1259 RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag
));
1260 CreateGrid( flag
, -1 );
1261 pgman
= m_pPropGridManager
;
1266 wxASSERT(wxPG_EX_INIT_NOCAT
== 0x00001000);
1268 for ( i
=12; i
<24; i
++ )
1271 RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag
));
1272 CreateGrid( -1, flag
);
1273 pgman
= m_pPropGridManager
;
1278 // Recreate the original grid
1279 CreateGrid( -1, -1 );
1280 pgman
= m_pPropGridManager
;
1287 if ( failures
|| errorMessages
.size() )
1295 s
= wxString::Format(wxT("%i tests failed!!!"), failures
);
1298 s
= wxString::Format(wxT("All tests were succesfull, but there were %i warnings!"), wxPGGlobalVars
->m_warnings
);
1301 for ( i
=0; i
<errorMessages
.size(); i
++ )
1302 RT_MSG(errorMessages
[i
])
1303 wxMessageBox(s
, wxT("Some Tests Failed"));
1307 RT_MSG(wxT("All tests succesfull"))
1314 pgman
->SelectPage(0);
1316 // Test may screw up the toolbar, so we need to refresh it.
1317 wxToolBar
* toolBar
= pgman
->GetToolBar();
1324 // -----------------------------------------------------------------------