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