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