]> git.saurik.com Git - wxWidgets.git/blob - tests/misc/guifuncs.cpp
Rebake all the samples, demos and tests makefiles.
[wxWidgets.git] / tests / misc / guifuncs.cpp
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
20 #ifndef WX_PRECOMP
21 #include "wx/gdicmn.h"
22 #endif // !PCH
23
24 #include "wx/defs.h"
25 #include "wx/clipbrd.h"
26 #include "wx/dataobj.h"
27
28 // ----------------------------------------------------------------------------
29 // test class
30 // ----------------------------------------------------------------------------
31
32 class MiscGUIFuncsTestCase : public CppUnit::TestCase
33 {
34 public:
35 MiscGUIFuncsTestCase() { }
36
37 private:
38 CPPUNIT_TEST_SUITE( MiscGUIFuncsTestCase );
39 CPPUNIT_TEST( DisplaySize );
40 CPPUNIT_TEST( URLDataObject );
41 CPPUNIT_TEST_SUITE_END();
42
43 void DisplaySize();
44 void URLDataObject();
45
46 DECLARE_NO_COPY_CLASS(MiscGUIFuncsTestCase)
47 };
48
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( MiscGUIFuncsTestCase );
51
52 // also include in it's own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscGUIFuncsTestCase, "MiscGUIFuncsTestCase" );
54
55 void MiscGUIFuncsTestCase::DisplaySize()
56 {
57 // test that different (almost) overloads return the same results
58 int w, h;
59 wxDisplaySize(&w, &h);
60 wxSize sz = wxGetDisplaySize();
61
62 CPPUNIT_ASSERT_EQUAL( w, sz.x );
63 CPPUNIT_ASSERT_EQUAL( h, sz.y );
64
65 // test that passing NULL works as expected, e.g. doesn't crash
66 wxDisplaySize(NULL, NULL);
67 wxDisplaySize(&w, NULL);
68 wxDisplaySize(NULL, &h);
69
70 CPPUNIT_ASSERT_EQUAL( w, sz.x );
71 CPPUNIT_ASSERT_EQUAL( h, sz.y );
72
73 // test that display PPI is something reasonable
74 sz = wxGetDisplayPPI();
75 CPPUNIT_ASSERT( sz.x < 1000 && sz.y < 1000 );
76 }
77
78 void MiscGUIFuncsTestCase::URLDataObject()
79 {
80 // this tests for buffer overflow, see #11102
81 const char * const
82 url = "http://something.long.to.overwrite.plenty.memory.example.com";
83 wxURLDataObject * const dobj = new wxURLDataObject(url);
84 CPPUNIT_ASSERT_EQUAL( url, dobj->GetURL() );
85
86 wxClipboardLocker lockClip;
87 CPPUNIT_ASSERT( wxTheClipboard->SetData(dobj) );
88 wxTheClipboard->Flush();
89 }
90