tests.cpp 44 KB

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