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