Test wxPropertyGrid::DoubleToString()
[wxWidgets.git] / samples / propgrid / tests.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/propgrid/tests.cpp
3 // Purpose: wxPropertyGrid tests
4 // Author: Jaakko Salli
5 // Modified by:
6 // Created: 2007-05-16
7 // RCS-ID: $Id$
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21
22 #include <wx/propgrid/propgrid.h>
23 #include <wx/propgrid/advprops.h>
24 #include <wx/propgrid/manager.h>
25
26 #include "propgrid.h"
27 #include "sampleprops.h"
28
29
30 // -----------------------------------------------------------------------
31 // wxTestCustomFlagsProperty
32 // -----------------------------------------------------------------------
33
34 //
35 // Test customizing wxColourProperty via subclassing
36 //
37 // * Includes custom colour entry.
38 // * Includes extra custom entry.
39 //
40 class MyColourProperty : public wxColourProperty
41 {
42 public:
43 MyColourProperty( const wxString& label = wxPG_LABEL,
44 const wxString& name = wxPG_LABEL,
45 const wxColour& value = *wxWHITE )
46 : wxColourProperty(label, name, value)
47 {
48 wxPGChoices colours;
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"));
56 m_choices = colours;
57 SetIndex(0);
58 wxVariant variant;
59 variant << value;
60 SetValue(variant);
61 }
62
63 virtual ~MyColourProperty()
64 {
65 }
66
67 virtual wxColour GetColour( int index ) const
68 {
69 switch (index)
70 {
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;
76 case 5:
77 // Return current colour for the custom entry
78 wxColour col;
79 if ( GetIndex() == GetCustomColourIndex() )
80 {
81 if ( m_value.IsNull() )
82 return col;
83 col << m_value;
84 return col;
85 }
86 return *wxWHITE;
87 };
88 return wxColour();
89 }
90
91 virtual wxString ColourToString( const wxColour& col, int index ) const
92 {
93 if ( index == (int)(m_choices.GetCount()-1) )
94 return wxT("");
95
96 return wxColourProperty::ColourToString(col, index);
97 }
98
99 virtual int GetCustomColourIndex() const
100 {
101 return m_choices.GetCount()-2;
102 }
103 };
104
105
106 void FormMain::AddTestProperties( wxPropertyGridPage* pg )
107 {
108 pg->Append( new MyColourProperty(wxT("CustomColourProperty"), wxPG_LABEL, *wxGREEN) );
109 pg->GetProperty(wxT("CustomColourProperty"))->SetAutoUnspecified(true);
110 pg->SetPropertyEditor( wxT("CustomColourProperty"), wxPGEditor_ComboBox );
111
112 pg->SetPropertyHelpString(wxT("CustomColourProperty"),
113 wxT("This is a MyColourProperty from the sample app. ")
114 wxT("It is built by subclassing wxColourProperty."));
115 }
116
117 // -----------------------------------------------------------------------
118
119 void FormMain::OnDumpList( wxCommandEvent& WXUNUSED(event) )
120 {
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.");
123 wxString t;
124
125 wxDialog* dlg = new wxDialog(this,-1,wxT("wxVariant Test"),
126 wxDefaultPosition,wxDefaultSize,wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);
127
128 unsigned int i;
129 for ( i = 0; i < (unsigned int)values.GetCount(); i++ )
130 {
131 wxVariant& v = values[i];
132
133 wxString strValue = v.GetString();
134
135 #if wxCHECK_VERSION(2,8,0)
136 if ( v.GetName().EndsWith(wxT("@attr")) )
137 #else
138 if ( v.GetName().Right(5) == wxT("@attr") )
139 #endif
140 {
141 text += wxString::Format(wxT("Attributes:\n"));
142
143 unsigned int n;
144 for ( n = 0; n < (unsigned int)v.GetCount(); n++ )
145 {
146 wxVariant& a = v[n];
147
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());
150 text += t;
151 }
152 }
153 else
154 {
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());
157 text += t;
158 }
159 }
160
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,
167 wxTE_MULTILINE);
168 rowsizer->Add( ed, 1, wxEXPAND|wxALL, spacing );
169 topsizer->Add( rowsizer, 1, wxEXPAND, 0 );
170 rowsizer = new wxBoxSizer( wxHORIZONTAL );
171 const int butSzFlags =
172 wxALIGN_CENTRE_HORIZONTAL|wxALIGN_CENTRE_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT;
173 rowsizer->Add( new wxButton(dlg,wxID_OK,wxT("Ok")),
174 0, butSzFlags, spacing );
175 topsizer->Add( rowsizer, 0, wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL, 0 );
176
177 dlg->SetSizer( topsizer );
178 topsizer->SetSizeHints( dlg );
179
180 dlg->SetSize(400,300);
181 dlg->Centre();
182 dlg->ShowModal();
183 }
184
185 // -----------------------------------------------------------------------
186
187 class TestRunner
188 {
189 public:
190
191 TestRunner( const wxString& name, wxPropertyGridManager* man, wxTextCtrl* ed, wxArrayString* errorMessages )
192 {
193 m_name = name;
194 m_man = man;
195 m_ed = ed;
196 m_errorMessages = errorMessages;
197 #ifdef __WXDEBUG__
198 m_preWarnings = wxPGGlobalVars->m_warnings;
199 #endif
200
201 if ( name != wxT("none") )
202 Msg(name+wxT("\n"));
203 }
204
205 ~TestRunner()
206 {
207 #ifdef __WXDEBUG__
208 int warningsOccurred = wxPGGlobalVars->m_warnings - m_preWarnings;
209 if ( warningsOccurred )
210 {
211 wxString s = wxString::Format(wxT("%i warnings occurred during test '%s'"), warningsOccurred, m_name.c_str());
212 m_errorMessages->push_back(s);
213 Msg(s);
214 }
215 #endif
216 }
217
218 void Msg( const wxString& text )
219 {
220 if ( m_ed )
221 {
222 m_ed->AppendText(text);
223 m_ed->AppendText(wxT("\n"));
224 }
225 wxLogDebug(text);
226 }
227
228 protected:
229 wxPropertyGridManager* m_man;
230 wxTextCtrl* m_ed;
231 wxArrayString* m_errorMessages;
232 wxString m_name;
233 #ifdef __WXDEBUG__
234 int m_preWarnings;
235 #endif
236 };
237
238
239 #define RT_START_TEST(TESTNAME) \
240 TestRunner tr(wxT(#TESTNAME), pgman, ed, &errorMessages);
241
242 #define RT_MSG(S) \
243 tr.Msg(S);
244
245 #define RT_FAILURE() \
246 { \
247 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
248 errorMessages.push_back(s1); \
249 wxLogDebug(s1); \
250 failures++; \
251 }
252
253 #define RT_ASSERT(COND) \
254 if (!(COND)) \
255 RT_FAILURE()
256
257 #define RT_FAILURE_MSG(MSG) \
258 { \
259 wxString s1 = wxString::Format(wxT("Test failure in tests.cpp, line %i."),__LINE__-1); \
260 errorMessages.push_back(s1); \
261 wxLogDebug(s1); \
262 wxString s2 = wxString::Format(wxT("Message: %s"),MSG); \
263 errorMessages.push_back(s2); \
264 wxLogDebug(s2); \
265 failures++; \
266 }
267
268 #define RT_VALIDATE_VIRTUAL_HEIGHT(PROPS, EXTRATEXT) \
269 { \
270 unsigned int h1_ = PROPS->GetVirtualHeight(); \
271 unsigned int h2_ = PROPS->GetActualVirtualHeight(); \
272 if ( h1_ != h2_ ) \
273 { \
274 wxString s_ = wxString::Format(wxT("VirtualHeight = %i, should be %i (%s)"), h1_, h2_, EXTRATEXT.c_str()); \
275 RT_FAILURE_MSG(s_.c_str()); \
276 _failed_ = true; \
277 } \
278 else \
279 { \
280 _failed_ = false; \
281 } \
282 }
283
284
285 int gpiro_cmpfunc(const void* a, const void* b)
286 {
287 const wxPGProperty* p1 = (const wxPGProperty*) a;
288 const wxPGProperty* p2 = (const wxPGProperty*) b;
289 return (int) (((size_t)p1->GetClientData()) - ((size_t)p2->GetClientData()));
290 }
291
292 wxArrayPGProperty GetPropertiesInRandomOrder( wxPropertyGridInterface* props, int iterationFlags = wxPG_ITERATE_ALL )
293 {
294 wxArrayPGProperty arr;
295
296 wxPropertyGridIterator it;
297
298 for ( it = props->GetIterator(iterationFlags);
299 !it.AtEnd();
300 it++ )
301 {
302 wxPGProperty* p = *it;
303 size_t randomNumber = rand();
304 p->SetClientData(reinterpret_cast<void*>(randomNumber));
305 arr.push_back(p);
306 }
307
308 wxPGProperty** firstEntry = &arr[0];
309 qsort(firstEntry, arr.size(), sizeof(wxPGProperty*), gpiro_cmpfunc);
310
311 return arr;
312 }
313
314 // Callback for testing property sorting
315 int MyPropertySortFunction(wxPropertyGrid* WXUNUSED(propGrid),
316 wxPGProperty* p1,
317 wxPGProperty* p2)
318 {
319 // Reverse alphabetical order
320 return p2->GetLabel().CmpNoCase( p1->GetBaseName() );
321 }
322
323 bool FormMain::RunTests( bool fullTest, bool interactive )
324 {
325 wxString t;
326
327 wxPropertyGridManager* pgman = m_pPropGridManager;
328 wxPropertyGrid* pg;
329
330 size_t i;
331
332 pgman->ClearSelection();
333
334 int failures = 0;
335 bool _failed_ = false;
336 wxArrayString errorMessages;
337 wxDialog* dlg = NULL;
338
339 dlg = new wxDialog(this,-1,wxT("wxPropertyGrid Regression Tests"),
340 wxDefaultPosition,wxDefaultSize,wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);
341
342 // multi-line text editor dialog
343 const int spacing = 8;
344 wxBoxSizer* topsizer = new wxBoxSizer( wxVERTICAL );
345 wxBoxSizer* rowsizer = new wxBoxSizer( wxHORIZONTAL );
346 wxTextCtrl* ed = new wxTextCtrl(dlg, 11, wxEmptyString,
347 wxDefaultPosition, wxDefaultSize,
348 wxTE_MULTILINE);
349 rowsizer->Add( ed, 1, wxEXPAND|wxALL, spacing );
350 topsizer->Add( rowsizer, 1, wxEXPAND, 0 );
351 rowsizer = new wxBoxSizer( wxHORIZONTAL );
352 const int butSzFlags =
353 wxALIGN_CENTRE_HORIZONTAL|wxALIGN_CENTRE_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT;
354 rowsizer->Add( new wxButton(dlg,wxID_OK,wxT("Ok")),
355 0, butSzFlags, spacing );
356 topsizer->Add( rowsizer, 0, wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL, 0 );
357
358 dlg->SetSizer( topsizer );
359 topsizer->SetSizeHints( dlg );
360
361 dlg->SetSize(400,300);
362 dlg->Move(wxSystemSettings::GetMetric(wxSYS_SCREEN_X)-dlg->GetSize().x,
363 wxSystemSettings::GetMetric(wxSYS_SCREEN_Y)-dlg->GetSize().y);
364 dlg->Show();
365
366 {
367 //
368 // Basic iterator tests
369 RT_START_TEST(GetIterator)
370
371 wxPGVIterator it;
372 int count;
373
374 count = 0;
375 for ( it = pgman->GetVIterator(wxPG_ITERATE_PROPERTIES);
376 !it.AtEnd();
377 it.Next() )
378 {
379 wxPGProperty* p = it.GetProperty();
380 if ( p->IsCategory() )
381 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a category (non-private child property expected)"),p->GetLabel().c_str()).c_str())
382 else if ( p->GetParent()->HasFlag(wxPG_PROP_AGGREGATE) )
383 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property expected)"),p->GetLabel().c_str()).c_str())
384 count++;
385 }
386
387 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES) -> %i entries"), count));
388
389 count = 0;
390 for ( it = pgman->GetVIterator(wxPG_ITERATE_CATEGORIES);
391 !it.AtEnd();
392 it.Next() )
393 {
394 wxPGProperty* p = it.GetProperty();
395 if ( !p->IsCategory() )
396 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is not a category (only category was expected)"),p->GetLabel().c_str()).c_str())
397 count++;
398 }
399
400 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_CATEGORIES) -> %i entries"), count));
401
402 count = 0;
403 for ( it = pgman->GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES);
404 !it.AtEnd();
405 it.Next() )
406 {
407 wxPGProperty* p = it.GetProperty();
408 if ( p->GetParent()->HasFlag(wxPG_PROP_AGGREGATE) )
409 RT_FAILURE_MSG(wxString::Format(wxT("'%s' is a private child (non-private child property or category expected)"),p->GetLabel().c_str()).c_str())
410 count++;
411 }
412
413 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_PROPERTIES|wxPG_ITERATE_CATEGORIES) -> %i entries"), count));
414
415 count = 0;
416 for ( it = pgman->GetVIterator(wxPG_ITERATE_VISIBLE);
417 !it.AtEnd();
418 it.Next() )
419 {
420 wxPGProperty* p = it.GetProperty();
421 if ( (p->GetParent() != p->GetParentState()->DoGetRoot() && !p->GetParent()->IsExpanded()) )
422 RT_FAILURE_MSG(wxString::Format(wxT("'%s' had collapsed parent (only visible properties expected)"),p->GetLabel().c_str()).c_str())
423 else if ( p->HasFlag(wxPG_PROP_HIDDEN) )
424 RT_FAILURE_MSG(wxString::Format(wxT("'%s' was hidden (only visible properties expected)"),p->GetLabel().c_str()).c_str())
425 count++;
426 }
427
428 RT_MSG(wxString::Format(wxT("GetVIterator(wxPG_ITERATE_VISIBLE) -> %i entries"), count));
429 }
430
431 if ( fullTest )
432 {
433 // Test that setting focus to properties does not crash things
434 RT_START_TEST(SelectProperty)
435
436 wxPropertyGridIterator it;
437 size_t ind;
438
439 for ( ind=0; ind<pgman->GetPageCount(); ind++ )
440 {
441 wxPropertyGridPage* page = pgman->GetPage(ind);
442 pgman->SelectPage(page);
443
444 for ( it = page->GetIterator(wxPG_ITERATE_VISIBLE);
445 !it.AtEnd();
446 it++ )
447 {
448 wxPGProperty* p = *it;
449 RT_MSG(p->GetLabel());
450 pgman->GetGrid()->SelectProperty(p, true);
451 ::wxMilliSleep(150);
452 Update();
453 }
454 }
455 }
456
457 {
458 //
459 // Delete everything in reverse order
460 RT_START_TEST(DeleteProperty)
461
462 wxPGVIterator it;
463 wxArrayPGProperty array;
464
465 for ( it = pgman->GetVIterator(wxPG_ITERATE_ALL&~(wxPG_IT_CHILDREN(wxPG_PROP_AGGREGATE)));
466 !it.AtEnd();
467 it.Next() )
468 array.push_back(it.GetProperty());
469
470 wxArrayPGProperty::reverse_iterator it2;
471
472 for ( it2 = array.rbegin(); it2 != array.rend(); it2++ )
473 {
474 wxPGProperty* p = (wxPGProperty*)*it2;
475 RT_MSG(wxString::Format(wxT("Deleting '%s' ('%s')"),p->GetLabel().c_str(),p->GetName().c_str()));
476 pgman->DeleteProperty(p);
477 }
478
479 // Recreate grid
480 CreateGrid( -1, -1 );
481 pgman = m_pPropGridManager;
482 }
483
484 {
485 //
486 // Test property default values
487 RT_START_TEST(Default_Values)
488
489 wxPGVIterator it;
490
491 for ( it = pgman->GetVIterator(wxPG_ITERATE_PROPERTIES);
492 !it.AtEnd();
493 it.Next() )
494 {
495 wxPGProperty* p = it.GetProperty();
496 pgman->SetPropertyValue(p, p->GetDefaultValue());
497 }
498
499 // Recreate grid
500 CreateGrid( -1, -1 );
501 pgman = m_pPropGridManager;
502 }
503
504 {
505 //
506 // Test wxAny<->wxVariant conversion
507 RT_START_TEST(WXVARIANT_TO_WXANY_CONVERSION)
508
509 wxPGProperty* prop;
510 wxAny any;
511
512 #if wxUSE_DATETIME
513 prop = pgman->GetProperty("DateProperty");
514 wxDateTime testTime = wxDateTime::Now();
515 any = testTime;
516 prop->SetValue(any);
517 if ( wxANY_AS(prop->GetValue().GetAny(), wxDateTime) != testTime )
518 RT_FAILURE();
519 #endif
520
521 prop = pgman->GetProperty("IntProperty");
522 int testInt = 25537983;
523 any = testInt;
524 prop->SetValue(any);
525 if ( wxANY_AS(prop->GetValue().GetAny(), int) != testInt )
526 RT_FAILURE();
527 #ifdef wxLongLong_t
528 if ( wxANY_AS(prop->GetValue().GetAny(), wxLongLong_t) != testInt )
529 RT_FAILURE();
530 #endif
531
532 prop = pgman->GetProperty("StringProperty");
533 wxString testString = "asd934jfyn3";
534 any = testString;
535 prop->SetValue(any);
536 if ( wxANY_AS(prop->GetValue().GetAny(), wxString) != testString )
537 RT_FAILURE();
538
539 // Test with a type generated with IMPLEMENT_VARIANT_OBJECT()
540 prop = pgman->GetProperty("ColourProperty");
541 wxColour testCol = *wxCYAN;
542 any = testCol;
543 prop->SetValue(any);
544 if ( wxANY_AS(prop->GetValue().GetAny(), wxColour) != testCol )
545 RT_FAILURE();
546
547 // Test with a type with custom wxVariantData defined by
548 // wxPG headers.
549 prop = pgman->GetProperty("Position");
550 wxPoint testPoint(199, 199);
551 any = testPoint;
552 prop->SetValue(any);
553 if ( wxANY_AS(prop->GetValue().GetAny(), wxPoint) != testPoint )
554 RT_FAILURE();
555 }
556
557 {
558 RT_START_TEST(GetPropertyValues)
559
560 for ( i=0; i<3; i++ )
561 {
562 wxString text;
563
564 wxPropertyGridPage* page = pgman->GetPage(i);
565
566 wxVariant values = page->GetPropertyValues();
567
568 unsigned int i;
569 for ( i = 0; i < (unsigned int)values.GetCount(); i++ )
570 {
571 wxVariant& v = values[i];
572
573 t.Printf(wxT("%i: name=\"%s\" type=\"%s\"\n"),(int)i,
574 v.GetName().c_str(),v.GetType().c_str());
575
576 text += t;
577 }
578 ed->AppendText(text);
579 }
580 }
581
582 {
583 RT_START_TEST(SetPropertyValue_and_GetPropertyValue)
584
585 // In this section, mixed up usage of wxT("propname") and "propname"
586 // in wxPropertyGridInterface functions is intentional.
587 // Purpose is to test wxPGPropArgCls ctors.
588
589 //pg = (wxPropertyGrid*) NULL;
590
591 wxArrayString test_arrstr_1;
592 test_arrstr_1.Add(wxT("Apple"));
593 test_arrstr_1.Add(wxT("Orange"));
594 test_arrstr_1.Add(wxT("Lemon"));
595
596 wxArrayString test_arrstr_2;
597 test_arrstr_2.Add(wxT("Potato"));
598 test_arrstr_2.Add(wxT("Cabbage"));
599 test_arrstr_2.Add(wxT("Cucumber"));
600
601 wxArrayInt test_arrint_1;
602 test_arrint_1.Add(1);
603 test_arrint_1.Add(2);
604 test_arrint_1.Add(3);
605
606 wxArrayInt test_arrint_2;
607 test_arrint_2.Add(0);
608 test_arrint_2.Add(1);
609 test_arrint_2.Add(4);
610
611 #if wxUSE_DATETIME
612 wxDateTime dt1 = wxDateTime::Now();
613 dt1.SetYear(dt1.GetYear()-1);
614
615 wxDateTime dt2 = wxDateTime::Now();
616 dt2.SetYear(dt2.GetYear()-10);
617 #endif
618
619 #define FLAG_TEST_SET1 (wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER)
620 #define FLAG_TEST_SET2 (wxSTAY_ON_TOP|wxCAPTION|wxICONIZE|wxSYSTEM_MENU)
621
622 pgman->SetPropertyValue(wxT("StringProperty"),wxT("Text1"));
623 pgman->SetPropertyValue(wxT("IntProperty"),1024);
624 pgman->SetPropertyValue(wxT("FloatProperty"),1024.0000000001);
625 pgman->SetPropertyValue(wxT("BoolProperty"),FALSE);
626 pgman->SetPropertyValue(wxT("EnumProperty"),120);
627 pgman->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_1);
628 wxColour emptyCol;
629 pgman->SetPropertyValue(wxT("ColourProperty"),emptyCol);
630 pgman->SetPropertyValue(wxT("ColourProperty"),(wxObject*)wxBLACK);
631 pgman->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(150,150)));
632 pgman->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(150,150)));
633 pgman->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_1);
634 #if wxUSE_DATETIME
635 pgman->SetPropertyValue(wxT("DateProperty"),dt1);
636 #endif
637
638 pgman->SelectPage(2);
639 pg = pgman->GetGrid();
640
641 if ( pg->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text1") )
642 RT_FAILURE();
643 if ( pg->GetPropertyValueAsInt(wxT("IntProperty")) != 1024 )
644 RT_FAILURE();
645 if ( pg->GetPropertyValueAsDouble(wxT("FloatProperty")) != 1024.0000000001 )
646 RT_FAILURE();
647 if ( pg->GetPropertyValueAsBool(wxT("BoolProperty")) != FALSE )
648 RT_FAILURE();
649 if ( pg->GetPropertyValueAsLong(wxT("EnumProperty")) != 120 )
650 RT_FAILURE();
651 if ( pg->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_1 )
652 RT_FAILURE();
653 wxColour col;
654 col << pgman->GetPropertyValue(wxT("ColourProperty"));
655 if ( col != *wxBLACK )
656 RT_FAILURE();
657 wxVariant varSize(pg->GetPropertyValue(wxT("Size")));
658 if ( wxSizeRefFromVariant(varSize) != wxSize(150,150) )
659 RT_FAILURE();
660 wxVariant varPos(pg->GetPropertyValue(wxT("Position")));
661 if ( wxPointRefFromVariant(varPos) != wxPoint(150,150) )
662 RT_FAILURE();
663 if ( !(pg->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_1) )
664 RT_FAILURE();
665 #if wxUSE_DATETIME
666 if ( !(pg->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt1) )
667 RT_FAILURE();
668 #endif
669
670 pgman->SetPropertyValue(wxT("IntProperty"),wxLL(10000000000));
671 if ( pg->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(10000000000) )
672 RT_FAILURE();
673
674 pg->SetPropertyValue(wxT("StringProperty"),wxT("Text2"));
675 pg->SetPropertyValue(wxT("IntProperty"),512);
676 pg->SetPropertyValue(wxT("FloatProperty"),512.0);
677 pg->SetPropertyValue(wxT("BoolProperty"),TRUE);
678 pg->SetPropertyValue(wxT("EnumProperty"),80);
679 pg->SetPropertyValue(wxT("ArrayStringProperty"),test_arrstr_2);
680 pg->SetPropertyValue(wxT("ColourProperty"),(wxObject*)wxWHITE);
681 pg->SetPropertyValue(wxT("Size"),WXVARIANT(wxSize(300,300)));
682 pg->SetPropertyValue(wxT("Position"),WXVARIANT(wxPoint(300,300)));
683 pg->SetPropertyValue(wxT("MultiChoiceProperty"),test_arrint_2);
684 #if wxUSE_DATETIME
685 pg->SetPropertyValue(wxT("DateProperty"),dt2);
686 #endif
687
688 //pg = (wxPropertyGrid*) NULL;
689
690 pgman->SelectPage(0);
691
692 if ( pgman->GetPropertyValueAsString(wxT("StringProperty")) != wxT("Text2") )
693 RT_FAILURE();
694 if ( pgman->GetPropertyValueAsInt(wxT("IntProperty")) != 512 )
695 RT_FAILURE();
696 if ( pgman->GetPropertyValueAsDouble(wxT("FloatProperty")) != 512.0 )
697 RT_FAILURE();
698 if ( pgman->GetPropertyValueAsBool(wxT("BoolProperty")) != TRUE )
699 RT_FAILURE();
700 if ( pgman->GetPropertyValueAsLong(wxT("EnumProperty")) != 80 )
701 RT_FAILURE();
702 if ( pgman->GetPropertyValueAsArrayString(wxT("ArrayStringProperty")) != test_arrstr_2 )
703 RT_FAILURE();
704 col << pgman->GetPropertyValue(wxT("ColourProperty"));
705 if ( col != *wxWHITE )
706 RT_FAILURE();
707 varSize = pgman->GetPropertyValue(wxT("Size"));
708 if ( wxSizeRefFromVariant(varSize) != wxSize(300,300) )
709 RT_FAILURE();
710 varPos = pgman->GetPropertyValue(wxT("Position"));
711 if ( wxPointRefFromVariant(varPos) != wxPoint(300,300) )
712 RT_FAILURE();
713 if ( !(pgman->GetPropertyValueAsArrayInt(wxT("MultiChoiceProperty")) == test_arrint_2) )
714 RT_FAILURE();
715 #if wxUSE_DATETIME
716 if ( !(pgman->GetPropertyValueAsDateTime(wxT("DateProperty")) == dt2) )
717 RT_FAILURE();
718 #endif
719
720 pgman->SetPropertyValue(wxT("IntProperty"),wxLL(-80000000000));
721 if ( pgman->GetPropertyValueAsLongLong(wxT("IntProperty")) != wxLL(-80000000000) )
722 RT_FAILURE();
723
724 // Make sure children of composite parent get updated as well
725 // Original string value: "Lamborghini Diablo SV; 5707; [300; 3.9; 8.6] 300000; Not Convertible"
726
727 //
728 // This updates children as well
729 wxString nvs = "Lamborghini Diablo XYZ; 5707; [100; 3.9; 8.6] 3000002; Convertible";
730 pgman->SetPropertyValue("Car", nvs);
731
732 if ( pgman->GetPropertyValueAsString("Car.Model") != "Lamborghini Diablo XYZ" )
733 {
734 wxLogDebug("Did not match: Car.Model=%s", pgman->GetPropertyValueAsString("Car.Model").c_str());
735 RT_FAILURE();
736 }
737
738 if ( pgman->GetPropertyValueAsInt("Car.Speeds.Max. Speed (mph)") != 100 )
739 {
740 wxLogDebug("Did not match: Car.Speeds.Max. Speed (mph)=%s", pgman->GetPropertyValueAsString("Car.Speeds.Max. Speed (mph)").c_str());
741 RT_FAILURE();
742 }
743
744 if ( pgman->GetPropertyValueAsInt("Car.Price ($)") != 3000002 )
745 {
746 wxLogDebug("Did not match: Car.Price ($)=%s", pgman->GetPropertyValueAsString("Car.Price ($)").c_str());
747 RT_FAILURE();
748 }
749
750 if ( !pgman->GetPropertyValueAsBool("Car.Convertible") )
751 {
752 wxLogDebug("Did not match: Car.Convertible=%s", pgman->GetPropertyValueAsString("Car.Convertible").c_str());
753 RT_FAILURE();
754 }
755
756 // SetPropertyValueString for special cases such as wxColour
757 pgman->SetPropertyValueString("ColourProperty", "(123,4,255)");
758 col << pgman->GetPropertyValue("ColourProperty");
759 if ( col != wxColour(123, 4, 255) )
760 RT_FAILURE();
761 pgman->SetPropertyValueString("ColourProperty", "#FE860B");
762 col << pgman->GetPropertyValue("ColourProperty");
763 if ( col != wxColour(254, 134, 11) )
764 RT_FAILURE();
765 }
766
767 {
768 RT_START_TEST(SetPropertyValueUnspecified)
769
770 // Null variant setter tests
771 pgman->SetPropertyValueUnspecified(wxT("StringProperty"));
772 pgman->SetPropertyValueUnspecified(wxT("IntProperty"));
773 pgman->SetPropertyValueUnspecified(wxT("FloatProperty"));
774 pgman->SetPropertyValueUnspecified(wxT("BoolProperty"));
775 pgman->SetPropertyValueUnspecified(wxT("EnumProperty"));
776 pgman->SetPropertyValueUnspecified(wxT("ArrayStringProperty"));
777 pgman->SetPropertyValueUnspecified(wxT("ColourProperty"));
778 pgman->SetPropertyValueUnspecified(wxT("Size"));
779 pgman->SetPropertyValueUnspecified(wxT("Position"));
780 pgman->SetPropertyValueUnspecified(wxT("MultiChoiceProperty"));
781 #if wxUSE_DATETIME
782 pgman->SetPropertyValueUnspecified(wxT("DateProperty"));
783 #endif
784 }
785
786 {
787 //
788 // Test multiple selection
789 RT_START_TEST(MULTIPLE_SELECTION)
790 if ( !(pgman->GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION) )
791 CreateGrid( -1, wxPG_EX_MULTIPLE_SELECTION);
792 pgman = m_pPropGridManager;
793
794 wxPropertyGrid* pg = pgman->GetGrid();
795
796 wxPGProperty* prop1 = pg->GetProperty(wxT("Label"));
797 wxPGProperty* prop2 = pg->GetProperty(wxT("Cell Text Colour"));
798 wxPGProperty* prop3 = pg->GetProperty(wxT("Height"));
799 wxPGProperty* catProp = pg->GetProperty(wxT("Appearance"));
800
801 RT_ASSERT( prop1 && prop2 && prop3 );
802
803 pg->ClearSelection();
804 pg->AddToSelection(prop1);
805 pg->AddToSelection(prop2);
806 pg->AddToSelection(prop3);
807
808 // Adding category to selection should fail silently
809 pg->AddToSelection(catProp);
810
811 wxArrayPGProperty selectedProperties = pg->GetSelectedProperties();
812
813 RT_ASSERT( selectedProperties.size() == 3 )
814 RT_ASSERT( pg->IsPropertySelected(prop1) )
815 RT_ASSERT( pg->IsPropertySelected(prop2) )
816 RT_ASSERT( pg->IsPropertySelected(prop3) )
817 RT_ASSERT( !pg->IsPropertySelected(catProp) )
818
819 pg->RemoveFromSelection(prop1);
820 wxArrayPGProperty selectedProperties2 = pg->GetSelectedProperties();
821
822 RT_ASSERT( selectedProperties2.size() == 2 )
823 RT_ASSERT( !pg->IsPropertySelected(prop1) )
824 RT_ASSERT( pg->IsPropertySelected(prop2) )
825 RT_ASSERT( pg->IsPropertySelected(prop3) )
826
827 pg->ClearSelection();
828
829 wxArrayPGProperty selectedProperties3 = pg->GetSelectedProperties();
830
831 RT_ASSERT( selectedProperties3.size() == 0 )
832 RT_ASSERT( !pg->IsPropertySelected(prop1) )
833 RT_ASSERT( !pg->IsPropertySelected(prop2) )
834 RT_ASSERT( !pg->IsPropertySelected(prop3) )
835
836 pg->SelectProperty(prop2);
837
838 RT_ASSERT( !pg->IsPropertySelected(prop1) )
839 RT_ASSERT( pg->IsPropertySelected(prop2) )
840 RT_ASSERT( !pg->IsPropertySelected(prop3) )
841 }
842
843 {
844 //
845 // Test label editing
846 RT_START_TEST(LABEL_EDITING)
847
848 wxPropertyGrid* pg = pgman->GetGrid();
849
850 // Just mostly test that these won't crash
851 pg->MakeColumnEditable(0, true);
852 pg->MakeColumnEditable(2, true);
853 pg->MakeColumnEditable(0, false);
854 pg->MakeColumnEditable(2, false);
855 pg->SelectProperty(wxT("Height"));
856 pg->BeginLabelEdit(0);
857 pg->BeginLabelEdit(0);
858 pg->EndLabelEdit(0);
859 pg->EndLabelEdit(0);
860
861 // Recreate grid
862 CreateGrid( -1, -1 );
863 pgman = m_pPropGridManager;
864 }
865
866 {
867 RT_START_TEST(Attributes)
868
869 wxPGProperty* prop = pgman->GetProperty(wxT("StringProperty"));
870 prop->SetAttribute(wxT("Dummy Attribute"), (long)15);
871
872 if ( prop->GetAttribute(wxT("Dummy Attribute")).GetLong() != 15 )
873 RT_FAILURE();
874
875 prop->SetAttribute(wxT("Dummy Attribute"), wxVariant());
876
877 if ( !prop->GetAttribute(wxT("Dummy Attribute")).IsNull() )
878 RT_FAILURE();
879 }
880
881 {
882 RT_START_TEST(DoubleToString)
883
884 // Locale-specific decimal separator
885 wxString sep = wxString::Format("%g", 1.1)[1];
886
887 wxString s;
888
889 if ( wxPropertyGrid::DoubleToString(s, 123.123, 2, true) !=
890 wxString::Format("123%s12", sep.c_str()) )
891 RT_FAILURE();
892 if ( wxPropertyGrid::DoubleToString(s, -123.123, 4, false) !=
893 wxString::Format("-123%s1230", sep.c_str()) )
894 RT_FAILURE();
895 if ( wxPropertyGrid::DoubleToString(s, -0.02, 1, false) !=
896 wxString::Format("0%s0", sep) )
897 RT_FAILURE();
898 if ( wxPropertyGrid::DoubleToString(s, -0.000123, 3, true) != "0" )
899 RT_FAILURE();
900 }
901
902 {
903 wxPropertyGridPage* page1;
904 wxPropertyGridPage* page2;
905 wxPropertyGridPage* page3;
906 wxVariant pg1_values;
907 wxVariant pg2_values;
908 wxVariant pg3_values;
909
910 {
911 RT_START_TEST(GetPropertyValues)
912
913 page1 = pgman->GetPage(0);
914 pg1_values = page1->GetPropertyValues(wxT("Page1"),NULL,wxPG_KEEP_STRUCTURE);
915 page2 = pgman->GetPage(1);
916 pg2_values = page2->GetPropertyValues(wxT("Page2"),NULL,wxPG_KEEP_STRUCTURE);
917 page3 = pgman->GetPage(2);
918 pg3_values = page3->GetPropertyValues(wxT("Page3"),NULL,wxPG_KEEP_STRUCTURE);
919 }
920
921 {
922 RT_START_TEST(SetPropertyValues)
923
924 page1->SetPropertyValues(pg3_values);
925 page2->SetPropertyValues(pg1_values);
926 page3->SetPropertyValues(pg2_values);
927 }
928 }
929
930 if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
931 {
932 RT_START_TEST(Collapse_and_GetFirstCategory_and_GetNextCategory)
933
934 for ( i=0; i<3; i++ )
935 {
936 wxPropertyGridPage* page = pgman->GetPage(i);
937
938 wxPropertyGridIterator it;
939
940 for ( it = page->GetIterator( wxPG_ITERATE_CATEGORIES );
941 !it.AtEnd();
942 it++ )
943 {
944 wxPGProperty* p = *it;
945
946 if ( !page->IsPropertyCategory(p) )
947 RT_FAILURE();
948
949 page->Collapse( p );
950
951 t.Printf(wxT("Collapsing: %s\n"),page->GetPropertyLabel(p).c_str());
952 ed->AppendText(t);
953 }
954 }
955 }
956
957 {
958 RT_START_TEST(Save_And_RestoreEditableState)
959
960 for ( i=0; i<3; i++ )
961 {
962 pgman->SelectPage(i);
963
964 wxString stringState = pgman->SaveEditableState();
965 bool res = pgman->RestoreEditableState(stringState);
966 if ( !res )
967 RT_FAILURE();
968 }
969 }
970
971 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
972 {
973 RT_START_TEST(Expand_and_GetFirstCategory_and_GetNextCategory)
974
975 for ( i=0; i<3; i++ )
976 {
977 wxPropertyGridPage* page = pgman->GetPage(i);
978
979 wxPropertyGridIterator it;
980
981 for ( it = page->GetIterator( wxPG_ITERATE_CATEGORIES );
982 !it.AtEnd();
983 it++ )
984 {
985 wxPGProperty* p = *it;
986
987 if ( !page->IsPropertyCategory(p) )
988 RT_FAILURE();
989
990 page->Expand( p );
991
992 t.Printf(wxT("Expand: %s\n"),page->GetPropertyLabel(p).c_str());
993 ed->AppendText(t);
994 }
995 }
996 }
997
998 {
999 RT_START_TEST(Choice_Manipulation)
1000
1001 wxPGProperty* enumProp = pgman->GetProperty(wxT("EnumProperty"));
1002
1003 pgman->SelectPage(2);
1004 pgman->SelectProperty(enumProp);
1005 wxASSERT(pgman->GetGrid()->GetSelection() == enumProp);
1006
1007 const wxPGChoices& choices = enumProp->GetChoices();
1008 int ind = enumProp->InsertChoice(wxT("New Choice"), choices.GetCount()/2);
1009 enumProp->DeleteChoice(ind);
1010
1011 // Recreate the original grid
1012 CreateGrid( -1, -1 );
1013 pgman = m_pPropGridManager;
1014 }
1015
1016 //if ( !(pgman->GetWindowStyleFlag()&wxPG_HIDE_CATEGORIES) )
1017 {
1018 RT_START_TEST(RandomCollapse)
1019
1020 // Select the most error prone page as visible.
1021 pgman->SelectPage(1);
1022
1023 for ( i=0; i<3; i++ )
1024 {
1025 wxArrayPtrVoid arr;
1026
1027 wxPropertyGridPage* page = pgman->GetPage(i);
1028
1029 wxPropertyGridIterator it;
1030
1031 for ( it = page->GetIterator( wxPG_ITERATE_CATEGORIES );
1032 !it.AtEnd();
1033 it++ )
1034 {
1035 arr.Add((void*)*it);
1036 }
1037
1038 if ( arr.GetCount() )
1039 {
1040 size_t n;
1041
1042 pgman->Collapse( (wxPGProperty*)arr.Item(0) );
1043
1044 for ( n=arr.GetCount()-1; n>0; n-- )
1045 {
1046 pgman->Collapse( (wxPGProperty*)arr.Item(n) );
1047 }
1048 }
1049
1050 }
1051 }
1052
1053 {
1054 RT_START_TEST(EnsureVisible)
1055 pgman->EnsureVisible(wxT("Cell Colour"));
1056 }
1057
1058 {
1059 RT_START_TEST(RemoveProperty)
1060
1061 wxPGProperty* p;
1062
1063 wxPGProperty* origParent =
1064 pgman->GetProperty("Window Styles")->GetParent();
1065
1066 // For testing purposes, let's set some custom cell colours
1067 p = pgman->GetProperty("Window Styles");
1068 p->SetCell(2, wxPGCell("style"));
1069 p = pgman->RemoveProperty("Window Styles");
1070 pgman->Refresh();
1071 pgman->Update();
1072
1073 pgman->AppendIn(origParent, p);
1074 wxASSERT( p->GetCell(2).GetText() == "style");
1075 pgman->Refresh();
1076 pgman->Update();
1077 }
1078
1079 {
1080 RT_START_TEST(SortFunction)
1081
1082 wxPGProperty* p;
1083
1084 // Make sure indexes are as supposed
1085
1086 p = pgman->GetProperty(wxT("User Name"));
1087 if ( p->GetIndexInParent() != 3 )
1088 RT_FAILURE();
1089
1090 p = pgman->GetProperty(wxT("User Id"));
1091 if ( p->GetIndexInParent() != 2 )
1092 RT_FAILURE();
1093
1094 p = pgman->GetProperty(wxT("User Home"));
1095 if ( p->GetIndexInParent() != 1 )
1096 RT_FAILURE();
1097
1098 p = pgman->GetProperty(wxT("Operating System"));
1099 if ( p->GetIndexInParent() != 0 )
1100 RT_FAILURE();
1101
1102 pgman->GetGrid()->SetSortFunction(MyPropertySortFunction);
1103
1104 pgman->GetGrid()->SortChildren(wxT("Environment"));
1105
1106 // Make sure indexes have been reversed
1107 p = pgman->GetProperty(wxT("User Name"));
1108 if ( p->GetIndexInParent() != 0 )
1109 RT_FAILURE();
1110
1111 p = pgman->GetProperty(wxT("User Id"));
1112 if ( p->GetIndexInParent() != 1 )
1113 RT_FAILURE();
1114
1115 p = pgman->GetProperty(wxT("User Home"));
1116 if ( p->GetIndexInParent() != 2 )
1117 RT_FAILURE();
1118
1119 p = pgman->GetProperty(wxT("Operating System"));
1120 if ( p->GetIndexInParent() != 3 )
1121 RT_FAILURE();
1122 }
1123
1124 {
1125 RT_START_TEST(SetPropertyBackgroundColour)
1126 wxCommandEvent evt;
1127 evt.SetInt(1); // IsChecked() will return TRUE.
1128 evt.SetId(ID_COLOURSCHEME4);
1129 OnCatColours(evt);
1130 OnColourScheme(evt);
1131 }
1132
1133 {
1134 RT_START_TEST(Clear)
1135
1136 // Manager clear
1137 pgman->SelectProperty("Label");
1138 pgman->Clear();
1139
1140 if ( pgman->GetPageCount() )
1141 RT_FAILURE();
1142
1143 if ( pgman->GetGrid()->GetRoot()->GetChildCount() )
1144 RT_FAILURE();
1145
1146 // Recreate the original grid
1147 CreateGrid( -1, -1 );
1148 pgman = m_pPropGridManager;
1149
1150 // Grid clear
1151 pgman->SelectProperty("Label");
1152 pgman->GetGrid()->Clear();
1153
1154 if ( pgman->GetGrid()->GetRoot()->GetChildCount() )
1155 RT_FAILURE();
1156
1157 // Recreate the original grid
1158 CreateGrid( -1, -1 );
1159 pgman = m_pPropGridManager;
1160 }
1161
1162 /*{
1163 // TODO: This test fails.
1164 RT_START_TEST(SetSplitterPosition)
1165
1166 InitPanel();
1167
1168 const int trySplitterPos = 50;
1169
1170 int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
1171 pgman = m_pPropGridManager =
1172 new wxPropertyGridManager(m_panel, wxID_ANY,
1173 wxDefaultPosition,
1174 wxDefaultSize,
1175 style );
1176
1177 PopulateGrid();
1178 pgman->SetSplitterPosition(trySplitterPos);
1179
1180 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1181 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1182
1183 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
1184 FinalizePanel();
1185
1186 wxSize sz = GetSize();
1187 wxSize origSz = sz;
1188 sz.x += 5;
1189 sz.y += 5;
1190
1191 if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
1192 RT_FAILURE_MSG(wxString::Format(wxT("Splitter position was %i (should have been %i)"),(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos).c_str());
1193
1194 SetSize(origSz);
1195
1196 // Recreate the original grid
1197 CreateGrid( -1, -1 );
1198 pgman = m_pPropGridManager;
1199 }*/
1200
1201 {
1202 RT_START_TEST(HideProperty)
1203
1204 wxPropertyGridPage* page = pgman->GetPage(0);
1205
1206 srand(0x1234);
1207
1208 wxArrayPGProperty arr1;
1209
1210 arr1 = GetPropertiesInRandomOrder(page);
1211
1212 if ( !_failed_ )
1213 {
1214 for ( i=0; i<arr1.size(); i++ )
1215 {
1216 wxPGProperty* p = arr1[i];
1217 page->HideProperty(p, true);
1218
1219 wxString s = wxString::Format(wxT("HideProperty(%i, %s)"), i, p->GetLabel().c_str());
1220 RT_VALIDATE_VIRTUAL_HEIGHT(page, s)
1221 if ( _failed_ )
1222 break;
1223 }
1224 }
1225
1226 if ( !_failed_ )
1227 {
1228 wxArrayPGProperty arr2 = GetPropertiesInRandomOrder(page);
1229
1230 for ( i=0; i<arr2.size(); i++ )
1231 {
1232 wxPGProperty* p = arr2[i];
1233 page->HideProperty(p, false);
1234
1235 wxString s = wxString::Format(wxT("ShowProperty(%i, %s)"), i, p->GetLabel().c_str());
1236 RT_VALIDATE_VIRTUAL_HEIGHT(page, s)
1237 if ( _failed_ )
1238 break;
1239 }
1240 }
1241
1242 //
1243 // Let's do some more, for better consistency
1244 arr1 = GetPropertiesInRandomOrder(page);
1245
1246 if ( !_failed_ )
1247 {
1248 for ( i=0; i<arr1.size(); i++ )
1249 {
1250 wxPGProperty* p = arr1[i];
1251 page->HideProperty(p, true);
1252
1253 wxString s = wxString::Format(wxT("HideProperty(%i, %s)"), i, p->GetLabel().c_str());
1254 RT_VALIDATE_VIRTUAL_HEIGHT(page, s)
1255 if ( _failed_ )
1256 break;
1257 }
1258 }
1259
1260 if ( !_failed_ )
1261 {
1262 wxArrayPGProperty arr2 = GetPropertiesInRandomOrder(page);
1263
1264 for ( i=0; i<arr2.size(); i++ )
1265 {
1266 wxPGProperty* p = arr2[i];
1267 page->HideProperty(p, false);
1268
1269 wxString s = wxString::Format(wxT("ShowProperty(%i, %s)"), i, p->GetLabel().c_str());
1270 RT_VALIDATE_VIRTUAL_HEIGHT(page, s)
1271 if ( _failed_ )
1272 break;
1273 }
1274 }
1275
1276 //
1277 // Ok, this time only hide half of them
1278 arr1 = GetPropertiesInRandomOrder(page);
1279 arr1.resize(arr1.size()/2);
1280
1281 if ( !_failed_ )
1282 {
1283 for ( i=0; i<arr1.size(); i++ )
1284 {
1285 wxPGProperty* p = arr1[i];
1286 page->HideProperty(p, true);
1287
1288 wxString s = wxString::Format(wxT("HideProperty(%i, %s)"), i, p->GetLabel().c_str());
1289 RT_VALIDATE_VIRTUAL_HEIGHT(page, s)
1290 if ( _failed_ )
1291 break;
1292 }
1293 }
1294
1295 if ( !_failed_ )
1296 {
1297 wxArrayPGProperty arr2 = GetPropertiesInRandomOrder(page);
1298
1299 for ( i=0; i<arr2.size(); i++ )
1300 {
1301 wxPGProperty* p = arr2[i];
1302 page->HideProperty(p, false);
1303
1304 wxString s = wxString::Format(wxT("ShowProperty(%i, %s)"), i, p->GetLabel().c_str());
1305 RT_VALIDATE_VIRTUAL_HEIGHT(page, s)
1306 if ( _failed_ )
1307 break;
1308 }
1309 }
1310
1311 // Recreate the original grid
1312 CreateGrid( -1, -1 );
1313 pgman = m_pPropGridManager;
1314 }
1315
1316 if ( fullTest )
1317 {
1318 RT_START_TEST(MultipleColumns)
1319
1320 // Test with multiple columns
1321 // FIXME: Does not display changes.
1322 for ( i=3; i<12; i+=2 )
1323 {
1324 RT_MSG(wxString::Format(wxT("%i columns"),i));
1325 CreateGrid( -1, -1 );
1326 pgman = m_pPropGridManager;
1327 pgman->SetColumnCount(i);
1328 Refresh();
1329 Update();
1330 wxMilliSleep(500);
1331 }
1332 }
1333
1334 if ( fullTest )
1335 {
1336 RT_START_TEST(WindowStyles)
1337
1338 // Recreate grid with all possible (single) flags
1339 wxASSERT(wxPG_AUTO_SORT == 0x000000010);
1340
1341 for ( i=4; i<16; i++ )
1342 {
1343 int flag = 1<<i;
1344 RT_MSG(wxString::Format(wxT("Style: 0x%X"),flag));
1345 CreateGrid( flag, -1 );
1346 pgman = m_pPropGridManager;
1347 Update();
1348 wxMilliSleep(500);
1349 }
1350
1351 wxASSERT(wxPG_EX_INIT_NOCAT == 0x00001000);
1352
1353 for ( i=12; i<27; i++ )
1354 {
1355 int flag = 1<<i;
1356 RT_MSG(wxString::Format(wxT("ExStyle: 0x%X"),flag));
1357 CreateGrid( -1, flag );
1358 pgman = m_pPropGridManager;
1359 Update();
1360 wxMilliSleep(500);
1361 }
1362
1363 // Recreate the original grid
1364 CreateGrid( -1, -1 );
1365 pgman = m_pPropGridManager;
1366 }
1367
1368 RT_START_TEST(none)
1369
1370 bool retVal;
1371
1372 if ( failures || errorMessages.size() )
1373 {
1374 retVal = false;
1375
1376 wxString s;
1377 #ifdef __WXDEBUG__
1378 if ( failures )
1379 #endif
1380 s = wxString::Format(wxT("%i tests failed!!!"), failures);
1381 #ifdef __WXDEBUG__
1382 else
1383 s = wxString::Format(wxT("All tests were succesfull, but there were %i warnings!"), wxPGGlobalVars->m_warnings);
1384 #endif
1385 RT_MSG(s)
1386 for ( i=0; i<errorMessages.size(); i++ )
1387 RT_MSG(errorMessages[i])
1388 wxMessageBox(s, wxT("Some Tests Failed"));
1389 }
1390 else
1391 {
1392 RT_MSG(wxT("All tests succesfull"))
1393 retVal = true;
1394
1395 if ( !interactive )
1396 dlg->Close();
1397 }
1398
1399 pgman->SelectPage(0);
1400
1401 // Test may screw up the toolbar, so we need to refresh it.
1402 wxToolBar* toolBar = pgman->GetToolBar();
1403 if ( toolBar )
1404 toolBar->Refresh();
1405
1406 return retVal;
1407 }
1408
1409 // -----------------------------------------------------------------------