clientsize.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/controls/clientsize.cpp
  3. // Purpose: Client vs. window size handling unit test
  4. // Author: Vaclav Slavik
  5. // Created: 2008-02-12
  6. // Copyright: (c) 2008 Vaclav Slavik <vslavik@fastmail.fm>
  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. // ----------------------------------------------------------------------------
  20. // test class
  21. // ----------------------------------------------------------------------------
  22. class ClientSizeTestCase : public CppUnit::TestCase
  23. {
  24. public:
  25. ClientSizeTestCase() { }
  26. virtual void setUp();
  27. virtual void tearDown();
  28. private:
  29. CPPUNIT_TEST_SUITE( ClientSizeTestCase );
  30. CPPUNIT_TEST( ClientToWindow );
  31. CPPUNIT_TEST( ClientSizeNotNegative );
  32. CPPUNIT_TEST( WindowToClient );
  33. CPPUNIT_TEST_SUITE_END();
  34. void ClientToWindow();
  35. void ClientSizeNotNegative();
  36. void WindowToClient();
  37. wxWindow *m_win;
  38. DECLARE_NO_COPY_CLASS(ClientSizeTestCase)
  39. };
  40. // register in the unnamed registry so that these tests are run by default
  41. CPPUNIT_TEST_SUITE_REGISTRATION( ClientSizeTestCase );
  42. // also include in its own registry so that these tests can be run alone
  43. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ClientSizeTestCase, "ClientSizeTestCase" );
  44. // ----------------------------------------------------------------------------
  45. // test initialization
  46. // ----------------------------------------------------------------------------
  47. void ClientSizeTestCase::setUp()
  48. {
  49. m_win = wxTheApp->GetTopWindow();
  50. }
  51. void ClientSizeTestCase::tearDown()
  52. {
  53. m_win = NULL;
  54. }
  55. // ----------------------------------------------------------------------------
  56. // tests themselves
  57. // ----------------------------------------------------------------------------
  58. void ClientSizeTestCase::ClientToWindow()
  59. {
  60. CPPUNIT_ASSERT(m_win->GetSize() ==
  61. m_win->ClientToWindowSize(m_win->GetClientSize()));
  62. }
  63. void ClientSizeTestCase::ClientSizeNotNegative()
  64. {
  65. wxWindow* w = new wxWindow(wxTheApp->GetTopWindow(), -1,
  66. wxDefaultPosition, wxDefaultSize,
  67. wxBORDER_THEME);
  68. w->SetSize(wxSize(1,1));
  69. const wxSize szw = w->GetClientSize();
  70. CPPUNIT_ASSERT(szw.GetWidth() >= 0);
  71. CPPUNIT_ASSERT(szw.GetHeight() >= 0);
  72. w->Destroy();
  73. }
  74. void ClientSizeTestCase::WindowToClient()
  75. {
  76. CPPUNIT_ASSERT(m_win->GetClientSize() ==
  77. m_win->WindowToClientSize(m_win->GetSize()));
  78. }