1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/propgrid/tests.cpp
3 // Purpose: wxPropertyGrid tests
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
22 #include <wx/propgrid/propgrid.h>
23 #include <wx/propgrid/advprops.h>
24 #include <wx/propgrid/manager.h>
27 #include "sampleprops.h"
30 // -----------------------------------------------------------------------
31 // wxTestCustomFlagsProperty
32 // -----------------------------------------------------------------------
35 // Constant definitions required by wxFlagsProperty examples.
38 static const wxChar
* _fs_framestyle_labels
[] = {
45 wxT("wxRESIZE_BORDER"),
46 wxT("wxFRAME_TOOL_WINDOW"),
47 wxT("wxFRAME_NO_TASKBAR"),
48 wxT("wxFRAME_FLOAT_ON_PARENT"),
49 wxT("wxFRAME_SHAPED"),
53 static const long _fs_framestyle_values
[] = {
63 wxFRAME_FLOAT_ON_PARENT
,
67 // Colour labels. Last (before NULL, if any) must be Custom.
68 static const wxChar
* mycolprop_labels
[] = {
76 // Relevant colour values as unsigned longs.
77 static unsigned long mycolprop_colours
[] = {
80 wxPG_COLOUR(166,124,81),
84 // -----------------------------------------------------------------------
87 // Test customizing wxColourProperty via subclassing
89 // * Includes custom colour entry.
90 // * Includes extra custom entry.
92 class MyColourProperty
: public wxColourProperty
95 MyColourProperty( const wxString
& label
= wxPG_LABEL
,
96 const wxString
& name
= wxPG_LABEL
,
97 const wxColour
& value
= *wxWHITE
)
98 : wxColourProperty(label
, name
, value
)
101 colours
.Add(wxT("White"));
102 colours
.Add(wxT("Black"));
103 colours
.Add(wxT("Red"));
104 colours
.Add(wxT("Green"));
105 colours
.Add(wxT("Blue"));
106 colours
.Add(wxT("Custom"));
107 colours
.Add(wxT("None"));
115 virtual ~MyColourProperty()
119 virtual wxColour
GetColour( int index
) const
123 case 0: return *wxWHITE
;
124 case 1: return *wxBLACK
;
125 case 2: return *wxRED
;
126 case 3: return *wxGREEN
;
127 case 4: return *wxBLUE
;
129 // Return current colour for the custom entry
131 if ( GetIndex() == GetCustomColourIndex() )
133 if ( m_value
.IsNull() )
143 virtual wxString
ColourToString( const wxColour
& col
, int index
) const
145 if ( index
== (int)(m_choices
.GetCount()-1) )
148 return wxColourProperty::ColourToString(col
, index
);
151 virtual int GetCustomColourIndex() const
153 return m_choices
.GetCount()-2;
158 void FormMain::AddTestProperties( wxPropertyGridPage
* pg
)
160 pg
->Append( new MyColourProperty(wxT("CustomColourProperty"), wxPG_LABEL
, *wxGREEN
) );
161 pg
->GetProperty(wxT("CustomColourProperty"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
162 pg
->SetPropertyEditor( wxT("CustomColourProperty"), wxPGEditor_ComboBox
);
164 pg
->SetPropertyHelpString(wxT("CustomColourProperty"),
165 wxT("This is a MyColourProperty from the sample app. ")
166 wxT("It is built by subclassing wxColourProperty."));
169 // -----------------------------------------------------------------------
171 void FormMain::OnDumpList( wxCommandEvent
& WXUNUSED(event
) )
173 wxVariant values
= m_pPropGridManager
->GetPropertyValues(wxT("list"), wxNullProperty
, wxPG_INC_ATTRIBUTES
);
174 wxString text
= wxT("This only tests that wxVariant related routines do not crash.");
177 wxDialog
* dlg
= new wxDialog(this,-1,wxT("wxVariant Test"),
178 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
181 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
183 wxVariant
& v
= values
[i
];
185 wxString strValue
= v
.GetString();
187 #if wxCHECK_VERSION(2,8,0)
188 if ( v
.GetName().EndsWith(wxT("@attr")) )
190 if ( v
.GetName().Right(5) == wxT("@attr") )
193 text
+= wxString::Format(wxT("Attributes:\n"));
196 for ( n
= 0; n
< (unsigned int)v
.GetCount(); n
++ )
200 t
.Printf(wxT(" atribute %i: name=\"%s\" (type=\"%s\" value=\"%s\")\n"),(int)n
,
201 a
.GetName().c_str(),a
.GetType().c_str(),a
.GetString().c_str());
207 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\" value=\"%s\"\n"),(int)i
,
208 v
.GetName().c_str(),v
.GetType().c_str(),strValue
.c_str());
213 // multi-line text editor dialog
214 const int spacing
= 8;
215 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
216 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
217 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,text
,
218 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
219 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
220 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
221 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
222 const int butSzFlags
=
223 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
224 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
225 0, butSzFlags
, spacing
);
226 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
228 dlg
->SetSizer( topsizer
);
229 topsizer
->SetSizeHints( dlg
);
231 dlg
->SetSize(400,300);
236 // -----------------------------------------------------------------------
242 TestRunner( const wxString
& name
, wxPropertyGridManager
* man
, wxTextCtrl
* ed
, wxArrayString
* errorMessages
)
247 m_errorMessages
= errorMessages
;
249 m_preWarnings
= wxPGGlobalVars
->m_warnings
;
252 if ( name
!= wxT("none") )
259 int warningsOccurred
= wxPGGlobalVars
->m_warnings
- m_preWarnings
;
260 if ( warningsOccurred
)
262 wxString s
= wxString::Format(wxT("%i warnings occurred during test '%s'"), warningsOccurred
, m_name
.c_str());
263 m_errorMessages
->push_back(s
);
269 void Msg( const wxString
& text
)
273 m_ed
->AppendText(text
);
274 m_ed
->AppendText(wxT("\n"));
280 wxPropertyGridManager
* m_man
;
282 wxArrayString
* m_errorMessages
;
290 #define RT_START_TEST(TESTNAME) \
291 TestRunner tr(wxT(#TESTNAME), pgman, ed, &errorMessages);
296 #define RT_FAILURE() \
298 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
299 errorMessages.push_back(s1); \
304 #define RT_FAILURE_MSG(MSG) \
306 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
307 errorMessages.push_back(s1); \
309 wxString s2 = wxString::Format(wxT("Message: %s"),MSG); \
310 errorMessages.push_back(s2); \
315 #define RT_VALIDATE_VIRTUAL_HEIGHT(PROPS, EXTRATEXT) \
317 unsigned int h1_ = PROPS->GetVirtualHeight(); \
318 unsigned int h2_ = PROPS->GetActualVirtualHeight(); \
321 wxString s_ = wxString::Format(wxT("VirtualHeight = %i, should be %i (%s)"), h1_, h2_, EXTRATEXT.c_str()); \
322 RT_FAILURE_MSG(s_.c_str()); \
332 int gpiro_cmpfunc(const void* a
, const void* b
)
334 const wxPGProperty
* p1
= (const wxPGProperty
*) a
;
335 const wxPGProperty
* p2
= (const wxPGProperty
*) b
;
336 return (int) (((size_t)p1
->GetClientData()) - ((size_t)p2
->GetClientData()));
339 wxArrayPGProperty
GetPropertiesInRandomOrder( wxPropertyGridInterface
* props
, int iterationFlags
= wxPG_ITERATE_ALL
)
341 wxArrayPGProperty arr
;
343 wxPropertyGridIterator it
;
345 for ( it
= props
->GetIterator(iterationFlags
);
349 wxPGProperty
* p
= *it
;
350 size_t randomNumber
= rand();
351 p
->SetClientData(reinterpret_cast<void*>(randomNumber
));
355 wxPGProperty
** firstEntry
= &arr
[0];
356 qsort(firstEntry
, arr
.size(), sizeof(wxPGProperty
*), gpiro_cmpfunc
);
361 bool FormMain::RunTests( bool fullTest
, bool interactive
)
365 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
370 pgman
->ClearSelection();
373 bool _failed_
= false;
374 wxArrayString errorMessages
;
375 wxDialog
* dlg
= NULL
;
377 dlg
= new wxDialog(this,-1,wxT("wxPropertyGrid Regression Tests"),
378 wxDefaultPosition
,wxDefaultSize
,wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
380 // multi-line text editor dialog
381 const int spacing
= 8;
382 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
383 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
384 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,wxEmptyString
,
385 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
|wxTE_READONLY
);
386 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
387 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
388 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
389 const int butSzFlags
=
390 wxALIGN_CENTRE_HORIZONTAL
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
391 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,wxT("Ok")),
392 0, butSzFlags
, spacing
);
393 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
395 dlg
->SetSizer( topsizer
);
396 topsizer
->SetSizeHints( dlg
);
398 dlg
->SetSize(400,300);
399 dlg
->Move(wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)-dlg
->GetSize().x
,
400 wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)-dlg
->GetSize().y
);
405 // Basic iterator tests
406 RT_START_TEST(GetIterator
)
412 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
416 wxPGProperty
* p
= it
.GetProperty();
417 if ( p
->IsCategory() )
418 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a category (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
419 else if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
420 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property expected)"),p
->GetLabel().c_str()).c_str())
424 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES) -> %i entries"), count
));
427 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_CATEGORIES
);
431 wxPGProperty
* p
= it
.GetProperty();
432 if ( !p
->IsCategory() )
433 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is not a category (only category was expected)"),p
->GetLabel().c_str()).c_str())
437 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
440 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
|wxPG_ITERATE_CATEGORIES
);
444 wxPGProperty
* p
= it
.GetProperty();
445 if ( p
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) )
446 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property or category expected)"),p
->GetLabel().c_str()).c_str())
450 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES) -> %i entries"), count
));
453 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_VISIBLE
);
457 wxPGProperty
* p
= it
.GetProperty();
458 if ( (p
->GetParent() != p
->GetParentState()->DoGetRoot() && !p
->GetParent()->IsExpanded()) )
459 RT_FAILURE_MSG(wxString::Format(wxT("'%s' had collapsed parent (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
460 else if ( p
->HasFlag(wxPG_PROP_HIDDEN
) )
461 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was hidden (only visible properties expected)"),p
->GetLabel().c_str()).c_str())
465 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_VISIBLE) -> %i entries"), count
));
470 // Test that setting focus to properties does not crash things
471 RT_START_TEST(SelectProperty
)
473 wxPropertyGridIterator it
;
476 for ( ind
=0; ind
<pgman
->GetPageCount(); ind
++ )
478 wxPropertyGridPage
* page
= pgman
->GetPage(ind
);
479 pgman
->SelectPage(page
);
481 for ( it
= page
->GetIterator(wxPG_ITERATE_VISIBLE
);
485 wxPGProperty
* p
= *it
;
486 RT_MSG(p
->GetLabel());
487 pgman
->GetGrid()->SelectProperty(p
, true);
496 // Delete everything in reverse order
497 RT_START_TEST(DeleteProperty
)
500 wxArrayPGProperty array
;
502 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_ALL
&~(wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE
)));
505 array
.push_back(it
.GetProperty());
507 wxArrayPGProperty::reverse_iterator it2
;
509 for ( it2
= array
.rbegin(); it2
!= array
.rend(); it2
++ )
511 wxPGProperty
* p
= (wxPGProperty
*)*it2
;
512 RT_MSG(wxString::Format(wxT("Deleting '%s' ('%s')"),p
->GetLabel().c_str(),p
->GetName().c_str()));
513 pgman
->DeleteProperty(p
);
517 CreateGrid( -1, -1 );
518 pgman
= m_pPropGridManager
;
523 // Test property default values
524 RT_START_TEST(Default_Values
)
528 for ( it
= pgman
->GetVIterator(wxPG_ITERATE_PROPERTIES
);
532 wxPGProperty
* p
= it
.GetProperty();
533 pgman
->SetPropertyValue(p
, p
->GetDefaultValue());
537 CreateGrid( -1, -1 );
538 pgman
= m_pPropGridManager
;
542 RT_START_TEST(GetPropertyValues
)
544 for ( i
=0; i
<3; i
++ )
548 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
550 wxVariant values
= page
->GetPropertyValues();
553 for ( i
= 0; i
< (unsigned int)values
.GetCount(); i
++ )
555 wxVariant
& v
= values
[i
];
557 t
.Printf(wxT("%i: name=\"%s\" type=\"%s\"\n"),(int)i
,
558 v
.GetName().c_str(),v
.GetType().c_str());
562 ed
->AppendText(text
);
567 RT_START_TEST(SetPropertyValue_and_GetPropertyValue
)
569 // In this section, mixed up usage of wxT("propname") and "propname"
570 // in wxPropertyGridInterface functions is intentional.
571 // Purpose is to test wxPGPropArgCls ctors.
573 //pg = (wxPropertyGrid*) NULL;
575 wxArrayString test_arrstr_1
;
576 test_arrstr_1
.Add(wxT("Apple"));
577 test_arrstr_1
.Add(wxT("Orange"));
578 test_arrstr_1
.Add(wxT("Lemon"));
580 wxArrayString test_arrstr_2
;
581 test_arrstr_2
.Add(wxT("Potato"));
582 test_arrstr_2
.Add(wxT("Cabbage"));
583 test_arrstr_2
.Add(wxT("Cucumber"));
585 wxArrayInt test_arrint_1
;
586 test_arrint_1
.Add(1);
587 test_arrint_1
.Add(2);
588 test_arrint_1
.Add(3);
590 wxArrayInt test_arrint_2
;
591 test_arrint_2
.Add(0);
592 test_arrint_2
.Add(1);
593 test_arrint_2
.Add(4);
596 wxDateTime dt1
= wxDateTime::Now();
597 dt1
.SetYear(dt1
.GetYear()-1);
599 wxDateTime dt2
= wxDateTime::Now();
600 dt2
.SetYear(dt2
.GetYear()-10);
603 #define FLAG_TEST_SET1 (wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER)
604 #define FLAG_TEST_SET2 (wxSTAY_ON_TOP|wxCAPTION|wxICONIZE|wxSYSTEM_MENU)
606 pgman
->SetPropertyValue(wxT("StringProperty"),wxT("Text1"));
607 pgman
->SetPropertyValue(wxT("IntProperty"),1024);
608 pgman
->SetPropertyValue(wxT("FloatProperty"),1024.0000000001);
609 pgman
->SetPropertyValue(wxT("BoolProperty"),FALSE
);
610 pgman
->SetPropertyValue(wxT("EnumProperty"),120);
611 pgman
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_1
);
613 pgman
->SetPropertyValue(wxT("ColourProperty"),emptyCol
);
614 pgman
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxBLACK
);
615 pgman
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(150,150)));
616 pgman
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(150,150)));
617 pgman
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_1
);
619 pgman
->SetPropertyValue(wxT("DateProperty"),dt1
);
622 pgman
->SelectPage(2);
623 pg
= pgman
->GetGrid();
625 if ( pg
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text1") )
627 if ( pg
->GetPropertyValueAsInt(wxT("IntProperty")) != 1024 )
629 if ( pg
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 1024.0000000001 )
631 if ( pg
->GetPropertyValueAsBool(wxT("BoolProperty")) != FALSE
)
633 if ( pg
->GetPropertyValueAsLong(wxT("EnumProperty")) != 120 )
635 if ( pg
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_1
)
638 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
639 if ( col
!= *wxBLACK
)
641 if ( wxSizeRefFromVariant(pg
->GetPropertyValue(wxT("Size"))) != wxSize(150,150) )
643 if ( wxPointRefFromVariant(pg
->GetPropertyValue(wxT("Position"))) != wxPoint(150,150) )
645 if ( !(pg
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_1
) )
648 if ( !(pg
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt1
) )
652 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(10000000000));
653 if ( pg
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(10000000000) )
656 pg
->SetPropertyValue(wxT("StringProperty"),wxT("Text2"));
657 pg
->SetPropertyValue(wxT("IntProperty"),512);
658 pg
->SetPropertyValue(wxT("FloatProperty"),512.0);
659 pg
->SetPropertyValue(wxT("BoolProperty"),TRUE
);
660 pg
->SetPropertyValue(wxT("EnumProperty"),80);
661 pg
->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_2
);
662 pg
->SetPropertyValue(wxT("ColourProperty"),(wxObject
*)wxWHITE
);
663 pg
->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(300,300)));
664 pg
->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(300,300)));
665 pg
->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_2
);
667 pg
->SetPropertyValue(wxT("DateProperty"),dt2
);
670 //pg = (wxPropertyGrid*) NULL;
672 pgman
->SelectPage(0);
674 if ( pgman
->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text2") )
676 if ( pgman
->GetPropertyValueAsInt(wxT("IntProperty")) != 512 )
678 if ( pgman
->GetPropertyValueAsDouble(wxT("FloatProperty")) != 512.0 )
680 if ( pgman
->GetPropertyValueAsBool(wxT("BoolProperty")) != TRUE
)
682 if ( pgman
->GetPropertyValueAsLong(wxT("EnumProperty")) != 80 )
684 if ( pgman
->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_2
)
686 col
<< pgman
->GetPropertyValue(wxT("ColourProperty"));
687 if ( col
!= *wxWHITE
)
689 if ( wxSizeRefFromVariant(pgman
->GetPropertyValue(wxT("Size"))) != wxSize(300,300) )
691 if ( wxPointRefFromVariant(pgman
->GetPropertyValue(wxT("Position"))) != wxPoint(300,300) )
693 if ( !(pgman
->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_2
) )
696 if ( !(pgman
->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt2
) )
700 pgman
->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000));
701 if ( pgman
->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) )
705 // Flexible wx(U)LongLong << operator safety conformance tests
710 prop
= pgman
->GetProperty(wxT("IntProperty"));
712 ll
<< prop
->GetValue();
716 prop
->SetValue(WXVARIANT(wxLL(68719476736)));
717 ll
<< prop
->GetValue();
718 if ( ll
.GetValue() != wxLL(68719476736) )
721 #if wxUSE_LONGLONG_NATIVE
723 ll_t
<< prop
->GetValue();
724 if ( ll_t
!= wxLL(68719476736) )
729 ll
<< prop
->GetValue();
733 prop
= pgman
->GetProperty(wxT("UIntProperty"));
735 ull
<< prop
->GetValue();
739 prop
->SetValue(WXVARIANT(wxULL(68719476739)));
740 ull
<< prop
->GetValue();
741 if ( ull
.GetValue() != wxULL(68719476739) )
744 #if wxUSE_LONGLONG_NATIVE
746 ull_t
<< prop
->GetValue();
747 if ( ull_t
!= wxLL(68719476739) )
752 ull
<< prop
->GetValue();
756 // Make sure children of composite parent get updated as well
757 // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000"
760 // This updates children as well
761 wxString nvs
= "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002";
762 pgman
->SetPropertyValue("Car", nvs
);
764 if ( pgman
->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
766 wxLogDebug("Did not match: Car.Model=%s", pgman
->GetPropertyValueAsString("Car.Model").c_str());
770 if ( pgman
->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
772 wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman
->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
776 if ( pgman
->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
778 wxLogDebug("Did not match: Car.Price ($)=%s", pgman
->GetPropertyValueAsString("Car.Price ($)").c_str());
784 RT_START_TEST(SetPropertyValueUnspecified
)
786 // Null variant setter tests
787 pgman
->SetPropertyValueUnspecified(wxT("StringProperty"));
788 pgman
->SetPropertyValueUnspecified(wxT("IntProperty"));
789 pgman
->SetPropertyValueUnspecified(wxT("FloatProperty"));
790 pgman
->SetPropertyValueUnspecified(wxT("BoolProperty"));
791 pgman
->SetPropertyValueUnspecified(wxT("EnumProperty"));
792 pgman
->SetPropertyValueUnspecified(wxT("ArrayStringProperty"));
793 pgman
->SetPropertyValueUnspecified(wxT("ColourProperty"));
794 pgman
->SetPropertyValueUnspecified(wxT("Size"));
795 pgman
->SetPropertyValueUnspecified(wxT("Position"));
796 pgman
->SetPropertyValueUnspecified(wxT("MultiChoiceProperty"));
798 pgman
->SetPropertyValueUnspecified(wxT("DateProperty"));
803 RT_START_TEST(Attributes
)
805 wxPGProperty
* prop
= pgman
->GetProperty(wxT("StringProperty"));
806 prop
->SetAttribute(wxT("Dummy Attribute"), (long)15);
808 if ( prop
->GetAttribute(wxT("Dummy Attribute")).GetLong() != 15 )
811 prop
->SetAttribute(wxT("Dummy Attribute"), wxVariant());
813 if ( !prop
->GetAttribute(wxT("Dummy Attribute")).IsNull() )
818 wxPropertyGridPage
* page1
;
819 wxPropertyGridPage
* page2
;
820 wxPropertyGridPage
* page3
;
821 wxVariant pg1_values
;
822 wxVariant pg2_values
;
823 wxVariant pg3_values
;
826 RT_START_TEST(GetPropertyValues
)
828 page1
= pgman
->GetPage(0);
829 pg1_values
= page1
->GetPropertyValues(wxT("Page1"),NULL
,wxPG_KEEP_STRUCTURE
);
830 page2
= pgman
->GetPage(1);
831 pg2_values
= page2
->GetPropertyValues(wxT("Page2"),NULL
,wxPG_KEEP_STRUCTURE
);
832 page3
= pgman
->GetPage(2);
833 pg3_values
= page3
->GetPropertyValues(wxT("Page3"),NULL
,wxPG_KEEP_STRUCTURE
);
837 RT_START_TEST(SetPropertyValues
)
839 page1
->SetPropertyValues(pg3_values
);
840 page2
->SetPropertyValues(pg1_values
);
841 page3
->SetPropertyValues(pg2_values
);
845 if ( !(pgman
->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES
) )
847 RT_START_TEST(Collapse_and_GetFirstCategory_and_GetNextCategory
)
849 for ( i
=0; i
<3; i
++ )
851 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
853 wxPropertyGridIterator it
;
855 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
859 wxPGProperty
* p
= *it
;
861 if ( !page
->IsPropertyCategory(p
) )
866 t
.Printf(wxT("Collapsing: %s\n"),page
->GetPropertyLabel(p
).c_str());
873 RT_START_TEST(Save_And_RestoreEditableState
)
875 for ( i
=0; i
<3; i
++ )
877 pgman
->SelectPage(i
);
879 wxString stringState
= pgman
->SaveEditableState();
880 bool res
= pgman
->RestoreEditableState(stringState
);
886 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
888 RT_START_TEST(Expand_and_GetFirstCategory_and_GetNextCategory
)
890 for ( i
=0; i
<3; i
++ )
892 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
894 wxPropertyGridIterator it
;
896 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
900 wxPGProperty
* p
= *it
;
902 if ( !page
->IsPropertyCategory(p
) )
907 t
.Printf(wxT("Expand: %s\n"),page
->GetPropertyLabel(p
).c_str());
914 RT_START_TEST(Choice_Manipulation
)
916 wxPGProperty
* enumProp
= pgman
->GetProperty(wxT("EnumProperty"));
918 pgman
->SelectPage(2);
919 pgman
->SelectProperty(enumProp
);
920 wxASSERT(pgman
->GetGrid()->GetSelection() == enumProp
);
922 const wxPGChoices
& choices
= enumProp
->GetChoices();
923 int ind
= enumProp
->InsertChoice(wxT("New Choice"), choices
.GetCount()/2);
924 enumProp
->DeleteChoice(ind
);
926 // Recreate the original grid
927 CreateGrid( -1, -1 );
928 pgman
= m_pPropGridManager
;
931 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
933 RT_START_TEST(RandomCollapse
)
935 // Select the most error prone page as visible.
936 pgman
->SelectPage(1);
938 for ( i
=0; i
<3; i
++ )
942 wxPropertyGridPage
* page
= pgman
->GetPage(i
);
944 wxPropertyGridIterator it
;
946 for ( it
= page
->GetIterator( wxPG_ITERATE_CATEGORIES
);
953 if ( arr
.GetCount() )
957 pgman
->Collapse( (wxPGProperty
*)arr
.Item(0) );
959 for ( n
=arr
.GetCount()-1; n
>0; n
-- )
961 pgman
->Collapse( (wxPGProperty
*)arr
.Item(n
) );
969 RT_START_TEST(EnsureVisible
)
970 pgman
->EnsureVisible(wxT("Cell Colour"));
974 RT_START_TEST(SetPropertyBackgroundColour
)
976 evt
.SetInt(1); // IsChecked() will return TRUE.
977 evt
.SetId(ID_COLOURSCHEME4
);
983 RT_START_TEST(ManagerClear
)
986 if ( pgman
->GetPageCount() )
989 // Recreate the original grid
990 CreateGrid( -1, -1 );
991 pgman
= m_pPropGridManager
;
996 // TODO: This test fails.
997 RT_START_TEST(SetSplitterPosition)
1001 const int trySplitterPos = 50;
1003 int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
1004 pgman = m_pPropGridManager =
1005 new wxPropertyGridManager(m_panel, wxID_ANY,
1011 pgman->SetSplitterPosition(trySplitterPos);
1013 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1014 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1016 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
1019 wxSize sz = GetSize();
1024 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1025 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1029 // Recreate the original grid
1030 CreateGrid( -1, -1 );
1031 pgman = m_pPropGridManager;
1036 RT_START_TEST(HideProperty
)
1038 wxPropertyGridPage
* page
= pgman
->GetPage(0);
1042 wxArrayPGProperty arr1
;
1044 arr1
= GetPropertiesInRandomOrder(page
);
1048 for ( i
=0; i
<arr1
.size(); i
++ )
1050 wxPGProperty
* p
= arr1
[i
];
1051 page
->HideProperty(p
, true);
1053 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1054 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1062 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1064 for ( i
=0; i
<arr2
.size(); i
++ )
1066 wxPGProperty
* p
= arr2
[i
];
1067 page
->HideProperty(p
, false);
1069 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1070 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1077 // Let's do some more, for better consistency
1078 arr1
= GetPropertiesInRandomOrder(page
);
1082 for ( i
=0; i
<arr1
.size(); i
++ )
1084 wxPGProperty
* p
= arr1
[i
];
1085 page
->HideProperty(p
, true);
1087 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1088 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1096 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1098 for ( i
=0; i
<arr2
.size(); i
++ )
1100 wxPGProperty
* p
= arr2
[i
];
1101 page
->HideProperty(p
, false);
1103 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1104 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1111 // Ok, this time only hide half of them
1112 arr1
= GetPropertiesInRandomOrder(page
);
1113 arr1
.resize(arr1
.size()/2);
1117 for ( i
=0; i
<arr1
.size(); i
++ )
1119 wxPGProperty
* p
= arr1
[i
];
1120 page
->HideProperty(p
, true);
1122 wxString s
= wxString::Format(wxT("HideProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1123 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1131 wxArrayPGProperty arr2
= GetPropertiesInRandomOrder(page
);
1133 for ( i
=0; i
<arr2
.size(); i
++ )
1135 wxPGProperty
* p
= arr2
[i
];
1136 page
->HideProperty(p
, false);
1138 wxString s
= wxString::Format(wxT("ShowProperty(%i, %s)"), i
, p
->GetLabel().c_str());
1139 RT_VALIDATE_VIRTUAL_HEIGHT(page
, s
)
1145 // Recreate the original grid
1146 CreateGrid( -1, -1 );
1147 pgman
= m_pPropGridManager
;
1152 RT_START_TEST(MultipleColumns
)
1154 // Test with multiple columns
1155 // FIXME: Does not display changes.
1156 for ( i
=3; i
<12; i
+=2 )
1158 RT_MSG(wxString::Format(wxT("%i columns"),i
));
1159 CreateGrid( -1, -1 );
1160 pgman
= m_pPropGridManager
;
1161 pgman
->SetColumnCount(i
);
1170 RT_START_TEST(WindowStyles
)
1172 // Recreate grid with all possible (single) flags
1173 wxASSERT(wxPG_AUTO_SORT
== 0x000000010);
1175 for ( i
=4; i
<16; i
++ )
1178 RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag
));
1179 CreateGrid( flag
, -1 );
1180 pgman
= m_pPropGridManager
;
1185 wxASSERT(wxPG_EX_INIT_NOCAT
== 0x00001000);
1187 for ( i
=12; i
<24; i
++ )
1190 RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag
));
1191 CreateGrid( -1, flag
);
1192 pgman
= m_pPropGridManager
;
1197 // Recreate the original grid
1198 CreateGrid( -1, -1 );
1199 pgman
= m_pPropGridManager
;
1206 if ( failures
|| errorMessages
.size() )
1214 s
= wxString::Format(wxT("%i tests failed!!!"), failures
);
1217 s
= wxString::Format(wxT("All tests were succesfull, but there were %i warnings!"), wxPGGlobalVars
->m_warnings
);
1220 for ( i
=0; i
<errorMessages
.size(); i
++ )
1221 RT_MSG(errorMessages
[i
])
1222 wxMessageBox(s
, wxT("Some Tests Failed"));
1226 RT_MSG(wxT("All tests succesfull"))
1233 pgman
->SelectPage(0);
1235 // Test may screw up the toolbar, so we need to refresh it.
1236 wxToolBar
* toolBar
= pgman
->GetToolBar();
1243 // -----------------------------------------------------------------------