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 // Test customizing wxColourProperty via subclassing
37 // * Includes custom colour entry.
38 // * Includes extra custom entry.
40 class MyColourProperty
: public wxColourProperty
43 MyColourProperty( const wxString
& label
= wxPG_LABEL
,
44 const wxString
& name
= wxPG_LABEL
,
45 const wxColour
& value
= *wxWHITE
)
46 : wxColourProperty(label
, name
, value
)
49 colours
.Add(wxT("White"));
50 colours
.Add(wxT("Black"));
51 colours
.Add(wxT("Red"));
52 colours
.Add(wxT("Green"));
53 colours
.Add(wxT("Blue"));
54 colours
.Add(wxT("Custom"));
55 colours
.Add(wxT("None"));
63 virtual ~MyColourProperty()
67 virtual wxColour
GetColour( int index
) const
71 case 0: return *wxWHITE
;
72 case 1: return *wxBLACK
;
73 case 2: return *wxRED
;
74 case 3: return *wxGREEN
;
75 case 4: return *wxBLUE
;
77 // Return current colour for the custom entry
79 if ( GetIndex() == GetCustomColourIndex() )
81 if ( m_value
.IsNull() )
91 virtual wxString
ColourToString( const wxColour
& col
, int index
) const
93 if ( index
== (int)(m_choices
.GetCount()-1) )
96 return wxColourProperty::ColourToString(col
, index
);
99 virtual int GetCustomColourIndex() const
101 return m_choices
.GetCount()-2;
106 void FormMain::AddTestProperties( wxPropertyGridPage
* pg
)
108 pg
->Append( new MyColourProperty(wxT("CustomColourProperty"), wxPG_LABEL
, *wxGREEN
) );
109 pg
->GetProperty(wxT("CustomColourProperty"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
110 pg
->SetPropertyEditor( wxT("CustomColourProperty"), wxPGEditor_ComboBox
);
112 pg
->SetPropertyHelpString(wxT("CustomColourProperty"),
113 wxT("This is a MyColourProperty from the sample app. ")
114 wxT("It is built by subclassing wxColourProperty."));
117 // -----------------------------------------------------------------------
119 void FormMain::OnDumpList( wxCommandEvent
& WXUNUSED(event
) )
121 wxVariant values
= m_pPropGridManager
->GetPropertyValues(wxT("list"), wxNullProperty
, wxPG_INC_ATTRIBUTES
);
122 wxString text
= wxT("This only tests that wxVariant related routines do not crash.");
125 wxDialog
* dlg
= new wxDialog(this,-1,wxT("wxVariant Test"),
126 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
129 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
131 wxVariant
& v
= values
[i
];
133 wxString strValue
= v
.GetString();
135 #if wxCHECK_VERSION(2,8,0)
136 if ( v
.GetName().EndsWith(wxT("@attr")) )
138 if ( v
.GetName().Right(5) == wxT("@attr") )
141 text
+= wxString::Format(wxT("Attributes:\n"));
144 for ( n
= 0; n
< (unsigned int)v
.GetCount(); n
++ )
148 t
.Printf(wxT(" atribute %i: name=\"%s\" (type=\"%s\" value=\"%s\")\n"),(int)n
,
149 a
.GetName().c_str(),a
.GetType().c_str(),a
.GetString().c_str());
155 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\" value=\"%s\"\n"),(int)i
,
156 v
.GetName().c_str(),v
.GetType().c_str(),strValue
.c_str());
161 // multi-line text editor dialog
162 const int spacing
= 8;
163 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
164 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
165 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,text
,
166 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
167 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
168 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
169 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
170 const int butSzFlags
=
171 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
172 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
173 0, butSzFlags
, spacing
);
174 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
176 dlg
->SetSizer( topsizer
);
177 topsizer
->SetSizeHints( dlg
);
179 dlg
->SetSize(400,300);
184 // -----------------------------------------------------------------------
190 TestRunner( const wxString
& name
, wxPropertyGridManager
* man
, wxTextCtrl
* ed
, wxArrayString
* errorMessages
)
195 m_errorMessages
= errorMessages
;
197 m_preWarnings
= wxPGGlobalVars
->m_warnings
;
200 if ( name
!= wxT("none") )
207 int warningsOccurred
= wxPGGlobalVars
->m_warnings
- m_preWarnings
;
208 if ( warningsOccurred
)
210 wxString s
= wxString::Format(wxT("%i warnings occurred during test '%s'"), warningsOccurred
, m_name
.c_str());
211 m_errorMessages
->push_back(s
);
217 void Msg( const wxString
& text
)
221 m_ed
->AppendText(text
);
222 m_ed
->AppendText(wxT("\n"));
228 wxPropertyGridManager
* m_man
;
230 wxArrayString
* m_errorMessages
;
238 #define RT_START_TEST(TESTNAME) \
239 TestRunner tr(wxT(#TESTNAME), pgman, ed, &errorMessages);
244 #define RT_FAILURE() \
246 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
247 errorMessages.push_back(s1); \
252 #define RT_ASSERT(COND) \
256 #define RT_FAILURE_MSG(MSG) \
258 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
259 errorMessages.push_back(s1); \
261 wxString s2 = wxString::Format(wxT("Message: %s"),MSG); \
262 errorMessages.push_back(s2); \
267 #define RT_VALIDATE_VIRTUAL_HEIGHT(PROPS, EXTRATEXT) \
269 unsigned int h1_ = PROPS->GetVirtualHeight(); \
270 unsigned int h2_ = PROPS->GetActualVirtualHeight(); \
273 wxString s_ = wxString::Format(wxT("VirtualHeight = %i, should be %i (%s)"), h1_, h2_, EXTRATEXT.c_str()); \
274 RT_FAILURE_MSG(s_.c_str()); \
284 int gpiro_cmpfunc(const void* a
, const void* b
)
286 const wxPGProperty
* p1
= (const wxPGProperty
*) a
;
287 const wxPGProperty
* p2
= (const wxPGProperty
*) b
;
288 return (int) (((size_t)p1
->GetClientData()) - ((size_t)p2
->GetClientData()));
291 wxArrayPGProperty
GetPropertiesInRandomOrder( wxPropertyGridInterface
* props
, int iterationFlags
= wxPG_ITERATE_ALL
)
293 wxArrayPGProperty arr
;
295 wxPropertyGridIterator it
;
297 for ( it
= props
->GetIterator(iterationFlags
);
301 wxPGProperty
* p
= *it
;
302 size_t randomNumber
= rand();
303 p
->SetClientData(reinterpret_cast<void*>(randomNumber
));
307 wxPGProperty
** firstEntry
= &arr
[0];
308 qsort(firstEntry
, arr
.size(), sizeof(wxPGProperty
*), gpiro_cmpfunc
);
313 // Callback for testing property sorting
314 int MyPropertySortFunction(wxPropertyGrid
* WXUNUSED(propGrid
),
318 // Reverse alphabetical order
319 return p2
->GetLabel().CmpNoCase( p1
->GetBaseName() );
322 bool FormMain::RunTests( bool fullTest
, bool interactive
)
326 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
331 pgman
->ClearSelection();
334 bool _failed_
= false;
335 wxArrayString errorMessages
;
336 wxDialog
* dlg
= NULL
;
338 dlg
= new wxDialog(this,-1,wxT("wxPropertyGrid Regression Tests"),
339 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
341 // multi-line text editor dialog
342 const int spacing
= 8;
343 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
344 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
345 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,wxEmptyString
,
346 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
347 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
348 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
349 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
350 const int butSzFlags
=
351 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
352 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
353 0, butSzFlags
, spacing
);
354 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
356 dlg
->SetSizer( topsizer
);
357 topsizer
->SetSizeHints( dlg
);
359 dlg
->SetSize(400,300);
360 dlg
->Move(wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)-dlg
->GetSize().x
,
361 wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)-dlg
->GetSize().y
);
366 // Basic iterator tests
367 RT_START_TEST(GetIterator
)
373 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
377 wxPGProperty
* p
= it
.GetProperty();
378 if ( p
->IsCategory() )
379 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a category (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
380 else if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
381 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
385 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES) -> %i entries"), count
));
388 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_CATEGORIES
);
392 wxPGProperty
* p
= it
.GetProperty();
393 if ( !p
->IsCategory() )
394 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is not a category (only category was expected)"),p
->GetLabel().c_str()).c_str())
398 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
401 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
|wxPG_ITERATE_CATEGORIES
);
405 wxPGProperty
* p
= it
.GetProperty();
406 if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
407 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property or category expected)"),p
->GetLabel().c_str()).c_str())
411 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
414 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_VISIBLE
);
418 wxPGProperty
* p
= it
.GetProperty();
419 if ( (p
->GetParent() != p
->GetParentState()->DoGetRoot() && !p
->GetParent()->IsExpanded()) )
420 RT_FAILURE_MSG(wxString::Format(wxT("'%s' had collapsed parent (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
421 else if ( p
->HasFlag(wxPG_PROP_HIDDEN
) )
422 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was hidden (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
426 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_VISIBLE) -> %i entries"), count
));
431 // Test that setting focus to properties does not crash things
432 RT_START_TEST(SelectProperty
)
434 wxPropertyGridIterator it
;
437 for ( ind
=0; ind
<pgman
->GetPageCount(); ind
++ )
439 wxPropertyGridPage
* page
= pgman
->GetPage(ind
);
440 pgman
->SelectPage(page
);
442 for ( it
= page
->GetIterator(wxPG_ITERATE_VISIBLE
);
446 wxPGProperty
* p
= *it
;
447 RT_MSG(p
->GetLabel());
448 pgman
->GetGrid()->SelectProperty(p
, true);
457 // Delete everything in reverse order
458 RT_START_TEST(DeleteProperty
)
461 wxArrayPGProperty array
;
463 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_ALL
&~(wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
)));
466 array
.push_back(it
.GetProperty());
468 wxArrayPGProperty::reverse_iterator it2
;
470 for ( it2
= array
.rbegin(); it2
!= array
.rend(); it2
++ )
472 wxPGProperty
* p
= (wxPGProperty
*)*it2
;
473 RT_MSG(wxString::Format(wxT("Deleting '%s' ('%s')"),p
->GetLabel().c_str(),p
->GetName().c_str()));
474 pgman
->DeleteProperty(p
);
478 CreateGrid( -1, -1 );
479 pgman
= m_pPropGridManager
;
484 // Test property default values
485 RT_START_TEST(Default_Values
)
489 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
493 wxPGProperty
* p
= it
.GetProperty();
494 pgman
->SetPropertyValue(p
, p
->GetDefaultValue());
498 CreateGrid( -1, -1 );
499 pgman
= m_pPropGridManager
;
503 RT_START_TEST(GetPropertyValues
)
505 for ( i
=0; i
<3; i
++ )
509 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
511 wxVariant values
= page
->GetPropertyValues();
514 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
516 wxVariant
& v
= values
[i
];
518 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\"\n"),(int)i
,
519 v
.GetName().c_str(),v
.GetType().c_str());
523 ed
->AppendText(text
);
528 RT_START_TEST(SetPropertyValue_and_GetPropertyValue
)
530 // In this section, mixed up usage of wxT("propname") and "propname"
531 // in wxPropertyGridInterface functions is intentional.
532 // Purpose is to test wxPGPropArgCls ctors.
534 //pg = (wxPropertyGrid*) NULL;
536 wxArrayString test_arrstr_1
;
537 test_arrstr_1
.Add(wxT("Apple"));
538 test_arrstr_1
.Add(wxT("Orange"));
539 test_arrstr_1
.Add(wxT("Lemon"));
541 wxArrayString test_arrstr_2
;
542 test_arrstr_2
.Add(wxT("Potato"));
543 test_arrstr_2
.Add(wxT("Cabbage"));
544 test_arrstr_2
.Add(wxT("Cucumber"));
546 wxArrayInt test_arrint_1
;
547 test_arrint_1
.Add(1);
548 test_arrint_1
.Add(2);
549 test_arrint_1
.Add(3);
551 wxArrayInt test_arrint_2
;
552 test_arrint_2
.Add(0);
553 test_arrint_2
.Add(1);
554 test_arrint_2
.Add(4);
557 wxDateTime dt1
= wxDateTime::Now();
558 dt1
.SetYear(dt1
.GetYear()-1);
560 wxDateTime dt2
= wxDateTime::Now();
561 dt2
.SetYear(dt2
.GetYear()-10);
564 #define FLAG_TEST_SET1 (wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER)
565 #define FLAG_TEST_SET2 (wxSTAY_ON_TOP|wxCAPTION|wxICONIZE|wxSYSTEM_MENU)
567 pgman
->SetPropertyValue(wxT("StringProperty"),wxT("Text1"));
568 pgman
->SetPropertyValue(wxT("IntProperty"),1024);
569 pgman
->SetPropertyValue(wxT("FloatProperty"),1024.0000000001);
570 pgman
->SetPropertyValue(wxT("BoolProperty"),FALSE
);
571 pgman
->SetPropertyValue(wxT("EnumProperty"),120);
572 pgman
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_1
);
574 pgman
->SetPropertyValue(wxT("ColourProperty"),emptyCol
);
575 pgman
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxBLACK
);
576 pgman
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(150,150)));
577 pgman
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(150,150)));
578 pgman
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_1
);
580 pgman
->SetPropertyValue(wxT("DateProperty"),dt1
);
583 pgman
->SelectPage(2);
584 pg
= pgman
->GetGrid();
586 if ( pg
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text1") )
588 if ( pg
->GetPropertyValueAsInt(wxT("IntProperty")) != 1024 )
590 if ( pg
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 1024.0000000001 )
592 if ( pg
->GetPropertyValueAsBool(wxT("BoolProperty")) != FALSE
)
594 if ( pg
->GetPropertyValueAsLong(wxT("EnumProperty")) != 120 )
596 if ( pg
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_1
)
599 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
600 if ( col
!= *wxBLACK
)
602 wxVariant
varSize(pg
->GetPropertyValue(wxT("Size")));
603 if ( wxSizeRefFromVariant(varSize
) != wxSize(150,150) )
605 wxVariant
varPos(pg
->GetPropertyValue(wxT("Position")));
606 if ( wxPointRefFromVariant(varPos
) != wxPoint(150,150) )
608 if ( !(pg
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_1
) )
611 if ( !(pg
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt1
) )
615 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(10000000000));
616 if ( pg
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(10000000000) )
619 pg
->SetPropertyValue(wxT("StringProperty"),wxT("Text2"));
620 pg
->SetPropertyValue(wxT("IntProperty"),512);
621 pg
->SetPropertyValue(wxT("FloatProperty"),512.0);
622 pg
->SetPropertyValue(wxT("BoolProperty"),TRUE
);
623 pg
->SetPropertyValue(wxT("EnumProperty"),80);
624 pg
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_2
);
625 pg
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxWHITE
);
626 pg
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(300,300)));
627 pg
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(300,300)));
628 pg
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_2
);
630 pg
->SetPropertyValue(wxT("DateProperty"),dt2
);
633 //pg = (wxPropertyGrid*) NULL;
635 pgman
->SelectPage(0);
637 if ( pgman
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text2") )
639 if ( pgman
->GetPropertyValueAsInt(wxT("IntProperty")) != 512 )
641 if ( pgman
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 512.0 )
643 if ( pgman
->GetPropertyValueAsBool(wxT("BoolProperty")) != TRUE
)
645 if ( pgman
->GetPropertyValueAsLong(wxT("EnumProperty")) != 80 )
647 if ( pgman
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_2
)
649 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
650 if ( col
!= *wxWHITE
)
652 varSize
= pgman
->GetPropertyValue(wxT("Size"));
653 if ( wxSizeRefFromVariant(varSize
) != wxSize(300,300) )
655 varPos
= pgman
->GetPropertyValue(wxT("Position"));
656 if ( wxPointRefFromVariant(varPos
) != wxPoint(300,300) )
658 if ( !(pgman
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_2
) )
661 if ( !(pgman
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt2
) )
665 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000));
666 if ( pgman
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) )
669 // Make sure children of composite parent get updated as well
670 // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000; Not Convertible"
673 // This updates children as well
674 wxString nvs
= "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002; Convertible";
675 pgman
->SetPropertyValue("Car", nvs
);
677 if ( pgman
->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
679 wxLogDebug("Did not match: Car.Model=%s", pgman
->GetPropertyValueAsString("Car.Model").c_str());
683 if ( pgman
->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
685 wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman
->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
689 if ( pgman
->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
691 wxLogDebug("Did not match: Car.Price ($)=%s", pgman
->GetPropertyValueAsString("Car.Price ($)").c_str());
695 if ( !pgman
->GetPropertyValueAsBool("Car.Convertible") )
697 wxLogDebug("Did not match: Car.Convertible=%s", pgman
->GetPropertyValueAsString("Car.Convertible").c_str());
703 RT_START_TEST(SetPropertyValueUnspecified
)
705 // Null variant setter tests
706 pgman
->SetPropertyValueUnspecified(wxT("StringProperty"));
707 pgman
->SetPropertyValueUnspecified(wxT("IntProperty"));
708 pgman
->SetPropertyValueUnspecified(wxT("FloatProperty"));
709 pgman
->SetPropertyValueUnspecified(wxT("BoolProperty"));
710 pgman
->SetPropertyValueUnspecified(wxT("EnumProperty"));
711 pgman
->SetPropertyValueUnspecified(wxT("ArrayStringProperty"));
712 pgman
->SetPropertyValueUnspecified(wxT("ColourProperty"));
713 pgman
->SetPropertyValueUnspecified(wxT("Size"));
714 pgman
->SetPropertyValueUnspecified(wxT("Position"));
715 pgman
->SetPropertyValueUnspecified(wxT("MultiChoiceProperty"));
717 pgman
->SetPropertyValueUnspecified(wxT("DateProperty"));
723 // Test multiple selection
724 RT_START_TEST(MULTIPLE_SELECTION
)
725 if ( !(pgman
->GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
726 CreateGrid( -1, wxPG_EX_MULTIPLE_SELECTION
);
727 pgman
= m_pPropGridManager
;
729 wxPropertyGrid
* pg
= pgman
->GetGrid();
731 wxPGProperty
* prop1
= pg
->GetProperty(wxT("Label"));
732 wxPGProperty
* prop2
= pg
->GetProperty(wxT("Cell Text Colour"));
733 wxPGProperty
* prop3
= pg
->GetProperty(wxT("Height"));
734 wxPGProperty
* catProp
= pg
->GetProperty(wxT("Appearance"));
736 RT_ASSERT( prop1
&& prop2
&& prop3
);
738 pg
->ClearSelection();
739 pg
->AddToSelection(prop1
);
740 pg
->AddToSelection(prop2
);
741 pg
->AddToSelection(prop3
);
743 // Adding category to selection should fail silently
744 pg
->AddToSelection(catProp
);
746 wxArrayPGProperty selectedProperties
= pg
->GetSelectedProperties();
748 RT_ASSERT( selectedProperties
.size() == 3 )
749 RT_ASSERT( pg
->IsPropertySelected(prop1
) )
750 RT_ASSERT( pg
->IsPropertySelected(prop2
) )
751 RT_ASSERT( pg
->IsPropertySelected(prop3
) )
752 RT_ASSERT( !pg
->IsPropertySelected(catProp
) )
754 pg
->RemoveFromSelection(prop1
);
755 wxArrayPGProperty selectedProperties2
= pg
->GetSelectedProperties();
757 RT_ASSERT( selectedProperties2
.size() == 2 )
758 RT_ASSERT( !pg
->IsPropertySelected(prop1
) )
759 RT_ASSERT( pg
->IsPropertySelected(prop2
) )
760 RT_ASSERT( pg
->IsPropertySelected(prop3
) )
762 pg
->ClearSelection();
764 wxArrayPGProperty selectedProperties3
= pg
->GetSelectedProperties();
766 RT_ASSERT( selectedProperties3
.size() == 0 )
767 RT_ASSERT( !pg
->IsPropertySelected(prop1
) )
768 RT_ASSERT( !pg
->IsPropertySelected(prop2
) )
769 RT_ASSERT( !pg
->IsPropertySelected(prop3
) )
771 pg
->SelectProperty(prop2
);
773 RT_ASSERT( !pg
->IsPropertySelected(prop1
) )
774 RT_ASSERT( pg
->IsPropertySelected(prop2
) )
775 RT_ASSERT( !pg
->IsPropertySelected(prop3
) )
780 // Test label editing
781 RT_START_TEST(LABEL_EDITING
)
783 wxPropertyGrid
* pg
= pgman
->GetGrid();
785 // Just mostly test that these won't crash
786 pg
->MakeColumnEditable(0, true);
787 pg
->MakeColumnEditable(2, true);
788 pg
->MakeColumnEditable(0, false);
789 pg
->MakeColumnEditable(2, false);
790 pg
->SelectProperty(wxT("Height"));
791 pg
->BeginLabelEdit(0);
792 pg
->BeginLabelEdit(0);
797 CreateGrid( -1, -1 );
798 pgman
= m_pPropGridManager
;
802 RT_START_TEST(Attributes
)
804 wxPGProperty
* prop
= pgman
->GetProperty(wxT("StringProperty"));
805 prop
->SetAttribute(wxT("Dummy Attribute"), (long)15);
807 if ( prop
->GetAttribute(wxT("Dummy Attribute")).GetLong() != 15 )
810 prop
->SetAttribute(wxT("Dummy Attribute"), wxVariant());
812 if ( !prop
->GetAttribute(wxT("Dummy Attribute")).IsNull() )
817 wxPropertyGridPage
* page1
;
818 wxPropertyGridPage
* page2
;
819 wxPropertyGridPage
* page3
;
820 wxVariant pg1_values
;
821 wxVariant pg2_values
;
822 wxVariant pg3_values
;
825 RT_START_TEST(GetPropertyValues
)
827 page1
= pgman
->GetPage(0);
828 pg1_values
= page1
->GetPropertyValues(wxT("Page1"),NULL
,wxPG_KEEP_STRUCTURE
);
829 page2
= pgman
->GetPage(1);
830 pg2_values
= page2
->GetPropertyValues(wxT("Page2"),NULL
,wxPG_KEEP_STRUCTURE
);
831 page3
= pgman
->GetPage(2);
832 pg3_values
= page3
->GetPropertyValues(wxT("Page3"),NULL
,wxPG_KEEP_STRUCTURE
);
836 RT_START_TEST(SetPropertyValues
)
838 page1
->SetPropertyValues(pg3_values
);
839 page2
->SetPropertyValues(pg1_values
);
840 page3
->SetPropertyValues(pg2_values
);
844 if ( !(pgman
->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES
) )
846 RT_START_TEST(Collapse_and_GetFirstCategory_and_GetNextCategory
)
848 for ( i
=0; i
<3; i
++ )
850 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
852 wxPropertyGridIterator it
;
854 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
858 wxPGProperty
* p
= *it
;
860 if ( !page
->IsPropertyCategory(p
) )
865 t
.Printf(wxT("Collapsing: %s\n"),page
->GetPropertyLabel(p
).c_str());
872 RT_START_TEST(Save_And_RestoreEditableState
)
874 for ( i
=0; i
<3; i
++ )
876 pgman
->SelectPage(i
);
878 wxString stringState
= pgman
->SaveEditableState();
879 bool res
= pgman
->RestoreEditableState(stringState
);
885 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
887 RT_START_TEST(Expand_and_GetFirstCategory_and_GetNextCategory
)
889 for ( i
=0; i
<3; i
++ )
891 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
893 wxPropertyGridIterator it
;
895 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
899 wxPGProperty
* p
= *it
;
901 if ( !page
->IsPropertyCategory(p
) )
906 t
.Printf(wxT("Expand: %s\n"),page
->GetPropertyLabel(p
).c_str());
913 RT_START_TEST(Choice_Manipulation
)
915 wxPGProperty
* enumProp
= pgman
->GetProperty(wxT("EnumProperty"));
917 pgman
->SelectPage(2);
918 pgman
->SelectProperty(enumProp
);
919 wxASSERT(pgman
->GetGrid()->GetSelection() == enumProp
);
921 const wxPGChoices
& choices
= enumProp
->GetChoices();
922 int ind
= enumProp
->InsertChoice(wxT("New Choice"), choices
.GetCount()/2);
923 enumProp
->DeleteChoice(ind
);
925 // Recreate the original grid
926 CreateGrid( -1, -1 );
927 pgman
= m_pPropGridManager
;
930 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
932 RT_START_TEST(RandomCollapse
)
934 // Select the most error prone page as visible.
935 pgman
->SelectPage(1);
937 for ( i
=0; i
<3; i
++ )
941 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
943 wxPropertyGridIterator it
;
945 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
952 if ( arr
.GetCount() )
956 pgman
->Collapse( (wxPGProperty
*)arr
.Item(0) );
958 for ( n
=arr
.GetCount()-1; n
>0; n
-- )
960 pgman
->Collapse( (wxPGProperty
*)arr
.Item(n
) );
968 RT_START_TEST(EnsureVisible
)
969 pgman
->EnsureVisible(wxT("Cell Colour"));
973 RT_START_TEST(RemoveProperty
)
977 wxPGProperty
* origParent
=
978 pgman
->GetProperty(wxT("Window Styles"))->GetParent();
980 p
= pgman
->RemoveProperty(wxT("Window Styles"));
984 pgman
->AppendIn(origParent
, p
);
990 RT_START_TEST(SortFunction
)
994 // Make sure indexes are as supposed
996 p
= pgman
->GetProperty(wxT("User Name"));
997 if ( p
->GetIndexInParent() != 3 )
1000 p
= pgman
->GetProperty(wxT("User Id"));
1001 if ( p
->GetIndexInParent() != 2 )
1004 p
= pgman
->GetProperty(wxT("User Home"));
1005 if ( p
->GetIndexInParent() != 1 )
1008 p
= pgman
->GetProperty(wxT("Operating System"));
1009 if ( p
->GetIndexInParent() != 0 )
1012 pgman
->GetGrid()->SetSortFunction(MyPropertySortFunction
);
1014 pgman
->GetGrid()->SortChildren(wxT("Environment"));
1016 // Make sure indexes have been reversed
1017 p
= pgman
->GetProperty(wxT("User Name"));
1018 if ( p
->GetIndexInParent() != 0 )
1021 p
= pgman
->GetProperty(wxT("User Id"));
1022 if ( p
->GetIndexInParent() != 1 )
1025 p
= pgman
->GetProperty(wxT("User Home"));
1026 if ( p
->GetIndexInParent() != 2 )
1029 p
= pgman
->GetProperty(wxT("Operating System"));
1030 if ( p
->GetIndexInParent() != 3 )
1035 RT_START_TEST(SetPropertyBackgroundColour
)
1037 evt
.SetInt(1); // IsChecked() will return TRUE.
1038 evt
.SetId(ID_COLOURSCHEME4
);
1040 OnColourScheme(evt
);
1044 RT_START_TEST(Clear
)
1047 pgman
->SelectProperty("Label");
1050 if ( pgman
->GetPageCount() )
1053 if ( pgman
->GetGrid()->GetRoot()->GetChildCount() )
1056 // Recreate the original grid
1057 CreateGrid( -1, -1 );
1058 pgman
= m_pPropGridManager
;
1061 pgman
->SelectProperty("Label");
1062 pgman
->GetGrid()->Clear();
1064 if ( pgman
->GetGrid()->GetRoot()->GetChildCount() )
1067 // Recreate the original grid
1068 CreateGrid( -1, -1 );
1069 pgman
= m_pPropGridManager
;
1073 // TODO: This test fails.
1074 RT_START_TEST(SetSplitterPosition)
1078 const int trySplitterPos = 50;
1080 int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
1081 pgman = m_pPropGridManager =
1082 new wxPropertyGridManager(m_panel, wxID_ANY,
1088 pgman->SetSplitterPosition(trySplitterPos);
1090 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1091 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1093 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
1096 wxSize sz = GetSize();
1101 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1102 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1106 // Recreate the original grid
1107 CreateGrid( -1, -1 );
1108 pgman = m_pPropGridManager;
1112 RT_START_TEST(HideProperty
)
1114 wxPropertyGridPage
* page
= pgman
->GetPage(0);
1118 wxArrayPGProperty arr1
;
1120 arr1
= GetPropertiesInRandomOrder(page
);
1124 for ( i
=0; i
<arr1
.size(); i
++ )
1126 wxPGProperty
* p
= arr1
[i
];
1127 page
->HideProperty(p
, true);
1129 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1130 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1138 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1140 for ( i
=0; i
<arr2
.size(); i
++ )
1142 wxPGProperty
* p
= arr2
[i
];
1143 page
->HideProperty(p
, false);
1145 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1146 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1153 // Let's do some more, for better consistency
1154 arr1
= GetPropertiesInRandomOrder(page
);
1158 for ( i
=0; i
<arr1
.size(); i
++ )
1160 wxPGProperty
* p
= arr1
[i
];
1161 page
->HideProperty(p
, true);
1163 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1164 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1172 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1174 for ( i
=0; i
<arr2
.size(); i
++ )
1176 wxPGProperty
* p
= arr2
[i
];
1177 page
->HideProperty(p
, false);
1179 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1180 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1187 // Ok, this time only hide half of them
1188 arr1
= GetPropertiesInRandomOrder(page
);
1189 arr1
.resize(arr1
.size()/2);
1193 for ( i
=0; i
<arr1
.size(); i
++ )
1195 wxPGProperty
* p
= arr1
[i
];
1196 page
->HideProperty(p
, true);
1198 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1199 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1207 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1209 for ( i
=0; i
<arr2
.size(); i
++ )
1211 wxPGProperty
* p
= arr2
[i
];
1212 page
->HideProperty(p
, false);
1214 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1215 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1221 // Recreate the original grid
1222 CreateGrid( -1, -1 );
1223 pgman
= m_pPropGridManager
;
1228 RT_START_TEST(MultipleColumns
)
1230 // Test with multiple columns
1231 // FIXME: Does not display changes.
1232 for ( i
=3; i
<12; i
+=2 )
1234 RT_MSG(wxString::Format(wxT("%i columns"),i
));
1235 CreateGrid( -1, -1 );
1236 pgman
= m_pPropGridManager
;
1237 pgman
->SetColumnCount(i
);
1246 RT_START_TEST(WindowStyles
)
1248 // Recreate grid with all possible (single) flags
1249 wxASSERT(wxPG_AUTO_SORT
== 0x000000010);
1251 for ( i
=4; i
<16; i
++ )
1254 RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag
));
1255 CreateGrid( flag
, -1 );
1256 pgman
= m_pPropGridManager
;
1261 wxASSERT(wxPG_EX_INIT_NOCAT
== 0x00001000);
1263 for ( i
=12; i
<27; i
++ )
1266 RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag
));
1267 CreateGrid( -1, flag
);
1268 pgman
= m_pPropGridManager
;
1273 // Recreate the original grid
1274 CreateGrid( -1, -1 );
1275 pgman
= m_pPropGridManager
;
1282 if ( failures
|| errorMessages
.size() )
1290 s
= wxString::Format(wxT("%i tests failed!!!"), failures
);
1293 s
= wxString::Format(wxT("All tests were succesfull, but there were %i warnings!"), wxPGGlobalVars
->m_warnings
);
1296 for ( i
=0; i
<errorMessages
.size(); i
++ )
1297 RT_MSG(errorMessages
[i
])
1298 wxMessageBox(s
, wxT("Some Tests Failed"));
1302 RT_MSG(wxT("All tests succesfull"))
1309 pgman
->SelectPage(0);
1311 // Test may screw up the toolbar, so we need to refresh it.
1312 wxToolBar
* toolBar
= pgman
->GetToolBar();
1319 // -----------------------------------------------------------------------