]> git.saurik.com Git - wxWidgets.git/blob - tests/toplevel/toplevel.cpp
Allow wxTextMeasure to work with non-native wxDC objects too.
[wxWidgets.git] / tests / toplevel / toplevel.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/toplevel/toplevel.cpp
3 // Purpose: Tests for wxTopLevelWindow
4 // Author: Kevin Ollivier
5 // Created: 2008-05-25
6 // RCS-ID: $Id$
7 // Copyright: (c) 2009 Kevin Ollivier <kevino@theolliviers.com>
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/dialog.h"
22 #include "wx/frame.h"
23 #include "wx/textctrl.h"
24 #include "wx/toplevel.h"
25 #endif // WX_PRECOMP
26
27 #include "wx/evtloop.h"
28
29 // ----------------------------------------------------------------------------
30 // test class
31 // ----------------------------------------------------------------------------
32
33 class TopLevelWindowTestCase : public CppUnit::TestCase
34 {
35 public:
36 TopLevelWindowTestCase() { }
37
38 private:
39 CPPUNIT_TEST_SUITE( TopLevelWindowTestCase );
40 CPPUNIT_TEST( DialogShowTest );
41 CPPUNIT_TEST( FrameShowTest );
42 CPPUNIT_TEST_SUITE_END();
43
44 void DialogShowTest();
45 void FrameShowTest();
46 void TopLevelWindowShowTest(wxTopLevelWindow* tlw);
47
48 DECLARE_NO_COPY_CLASS(TopLevelWindowTestCase)
49 };
50
51 // register in the unnamed registry so that these tests are run by default
52 //CPPUNIT_TEST_SUITE_REGISTRATION( TopLevelWindowTestCase );
53
54 // also include in its own registry so that these tests can be run alone
55 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TopLevelWindowTestCase, "fixme" );
56
57 // ----------------------------------------------------------------------------
58 // tests themselves
59 // ----------------------------------------------------------------------------
60
61 void TopLevelWindowTestCase::DialogShowTest()
62 {
63 wxDialog* dialog = new wxDialog(NULL, -1, "Dialog Test");
64 TopLevelWindowShowTest(dialog);
65 dialog->Destroy();
66 }
67
68 void TopLevelWindowTestCase::FrameShowTest()
69 {
70 wxFrame* frame = new wxFrame(NULL, -1, "Frame test");
71 TopLevelWindowShowTest(frame);
72 frame->Destroy();
73 }
74
75 void TopLevelWindowTestCase::TopLevelWindowShowTest(wxTopLevelWindow* tlw)
76 {
77 CPPUNIT_ASSERT(!tlw->IsShown());
78
79 wxTextCtrl* textCtrl = new wxTextCtrl(tlw, -1, "test");
80 textCtrl->SetFocus();
81
82 // only run this test on platforms where ShowWithoutActivating is implemented.
83 #if defined(__WXMSW__) || defined(__WXMAC__)
84 tlw->ShowWithoutActivating();
85 CPPUNIT_ASSERT(tlw->IsShown());
86 CPPUNIT_ASSERT(!tlw->IsActive());
87
88 tlw->Hide();
89 CPPUNIT_ASSERT(!tlw->IsShown());
90 CPPUNIT_ASSERT(!tlw->IsActive());
91 #endif
92
93 tlw->Show(true);
94 CPPUNIT_ASSERT(tlw->IsActive());
95 CPPUNIT_ASSERT(tlw->IsShown());
96
97 tlw->Hide();
98 CPPUNIT_ASSERT(!tlw->IsShown());
99 CPPUNIT_ASSERT(tlw->IsActive());
100 }