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