1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/misc/misctests.cpp
3 // Purpose: test miscellaneous GUI functions
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
23 #include "wx/gdicmn.h"
24 #include "wx/filefn.h"
28 #include "wx/button.h"
29 #include "wx/clipbrd.h"
30 #include "wx/dataobj.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 class MiscGUIFuncsTestCase
: public CppUnit::TestCase
39 MiscGUIFuncsTestCase() { }
42 CPPUNIT_TEST_SUITE( MiscGUIFuncsTestCase
);
43 CPPUNIT_TEST( DisplaySize
);
44 CPPUNIT_TEST( URLDataObject
);
45 CPPUNIT_TEST( ParseFileDialogFilter
);
46 CPPUNIT_TEST( FindWindowAtPoint
);
47 CPPUNIT_TEST_SUITE_END();
51 void ParseFileDialogFilter();
52 void FindWindowAtPoint();
54 DECLARE_NO_COPY_CLASS(MiscGUIFuncsTestCase
)
57 // register in the unnamed registry so that these tests are run by default
58 CPPUNIT_TEST_SUITE_REGISTRATION( MiscGUIFuncsTestCase
);
60 // also include in its own registry so that these tests can be run alone
61 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscGUIFuncsTestCase
, "MiscGUIFuncsTestCase" );
63 void MiscGUIFuncsTestCase::DisplaySize()
65 // test that different (almost) overloads return the same results
67 wxDisplaySize(&w
, &h
);
68 wxSize sz
= wxGetDisplaySize();
70 CPPUNIT_ASSERT_EQUAL( w
, sz
.x
);
71 CPPUNIT_ASSERT_EQUAL( h
, sz
.y
);
73 // test that passing NULL works as expected, e.g. doesn't crash
74 wxDisplaySize(NULL
, NULL
);
75 wxDisplaySize(&w
, NULL
);
76 wxDisplaySize(NULL
, &h
);
78 CPPUNIT_ASSERT_EQUAL( w
, sz
.x
);
79 CPPUNIT_ASSERT_EQUAL( h
, sz
.y
);
81 // test that display PPI is something reasonable
82 sz
= wxGetDisplayPPI();
83 CPPUNIT_ASSERT( sz
.x
< 1000 && sz
.y
< 1000 );
86 void MiscGUIFuncsTestCase::URLDataObject()
88 // this tests for buffer overflow, see #11102
90 url
= "http://something.long.to.overwrite.plenty.memory.example.com";
91 wxURLDataObject
* const dobj
= new wxURLDataObject(url
);
92 CPPUNIT_ASSERT_EQUAL( url
, dobj
->GetURL() );
94 wxClipboardLocker lockClip
;
95 CPPUNIT_ASSERT( wxTheClipboard
->SetData(dobj
) );
96 wxTheClipboard
->Flush();
99 void MiscGUIFuncsTestCase::ParseFileDialogFilter()
107 wxParseCommonDialogsFilter("Image files|*.jpg;*.png", descs
, filters
)
110 CPPUNIT_ASSERT_EQUAL( "Image files", descs
[0] );
111 CPPUNIT_ASSERT_EQUAL( "*.jpg;*.png", filters
[0] );
116 wxParseCommonDialogsFilter
118 "All files (*.*)|*.*|Python source (*.py)|*.py",
123 CPPUNIT_ASSERT_EQUAL( "*.*", filters
[0] );
124 CPPUNIT_ASSERT_EQUAL( "*.py", filters
[1] );
126 // Test some invalid ones too.
127 WX_ASSERT_FAILS_WITH_ASSERT
129 wxParseCommonDialogsFilter
131 "All files (*.*)|*.*|Python source (*.py)|*.py|",
137 void MiscGUIFuncsTestCase::FindWindowAtPoint()
139 wxWindow
* const parent
= wxTheApp
->GetTopWindow();
140 CPPUNIT_ASSERT( parent
);
142 CPPUNIT_ASSERT_MESSAGE
144 "No window for a point outside of the window",
145 !wxFindWindowAtPoint(parent
->ClientToScreen(wxPoint(900, 900)))
148 wxWindow
* const btn1
= new wxButton(parent
, wxID_ANY
, "1", wxPoint(10, 10));
149 CPPUNIT_ASSERT_EQUAL_MESSAGE
151 "Point over a child control corresponds to it",
153 wxFindWindowAtPoint(parent
->ClientToScreen(wxPoint(11, 11)))
156 CPPUNIT_ASSERT_EQUAL_MESSAGE
158 "Point outside of any child control returns the TLW itself",
160 wxFindWindowAtPoint(parent
->ClientToScreen(wxPoint(5, 5)))
163 wxWindow
* const btn2
= new wxButton(parent
, wxID_ANY
, "2", wxPoint(10, 90));
165 CPPUNIT_ASSERT_EQUAL_MESSAGE
167 "Point over a disabled child control still corresponds to it",
169 wxFindWindowAtPoint(parent
->ClientToScreen(wxPoint(11, 91)))
173 CPPUNIT_ASSERT_EQUAL_MESSAGE
175 "Point over a hidden child control doesn't take it into account",
177 wxFindWindowAtPoint(parent
->ClientToScreen(wxPoint(11, 91)))