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 // ----------------------------------------------------------------------------
10 // headers
11 // ----------------------------------------------------------------------------
12 
13 #include "testprec.h"
14 
15 #ifdef __BORLANDC__
16     #pragma hdrstop
17 #endif
18 
19 #ifndef WX_PRECOMP
20     #include "wx/app.h"
21     #include "wx/window.h"
22 #endif // WX_PRECOMP
23 
24 // ----------------------------------------------------------------------------
25 // test class
26 // ----------------------------------------------------------------------------
27 
28 class ClientSizeTestCase : public CppUnit::TestCase
29 {
30 public:
ClientSizeTestCase()31     ClientSizeTestCase() { }
32 
33     virtual void setUp();
34     virtual void tearDown();
35 
36 private:
37     CPPUNIT_TEST_SUITE( ClientSizeTestCase );
38         CPPUNIT_TEST( ClientToWindow );
39         CPPUNIT_TEST( ClientSizeNotNegative );
40         CPPUNIT_TEST( WindowToClient );
41     CPPUNIT_TEST_SUITE_END();
42 
43     void ClientToWindow();
44     void ClientSizeNotNegative();
45     void WindowToClient();
46 
47     wxWindow *m_win;
48 
49     DECLARE_NO_COPY_CLASS(ClientSizeTestCase)
50 };
51 
52 // register in the unnamed registry so that these tests are run by default
53 CPPUNIT_TEST_SUITE_REGISTRATION( ClientSizeTestCase );
54 
55 // also include in its own registry so that these tests can be run alone
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ClientSizeTestCase, "ClientSizeTestCase" );
57 
58 // ----------------------------------------------------------------------------
59 // test initialization
60 // ----------------------------------------------------------------------------
61 
setUp()62 void ClientSizeTestCase::setUp()
63 {
64     m_win = wxTheApp->GetTopWindow();
65 }
66 
tearDown()67 void ClientSizeTestCase::tearDown()
68 {
69     m_win = NULL;
70 }
71 
72 // ----------------------------------------------------------------------------
73 // tests themselves
74 // ----------------------------------------------------------------------------
75 
ClientToWindow()76 void ClientSizeTestCase::ClientToWindow()
77 {
78     CPPUNIT_ASSERT(m_win->GetSize() ==
79                    m_win->ClientToWindowSize(m_win->GetClientSize()));
80 }
81 
ClientSizeNotNegative()82 void ClientSizeTestCase::ClientSizeNotNegative()
83 {
84     wxWindow* w = new wxWindow(wxTheApp->GetTopWindow(), -1,
85                                wxDefaultPosition, wxDefaultSize,
86                                wxBORDER_THEME);
87     w->SetSize(wxSize(1,1));
88     const wxSize szw = w->GetClientSize();
89     CPPUNIT_ASSERT(szw.GetWidth() >= 0);
90     CPPUNIT_ASSERT(szw.GetHeight() >= 0);
91     w->Destroy();
92 }
93 
WindowToClient()94 void ClientSizeTestCase::WindowToClient()
95 {
96     CPPUNIT_ASSERT(m_win->GetClientSize() ==
97                    m_win->WindowToClientSize(m_win->GetSize()));
98 }
99