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"
22 #include "wx/filefn.h"
26 #include "wx/clipbrd.h"
27 #include "wx/dataobj.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 class MiscGUIFuncsTestCase
: public CppUnit::TestCase
36 MiscGUIFuncsTestCase() { }
39 CPPUNIT_TEST_SUITE( MiscGUIFuncsTestCase
);
40 CPPUNIT_TEST( DisplaySize
);
41 CPPUNIT_TEST( URLDataObject
);
42 CPPUNIT_TEST( ParseFileDialogFilter
);
43 CPPUNIT_TEST_SUITE_END();
47 void ParseFileDialogFilter();
49 DECLARE_NO_COPY_CLASS(MiscGUIFuncsTestCase
)
52 // register in the unnamed registry so that these tests are run by default
53 CPPUNIT_TEST_SUITE_REGISTRATION( MiscGUIFuncsTestCase
);
55 // also include in its own registry so that these tests can be run alone
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscGUIFuncsTestCase
, "MiscGUIFuncsTestCase" );
58 void MiscGUIFuncsTestCase::DisplaySize()
60 // test that different (almost) overloads return the same results
62 wxDisplaySize(&w
, &h
);
63 wxSize sz
= wxGetDisplaySize();
65 CPPUNIT_ASSERT_EQUAL( w
, sz
.x
);
66 CPPUNIT_ASSERT_EQUAL( h
, sz
.y
);
68 // test that passing NULL works as expected, e.g. doesn't crash
69 wxDisplaySize(NULL
, NULL
);
70 wxDisplaySize(&w
, NULL
);
71 wxDisplaySize(NULL
, &h
);
73 CPPUNIT_ASSERT_EQUAL( w
, sz
.x
);
74 CPPUNIT_ASSERT_EQUAL( h
, sz
.y
);
76 // test that display PPI is something reasonable
77 sz
= wxGetDisplayPPI();
78 CPPUNIT_ASSERT( sz
.x
< 1000 && sz
.y
< 1000 );
81 void MiscGUIFuncsTestCase::URLDataObject()
83 // this tests for buffer overflow, see #11102
85 url
= "http://something.long.to.overwrite.plenty.memory.example.com";
86 wxURLDataObject
* const dobj
= new wxURLDataObject(url
);
87 CPPUNIT_ASSERT_EQUAL( url
, dobj
->GetURL() );
89 wxClipboardLocker lockClip
;
90 CPPUNIT_ASSERT( wxTheClipboard
->SetData(dobj
) );
91 wxTheClipboard
->Flush();
94 void MiscGUIFuncsTestCase::ParseFileDialogFilter()
102 wxParseCommonDialogsFilter("Image files|*.jpg;*.png", descs
, filters
)
105 CPPUNIT_ASSERT_EQUAL( "Image files", descs
[0] );
106 CPPUNIT_ASSERT_EQUAL( "*.jpg;*.png", filters
[0] );
111 wxParseCommonDialogsFilter
113 "All files (*.*)|*.*|Python source (*.py)|*.py",
118 CPPUNIT_ASSERT_EQUAL( "*.*", filters
[0] );
119 CPPUNIT_ASSERT_EQUAL( "*.py", filters
[1] );
121 // Test some invalid ones too.
122 WX_ASSERT_FAILS_WITH_ASSERT
124 wxParseCommonDialogsFilter
126 "All files (*.*)|*.*|Python source (*.py)|*.py|",