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 static void PropertiesToNames( wxPropertyGridInterface
* WXUNUSED(iface
),
443 wxArrayString
* names
,
444 const wxArrayPGProperty
& properties
)
447 for ( i
=0; i
<properties
.size(); i
++ )
448 names
->Add( properties
[i
]->GetName() );
451 static void NamesToProperties( wxPropertyGridInterface
* iface
,
452 wxArrayPGProperty
* properties
,
453 const wxArrayString
& names
)
456 for ( i
=0; i
<names
.size(); i
++ )
458 wxPGProperty
* p
= iface
->GetPropertyByName(names
[i
]);
460 properties
->push_back(p
);
464 bool FormMain::RunTests( bool fullTest
, bool interactive
)
468 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
473 pgman
->ClearSelection();
476 bool _failed_
= false;
477 wxArrayString errorMessages
;
478 wxDialog
* dlg
= NULL
;
480 dlg
= new wxDialog(this,-1,wxT("wxPropertyGrid Regression Tests"),
481 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
483 // multi-line text editor dialog
484 const int spacing
= 8;
485 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
486 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
487 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,wxEmptyString
,
488 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
489 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
490 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
491 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
492 const int butSzFlags
=
493 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
494 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
495 0, butSzFlags
, spacing
);
496 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
498 dlg
->SetSizer( topsizer
);
499 topsizer
->SetSizeHints( dlg
);
501 dlg
->SetSize(400,300);
502 dlg
->Move(wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)-dlg
->GetSize().x
,
503 wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)-dlg
->GetSize().y
);
508 // Basic iterator tests
509 RT_START_TEST(GetIterator
)
515 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
519 wxPGProperty
* p
= it
.GetProperty();
520 if ( p
->IsCategory() )
521 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a category (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
522 else if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
523 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
527 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES) -> %i entries"), count
));
530 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_CATEGORIES
);
534 wxPGProperty
* p
= it
.GetProperty();
535 if ( !p
->IsCategory() )
536 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is not a category (only category was expected)"),p
->GetLabel().c_str()).c_str())
540 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
543 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
|wxPG_ITERATE_CATEGORIES
);
547 wxPGProperty
* p
= it
.GetProperty();
548 if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
549 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property or category expected)"),p
->GetLabel().c_str()).c_str())
553 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
556 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_VISIBLE
);
560 wxPGProperty
* p
= it
.GetProperty();
561 if ( (p
->GetParent() != p
->GetParentState()->DoGetRoot() && !p
->GetParent()->IsExpanded()) )
562 RT_FAILURE_MSG(wxString::Format(wxT("'%s' had collapsed parent (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
563 else if ( p
->HasFlag(wxPG_PROP_HIDDEN
) )
564 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was hidden (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
568 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_VISIBLE) -> %i entries"), count
));
573 // Test that setting focus to properties does not crash things
574 RT_START_TEST(SelectProperty
)
576 wxPropertyGridIterator it
;
579 for ( ind
=0; ind
<pgman
->GetPageCount(); ind
++ )
581 wxPropertyGridPage
* page
= pgman
->GetPage(ind
);
582 pgman
->SelectPage(page
);
584 for ( it
= page
->GetIterator(wxPG_ITERATE_VISIBLE
);
588 wxPGProperty
* p
= *it
;
589 RT_MSG(p
->GetLabel());
590 pgman
->GetGrid()->SelectProperty(p
, true);
598 RT_START_TEST(GetPropertiesWithFlag
)
601 // Get list of expanded properties
602 wxArrayPGProperty array
= pgman
->GetExpandedProperties();
604 // Make sure list only has items with children
605 for ( i
=0; i
<array
.size(); i
++ )
607 wxPGProperty
* p
= array
[i
];
608 if ( !p
->IsKindOf(CLASSINFO(wxPGProperty
)) )
609 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was returned by GetExpandedProperties(), but was not a parent"),p
->GetName().c_str()).c_str());
613 PropertiesToNames( pgman
, &names
, array
);
616 // ... and then collapse them
617 wxArrayPGProperty array2
;
618 NamesToProperties( pgman
, &array2
, names
);
620 for ( i
=0; i
<array2
.size(); i
++ )
622 wxPGProperty
* p
= array
[i
];
623 p
->SetExpanded(false);
626 // Make sure everything is collapsed
629 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_ALL
);
633 wxPGProperty
* p
= it
.GetProperty();
634 if ( p
->IsExpanded() )
635 RT_FAILURE_MSG(wxString::Format(wxT("'%s.%s' was expanded"),p
->GetParent()->GetName().c_str(),p
->GetName().c_str()).c_str());
643 // Delete everything in reverse order
644 RT_START_TEST(DeleteProperty
)
647 wxArrayPGProperty array
;
649 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_ALL
&~(wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
)));
652 array
.push_back(it
.GetProperty());
654 wxArrayPGProperty::reverse_iterator it2
;
656 for ( it2
= array
.rbegin(); it2
!= array
.rend(); it2
++ )
658 wxPGProperty
* p
= (wxPGProperty
*)*it2
;
659 RT_MSG(wxString::Format(wxT("Deleting '%s' ('%s')"),p
->GetLabel().c_str(),p
->GetName().c_str()));
660 pgman
->DeleteProperty(p
);
664 CreateGrid( -1, -1 );
665 pgman
= m_pPropGridManager
;
670 // Clear property value
671 RT_START_TEST(ClearPropertyValue
)
675 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
679 RT_MSG(wxString::Format(wxT("Clearing value of '%s'"),it
.GetProperty()->GetLabel().c_str()));
680 pgman
->ClearPropertyValue(it
.GetProperty());
684 CreateGrid( -1, -1 );
685 pgman
= m_pPropGridManager
;
689 RT_START_TEST(GetPropertyValues
)
691 for ( i
=0; i
<3; i
++ )
695 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
697 wxVariant values
= page
->GetPropertyValues();
700 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
702 wxVariant
& v
= values
[i
];
704 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\"\n"),(int)i
,
705 v
.GetName().c_str(),v
.GetType().c_str());
709 ed
->AppendText(text
);
714 RT_START_TEST(SetPropertyValue_and_GetPropertyValue
)
716 // In this section, mixed up usage of wxT("propname") and "propname"
717 // in wxPropertyGridInterface functions is intentional.
718 // Purpose is to test wxPGPropArgCls ctors.
720 //pg = (wxPropertyGrid*) NULL;
722 wxArrayString test_arrstr_1
;
723 test_arrstr_1
.Add(wxT("Apple"));
724 test_arrstr_1
.Add(wxT("Orange"));
725 test_arrstr_1
.Add(wxT("Lemon"));
727 wxArrayString test_arrstr_2
;
728 test_arrstr_2
.Add(wxT("Potato"));
729 test_arrstr_2
.Add(wxT("Cabbage"));
730 test_arrstr_2
.Add(wxT("Cucumber"));
732 wxArrayInt test_arrint_1
;
733 test_arrint_1
.Add(1);
734 test_arrint_1
.Add(2);
735 test_arrint_1
.Add(3);
737 wxArrayInt test_arrint_2
;
738 test_arrint_2
.Add(0);
739 test_arrint_2
.Add(1);
740 test_arrint_2
.Add(4);
743 wxDateTime dt1
= wxDateTime::Now();
744 dt1
.SetYear(dt1
.GetYear()-1);
746 wxDateTime dt2
= wxDateTime::Now();
747 dt2
.SetYear(dt2
.GetYear()-10);
750 #define FLAG_TEST_SET1 (wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER)
751 #define FLAG_TEST_SET2 (wxSTAY_ON_TOP|wxCAPTION|wxICONIZE|wxSYSTEM_MENU)
753 pgman
->SetPropertyValue(wxT("StringProperty"),wxT("Text1"));
754 pgman
->SetPropertyValue(wxT("IntProperty"),1024);
755 pgman
->SetPropertyValue(wxT("FloatProperty"),1024.0000000001);
756 pgman
->SetPropertyValue(wxT("BoolProperty"),FALSE
);
757 pgman
->SetPropertyValue(wxT("EnumProperty"),120);
758 pgman
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_1
);
760 pgman
->SetPropertyValue(wxT("ColourProperty"),emptyCol
);
761 pgman
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxBLACK
);
762 pgman
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(150,150)));
763 pgman
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(150,150)));
764 pgman
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_1
);
766 pgman
->SetPropertyValue(wxT("DateProperty"),dt1
);
769 pgman
->SelectPage(2);
770 pg
= pgman
->GetGrid();
772 if ( pg
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text1") )
774 if ( pg
->GetPropertyValueAsInt(wxT("IntProperty")) != 1024 )
776 if ( pg
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 1024.0000000001 )
778 if ( pg
->GetPropertyValueAsBool(wxT("BoolProperty")) != FALSE
)
780 if ( pg
->GetPropertyValueAsLong(wxT("EnumProperty")) != 120 )
782 if ( pg
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_1
)
785 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
786 if ( col
!= *wxBLACK
)
788 if ( wxSizeRefFromVariant(pg
->GetPropertyValue(wxT("Size"))) != wxSize(150,150) )
790 if ( wxPointRefFromVariant(pg
->GetPropertyValue(wxT("Position"))) != wxPoint(150,150) )
792 if ( !(pg
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_1
) )
795 if ( !(pg
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt1
) )
799 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(10000000000));
800 if ( pg
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(10000000000) )
803 pg
->SetPropertyValue(wxT("StringProperty"),wxT("Text2"));
804 pg
->SetPropertyValue(wxT("IntProperty"),512);
805 pg
->SetPropertyValue(wxT("FloatProperty"),512.0);
806 pg
->SetPropertyValue(wxT("BoolProperty"),TRUE
);
807 pg
->SetPropertyValue(wxT("EnumProperty"),80);
808 pg
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_2
);
809 pg
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxWHITE
);
810 pg
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(300,300)));
811 pg
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(300,300)));
812 pg
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_2
);
814 pg
->SetPropertyValue(wxT("DateProperty"),dt2
);
817 //pg = (wxPropertyGrid*) NULL;
819 pgman
->SelectPage(0);
821 if ( pgman
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text2") )
823 if ( pgman
->GetPropertyValueAsInt(wxT("IntProperty")) != 512 )
825 if ( pgman
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 512.0 )
827 if ( pgman
->GetPropertyValueAsBool(wxT("BoolProperty")) != TRUE
)
829 if ( pgman
->GetPropertyValueAsLong(wxT("EnumProperty")) != 80 )
831 if ( pgman
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_2
)
833 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
834 if ( col
!= *wxWHITE
)
836 if ( wxSizeRefFromVariant(pgman
->GetPropertyValue(wxT("Size"))) != wxSize(300,300) )
838 if ( wxPointRefFromVariant(pgman
->GetPropertyValue(wxT("Position"))) != wxPoint(300,300) )
840 if ( !(pgman
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_2
) )
843 if ( !(pgman
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt2
) )
847 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000));
848 if ( pgman
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) )
852 // Flexible wx(U)LongLong << operator safety conformance tests
857 prop
= pgman
->GetProperty(wxT("IntProperty"));
859 ll
<< prop
->GetValue();
863 prop
->SetValue(WXVARIANT(wxLL(68719476736)));
864 ll
<< prop
->GetValue();
865 if ( ll
.GetValue() != wxLL(68719476736) )
868 #if wxUSE_LONGLONG_NATIVE
870 ll_t
<< prop
->GetValue();
871 if ( ll_t
!= wxLL(68719476736) )
876 ll
<< prop
->GetValue();
880 prop
= pgman
->GetProperty(wxT("UIntProperty"));
882 ull
<< prop
->GetValue();
886 prop
->SetValue(WXVARIANT(wxULL(68719476739)));
887 ull
<< prop
->GetValue();
888 if ( ull
.GetValue() != wxULL(68719476739) )
891 #if wxUSE_LONGLONG_NATIVE
893 ull_t
<< prop
->GetValue();
894 if ( ull_t
!= wxLL(68719476739) )
899 ull
<< prop
->GetValue();
903 // Make sure children of composite parent get updated as well
904 // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000"
907 // This updates children as well
908 wxString nvs
= "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002";
909 pgman
->SetPropertyValue("Car", nvs
);
911 if ( pgman
->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
913 wxLogDebug("Did not match: Car.Model=%s", pgman
->GetPropertyValueAsString("Car.Model").c_str());
917 if ( pgman
->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
919 wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman
->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
923 if ( pgman
->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
925 wxLogDebug("Did not match: Car.Price ($)=%s", pgman
->GetPropertyValueAsString("Car.Price ($)").c_str());
931 RT_START_TEST(SetPropertyValueUnspecified
)
933 // Null variant setter tests
934 pgman
->SetPropertyValueUnspecified(wxT("StringProperty"));
935 pgman
->SetPropertyValueUnspecified(wxT("IntProperty"));
936 pgman
->SetPropertyValueUnspecified(wxT("FloatProperty"));
937 pgman
->SetPropertyValueUnspecified(wxT("BoolProperty"));
938 pgman
->SetPropertyValueUnspecified(wxT("EnumProperty"));
939 pgman
->SetPropertyValueUnspecified(wxT("ArrayStringProperty"));
940 pgman
->SetPropertyValueUnspecified(wxT("ColourProperty"));
941 pgman
->SetPropertyValueUnspecified(wxT("Size"));
942 pgman
->SetPropertyValueUnspecified(wxT("Position"));
943 pgman
->SetPropertyValueUnspecified(wxT("MultiChoiceProperty"));
945 pgman
->SetPropertyValueUnspecified(wxT("DateProperty"));
950 RT_START_TEST(Attributes
)
952 wxPGProperty
* prop
= pgman
->GetProperty(wxT("StringProperty"));
953 prop
->SetAttribute(wxT("Dummy Attribute"), (long)15);
955 if ( prop
->GetAttribute(wxT("Dummy Attribute")).GetLong() != 15 )
958 prop
->SetAttribute(wxT("Dummy Attribute"), wxVariant());
960 if ( !prop
->GetAttribute(wxT("Dummy Attribute")).IsNull() )
965 wxPropertyGridPage
* page1
;
966 wxPropertyGridPage
* page2
;
967 wxPropertyGridPage
* page3
;
968 wxVariant pg1_values
;
969 wxVariant pg2_values
;
970 wxVariant pg3_values
;
973 RT_START_TEST(GetPropertyValues
)
975 page1
= pgman
->GetPage(0);
976 pg1_values
= page1
->GetPropertyValues(wxT("Page1"),NULL
,wxPG_KEEP_STRUCTURE
);
977 page2
= pgman
->GetPage(1);
978 pg2_values
= page2
->GetPropertyValues(wxT("Page2"),NULL
,wxPG_KEEP_STRUCTURE
);
979 page3
= pgman
->GetPage(2);
980 pg3_values
= page3
->GetPropertyValues(wxT("Page3"),NULL
,wxPG_KEEP_STRUCTURE
);
984 RT_START_TEST(SetPropertyValues
)
986 page1
->SetPropertyValues(pg3_values
);
987 page2
->SetPropertyValues(pg1_values
);
988 page3
->SetPropertyValues(pg2_values
);
992 if ( !(pgman
->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES
) )
994 RT_START_TEST(Collapse_and_GetFirstCategory_and_GetNextCategory
)
996 for ( i
=0; i
<3; i
++ )
998 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
1000 wxPropertyGridIterator it
;
1002 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
1006 wxPGProperty
* p
= *it
;
1008 if ( !page
->IsPropertyCategory(p
) )
1011 page
->Collapse( p
);
1013 t
.Printf(wxT("Collapsing: %s\n"),page
->GetPropertyLabel(p
).c_str());
1020 RT_START_TEST(Save_And_RestoreEditableState
)
1022 for ( i
=0; i
<3; i
++ )
1024 pgman
->SelectPage(i
);
1026 wxString stringState
= pgman
->SaveEditableState();
1027 bool res
= pgman
->RestoreEditableState(stringState
);
1033 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
1035 RT_START_TEST(Expand_and_GetFirstCategory_and_GetNextCategory
)
1037 for ( i
=0; i
<3; i
++ )
1039 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
1041 wxPropertyGridIterator it
;
1043 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
1047 wxPGProperty
* p
= *it
;
1049 if ( !page
->IsPropertyCategory(p
) )
1054 t
.Printf(wxT("Expand: %s\n"),page
->GetPropertyLabel(p
).c_str());
1061 RT_START_TEST(Choice_Manipulation
)
1063 wxPGProperty
* enumProp
= pgman
->GetProperty(wxT("EnumProperty"));
1065 pgman
->SelectPage(2);
1066 pgman
->SelectProperty(enumProp
);
1067 wxASSERT(pgman
->GetGrid()->GetSelection() == enumProp
);
1069 const wxPGChoices
& choices
= enumProp
->GetChoices();
1070 int ind
= enumProp
->InsertChoice(wxT("New Choice"), choices
.GetCount()/2);
1071 enumProp
->DeleteChoice(ind
);
1073 // Recreate the original grid
1074 CreateGrid( -1, -1 );
1075 pgman
= m_pPropGridManager
;
1078 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
1080 RT_START_TEST(RandomCollapse
)
1082 // Select the most error prone page as visible.
1083 pgman
->SelectPage(1);
1085 for ( i
=0; i
<3; i
++ )
1089 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
1091 wxPropertyGridIterator it
;
1093 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
1097 arr
.Add((void*)*it
);
1100 if ( arr
.GetCount() )
1104 pgman
->Collapse( (wxPGProperty
*)arr
.Item(0) );
1106 for ( n
=arr
.GetCount()-1; n
>0; n
-- )
1108 pgman
->Collapse( (wxPGProperty
*)arr
.Item(n
) );
1116 RT_START_TEST(EnsureVisible
)
1117 pgman
->EnsureVisible(wxT("Cell Colour"));
1121 RT_START_TEST(SetPropertyBackgroundColour
)
1123 evt
.SetInt(1); // IsChecked() will return TRUE.
1124 evt
.SetId(ID_COLOURSCHEME4
);
1126 OnColourScheme(evt
);
1130 // Test ClearPropertyValue
1131 RT_START_TEST(ClearPropertyValue
)
1133 for ( i
=0; i
<3; i
++ )
1135 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
1137 // Iterate over all properties.
1138 wxPropertyGridIterator it
;
1140 for ( it
= page
->GetIterator();
1144 wxLogDebug((*it
)->GetLabel());
1145 pgman
->ClearPropertyValue( *it
);
1152 RT_START_TEST(ManagerClear
)
1155 if ( pgman
->GetPageCount() )
1158 // Recreate the original grid
1159 CreateGrid( -1, -1 );
1160 pgman
= m_pPropGridManager
;
1165 // TODO: This test fails.
1166 RT_START_TEST(SetSplitterPosition)
1170 const int trySplitterPos = 50;
1172 int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
1173 pgman = m_pPropGridManager =
1174 new wxPropertyGridManager(m_panel, wxID_ANY,
1180 pgman->SetSplitterPosition(trySplitterPos);
1182 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1183 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1185 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
1188 wxSize sz = GetSize();
1193 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1194 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1198 // Recreate the original grid
1199 CreateGrid( -1, -1 );
1200 pgman = m_pPropGridManager;
1205 RT_START_TEST(HideProperty
)
1207 wxPropertyGridPage
* page
= pgman
->GetPage(0);
1211 wxArrayPGProperty arr1
;
1213 arr1
= GetPropertiesInRandomOrder(page
);
1217 for ( i
=0; i
<arr1
.size(); i
++ )
1219 wxPGProperty
* p
= arr1
[i
];
1220 page
->HideProperty(p
, true);
1222 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1223 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1231 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1233 for ( i
=0; i
<arr2
.size(); i
++ )
1235 wxPGProperty
* p
= arr2
[i
];
1236 page
->HideProperty(p
, false);
1238 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1239 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1246 // Let's do some more, for better consistency
1247 arr1
= GetPropertiesInRandomOrder(page
);
1251 for ( i
=0; i
<arr1
.size(); i
++ )
1253 wxPGProperty
* p
= arr1
[i
];
1254 page
->HideProperty(p
, true);
1256 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1257 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1265 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1267 for ( i
=0; i
<arr2
.size(); i
++ )
1269 wxPGProperty
* p
= arr2
[i
];
1270 page
->HideProperty(p
, false);
1272 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1273 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1280 // Ok, this time only hide half of them
1281 arr1
= GetPropertiesInRandomOrder(page
);
1282 arr1
.resize(arr1
.size()/2);
1286 for ( i
=0; i
<arr1
.size(); i
++ )
1288 wxPGProperty
* p
= arr1
[i
];
1289 page
->HideProperty(p
, true);
1291 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1292 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1300 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1302 for ( i
=0; i
<arr2
.size(); i
++ )
1304 wxPGProperty
* p
= arr2
[i
];
1305 page
->HideProperty(p
, false);
1307 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1308 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1314 // Recreate the original grid
1315 CreateGrid( -1, -1 );
1316 pgman
= m_pPropGridManager
;
1321 RT_START_TEST(MultipleColumns
)
1323 // Test with multiple columns
1324 // FIXME: Does not display changes.
1325 for ( i
=3; i
<12; i
+=2 )
1327 RT_MSG(wxString::Format(wxT("%i columns"),i
));
1328 CreateGrid( -1, -1 );
1329 pgman
= m_pPropGridManager
;
1330 pgman
->SetColumnCount(i
);
1339 RT_START_TEST(WindowStyles
)
1341 // Recreate grid with all possible (single) flags
1342 wxASSERT(wxPG_AUTO_SORT
== 0x000000010);
1344 for ( i
=4; i
<16; i
++ )
1347 RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag
));
1348 CreateGrid( flag
, -1 );
1349 pgman
= m_pPropGridManager
;
1354 wxASSERT(wxPG_EX_INIT_NOCAT
== 0x00001000);
1356 for ( i
=12; i
<24; i
++ )
1359 RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag
));
1360 CreateGrid( -1, flag
);
1361 pgman
= m_pPropGridManager
;
1366 // Recreate the original grid
1367 CreateGrid( -1, -1 );
1368 pgman
= m_pPropGridManager
;
1375 if ( failures
|| errorMessages
.size() )
1383 s
= wxString::Format(wxT("%i tests failed!!!"), failures
);
1386 s
= wxString::Format(wxT("All tests were succesfull, but there were %i warnings!"), wxPGGlobalVars
->m_warnings
);
1389 for ( i
=0; i
<errorMessages
.size(); i
++ )
1390 RT_MSG(errorMessages
[i
])
1391 wxMessageBox(s
, wxT("Some Tests Failed"));
1395 RT_MSG(wxT("All tests succesfull"))
1402 pgman
->SelectPage(0);
1404 // Test may screw up the toolbar, so we need to refresh it.
1405 wxToolBar
* toolBar
= pgman
->GetToolBar();
1412 // -----------------------------------------------------------------------