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 // ----------------------------------------------------------------------------
21 #include "wx/gdicmn.h"
25 #include "wx/clipbrd.h"
26 #include "wx/dataobj.h"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 class MiscGUIFuncsTestCase
: public CppUnit::TestCase
35 MiscGUIFuncsTestCase() { }
38 CPPUNIT_TEST_SUITE( MiscGUIFuncsTestCase
);
39 CPPUNIT_TEST( DisplaySize
);
40 CPPUNIT_TEST( URLDataObject
);
41 CPPUNIT_TEST_SUITE_END();
46 DECLARE_NO_COPY_CLASS(MiscGUIFuncsTestCase
)
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( MiscGUIFuncsTestCase
);
52 // also include in it's own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscGUIFuncsTestCase
, "MiscGUIFuncsTestCase" );
55 void MiscGUIFuncsTestCase::DisplaySize()
57 // test that different (almost) overloads return the same results
59 wxDisplaySize(&w
, &h
);
60 wxSize sz
= wxGetDisplaySize();
62 CPPUNIT_ASSERT_EQUAL( w
, sz
.x
);
63 CPPUNIT_ASSERT_EQUAL( h
, sz
.y
);
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
);
70 CPPUNIT_ASSERT_EQUAL( w
, sz
.x
);
71 CPPUNIT_ASSERT_EQUAL( h
, sz
.y
);
73 // test that display PPI is something reasonable
74 sz
= wxGetDisplayPPI();
75 CPPUNIT_ASSERT( sz
.x
< 1000 && sz
.y
< 1000 );
78 void MiscGUIFuncsTestCase::URLDataObject()
80 // this tests for buffer overflow, see #11102
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() );
86 wxClipboardLocker lockClip
;
87 CPPUNIT_ASSERT( wxTheClipboard
->SetData(dobj
) );
88 wxTheClipboard
->Flush();