]>
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 | ||
fbfd8b1a VZ |
20 | #ifndef WX_PRECOMP |
21 | #include "wx/gdicmn.h" | |
2ab92d62 | 22 | #include "wx/filefn.h" |
fbfd8b1a VZ |
23 | #endif // !PCH |
24 | ||
841a25bb | 25 | #include "wx/defs.h" |
791f7574 VZ |
26 | #include "wx/clipbrd.h" |
27 | #include "wx/dataobj.h" | |
841a25bb VZ |
28 | |
29 | // ---------------------------------------------------------------------------- | |
30 | // test class | |
31 | // ---------------------------------------------------------------------------- | |
32 | ||
33 | class MiscGUIFuncsTestCase : public CppUnit::TestCase | |
34 | { | |
35 | public: | |
36 | MiscGUIFuncsTestCase() { } | |
37 | ||
38 | private: | |
39 | CPPUNIT_TEST_SUITE( MiscGUIFuncsTestCase ); | |
40 | CPPUNIT_TEST( DisplaySize ); | |
791f7574 | 41 | CPPUNIT_TEST( URLDataObject ); |
2ab92d62 | 42 | CPPUNIT_TEST( ParseFileDialogFilter ); |
841a25bb VZ |
43 | CPPUNIT_TEST_SUITE_END(); |
44 | ||
45 | void DisplaySize(); | |
791f7574 | 46 | void URLDataObject(); |
2ab92d62 | 47 | void ParseFileDialogFilter(); |
841a25bb VZ |
48 | |
49 | DECLARE_NO_COPY_CLASS(MiscGUIFuncsTestCase) | |
50 | }; | |
51 | ||
52 | // register in the unnamed registry so that these tests are run by default | |
53 | CPPUNIT_TEST_SUITE_REGISTRATION( MiscGUIFuncsTestCase ); | |
54 | ||
e3778b4d | 55 | // also include in its own registry so that these tests can be run alone |
841a25bb VZ |
56 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscGUIFuncsTestCase, "MiscGUIFuncsTestCase" ); |
57 | ||
58 | void MiscGUIFuncsTestCase::DisplaySize() | |
59 | { | |
60 | // test that different (almost) overloads return the same results | |
61 | int w, h; | |
62 | wxDisplaySize(&w, &h); | |
63 | wxSize sz = wxGetDisplaySize(); | |
64 | ||
65 | CPPUNIT_ASSERT_EQUAL( w, sz.x ); | |
66 | CPPUNIT_ASSERT_EQUAL( h, sz.y ); | |
67 | ||
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); | |
72 | ||
73 | CPPUNIT_ASSERT_EQUAL( w, sz.x ); | |
74 | CPPUNIT_ASSERT_EQUAL( h, sz.y ); | |
75 | ||
76 | // test that display PPI is something reasonable | |
77 | sz = wxGetDisplayPPI(); | |
78 | CPPUNIT_ASSERT( sz.x < 1000 && sz.y < 1000 ); | |
79 | } | |
80 | ||
791f7574 VZ |
81 | void MiscGUIFuncsTestCase::URLDataObject() |
82 | { | |
83 | // this tests for buffer overflow, see #11102 | |
84 | const char * const | |
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() ); | |
88 | ||
89 | wxClipboardLocker lockClip; | |
90 | CPPUNIT_ASSERT( wxTheClipboard->SetData(dobj) ); | |
91 | wxTheClipboard->Flush(); | |
92 | } | |
93 | ||
2ab92d62 VZ |
94 | void MiscGUIFuncsTestCase::ParseFileDialogFilter() |
95 | { | |
96 | wxArrayString descs, | |
97 | filters; | |
98 | ||
99 | CPPUNIT_ASSERT_EQUAL | |
100 | ( | |
101 | 1, | |
102 | wxParseCommonDialogsFilter("Image files|*.jpg;*.png", descs, filters) | |
103 | ); | |
104 | ||
105 | CPPUNIT_ASSERT_EQUAL( "Image files", descs[0] ); | |
106 | CPPUNIT_ASSERT_EQUAL( "*.jpg;*.png", filters[0] ); | |
107 | ||
108 | CPPUNIT_ASSERT_EQUAL | |
109 | ( | |
110 | 2, | |
111 | wxParseCommonDialogsFilter | |
112 | ( | |
113 | "All files (*.*)|*.*|Python source (*.py)|*.py", | |
114 | descs, filters | |
115 | ) | |
116 | ); | |
117 | ||
118 | CPPUNIT_ASSERT_EQUAL( "*.*", filters[0] ); | |
119 | CPPUNIT_ASSERT_EQUAL( "*.py", filters[1] ); | |
120 | ||
121 | // Test some invalid ones too. | |
122 | WX_ASSERT_FAILS_WITH_ASSERT | |
123 | ( | |
124 | wxParseCommonDialogsFilter | |
125 | ( | |
126 | "All files (*.*)|*.*|Python source (*.py)|*.py|", | |
127 | descs, filters | |
128 | ) | |
129 | ); | |
130 | } | |
131 |