toplevel.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/toplevel/toplevel.cpp
  3. // Purpose: Tests for wxTopLevelWindow
  4. // Author: Kevin Ollivier
  5. // Created: 2008-05-25
  6. // Copyright: (c) 2009 Kevin Ollivier <kevino@theolliviers.com>
  7. ///////////////////////////////////////////////////////////////////////////////
  8. // ----------------------------------------------------------------------------
  9. // headers
  10. // ----------------------------------------------------------------------------
  11. #include "testprec.h"
  12. #ifdef __BORLANDC__
  13. #pragma hdrstop
  14. #endif
  15. #ifndef WX_PRECOMP
  16. #include "wx/dialog.h"
  17. #include "wx/frame.h"
  18. #include "wx/textctrl.h"
  19. #include "wx/toplevel.h"
  20. #endif // WX_PRECOMP
  21. #include "wx/evtloop.h"
  22. // ----------------------------------------------------------------------------
  23. // test class
  24. // ----------------------------------------------------------------------------
  25. class TopLevelWindowTestCase : public CppUnit::TestCase
  26. {
  27. public:
  28. TopLevelWindowTestCase() { }
  29. private:
  30. CPPUNIT_TEST_SUITE( TopLevelWindowTestCase );
  31. CPPUNIT_TEST( DialogShowTest );
  32. CPPUNIT_TEST( FrameShowTest );
  33. CPPUNIT_TEST_SUITE_END();
  34. void DialogShowTest();
  35. void FrameShowTest();
  36. void TopLevelWindowShowTest(wxTopLevelWindow* tlw);
  37. DECLARE_NO_COPY_CLASS(TopLevelWindowTestCase)
  38. };
  39. // register in the unnamed registry so that these tests are run by default
  40. //CPPUNIT_TEST_SUITE_REGISTRATION( TopLevelWindowTestCase );
  41. // also include in its own registry so that these tests can be run alone
  42. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TopLevelWindowTestCase, "fixme" );
  43. // ----------------------------------------------------------------------------
  44. // tests themselves
  45. // ----------------------------------------------------------------------------
  46. void TopLevelWindowTestCase::DialogShowTest()
  47. {
  48. wxDialog* dialog = new wxDialog(NULL, -1, "Dialog Test");
  49. TopLevelWindowShowTest(dialog);
  50. dialog->Destroy();
  51. }
  52. void TopLevelWindowTestCase::FrameShowTest()
  53. {
  54. wxFrame* frame = new wxFrame(NULL, -1, "Frame test");
  55. TopLevelWindowShowTest(frame);
  56. frame->Destroy();
  57. }
  58. void TopLevelWindowTestCase::TopLevelWindowShowTest(wxTopLevelWindow* tlw)
  59. {
  60. CPPUNIT_ASSERT(!tlw->IsShown());
  61. wxTextCtrl* textCtrl = new wxTextCtrl(tlw, -1, "test");
  62. textCtrl->SetFocus();
  63. // only run this test on platforms where ShowWithoutActivating is implemented.
  64. #if defined(__WXMSW__) || defined(__WXMAC__)
  65. tlw->ShowWithoutActivating();
  66. CPPUNIT_ASSERT(tlw->IsShown());
  67. CPPUNIT_ASSERT(!tlw->IsActive());
  68. tlw->Hide();
  69. CPPUNIT_ASSERT(!tlw->IsShown());
  70. CPPUNIT_ASSERT(!tlw->IsActive());
  71. #endif
  72. tlw->Show(true);
  73. CPPUNIT_ASSERT(tlw->IsActive());
  74. CPPUNIT_ASSERT(tlw->IsShown());
  75. tlw->Hide();
  76. CPPUNIT_ASSERT(!tlw->IsShown());
  77. CPPUNIT_ASSERT(tlw->IsActive());
  78. }