]>
Commit | Line | Data |
---|---|---|
841a25bb VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/misc/misctests.cpp | |
3 | // Purpose: test miscellaneous GUI functions | |
4 | // Author: Vadim Zeitlin | |
5 | // Created: 2008-09-22 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2008 Vadim Zeitlin | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // ---------------------------------------------------------------------------- | |
11 | // headers | |
12 | // ---------------------------------------------------------------------------- | |
13 | ||
14 | #include "testprec.h" | |
15 | ||
16 | #ifdef __BORLANDC__ | |
17 | #pragma hdrstop | |
18 | #endif | |
19 | ||
e18a74e2 VZ |
20 | #include "wx/defs.h" |
21 | ||
fbfd8b1a VZ |
22 | #ifndef WX_PRECOMP |
23 | #include "wx/gdicmn.h" | |
2ab92d62 | 24 | #include "wx/filefn.h" |
fbfd8b1a VZ |
25 | #endif // !PCH |
26 | ||
e18a74e2 VZ |
27 | #include "wx/app.h" |
28 | #include "wx/button.h" | |
791f7574 VZ |
29 | #include "wx/clipbrd.h" |
30 | #include "wx/dataobj.h" | |
841a25bb VZ |
31 | |
32 | // ---------------------------------------------------------------------------- | |
33 | // test class | |
34 | // ---------------------------------------------------------------------------- | |
35 | ||
36 | class MiscGUIFuncsTestCase : public CppUnit::TestCase | |
37 | { | |
38 | public: | |
39 | MiscGUIFuncsTestCase() { } | |
40 | ||
41 | private: | |
42 | CPPUNIT_TEST_SUITE( MiscGUIFuncsTestCase ); | |
43 | CPPUNIT_TEST( DisplaySize ); | |
791f7574 | 44 | CPPUNIT_TEST( URLDataObject ); |
2ab92d62 | 45 | CPPUNIT_TEST( ParseFileDialogFilter ); |
e18a74e2 | 46 | CPPUNIT_TEST( FindWindowAtPoint ); |
841a25bb VZ |
47 | CPPUNIT_TEST_SUITE_END(); |
48 | ||
49 | void DisplaySize(); | |
791f7574 | 50 | void URLDataObject(); |
2ab92d62 | 51 | void ParseFileDialogFilter(); |
e18a74e2 | 52 | void FindWindowAtPoint(); |
841a25bb VZ |
53 | |
54 | DECLARE_NO_COPY_CLASS(MiscGUIFuncsTestCase) | |
55 | }; | |
56 | ||
57 | // register in the unnamed registry so that these tests are run by default | |
58 | CPPUNIT_TEST_SUITE_REGISTRATION( MiscGUIFuncsTestCase ); | |
59 | ||
e3778b4d | 60 | // also include in its own registry so that these tests can be run alone |
841a25bb VZ |
61 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscGUIFuncsTestCase, "MiscGUIFuncsTestCase" ); |
62 | ||
63 | void MiscGUIFuncsTestCase::DisplaySize() | |
64 | { | |
65 | // test that different (almost) overloads return the same results | |
66 | int w, h; | |
67 | wxDisplaySize(&w, &h); | |
68 | wxSize sz = wxGetDisplaySize(); | |
69 | ||
70 | CPPUNIT_ASSERT_EQUAL( w, sz.x ); | |
71 | CPPUNIT_ASSERT_EQUAL( h, sz.y ); | |
72 | ||
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); | |
77 | ||
78 | CPPUNIT_ASSERT_EQUAL( w, sz.x ); | |
79 | CPPUNIT_ASSERT_EQUAL( h, sz.y ); | |
80 | ||
81 | // test that display PPI is something reasonable | |
82 | sz = wxGetDisplayPPI(); | |
83 | CPPUNIT_ASSERT( sz.x < 1000 && sz.y < 1000 ); | |
84 | } | |
85 | ||
791f7574 VZ |
86 | void MiscGUIFuncsTestCase::URLDataObject() |
87 | { | |
88 | // this tests for buffer overflow, see #11102 | |
89 | const char * const | |
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() ); | |
93 | ||
94 | wxClipboardLocker lockClip; | |
95 | CPPUNIT_ASSERT( wxTheClipboard->SetData(dobj) ); | |
96 | wxTheClipboard->Flush(); | |
97 | } | |
98 | ||
2ab92d62 VZ |
99 | void MiscGUIFuncsTestCase::ParseFileDialogFilter() |
100 | { | |
101 | wxArrayString descs, | |
102 | filters; | |
103 | ||
104 | CPPUNIT_ASSERT_EQUAL | |
105 | ( | |
106 | 1, | |
107 | wxParseCommonDialogsFilter("Image files|*.jpg;*.png", descs, filters) | |
108 | ); | |
109 | ||
110 | CPPUNIT_ASSERT_EQUAL( "Image files", descs[0] ); | |
111 | CPPUNIT_ASSERT_EQUAL( "*.jpg;*.png", filters[0] ); | |
112 | ||
113 | CPPUNIT_ASSERT_EQUAL | |
114 | ( | |
115 | 2, | |
116 | wxParseCommonDialogsFilter | |
117 | ( | |
118 | "All files (*.*)|*.*|Python source (*.py)|*.py", | |
119 | descs, filters | |
120 | ) | |
121 | ); | |
122 | ||
123 | CPPUNIT_ASSERT_EQUAL( "*.*", filters[0] ); | |
124 | CPPUNIT_ASSERT_EQUAL( "*.py", filters[1] ); | |
125 | ||
126 | // Test some invalid ones too. | |
127 | WX_ASSERT_FAILS_WITH_ASSERT | |
128 | ( | |
129 | wxParseCommonDialogsFilter | |
130 | ( | |
131 | "All files (*.*)|*.*|Python source (*.py)|*.py|", | |
132 | descs, filters | |
133 | ) | |
134 | ); | |
135 | } | |
136 | ||
e18a74e2 VZ |
137 | void MiscGUIFuncsTestCase::FindWindowAtPoint() |
138 | { | |
139 | wxWindow* const parent = wxTheApp->GetTopWindow(); | |
140 | CPPUNIT_ASSERT( parent ); | |
141 | ||
142 | CPPUNIT_ASSERT_MESSAGE | |
143 | ( | |
144 | "No window for a point outside of the window", | |
145 | !wxFindWindowAtPoint(parent->ClientToScreen(wxPoint(900, 900))) | |
146 | ); | |
147 | ||
148 | wxWindow* const btn1 = new wxButton(parent, wxID_ANY, "1", wxPoint(10, 10)); | |
149 | CPPUNIT_ASSERT_EQUAL_MESSAGE | |
150 | ( | |
151 | "Point over a child control corresponds to it", | |
152 | btn1, | |
153 | wxFindWindowAtPoint(parent->ClientToScreen(wxPoint(11, 11))) | |
154 | ); | |
155 | ||
156 | CPPUNIT_ASSERT_EQUAL_MESSAGE | |
157 | ( | |
158 | "Point outside of any child control returns the TLW itself", | |
159 | parent, | |
160 | wxFindWindowAtPoint(parent->ClientToScreen(wxPoint(5, 5))) | |
161 | ); | |
162 | ||
163 | wxWindow* const btn2 = new wxButton(parent, wxID_ANY, "2", wxPoint(10, 90)); | |
164 | btn2->Disable(); | |
165 | CPPUNIT_ASSERT_EQUAL_MESSAGE | |
166 | ( | |
167 | "Point over a disabled child control still corresponds to it", | |
168 | btn2, | |
169 | wxFindWindowAtPoint(parent->ClientToScreen(wxPoint(11, 91))) | |
170 | ); | |
171 | ||
172 | btn2->Hide(); | |
173 | CPPUNIT_ASSERT_EQUAL_MESSAGE | |
174 | ( | |
175 | "Point over a hidden child control doesn't take it into account", | |
176 | parent, | |
177 | wxFindWindowAtPoint(parent->ClientToScreen(wxPoint(11, 91))) | |
178 | ); | |
179 | } |