clone.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/events/clone.cpp
  3. // Purpose: Test wxEvent::Clone() implementation by all event classes
  4. // Author: Vadim Zeitlin, based on the code by Francesco Montorsi
  5. // Created: 2009-03-22
  6. // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
  7. ///////////////////////////////////////////////////////////////////////////////
  8. // ----------------------------------------------------------------------------
  9. // headers
  10. // ----------------------------------------------------------------------------
  11. #include "testprec.h"
  12. #ifdef __BORLANDC__
  13. #pragma hdrstop
  14. #endif
  15. #ifndef WX_PRECOMP
  16. #include "wx/event.h"
  17. #endif // WX_PRECOMP
  18. // --------------------------------------------------------------------------
  19. // test class
  20. // --------------------------------------------------------------------------
  21. class EventCloneTestCase : public CppUnit::TestCase
  22. {
  23. public:
  24. EventCloneTestCase() {}
  25. private:
  26. CPPUNIT_TEST_SUITE( EventCloneTestCase );
  27. CPPUNIT_TEST( CheckAll );
  28. CPPUNIT_TEST_SUITE_END();
  29. void CheckAll();
  30. DECLARE_NO_COPY_CLASS(EventCloneTestCase)
  31. };
  32. // register in the unnamed registry so that these tests are run by default
  33. CPPUNIT_TEST_SUITE_REGISTRATION( EventCloneTestCase );
  34. // also include in its own registry so that these tests can be run alone
  35. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EventCloneTestCase, "EventCloneTestCase" );
  36. void EventCloneTestCase::CheckAll()
  37. {
  38. // check if event classes implement Clone() correctly
  39. // NOTE: the check is done against _all_ event classes which are linked to
  40. // the executable currently running, which are not necessarily all
  41. // wxWidgets event classes.
  42. const wxClassInfo *ci = wxClassInfo::GetFirst();
  43. for (; ci; ci = ci->GetNext())
  44. {
  45. wxString cn = wxString(ci->GetClassName());
  46. // is this class derived from wxEvent?
  47. if ( !ci->IsKindOf(CLASSINFO(wxEvent)) ||
  48. cn == "wxEvent" )
  49. continue;
  50. const std::string
  51. msg = std::string("Event class \"") +
  52. std::string(cn.c_str()) + "\"";
  53. CPPUNIT_ASSERT_MESSAGE( msg, ci->IsDynamic() );
  54. wxEvent * const test = wxDynamicCast(ci->CreateObject(),wxEvent);
  55. CPPUNIT_ASSERT_MESSAGE( msg, test );
  56. wxEvent * const cloned = test->Clone();
  57. delete test;
  58. CPPUNIT_ASSERT_MESSAGE( msg, cloned );
  59. CPPUNIT_ASSERT_MESSAGE( msg, cloned->GetClassInfo() == ci );
  60. delete cloned;
  61. }
  62. }