]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/dialogtest.cpp
Add a test for eol-native file existence in the release script.
[wxWidgets.git] / tests / controls / dialogtest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/dialogtest.cpp
3 // Purpose: wxWindow unit test
4 // Author: Vaclav Slavik
5 // Created: 2012-08-30
6 // RCS-ID: $Id$
7 // Copyright: (c) 2012 Vaclav Slavik
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "testprec.h"
11
12 #ifdef __BORLANDC__
13 #pragma hdrstop
14 #endif
15
16 #include "wx/testing.h"
17
18 #ifdef HAVE_VARIADIC_MACROS
19
20 #include "wx/msgdlg.h"
21 #include "wx/filedlg.h"
22
23 // This test suite tests helpers from wx/testing.h intended for testing of code
24 // that calls modal dialogs. It does not test the implementation of wxWidgets'
25 // dialogs.
26 class ModalDialogsTestCase : public CppUnit::TestCase
27 {
28 public:
29 ModalDialogsTestCase() { }
30
31 private:
32 CPPUNIT_TEST_SUITE( ModalDialogsTestCase );
33 CPPUNIT_TEST( MessageDialog );
34 CPPUNIT_TEST( FileDialog );
35 CPPUNIT_TEST( CustomDialog );
36 CPPUNIT_TEST_SUITE_END();
37
38 void MessageDialog();
39 void FileDialog();
40 void CustomDialog();
41
42 DECLARE_NO_COPY_CLASS(ModalDialogsTestCase)
43 };
44
45 // register in the unnamed registry so that these tests are run by default
46 CPPUNIT_TEST_SUITE_REGISTRATION( ModalDialogsTestCase );
47
48 // also include in its own registry so that these tests can be run alone
49 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ModalDialogsTestCase, "ModalDialogsTestCase" );
50
51 void ModalDialogsTestCase::MessageDialog()
52 {
53 int rc;
54
55 wxTEST_DIALOG
56 (
57 rc = wxMessageBox("Should I fail?", "Question", wxYES|wxNO),
58 wxExpectModal<wxMessageDialog>(wxNO),
59 wxExpectModal<wxFileDialog>(wxGetCwd() + "/test.txt").Optional()
60 );
61
62 CPPUNIT_ASSERT_EQUAL(wxNO, rc);
63 }
64
65 void ModalDialogsTestCase::FileDialog()
66 {
67 wxFileDialog dlg(NULL);
68 int rc;
69
70 wxTEST_DIALOG
71 (
72 rc = dlg.ShowModal(),
73 wxExpectModal<wxFileDialog>(wxGetCwd() + "/test.txt")
74 );
75
76 CPPUNIT_ASSERT_EQUAL((int)wxID_OK, rc);
77
78 CPPUNIT_ASSERT_EQUAL("test.txt", dlg.GetFilename());
79 }
80
81
82 class MyDialog : public wxDialog
83 {
84 public:
85 MyDialog(wxWindow *parent) : wxDialog(parent, wxID_ANY, "Entry"), m_value(-1)
86 {
87 // Dummy. Imagine it's a real dialog that shows some number-entry
88 // controls.
89 }
90
91 int m_value;
92 };
93
94
95 template<>
96 class wxExpectModal<MyDialog> : public wxExpectModalBase<MyDialog>
97 {
98 public:
99 wxExpectModal(int valueToSet) : m_valueToSet(valueToSet) {}
100
101 protected:
102 virtual int OnInvoked(MyDialog *dlg) const
103 {
104 // Simulate the user entering the expected number:
105 dlg->m_value = m_valueToSet;
106 return wxID_OK;
107 }
108
109 int m_valueToSet;
110 };
111
112 void ModalDialogsTestCase::CustomDialog()
113 {
114 MyDialog dlg(NULL);
115
116 wxTEST_DIALOG
117 (
118 dlg.ShowModal(),
119 wxExpectModal<MyDialog>(42)
120 );
121
122 CPPUNIT_ASSERT_EQUAL( 42, dlg.m_value );
123 }
124
125 #endif // HAVE_VARIADIC_MACROS