]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/dialogtest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/dialogtest.cpp
3 // Purpose: wxWindow unit test
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2012 Vaclav Slavik
7 ///////////////////////////////////////////////////////////////////////////////
15 #include "wx/testing.h"
17 #ifdef HAVE_VARIADIC_MACROS
19 #include "wx/msgdlg.h"
20 #include "wx/filedlg.h"
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'
25 class ModalDialogsTestCase
: public CppUnit::TestCase
28 ModalDialogsTestCase() { }
31 CPPUNIT_TEST_SUITE( ModalDialogsTestCase
);
32 CPPUNIT_TEST( MessageDialog
);
33 CPPUNIT_TEST( FileDialog
);
34 CPPUNIT_TEST( CustomDialog
);
35 CPPUNIT_TEST_SUITE_END();
41 DECLARE_NO_COPY_CLASS(ModalDialogsTestCase
)
44 // register in the unnamed registry so that these tests are run by default
45 CPPUNIT_TEST_SUITE_REGISTRATION( ModalDialogsTestCase
);
47 // also include in its own registry so that these tests can be run alone
48 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ModalDialogsTestCase
, "ModalDialogsTestCase" );
50 void ModalDialogsTestCase::MessageDialog()
56 rc
= wxMessageBox("Should I fail?", "Question", wxYES
|wxNO
),
57 wxExpectModal
<wxMessageDialog
>(wxNO
),
58 wxExpectModal
<wxFileDialog
>(wxGetCwd() + "/test.txt").Optional()
61 CPPUNIT_ASSERT_EQUAL(wxNO
, rc
);
64 void ModalDialogsTestCase::FileDialog()
66 wxFileDialog
dlg(NULL
);
72 wxExpectModal
<wxFileDialog
>(wxGetCwd() + "/test.txt")
75 CPPUNIT_ASSERT_EQUAL((int)wxID_OK
, rc
);
77 CPPUNIT_ASSERT_EQUAL("test.txt", dlg
.GetFilename());
81 class MyDialog
: public wxDialog
84 MyDialog(wxWindow
*parent
) : wxDialog(parent
, wxID_ANY
, "Entry"), m_value(-1)
86 // Dummy. Imagine it's a real dialog that shows some number-entry
95 class wxExpectModal
<MyDialog
> : public wxExpectModalBase
<MyDialog
>
98 wxExpectModal(int valueToSet
) : m_valueToSet(valueToSet
) {}
101 virtual int OnInvoked(MyDialog
*dlg
) const
103 // Simulate the user entering the expected number:
104 dlg
->m_value
= m_valueToSet
;
111 void ModalDialogsTestCase::CustomDialog()
118 wxExpectModal
<MyDialog
>(42)
121 CPPUNIT_ASSERT_EQUAL( 42, dlg
.m_value
);
124 #endif // HAVE_VARIADIC_MACROS