]> git.saurik.com Git - wxWidgets.git/blob - tests/toplevel/toplevel.cpp
Don't block the main UI thread while generating completions in wxMSW.
[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/app.h"
22 #include "wx/window.h"
23 #endif // WX_PRECOMP
24
25 #include "wx/evtloop.h"
26
27 // ----------------------------------------------------------------------------
28 // test class
29 // ----------------------------------------------------------------------------
30
31 class TopLevelWindowTestCase : public CppUnit::TestCase
32 {
33 public:
34 TopLevelWindowTestCase() { }
35
36 virtual void setUp();
37 virtual void tearDown();
38
39 private:
40 CPPUNIT_TEST_SUITE( TopLevelWindowTestCase );
41 CPPUNIT_TEST( DialogShowTest );
42 CPPUNIT_TEST( FrameShowTest );
43 CPPUNIT_TEST_SUITE_END();
44
45 void DialogShowTest();
46 void FrameShowTest();
47 void TopLevelWindowShowTest(wxTopLevelWindow* tlw);
48
49 DECLARE_NO_COPY_CLASS(TopLevelWindowTestCase)
50 };
51
52 // register in the unnamed registry so that these tests are run by default
53 CPPUNIT_TEST_SUITE_REGISTRATION( TopLevelWindowTestCase );
54
55 // also include in it's own registry so that these tests can be run alone
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TopLevelWindowTestCase, "TopLevelWindowTestCase" );
57
58 // ----------------------------------------------------------------------------
59 // test initialization
60 // ----------------------------------------------------------------------------
61
62 void TopLevelWindowTestCase::setUp()
63 {
64 }
65
66 void TopLevelWindowTestCase::tearDown()
67 {
68 }
69
70 // ----------------------------------------------------------------------------
71 // tests themselves
72 // ----------------------------------------------------------------------------
73
74 void TopLevelWindowTestCase::DialogShowTest()
75 {
76 wxDialog* dialog = new wxDialog(NULL, -1, "Dialog Test");
77 TopLevelWindowShowTest(dialog);
78 dialog->Destroy();
79 }
80
81 void TopLevelWindowTestCase::FrameShowTest()
82 {
83 wxFrame* frame = new wxFrame(NULL, -1, "Frame test");
84 TopLevelWindowShowTest(frame);
85 frame->Destroy();
86 }
87
88 void TopLevelWindowTestCase::TopLevelWindowShowTest(wxTopLevelWindow* tlw)
89 {
90 CPPUNIT_ASSERT(!tlw->IsShown());
91
92 wxTextCtrl* textCtrl = new wxTextCtrl(tlw, -1, "test");
93 textCtrl->SetFocus();
94
95 // only run this test on platforms where ShowWithoutActivating is implemented.
96 #ifdef __WXMSW__ || defined(__WXMAC__)
97 tlw->ShowWithoutActivating();
98 CPPUNIT_ASSERT(tlw->IsShown());
99 CPPUNIT_ASSERT(!tlw->IsActive());
100
101 tlw->Hide();
102 CPPUNIT_ASSERT(!tlw->IsShown());
103 CPPUNIT_ASSERT(!tlw->IsActive());
104 #endif
105
106 tlw->Show(true);
107 CPPUNIT_ASSERT(tlw->IsActive());
108 CPPUNIT_ASSERT(tlw->IsShown());
109
110 tlw->Hide();
111 CPPUNIT_ASSERT(!tlw->IsShown());
112 CPPUNIT_ASSERT(tlw->IsActive());
113 }