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_FAILURE_MSG(MSG) \
254 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
255 errorMessages.push_back(s1); \
257 wxString s2 = wxString::Format(wxT("Message: %s"),MSG); \
258 errorMessages.push_back(s2); \
263 #define RT_VALIDATE_VIRTUAL_HEIGHT(PROPS, EXTRATEXT) \
265 unsigned int h1_ = PROPS->GetVirtualHeight(); \
266 unsigned int h2_ = PROPS->GetActualVirtualHeight(); \
269 wxString s_ = wxString::Format(wxT("VirtualHeight = %i, should be %i (%s)"), h1_, h2_, EXTRATEXT.c_str()); \
270 RT_FAILURE_MSG(s_.c_str()); \
280 int gpiro_cmpfunc(const void* a
, const void* b
)
282 const wxPGProperty
* p1
= (const wxPGProperty
*) a
;
283 const wxPGProperty
* p2
= (const wxPGProperty
*) b
;
284 return (int) (((size_t)p1
->GetClientData()) - ((size_t)p2
->GetClientData()));
287 wxArrayPGProperty
GetPropertiesInRandomOrder( wxPropertyGridInterface
* props
, int iterationFlags
= wxPG_ITERATE_ALL
)
289 wxArrayPGProperty arr
;
291 wxPropertyGridIterator it
;
293 for ( it
= props
->GetIterator(iterationFlags
);
297 wxPGProperty
* p
= *it
;
298 size_t randomNumber
= rand();
299 p
->SetClientData(reinterpret_cast<void*>(randomNumber
));
303 wxPGProperty
** firstEntry
= &arr
[0];
304 qsort(firstEntry
, arr
.size(), sizeof(wxPGProperty
*), gpiro_cmpfunc
);
309 // Callback for testing property sorting
310 int MyPropertySortFunction(wxPropertyGrid
* WXUNUSED(propGrid
),
314 // Reverse alphabetical order
315 return p2
->GetLabel().CmpNoCase( p1
->GetBaseName() );
318 bool FormMain::RunTests( bool fullTest
, bool interactive
)
322 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
327 pgman
->ClearSelection();
330 bool _failed_
= false;
331 wxArrayString errorMessages
;
332 wxDialog
* dlg
= NULL
;
334 dlg
= new wxDialog(this,-1,wxT("wxPropertyGrid Regression Tests"),
335 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
337 // multi-line text editor dialog
338 const int spacing
= 8;
339 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
340 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
341 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,wxEmptyString
,
342 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
343 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
344 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
345 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
346 const int butSzFlags
=
347 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
348 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
349 0, butSzFlags
, spacing
);
350 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
352 dlg
->SetSizer( topsizer
);
353 topsizer
->SetSizeHints( dlg
);
355 dlg
->SetSize(400,300);
356 dlg
->Move(wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)-dlg
->GetSize().x
,
357 wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)-dlg
->GetSize().y
);
362 // Basic iterator tests
363 RT_START_TEST(GetIterator
)
369 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
373 wxPGProperty
* p
= it
.GetProperty();
374 if ( p
->IsCategory() )
375 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a category (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
376 else if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
377 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
381 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES) -> %i entries"), count
));
384 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_CATEGORIES
);
388 wxPGProperty
* p
= it
.GetProperty();
389 if ( !p
->IsCategory() )
390 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is not a category (only category was expected)"),p
->GetLabel().c_str()).c_str())
394 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
397 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
|wxPG_ITERATE_CATEGORIES
);
401 wxPGProperty
* p
= it
.GetProperty();
402 if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
403 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property or category expected)"),p
->GetLabel().c_str()).c_str())
407 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
410 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_VISIBLE
);
414 wxPGProperty
* p
= it
.GetProperty();
415 if ( (p
->GetParent() != p
->GetParentState()->DoGetRoot() && !p
->GetParent()->IsExpanded()) )
416 RT_FAILURE_MSG(wxString::Format(wxT("'%s' had collapsed parent (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
417 else if ( p
->HasFlag(wxPG_PROP_HIDDEN
) )
418 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was hidden (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
422 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_VISIBLE) -> %i entries"), count
));
427 // Test that setting focus to properties does not crash things
428 RT_START_TEST(SelectProperty
)
430 wxPropertyGridIterator it
;
433 for ( ind
=0; ind
<pgman
->GetPageCount(); ind
++ )
435 wxPropertyGridPage
* page
= pgman
->GetPage(ind
);
436 pgman
->SelectPage(page
);
438 for ( it
= page
->GetIterator(wxPG_ITERATE_VISIBLE
);
442 wxPGProperty
* p
= *it
;
443 RT_MSG(p
->GetLabel());
444 pgman
->GetGrid()->SelectProperty(p
, true);
453 // Delete everything in reverse order
454 RT_START_TEST(DeleteProperty
)
457 wxArrayPGProperty array
;
459 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_ALL
&~(wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
)));
462 array
.push_back(it
.GetProperty());
464 wxArrayPGProperty::reverse_iterator it2
;
466 for ( it2
= array
.rbegin(); it2
!= array
.rend(); it2
++ )
468 wxPGProperty
* p
= (wxPGProperty
*)*it2
;
469 RT_MSG(wxString::Format(wxT("Deleting '%s' ('%s')"),p
->GetLabel().c_str(),p
->GetName().c_str()));
470 pgman
->DeleteProperty(p
);
474 CreateGrid( -1, -1 );
475 pgman
= m_pPropGridManager
;
480 // Test property default values
481 RT_START_TEST(Default_Values
)
485 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
489 wxPGProperty
* p
= it
.GetProperty();
490 pgman
->SetPropertyValue(p
, p
->GetDefaultValue());
494 CreateGrid( -1, -1 );
495 pgman
= m_pPropGridManager
;
499 RT_START_TEST(GetPropertyValues
)
501 for ( i
=0; i
<3; i
++ )
505 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
507 wxVariant values
= page
->GetPropertyValues();
510 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
512 wxVariant
& v
= values
[i
];
514 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\"\n"),(int)i
,
515 v
.GetName().c_str(),v
.GetType().c_str());
519 ed
->AppendText(text
);
524 RT_START_TEST(SetPropertyValue_and_GetPropertyValue
)
526 // In this section, mixed up usage of wxT("propname") and "propname"
527 // in wxPropertyGridInterface functions is intentional.
528 // Purpose is to test wxPGPropArgCls ctors.
530 //pg = (wxPropertyGrid*) NULL;
532 wxArrayString test_arrstr_1
;
533 test_arrstr_1
.Add(wxT("Apple"));
534 test_arrstr_1
.Add(wxT("Orange"));
535 test_arrstr_1
.Add(wxT("Lemon"));
537 wxArrayString test_arrstr_2
;
538 test_arrstr_2
.Add(wxT("Potato"));
539 test_arrstr_2
.Add(wxT("Cabbage"));
540 test_arrstr_2
.Add(wxT("Cucumber"));
542 wxArrayInt test_arrint_1
;
543 test_arrint_1
.Add(1);
544 test_arrint_1
.Add(2);
545 test_arrint_1
.Add(3);
547 wxArrayInt test_arrint_2
;
548 test_arrint_2
.Add(0);
549 test_arrint_2
.Add(1);
550 test_arrint_2
.Add(4);
553 wxDateTime dt1
= wxDateTime::Now();
554 dt1
.SetYear(dt1
.GetYear()-1);
556 wxDateTime dt2
= wxDateTime::Now();
557 dt2
.SetYear(dt2
.GetYear()-10);
560 #define FLAG_TEST_SET1 (wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER)
561 #define FLAG_TEST_SET2 (wxSTAY_ON_TOP|wxCAPTION|wxICONIZE|wxSYSTEM_MENU)
563 pgman
->SetPropertyValue(wxT("StringProperty"),wxT("Text1"));
564 pgman
->SetPropertyValue(wxT("IntProperty"),1024);
565 pgman
->SetPropertyValue(wxT("FloatProperty"),1024.0000000001);
566 pgman
->SetPropertyValue(wxT("BoolProperty"),FALSE
);
567 pgman
->SetPropertyValue(wxT("EnumProperty"),120);
568 pgman
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_1
);
570 pgman
->SetPropertyValue(wxT("ColourProperty"),emptyCol
);
571 pgman
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxBLACK
);
572 pgman
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(150,150)));
573 pgman
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(150,150)));
574 pgman
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_1
);
576 pgman
->SetPropertyValue(wxT("DateProperty"),dt1
);
579 pgman
->SelectPage(2);
580 pg
= pgman
->GetGrid();
582 if ( pg
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text1") )
584 if ( pg
->GetPropertyValueAsInt(wxT("IntProperty")) != 1024 )
586 if ( pg
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 1024.0000000001 )
588 if ( pg
->GetPropertyValueAsBool(wxT("BoolProperty")) != FALSE
)
590 if ( pg
->GetPropertyValueAsLong(wxT("EnumProperty")) != 120 )
592 if ( pg
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_1
)
595 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
596 if ( col
!= *wxBLACK
)
598 if ( wxSizeRefFromVariant(pg
->GetPropertyValue(wxT("Size"))) != wxSize(150,150) )
600 if ( wxPointRefFromVariant(pg
->GetPropertyValue(wxT("Position"))) != wxPoint(150,150) )
602 if ( !(pg
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_1
) )
605 if ( !(pg
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt1
) )
609 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(10000000000));
610 if ( pg
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(10000000000) )
613 pg
->SetPropertyValue(wxT("StringProperty"),wxT("Text2"));
614 pg
->SetPropertyValue(wxT("IntProperty"),512);
615 pg
->SetPropertyValue(wxT("FloatProperty"),512.0);
616 pg
->SetPropertyValue(wxT("BoolProperty"),TRUE
);
617 pg
->SetPropertyValue(wxT("EnumProperty"),80);
618 pg
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_2
);
619 pg
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxWHITE
);
620 pg
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(300,300)));
621 pg
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(300,300)));
622 pg
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_2
);
624 pg
->SetPropertyValue(wxT("DateProperty"),dt2
);
627 //pg = (wxPropertyGrid*) NULL;
629 pgman
->SelectPage(0);
631 if ( pgman
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text2") )
633 if ( pgman
->GetPropertyValueAsInt(wxT("IntProperty")) != 512 )
635 if ( pgman
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 512.0 )
637 if ( pgman
->GetPropertyValueAsBool(wxT("BoolProperty")) != TRUE
)
639 if ( pgman
->GetPropertyValueAsLong(wxT("EnumProperty")) != 80 )
641 if ( pgman
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_2
)
643 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
644 if ( col
!= *wxWHITE
)
646 if ( wxSizeRefFromVariant(pgman
->GetPropertyValue(wxT("Size"))) != wxSize(300,300) )
648 if ( wxPointRefFromVariant(pgman
->GetPropertyValue(wxT("Position"))) != wxPoint(300,300) )
650 if ( !(pgman
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_2
) )
653 if ( !(pgman
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt2
) )
657 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000));
658 if ( pgman
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) )
662 // Flexible wx(U)LongLong << operator safety conformance tests
667 prop
= pgman
->GetProperty(wxT("IntProperty"));
669 ll
<< prop
->GetValue();
673 prop
->SetValue(WXVARIANT(wxLL(68719476736)));
674 ll
<< prop
->GetValue();
675 if ( ll
.GetValue() != wxLL(68719476736) )
678 #if wxUSE_LONGLONG_NATIVE
680 ll_t
<< prop
->GetValue();
681 if ( ll_t
!= wxLL(68719476736) )
686 ll
<< prop
->GetValue();
690 prop
= pgman
->GetProperty(wxT("UIntProperty"));
692 ull
<< prop
->GetValue();
696 prop
->SetValue(WXVARIANT(wxULL(68719476739)));
697 ull
<< prop
->GetValue();
698 if ( ull
.GetValue() != wxULL(68719476739) )
701 #if wxUSE_LONGLONG_NATIVE
703 ull_t
<< prop
->GetValue();
704 if ( ull_t
!= wxLL(68719476739) )
709 ull
<< prop
->GetValue();
713 // Make sure children of composite parent get updated as well
714 // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000; Not Convertible"
717 // This updates children as well
718 wxString nvs
= "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002; Convertible";
719 pgman
->SetPropertyValue("Car", nvs
);
721 if ( pgman
->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
723 wxLogDebug("Did not match: Car.Model=%s", pgman
->GetPropertyValueAsString("Car.Model").c_str());
727 if ( pgman
->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
729 wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman
->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
733 if ( pgman
->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
735 wxLogDebug("Did not match: Car.Price ($)=%s", pgman
->GetPropertyValueAsString("Car.Price ($)").c_str());
739 if ( !pgman
->GetPropertyValueAsBool("Car.Convertible") )
741 wxLogDebug("Did not match: Car.Convertible=%s", pgman
->GetPropertyValueAsString("Car.Convertible").c_str());
747 RT_START_TEST(SetPropertyValueUnspecified
)
749 // Null variant setter tests
750 pgman
->SetPropertyValueUnspecified(wxT("StringProperty"));
751 pgman
->SetPropertyValueUnspecified(wxT("IntProperty"));
752 pgman
->SetPropertyValueUnspecified(wxT("FloatProperty"));
753 pgman
->SetPropertyValueUnspecified(wxT("BoolProperty"));
754 pgman
->SetPropertyValueUnspecified(wxT("EnumProperty"));
755 pgman
->SetPropertyValueUnspecified(wxT("ArrayStringProperty"));
756 pgman
->SetPropertyValueUnspecified(wxT("ColourProperty"));
757 pgman
->SetPropertyValueUnspecified(wxT("Size"));
758 pgman
->SetPropertyValueUnspecified(wxT("Position"));
759 pgman
->SetPropertyValueUnspecified(wxT("MultiChoiceProperty"));
761 pgman
->SetPropertyValueUnspecified(wxT("DateProperty"));
766 RT_START_TEST(Attributes
)
768 wxPGProperty
* prop
= pgman
->GetProperty(wxT("StringProperty"));
769 prop
->SetAttribute(wxT("Dummy Attribute"), (long)15);
771 if ( prop
->GetAttribute(wxT("Dummy Attribute")).GetLong() != 15 )
774 prop
->SetAttribute(wxT("Dummy Attribute"), wxVariant());
776 if ( !prop
->GetAttribute(wxT("Dummy Attribute")).IsNull() )
781 wxPropertyGridPage
* page1
;
782 wxPropertyGridPage
* page2
;
783 wxPropertyGridPage
* page3
;
784 wxVariant pg1_values
;
785 wxVariant pg2_values
;
786 wxVariant pg3_values
;
789 RT_START_TEST(GetPropertyValues
)
791 page1
= pgman
->GetPage(0);
792 pg1_values
= page1
->GetPropertyValues(wxT("Page1"),NULL
,wxPG_KEEP_STRUCTURE
);
793 page2
= pgman
->GetPage(1);
794 pg2_values
= page2
->GetPropertyValues(wxT("Page2"),NULL
,wxPG_KEEP_STRUCTURE
);
795 page3
= pgman
->GetPage(2);
796 pg3_values
= page3
->GetPropertyValues(wxT("Page3"),NULL
,wxPG_KEEP_STRUCTURE
);
800 RT_START_TEST(SetPropertyValues
)
802 page1
->SetPropertyValues(pg3_values
);
803 page2
->SetPropertyValues(pg1_values
);
804 page3
->SetPropertyValues(pg2_values
);
808 if ( !(pgman
->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES
) )
810 RT_START_TEST(Collapse_and_GetFirstCategory_and_GetNextCategory
)
812 for ( i
=0; i
<3; i
++ )
814 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
816 wxPropertyGridIterator it
;
818 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
822 wxPGProperty
* p
= *it
;
824 if ( !page
->IsPropertyCategory(p
) )
829 t
.Printf(wxT("Collapsing: %s\n"),page
->GetPropertyLabel(p
).c_str());
836 RT_START_TEST(Save_And_RestoreEditableState
)
838 for ( i
=0; i
<3; i
++ )
840 pgman
->SelectPage(i
);
842 wxString stringState
= pgman
->SaveEditableState();
843 bool res
= pgman
->RestoreEditableState(stringState
);
849 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
851 RT_START_TEST(Expand_and_GetFirstCategory_and_GetNextCategory
)
853 for ( i
=0; i
<3; i
++ )
855 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
857 wxPropertyGridIterator it
;
859 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
863 wxPGProperty
* p
= *it
;
865 if ( !page
->IsPropertyCategory(p
) )
870 t
.Printf(wxT("Expand: %s\n"),page
->GetPropertyLabel(p
).c_str());
877 RT_START_TEST(Choice_Manipulation
)
879 wxPGProperty
* enumProp
= pgman
->GetProperty(wxT("EnumProperty"));
881 pgman
->SelectPage(2);
882 pgman
->SelectProperty(enumProp
);
883 wxASSERT(pgman
->GetGrid()->GetSelection() == enumProp
);
885 const wxPGChoices
& choices
= enumProp
->GetChoices();
886 int ind
= enumProp
->InsertChoice(wxT("New Choice"), choices
.GetCount()/2);
887 enumProp
->DeleteChoice(ind
);
889 // Recreate the original grid
890 CreateGrid( -1, -1 );
891 pgman
= m_pPropGridManager
;
894 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
896 RT_START_TEST(RandomCollapse
)
898 // Select the most error prone page as visible.
899 pgman
->SelectPage(1);
901 for ( i
=0; i
<3; i
++ )
905 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
907 wxPropertyGridIterator it
;
909 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
916 if ( arr
.GetCount() )
920 pgman
->Collapse( (wxPGProperty
*)arr
.Item(0) );
922 for ( n
=arr
.GetCount()-1; n
>0; n
-- )
924 pgman
->Collapse( (wxPGProperty
*)arr
.Item(n
) );
932 RT_START_TEST(EnsureVisible
)
933 pgman
->EnsureVisible(wxT("Cell Colour"));
937 RT_START_TEST(RemoveProperty
)
941 wxPGProperty
* origParent
=
942 pgman
->GetProperty(wxT("Window Styles"))->GetParent();
944 p
= pgman
->RemoveProperty(wxT("Window Styles"));
948 pgman
->AppendIn(origParent
, p
);
954 RT_START_TEST(SortFunction
)
958 // Make sure indexes are as supposed
960 p
= pgman
->GetProperty(wxT("User Name"));
961 if ( p
->GetIndexInParent() != 3 )
964 p
= pgman
->GetProperty(wxT("User Id"));
965 if ( p
->GetIndexInParent() != 2 )
968 p
= pgman
->GetProperty(wxT("User Home"));
969 if ( p
->GetIndexInParent() != 1 )
972 p
= pgman
->GetProperty(wxT("Operating System"));
973 if ( p
->GetIndexInParent() != 0 )
976 pgman
->GetGrid()->SetSortFunction(MyPropertySortFunction
);
978 pgman
->GetGrid()->SortChildren(wxT("Environment"));
980 // Make sure indexes have been reversed
981 p
= pgman
->GetProperty(wxT("User Name"));
982 if ( p
->GetIndexInParent() != 0 )
985 p
= pgman
->GetProperty(wxT("User Id"));
986 if ( p
->GetIndexInParent() != 1 )
989 p
= pgman
->GetProperty(wxT("User Home"));
990 if ( p
->GetIndexInParent() != 2 )
993 p
= pgman
->GetProperty(wxT("Operating System"));
994 if ( p
->GetIndexInParent() != 3 )
999 RT_START_TEST(SetPropertyBackgroundColour
)
1001 evt
.SetInt(1); // IsChecked() will return TRUE.
1002 evt
.SetId(ID_COLOURSCHEME4
);
1004 OnColourScheme(evt
);
1008 RT_START_TEST(Clear
)
1011 pgman
->SelectProperty("Label");
1014 if ( pgman
->GetPageCount() )
1017 if ( pgman
->GetGrid()->GetRoot()->GetChildCount() )
1020 // Recreate the original grid
1021 CreateGrid( -1, -1 );
1022 pgman
= m_pPropGridManager
;
1025 pgman
->SelectProperty("Label");
1026 pgman
->GetGrid()->Clear();
1028 if ( pgman
->GetGrid()->GetRoot()->GetChildCount() )
1031 // Recreate the original grid
1032 CreateGrid( -1, -1 );
1033 pgman
= m_pPropGridManager
;
1038 // TODO: This test fails.
1039 RT_START_TEST(SetSplitterPosition)
1043 const int trySplitterPos = 50;
1045 int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
1046 pgman = m_pPropGridManager =
1047 new wxPropertyGridManager(m_panel, wxID_ANY,
1053 pgman->SetSplitterPosition(trySplitterPos);
1055 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1056 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1058 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
1061 wxSize sz = GetSize();
1066 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1067 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1071 // Recreate the original grid
1072 CreateGrid( -1, -1 );
1073 pgman = m_pPropGridManager;
1078 RT_START_TEST(HideProperty
)
1080 wxPropertyGridPage
* page
= pgman
->GetPage(0);
1084 wxArrayPGProperty arr1
;
1086 arr1
= GetPropertiesInRandomOrder(page
);
1090 for ( i
=0; i
<arr1
.size(); i
++ )
1092 wxPGProperty
* p
= arr1
[i
];
1093 page
->HideProperty(p
, true);
1095 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1096 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1104 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1106 for ( i
=0; i
<arr2
.size(); i
++ )
1108 wxPGProperty
* p
= arr2
[i
];
1109 page
->HideProperty(p
, false);
1111 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1112 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1119 // Let's do some more, for better consistency
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 // Ok, this time only hide half of them
1154 arr1
= GetPropertiesInRandomOrder(page
);
1155 arr1
.resize(arr1
.size()/2);
1159 for ( i
=0; i
<arr1
.size(); i
++ )
1161 wxPGProperty
* p
= arr1
[i
];
1162 page
->HideProperty(p
, true);
1164 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1165 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1173 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1175 for ( i
=0; i
<arr2
.size(); i
++ )
1177 wxPGProperty
* p
= arr2
[i
];
1178 page
->HideProperty(p
, false);
1180 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1181 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1187 // Recreate the original grid
1188 CreateGrid( -1, -1 );
1189 pgman
= m_pPropGridManager
;
1194 RT_START_TEST(MultipleColumns
)
1196 // Test with multiple columns
1197 // FIXME: Does not display changes.
1198 for ( i
=3; i
<12; i
+=2 )
1200 RT_MSG(wxString::Format(wxT("%i columns"),i
));
1201 CreateGrid( -1, -1 );
1202 pgman
= m_pPropGridManager
;
1203 pgman
->SetColumnCount(i
);
1212 RT_START_TEST(WindowStyles
)
1214 // Recreate grid with all possible (single) flags
1215 wxASSERT(wxPG_AUTO_SORT
== 0x000000010);
1217 for ( i
=4; i
<16; i
++ )
1220 RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag
));
1221 CreateGrid( flag
, -1 );
1222 pgman
= m_pPropGridManager
;
1227 wxASSERT(wxPG_EX_INIT_NOCAT
== 0x00001000);
1229 for ( i
=12; i
<24; i
++ )
1232 RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag
));
1233 CreateGrid( -1, flag
);
1234 pgman
= m_pPropGridManager
;
1239 // Recreate the original grid
1240 CreateGrid( -1, -1 );
1241 pgman
= m_pPropGridManager
;
1248 if ( failures
|| errorMessages
.size() )
1256 s
= wxString::Format(wxT("%i tests failed!!!"), failures
);
1259 s
= wxString::Format(wxT("All tests were succesfull, but there were %i warnings!"), wxPGGlobalVars
->m_warnings
);
1262 for ( i
=0; i
<errorMessages
.size(); i
++ )
1263 RT_MSG(errorMessages
[i
])
1264 wxMessageBox(s
, wxT("Some Tests Failed"));
1268 RT_MSG(wxT("All tests succesfull"))
1275 pgman
->SelectPage(0);
1277 // Test may screw up the toolbar, so we need to refresh it.
1278 wxToolBar
* toolBar
= pgman
->GetToolBar();
1285 // -----------------------------------------------------------------------