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