setsize.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/window/setsize.cpp
  3. // Purpose: Tests for SetSize() and related wxWindow methods
  4. // Author: Vadim Zeitlin
  5. // Created: 2008-05-25
  6. // Copyright: (c) 2008 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/app.h"
  17. #include "wx/window.h"
  18. #endif // WX_PRECOMP
  19. #include "asserthelper.h"
  20. // ----------------------------------------------------------------------------
  21. // test class
  22. // ----------------------------------------------------------------------------
  23. class SetSizeTestCase : public CppUnit::TestCase
  24. {
  25. public:
  26. SetSizeTestCase() { }
  27. virtual void setUp();
  28. virtual void tearDown();
  29. private:
  30. CPPUNIT_TEST_SUITE( SetSizeTestCase );
  31. CPPUNIT_TEST( SetSize );
  32. CPPUNIT_TEST( SetSizeLessThanMinSize );
  33. CPPUNIT_TEST( BestSize );
  34. CPPUNIT_TEST_SUITE_END();
  35. void SetSize();
  36. void SetSizeLessThanMinSize();
  37. void BestSize();
  38. // Helper class overriding DoGetBestSize() for testing purposes.
  39. class MyWindow : public wxWindow
  40. {
  41. public:
  42. MyWindow(wxWindow* parent)
  43. : wxWindow(parent, wxID_ANY)
  44. {
  45. }
  46. protected:
  47. virtual wxSize DoGetBestSize() const { return wxSize(50, 250); }
  48. };
  49. wxWindow *m_win;
  50. DECLARE_NO_COPY_CLASS(SetSizeTestCase)
  51. };
  52. // register in the unnamed registry so that these tests are run by default
  53. CPPUNIT_TEST_SUITE_REGISTRATION( SetSizeTestCase );
  54. // also include in its own registry so that these tests can be run alone
  55. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SetSizeTestCase, "SetSizeTestCase" );
  56. // ----------------------------------------------------------------------------
  57. // test initialization
  58. // ----------------------------------------------------------------------------
  59. void SetSizeTestCase::setUp()
  60. {
  61. m_win = new MyWindow(wxTheApp->GetTopWindow());
  62. }
  63. void SetSizeTestCase::tearDown()
  64. {
  65. delete m_win;
  66. m_win = NULL;
  67. }
  68. // ----------------------------------------------------------------------------
  69. // tests themselves
  70. // ----------------------------------------------------------------------------
  71. void SetSizeTestCase::SetSize()
  72. {
  73. const wxSize size(127, 35);
  74. m_win->SetSize(size);
  75. CPPUNIT_ASSERT_EQUAL( size, m_win->GetSize() );
  76. }
  77. void SetSizeTestCase::SetSizeLessThanMinSize()
  78. {
  79. m_win->SetMinSize(wxSize(100, 100));
  80. const wxSize size(200, 50);
  81. m_win->SetSize(size);
  82. CPPUNIT_ASSERT_EQUAL( size, m_win->GetSize() );
  83. }
  84. void SetSizeTestCase::BestSize()
  85. {
  86. CPPUNIT_ASSERT_EQUAL( wxSize(50, 250), m_win->GetBestSize() );
  87. m_win->SetMinSize(wxSize(100, 100));
  88. CPPUNIT_ASSERT_EQUAL( wxSize(100, 250), m_win->GetBestSize() );
  89. m_win->SetMaxSize(wxSize(200, 200));
  90. CPPUNIT_ASSERT_EQUAL( wxSize(100, 200), m_win->GetBestSize() );
  91. }