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 // Declare custom test properties
32 // -----------------------------------------------------------------------
34 WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY(wxTestCustomFlagsProperty
)
36 WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY(wxTestCustomEnumProperty
)
39 // -----------------------------------------------------------------------
40 // wxTestCustomFlagsProperty
41 // -----------------------------------------------------------------------
44 // Constant definitions required by wxFlagsProperty examples.
47 static const wxChar
* _fs_framestyle_labels
[] = {
54 wxT("wxRESIZE_BORDER"),
55 wxT("wxFRAME_TOOL_WINDOW"),
56 wxT("wxFRAME_NO_TASKBAR"),
57 wxT("wxFRAME_FLOAT_ON_PARENT"),
58 wxT("wxFRAME_SHAPED"),
62 static const long _fs_framestyle_values
[] = {
72 wxFRAME_FLOAT_ON_PARENT
,
77 WX_PG_IMPLEMENT_CUSTOM_FLAGS_PROPERTY(wxTestCustomFlagsProperty
,
78 _fs_framestyle_labels
,
79 _fs_framestyle_values
,
80 wxDEFAULT_FRAME_STYLE
)
82 WX_PG_IMPLEMENT_CUSTOM_ENUM_PROPERTY(wxTestCustomEnumProperty
,
83 _fs_framestyle_labels
,
84 _fs_framestyle_values
,
88 // Colour labels. Last (before NULL, if any) must be Custom.
89 static const wxChar
* mycolprop_labels
[] = {
97 // Relevant colour values as unsigned longs.
98 static unsigned long mycolprop_colours
[] = {
100 wxPG_COLOUR(0,0,255),
101 wxPG_COLOUR(166,124,81),
105 // Implement property class. Third argument is optional values array,
106 // but in this example we are only interested in creating a shortcut
107 // for user to access the colour values. Last arg is itemcount, but
108 // it will be deprecated in the future.
109 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(wxMyColourProperty
)
110 WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(wxMyColourProperty
,
116 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY(wxMyColour2Property
)
117 WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(wxMyColour2Property
,
124 // Just testing the macros
125 WX_PG_DECLARE_STRING_PROPERTY(wxTestStringProperty
)
126 WX_PG_IMPLEMENT_STRING_PROPERTY(wxTestStringProperty
,wxPG_NO_ESCAPE
)
127 bool wxTestStringProperty::OnButtonClick( wxPropertyGrid
*,
130 ::wxMessageBox(wxT("Button Clicked"));
134 WX_PG_DECLARE_STRING_PROPERTY(wxTextStringPropertyWithValidator
)
135 WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(wxTextStringPropertyWithValidator
,
138 bool wxTextStringPropertyWithValidator::OnButtonClick( wxPropertyGrid
* WXUNUSED(propgrid
),
139 wxString
& WXUNUSED(value
) )
141 ::wxMessageBox(wxT("Button Clicked"));
145 wxValidator
* wxTextStringPropertyWithValidator::DoGetValidator() const
148 WX_PG_DOGETVALIDATOR_ENTRY()
149 wxTextValidator
* validator
= new
150 wxTextValidator(wxFILTER_INCLUDE_CHAR_LIST
);
151 wxArrayString oValid
;
152 oValid
.Add(wxT("0"));
153 oValid
.Add(wxT("1"));
154 oValid
.Add(wxT("2"));
155 oValid
.Add(wxT("3"));
156 oValid
.Add(wxT("4"));
157 oValid
.Add(wxT("5"));
158 oValid
.Add(wxT("6"));
159 oValid
.Add(wxT("7"));
160 oValid
.Add(wxT("8"));
161 oValid
.Add(wxT("9"));
162 oValid
.Add(wxT("$"));
163 validator
->SetIncludes(oValid
);
164 WX_PG_DOGETVALIDATOR_EXIT(validator
)
170 // -----------------------------------------------------------------------
173 // Test customizing wxColourProperty via subclassing
175 // * Includes custom colour entry.
176 // * Includes extra custom entry.
178 class MyColourProperty3
: public wxColourProperty
181 MyColourProperty3( const wxString
& label
= wxPG_LABEL
,
182 const wxString
& name
= wxPG_LABEL
,
183 const wxColour
& value
= *wxWHITE
)
184 : wxColourProperty(label
, name
, value
)
187 colours
.Add(wxT("White"));
188 colours
.Add(wxT("Black"));
189 colours
.Add(wxT("Red"));
190 colours
.Add(wxT("Green"));
191 colours
.Add(wxT("Blue"));
192 colours
.Add(wxT("Custom"));
193 colours
.Add(wxT("None"));
201 virtual ~MyColourProperty3()
205 virtual wxColour
GetColour( int index
) const
209 case 0: return *wxWHITE
;
210 case 1: return *wxBLACK
;
211 case 2: return *wxRED
;
212 case 3: return *wxGREEN
;
213 case 4: return *wxBLUE
;
215 // Return current colour for the custom entry
217 if ( GetIndex() == GetCustomColourIndex() )
219 if ( m_value
.IsNull() )
229 virtual wxString
ColourToString( const wxColour
& col
, int index
) const
231 if ( index
== (int)(m_choices
.GetCount()-1) )
234 return wxColourProperty::ColourToString(col
, index
);
237 virtual int GetCustomColourIndex() const
239 return m_choices
.GetCount()-2;
244 void FormMain::AddTestProperties( wxPropertyGridPage
* pg
)
246 pg
->Append( new wxTestCustomFlagsProperty(wxT("Custom FlagsProperty"), wxPG_LABEL
) );
247 pg
->SetPropertyEditor( wxT("Custom FlagsProperty"), wxPG_EDITOR(TextCtrlAndButton
) );
249 pg
->Append( new wxTestCustomEnumProperty(wxT("Custom EnumProperty"), wxPG_LABEL
) );
251 pg
->Append( new wxMyColourProperty(wxT("CustomColourProperty1")) );
253 pg
->SetPropertyHelpString(wxT("CustomColourProperty1"),
254 wxT("This is a wxMyColourProperty from the sample app. ")
255 wxT("It is built with WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR macro ")
256 wxT("and has wxColour as its data type"));
258 pg
->Append( new wxMyColour2Property(wxT("CustomColourProperty2")) );
260 pg
->SetPropertyHelpString(wxT("CustomColourProperty2"),
261 wxT("This is a wxMyColour2Property from the sample app. ")
262 wxT("It is built with WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY macro ")
263 wxT("and has wxColourPropertyValue as its data type"));
265 pg
->Append( new MyColourProperty3(wxT("CustomColourProperty3"), wxPG_LABEL
, *wxGREEN
) );
266 pg
->GetProperty(wxT("CustomColourProperty3"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
267 pg
->SetPropertyEditor( wxT("CustomColourProperty3"), wxPG_EDITOR(ComboBox
) );
269 pg
->SetPropertyHelpString(wxT("CustomColourProperty3"),
270 wxT("This is a MyColourProperty3 from the sample app. ")
271 wxT("It is built by subclassing wxColourProperty."));
273 pg
->Append( new wxTextStringPropertyWithValidator(wxT("TestProp1"), wxPG_LABEL
) );
276 // -----------------------------------------------------------------------
278 void FormMain::OnDumpList( wxCommandEvent
& WXUNUSED(event
) )
280 wxVariant values
= m_pPropGridManager
->GetPropertyValues(wxT("list"), wxNullProperty
, wxPG_INC_ATTRIBUTES
);
281 wxString text
= wxT("This only tests that wxVariant related routines do not crash.");
284 wxDialog
* dlg
= new wxDialog(this,-1,wxT("wxVariant Test"),
285 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
288 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
290 wxVariant
& v
= values
[i
];
292 wxString strValue
= v
.GetString();
294 #if wxCHECK_VERSION(2,8,0)
295 if ( v
.GetName().EndsWith(wxT("@attr")) )
297 if ( v
.GetName().Right(5) == wxT("@attr") )
300 text
+= wxString::Format(wxT("Attributes:\n"));
303 for ( n
= 0; n
< (unsigned int)v
.GetCount(); n
++ )
307 t
.Printf(wxT(" atribute %i: name=\"%s\" (type=\"%s\" value=\"%s\")\n"),(int)n
,
308 a
.GetName().c_str(),a
.GetType().c_str(),a
.GetString().c_str());
314 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\" value=\"%s\"\n"),(int)i
,
315 v
.GetName().c_str(),v
.GetType().c_str(),strValue
.c_str());
320 // multi-line text editor dialog
321 const int spacing
= 8;
322 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
323 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
324 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,text
,
325 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
326 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
327 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
328 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
329 const int butSzFlags
=
330 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
331 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
332 0, butSzFlags
, spacing
);
333 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
335 dlg
->SetSizer( topsizer
);
336 topsizer
->SetSizeHints( dlg
);
338 dlg
->SetSize(400,300);
343 // -----------------------------------------------------------------------
349 TestRunner( const wxString
& name
, wxPropertyGridManager
* man
, wxTextCtrl
* ed
, wxArrayString
* errorMessages
)
354 m_errorMessages
= errorMessages
;
356 m_preWarnings
= wxPGGlobalVars
->m_warnings
;
359 if ( name
!= wxT("none") )
366 int warningsOccurred
= wxPGGlobalVars
->m_warnings
- m_preWarnings
;
367 if ( warningsOccurred
)
369 wxString s
= wxString::Format(wxT("%i warnings occurred during test '%s'"), warningsOccurred
, m_name
.c_str());
370 m_errorMessages
->push_back(s
);
376 void Msg( const wxString
& text
)
380 m_ed
->AppendText(text
);
381 m_ed
->AppendText(wxT("\n"));
387 wxPropertyGridManager
* m_man
;
389 wxArrayString
* m_errorMessages
;
397 #define RT_START_TEST(TESTNAME) \
398 TestRunner tr(wxT(#TESTNAME), pgman, ed, &errorMessages);
403 #define RT_FAILURE() \
405 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
406 errorMessages.push_back(s1); \
411 #define RT_FAILURE_MSG(MSG) \
413 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
414 errorMessages.push_back(s1); \
416 wxString s2 = wxString::Format(wxT("Message: %s"),MSG); \
417 errorMessages.push_back(s2); \
422 #define RT_VALIDATE_VIRTUAL_HEIGHT(PROPS, EXTRATEXT) \
424 unsigned int h1_ = PROPS->GetVirtualHeight(); \
425 unsigned int h2_ = PROPS->GetActualVirtualHeight(); \
428 wxString s_ = wxString::Format(wxT("VirtualHeight = %i, should be %i (%s)"), h1_, h2_, EXTRATEXT.c_str()); \
429 RT_FAILURE_MSG(s_.c_str()); \
439 int gpiro_cmpfunc(const void* a
, const void* b
)
441 const wxPGProperty
* p1
= (const wxPGProperty
*) a
;
442 const wxPGProperty
* p2
= (const wxPGProperty
*) b
;
443 return (int) (((size_t)p1
->GetClientData()) - ((size_t)p2
->GetClientData()));
446 wxArrayPGProperty
GetPropertiesInRandomOrder( wxPropertyGridInterface
* props
, int iterationFlags
= wxPG_ITERATE_ALL
)
448 wxArrayPGProperty arr
;
450 wxPropertyGridIterator it
;
452 for ( it
= props
->GetIterator(iterationFlags
);
456 wxPGProperty
* p
= *it
;
457 size_t randomNumber
= rand();
458 p
->SetClientData(reinterpret_cast<void*>(randomNumber
));
462 wxPGProperty
** firstEntry
= &arr
[0];
463 qsort(firstEntry
, arr
.size(), sizeof(wxPGProperty
*), gpiro_cmpfunc
);
468 static void PropertiesToNames( wxPropertyGridInterface
* WXUNUSED(iface
),
469 wxArrayString
* names
,
470 const wxArrayPGProperty
& properties
)
473 for ( i
=0; i
<properties
.size(); i
++ )
474 names
->Add( properties
[i
]->GetName() );
477 static void NamesToProperties( wxPropertyGridInterface
* iface
,
478 wxArrayPGProperty
* properties
,
479 const wxArrayString
& names
)
482 for ( i
=0; i
<names
.size(); i
++ )
484 wxPGProperty
* p
= iface
->GetPropertyByName(names
[i
]);
486 properties
->push_back(p
);
490 bool FormMain::RunTests( bool fullTest
, bool interactive
)
494 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
499 pgman
->ClearSelection();
502 bool _failed_
= false;
503 wxArrayString errorMessages
;
504 wxDialog
* dlg
= NULL
;
506 dlg
= new wxDialog(this,-1,wxT("wxPropertyGrid Regression Tests"),
507 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
509 // multi-line text editor dialog
510 const int spacing
= 8;
511 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
512 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
513 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,wxEmptyString
,
514 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
515 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
516 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
517 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
518 const int butSzFlags
=
519 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
520 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
521 0, butSzFlags
, spacing
);
522 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
524 dlg
->SetSizer( topsizer
);
525 topsizer
->SetSizeHints( dlg
);
527 dlg
->SetSize(400,300);
528 dlg
->Move(wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)-dlg
->GetSize().x
,
529 wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)-dlg
->GetSize().y
);
534 // Basic iterator tests
535 RT_START_TEST(GetIterator
)
541 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
545 wxPGProperty
* p
= it
.GetProperty();
546 if ( p
->IsCategory() )
547 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a category (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
548 else if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
549 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
553 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES) -> %i entries"), count
));
556 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_CATEGORIES
);
560 wxPGProperty
* p
= it
.GetProperty();
561 if ( !p
->IsCategory() )
562 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is not a category (only category was expected)"),p
->GetLabel().c_str()).c_str())
566 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
569 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
|wxPG_ITERATE_CATEGORIES
);
573 wxPGProperty
* p
= it
.GetProperty();
574 if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
575 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property or category expected)"),p
->GetLabel().c_str()).c_str())
579 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
582 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_VISIBLE
);
586 wxPGProperty
* p
= it
.GetProperty();
587 if ( (p
->GetParent() != p
->GetParentState()->DoGetRoot() && !p
->GetParent()->IsExpanded()) )
588 RT_FAILURE_MSG(wxString::Format(wxT("'%s' had collapsed parent (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
589 else if ( p
->HasFlag(wxPG_PROP_HIDDEN
) )
590 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was hidden (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
594 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_VISIBLE) -> %i entries"), count
));
599 // Test that setting focus to properties does not crash things
600 RT_START_TEST(SelectProperty
)
602 wxPropertyGridIterator it
;
605 for ( ind
=0; ind
<pgman
->GetPageCount(); ind
++ )
607 wxPropertyGridPage
* page
= pgman
->GetPage(ind
);
608 pgman
->SelectPage(page
);
610 for ( it
= page
->GetIterator(wxPG_ITERATE_VISIBLE
);
614 wxPGProperty
* p
= *it
;
615 RT_MSG(p
->GetLabel());
616 pgman
->GetGrid()->SelectProperty(p
, true);
624 RT_START_TEST(GetPropertiesWithFlag
)
627 // Get list of expanded properties
628 wxArrayPGProperty array
= pgman
->GetExpandedProperties();
630 // Make sure list only has items with children
631 for ( i
=0; i
<array
.size(); i
++ )
633 wxPGProperty
* p
= array
[i
];
634 if ( !p
->IsKindOf(CLASSINFO(wxPGProperty
)) )
635 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was returned by GetExpandedProperties(), but was not a parent"),p
->GetName().c_str()).c_str());
639 PropertiesToNames( pgman
, &names
, array
);
642 // ... and then collapse them
643 wxArrayPGProperty array2
;
644 NamesToProperties( pgman
, &array2
, names
);
646 for ( i
=0; i
<array2
.size(); i
++ )
648 wxPGProperty
* p
= array
[i
];
649 p
->SetExpanded(false);
652 // Make sure everything is collapsed
655 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_ALL
);
659 wxPGProperty
* p
= it
.GetProperty();
660 if ( p
->IsExpanded() )
661 RT_FAILURE_MSG(wxString::Format(wxT("'%s.%s' was expanded"),p
->GetParent()->GetName().c_str(),p
->GetName().c_str()).c_str());
669 // Delete everything in reverse order
670 RT_START_TEST(DeleteProperty
)
673 wxArrayPGProperty array
;
675 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_ALL
&~(wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
)));
678 array
.push_back(it
.GetProperty());
680 wxArrayPGProperty::reverse_iterator it2
;
682 for ( it2
= array
.rbegin(); it2
!= array
.rend(); it2
++ )
684 wxPGProperty
* p
= (wxPGProperty
*)*it2
;
685 RT_MSG(wxString::Format(wxT("Deleting '%s' ('%s')"),p
->GetLabel().c_str(),p
->GetName().c_str()));
686 pgman
->DeleteProperty(p
);
690 CreateGrid( -1, -1 );
691 pgman
= m_pPropGridManager
;
696 // Clear property value
697 RT_START_TEST(ClearPropertyValue
)
701 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
705 RT_MSG(wxString::Format(wxT("Clearing value of '%s'"),it
.GetProperty()->GetLabel().c_str()));
706 pgman
->ClearPropertyValue(it
.GetProperty());
710 CreateGrid( -1, -1 );
711 pgman
= m_pPropGridManager
;
715 RT_START_TEST(GetPropertyValues
)
717 for ( i
=0; i
<3; i
++ )
721 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
723 wxVariant values
= page
->GetPropertyValues();
726 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
728 wxVariant
& v
= values
[i
];
730 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\"\n"),(int)i
,
731 v
.GetName().c_str(),v
.GetType().c_str());
735 ed
->AppendText(text
);
740 RT_START_TEST(SetPropertyValue_and_GetPropertyValue
)
742 // In this section, mixed up usage of wxT("propname") and "propname"
743 // in wxPropertyGridInterface functions is intentional.
744 // Purpose is to test wxPGPropArgCls ctors.
746 //pg = (wxPropertyGrid*) NULL;
748 wxArrayString test_arrstr_1
;
749 test_arrstr_1
.Add(wxT("Apple"));
750 test_arrstr_1
.Add(wxT("Orange"));
751 test_arrstr_1
.Add(wxT("Lemon"));
753 wxArrayString test_arrstr_2
;
754 test_arrstr_2
.Add(wxT("Potato"));
755 test_arrstr_2
.Add(wxT("Cabbage"));
756 test_arrstr_2
.Add(wxT("Cucumber"));
758 wxArrayInt test_arrint_1
;
759 test_arrint_1
.Add(1);
760 test_arrint_1
.Add(2);
761 test_arrint_1
.Add(3);
763 wxArrayInt test_arrint_2
;
764 test_arrint_2
.Add(0);
765 test_arrint_2
.Add(1);
766 test_arrint_2
.Add(4);
769 wxDateTime dt1
= wxDateTime::Now();
770 dt1
.SetYear(dt1
.GetYear()-1);
772 wxDateTime dt2
= wxDateTime::Now();
773 dt2
.SetYear(dt2
.GetYear()-10);
776 #define FLAG_TEST_SET1 (wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER)
777 #define FLAG_TEST_SET2 (wxSTAY_ON_TOP|wxCAPTION|wxICONIZE|wxSYSTEM_MENU)
779 pgman
->SetPropertyValue(wxT("StringProperty"),wxT("Text1"));
780 pgman
->SetPropertyValue(wxT("IntProperty"),1024);
781 pgman
->SetPropertyValue(wxT("FloatProperty"),1024.0000000001);
782 pgman
->SetPropertyValue(wxT("BoolProperty"),FALSE
);
783 pgman
->SetPropertyValue(wxT("EnumProperty"),120);
784 pgman
->SetPropertyValue(wxT("Custom FlagsProperty"),FLAG_TEST_SET1
);
785 pgman
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_1
);
787 pgman
->SetPropertyValue(wxT("ColourProperty"),emptyCol
);
788 pgman
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxBLACK
);
789 pgman
->SetPropertyValue(wxT("Size"),wxSize(150,150));
790 pgman
->SetPropertyValue(wxT("Position"),wxPoint(150,150));
791 pgman
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_1
);
793 pgman
->SetPropertyValue(wxT("DateProperty"),dt1
);
796 pgman
->SelectPage(2);
797 pg
= pgman
->GetGrid();
799 if ( pg
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text1") )
801 if ( pg
->GetPropertyValueAsInt(wxT("IntProperty")) != 1024 )
803 if ( pg
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 1024.0000000001 )
805 if ( pg
->GetPropertyValueAsBool(wxT("BoolProperty")) != FALSE
)
807 if ( pg
->GetPropertyValueAsLong(wxT("EnumProperty")) != 120 )
809 if ( pg
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_1
)
811 if ( pg
->GetPropertyValueAsLong(wxT("Custom FlagsProperty")) != FLAG_TEST_SET1
)
814 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
815 if ( col
!= *wxBLACK
)
817 if ( pg
->GetPropertyValueAsSize(wxT("Size")) != wxSize(150,150) )
819 if ( pg
->GetPropertyValueAsPoint(wxT("Position")) != wxPoint(150,150) )
821 if ( !(pg
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_1
) )
824 if ( !(pg
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt1
) )
828 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(10000000000));
829 if ( pg
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(10000000000) )
832 pg
->SetPropertyValue(wxT("StringProperty"),wxT("Text2"));
833 pg
->SetPropertyValue(wxT("IntProperty"),512);
834 pg
->SetPropertyValue(wxT("FloatProperty"),512.0);
835 pg
->SetPropertyValue(wxT("BoolProperty"),TRUE
);
836 pg
->SetPropertyValue(wxT("EnumProperty"),80);
837 pg
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_2
);
838 pg
->SetPropertyValue(wxT("Custom FlagsProperty"),FLAG_TEST_SET2
);
839 pg
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxWHITE
);
840 pg
->SetPropertyValue(wxT("Size"),wxSize(300,300));
841 pg
->SetPropertyValue(wxT("Position"),wxPoint(300,300));
842 pg
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_2
);
844 pg
->SetPropertyValue(wxT("DateProperty"),dt2
);
847 //pg = (wxPropertyGrid*) NULL;
849 pgman
->SelectPage(0);
851 if ( pgman
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text2") )
853 if ( pgman
->GetPropertyValueAsInt(wxT("IntProperty")) != 512 )
855 if ( pgman
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 512.0 )
857 if ( pgman
->GetPropertyValueAsBool(wxT("BoolProperty")) != TRUE
)
859 if ( pgman
->GetPropertyValueAsLong(wxT("EnumProperty")) != 80 )
861 if ( pgman
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_2
)
863 if ( pgman
->GetPropertyValueAsLong(wxT("Custom FlagsProperty")) != FLAG_TEST_SET2
)
865 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
866 if ( col
!= *wxWHITE
)
868 if ( pgman
->GetPropertyValueAsSize(wxT("Size")) != wxSize(300,300) )
870 if ( pgman
->GetPropertyValueAsPoint(wxT("Position")) != wxPoint(300,300) )
872 if ( !(pgman
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_2
) )
875 if ( !(pgman
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt2
) )
879 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000));
880 if ( pgman
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) )
883 // Make sure children of composite parent get updated as well
884 // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000"
887 // This updates children as well
888 wxString nvs
= "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002";
889 pgman
->SetPropertyValue("Car", nvs
);
891 if ( pgman
->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
893 wxLogDebug("Did not match: Car.Model=%s", pgman
->GetPropertyValueAsString("Car.Model").c_str());
897 if ( pgman
->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
899 wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman
->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
903 if ( pgman
->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
905 wxLogDebug("Did not match: Car.Price ($)=%s", pgman
->GetPropertyValueAsString("Car.Price ($)").c_str());
911 RT_START_TEST(SetPropertyValueUnspecified
)
913 // Null variant setter tests
914 pgman
->SetPropertyValueUnspecified(wxT("StringProperty"));
915 pgman
->SetPropertyValueUnspecified(wxT("IntProperty"));
916 pgman
->SetPropertyValueUnspecified(wxT("FloatProperty"));
917 pgman
->SetPropertyValueUnspecified(wxT("BoolProperty"));
918 pgman
->SetPropertyValueUnspecified(wxT("EnumProperty"));
919 pgman
->SetPropertyValueUnspecified(wxT("ArrayStringProperty"));
920 pgman
->SetPropertyValueUnspecified(wxT("Custom FlagsProperty"));
921 pgman
->SetPropertyValueUnspecified(wxT("ColourProperty"));
922 pgman
->SetPropertyValueUnspecified(wxT("Size"));
923 pgman
->SetPropertyValueUnspecified(wxT("Position"));
924 pgman
->SetPropertyValueUnspecified(wxT("MultiChoiceProperty"));
926 pgman
->SetPropertyValueUnspecified(wxT("DateProperty"));
931 wxPropertyGridPage
* page1
;
932 wxPropertyGridPage
* page2
;
933 wxPropertyGridPage
* page3
;
934 wxVariant pg1_values
;
935 wxVariant pg2_values
;
936 wxVariant pg3_values
;
939 RT_START_TEST(GetPropertyValues
)
941 page1
= pgman
->GetPage(0);
942 pg1_values
= page1
->GetPropertyValues(wxT("Page1"),NULL
,wxPG_KEEP_STRUCTURE
);
943 page2
= pgman
->GetPage(1);
944 pg2_values
= page2
->GetPropertyValues(wxT("Page2"),NULL
,wxPG_KEEP_STRUCTURE
);
945 page3
= pgman
->GetPage(2);
946 pg3_values
= page3
->GetPropertyValues(wxT("Page3"),NULL
,wxPG_KEEP_STRUCTURE
);
950 RT_START_TEST(SetPropertyValues
)
952 page1
->SetPropertyValues(pg3_values
);
953 page2
->SetPropertyValues(pg1_values
);
954 page3
->SetPropertyValues(pg2_values
);
958 if ( !(pgman
->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES
) )
960 RT_START_TEST(Collapse_and_GetFirstCategory_and_GetNextCategory
)
962 for ( i
=0; i
<3; i
++ )
964 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
966 wxPropertyGridIterator it
;
968 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
972 wxPGProperty
* p
= *it
;
974 if ( !page
->IsPropertyCategory(p
) )
979 t
.Printf(wxT("Collapsing: %s\n"),page
->GetPropertyLabel(p
).c_str());
986 RT_START_TEST(Save_And_RestoreEditableState
)
988 for ( i
=0; i
<3; i
++ )
990 pgman
->SelectPage(i
);
992 wxString stringState
= pgman
->SaveEditableState();
993 bool res
= pgman
->RestoreEditableState(stringState
);
999 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
1001 RT_START_TEST(Expand_and_GetFirstCategory_and_GetNextCategory
)
1003 for ( i
=0; i
<3; i
++ )
1005 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
1007 wxPropertyGridIterator it
;
1009 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
1013 wxPGProperty
* p
= *it
;
1015 if ( !page
->IsPropertyCategory(p
) )
1020 t
.Printf(wxT("Expand: %s\n"),page
->GetPropertyLabel(p
).c_str());
1026 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
1028 RT_START_TEST(RandomCollapse
)
1030 // Select the most error prone page as visible.
1031 pgman
->SelectPage(1);
1033 for ( i
=0; i
<3; i
++ )
1037 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
1039 wxPropertyGridIterator it
;
1041 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
1045 arr
.Add((void*)*it
);
1048 if ( arr
.GetCount() )
1052 pgman
->Collapse( (wxPGProperty
*)arr
.Item(0) );
1054 for ( n
=arr
.GetCount()-1; n
>0; n
-- )
1056 pgman
->Collapse( (wxPGProperty
*)arr
.Item(n
) );
1064 RT_START_TEST(EnsureVisible
)
1065 pgman
->EnsureVisible(wxT("Cell Colour"));
1069 RT_START_TEST(SetPropertyBackgroundColour
)
1071 evt
.SetInt(1); // IsChecked() will return TRUE.
1072 evt
.SetId(ID_COLOURSCHEME4
);
1074 OnColourScheme(evt
);
1078 // Test ClearPropertyValue
1079 RT_START_TEST(ClearPropertyValue
)
1081 for ( i
=0; i
<3; i
++ )
1083 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
1085 // Iterate over all properties.
1086 wxPropertyGridIterator it
;
1088 for ( it
= page
->GetIterator();
1092 wxLogDebug((*it
)->GetLabel());
1093 pgman
->ClearPropertyValue( *it
);
1100 RT_START_TEST(ManagerClear
)
1103 if ( pgman
->GetPageCount() )
1106 // Recreate the original grid
1107 CreateGrid( -1, -1 );
1108 pgman
= m_pPropGridManager
;
1113 // TODO: This test fails.
1114 RT_START_TEST(SetSplitterPosition)
1118 const int trySplitterPos = 50;
1120 int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
1121 pgman = m_pPropGridManager =
1122 new wxPropertyGridManager(m_panel, wxID_ANY,
1128 pgman->SetSplitterPosition(trySplitterPos);
1130 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1131 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1133 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
1136 wxSize sz = GetSize();
1141 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1142 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1146 // Recreate the original grid
1147 CreateGrid( -1, -1 );
1148 pgman = m_pPropGridManager;
1153 RT_START_TEST(HideProperty
)
1155 wxPropertyGridPage
* page
= pgman
->GetPage(0);
1159 wxArrayPGProperty arr1
;
1161 arr1
= GetPropertiesInRandomOrder(page
);
1165 for ( i
=0; i
<arr1
.size(); i
++ )
1167 wxPGProperty
* p
= arr1
[i
];
1168 page
->HideProperty(p
, true);
1170 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1171 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1179 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1181 for ( i
=0; i
<arr2
.size(); i
++ )
1183 wxPGProperty
* p
= arr2
[i
];
1184 page
->HideProperty(p
, false);
1186 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1187 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1194 // Let's do some more, for better consistency
1195 arr1
= GetPropertiesInRandomOrder(page
);
1199 for ( i
=0; i
<arr1
.size(); i
++ )
1201 wxPGProperty
* p
= arr1
[i
];
1202 page
->HideProperty(p
, true);
1204 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1205 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1213 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1215 for ( i
=0; i
<arr2
.size(); i
++ )
1217 wxPGProperty
* p
= arr2
[i
];
1218 page
->HideProperty(p
, false);
1220 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1221 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1228 // Ok, this time only hide half of them
1229 arr1
= GetPropertiesInRandomOrder(page
);
1230 arr1
.resize(arr1
.size()/2);
1234 for ( i
=0; i
<arr1
.size(); i
++ )
1236 wxPGProperty
* p
= arr1
[i
];
1237 page
->HideProperty(p
, true);
1239 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1240 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1248 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1250 for ( i
=0; i
<arr2
.size(); i
++ )
1252 wxPGProperty
* p
= arr2
[i
];
1253 page
->HideProperty(p
, false);
1255 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1256 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1262 // Recreate the original grid
1263 CreateGrid( -1, -1 );
1264 pgman
= m_pPropGridManager
;
1269 RT_START_TEST(MultipleColumns
)
1271 // Test with multiple columns
1272 // FIXME: Does not display changes.
1273 for ( i
=3; i
<12; i
+=2 )
1275 RT_MSG(wxString::Format(wxT("%i columns"),i
));
1276 CreateGrid( -1, -1 );
1277 pgman
= m_pPropGridManager
;
1278 pgman
->SetColumnCount(i
);
1287 RT_START_TEST(WindowStyles
)
1289 // Recreate grid with all possible (single) flags
1290 wxASSERT(wxPG_AUTO_SORT
== 0x000000010);
1292 for ( i
=4; i
<16; i
++ )
1295 RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag
));
1296 CreateGrid( flag
, -1 );
1297 pgman
= m_pPropGridManager
;
1302 wxASSERT(wxPG_EX_INIT_NOCAT
== 0x00001000);
1304 for ( i
=12; i
<24; i
++ )
1307 RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag
));
1308 CreateGrid( -1, flag
);
1309 pgman
= m_pPropGridManager
;
1314 // Recreate the original grid
1315 CreateGrid( -1, -1 );
1316 pgman
= m_pPropGridManager
;
1323 if ( failures
|| errorMessages
.size() )
1331 s
= wxString::Format(wxT("%i tests failed!!!"), failures
);
1334 s
= wxString::Format(wxT("All tests were succesfull, but there were %i warnings!"), wxPGGlobalVars
->m_warnings
);
1337 for ( i
=0; i
<errorMessages
.size(); i
++ )
1338 RT_MSG(errorMessages
[i
])
1339 wxMessageBox(s
, wxT("Some Tests Failed"));
1343 RT_MSG(wxT("All tests succesfull"))
1350 pgman
->SelectPage(0);
1352 // Test may screw up the toolbar, so we need to refresh it.
1353 wxToolBar
* toolBar
= pgman
->GetToolBar();
1360 // -----------------------------------------------------------------------