]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/dialogtest.cpp
d4780f15c5cc97e245d8edb122ce89fc673f115b
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/dialogtest.cpp
3 // Purpose: wxWindow unit test
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2012 Vaclav Slavik
8 ///////////////////////////////////////////////////////////////////////////////
16 #include "wx/testing.h"
18 #ifdef HAVE_VARIADIC_MACROS
20 #include "wx/msgdlg.h"
21 #include "wx/filedlg.h"
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'
26 class ModalDialogsTestCase
: public CppUnit::TestCase
29 ModalDialogsTestCase() { }
32 CPPUNIT_TEST_SUITE( ModalDialogsTestCase
);
33 CPPUNIT_TEST( MessageDialog
);
34 CPPUNIT_TEST( FileDialog
);
35 CPPUNIT_TEST( CustomDialog
);
36 CPPUNIT_TEST_SUITE_END();
42 DECLARE_NO_COPY_CLASS(ModalDialogsTestCase
)
45 // register in the unnamed registry so that these tests are run by default
46 CPPUNIT_TEST_SUITE_REGISTRATION( ModalDialogsTestCase
);
48 // also include in its own registry so that these tests can be run alone
49 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ModalDialogsTestCase
, "ModalDialogsTestCase" );
51 void ModalDialogsTestCase::MessageDialog()
57 rc
= wxMessageBox("Should I fail?", "Question", wxYES
|wxNO
),
58 wxExpectModal
<wxMessageDialog
>(wxNO
),
59 wxExpectModal
<wxFileDialog
>(wxGetCwd() + "/test.txt").Optional()
62 CPPUNIT_ASSERT_EQUAL(wxNO
, rc
);
65 void ModalDialogsTestCase::FileDialog()
67 wxFileDialog
dlg(NULL
);
73 wxExpectModal
<wxFileDialog
>(wxGetCwd() + "/test.txt")
76 CPPUNIT_ASSERT_EQUAL((int)wxID_OK
, rc
);
78 CPPUNIT_ASSERT_EQUAL("test.txt", dlg
.GetFilename());
82 class MyDialog
: public wxDialog
85 MyDialog(wxWindow
*parent
) : wxDialog(parent
, wxID_ANY
, "Entry"), m_value(-1)
87 // Dummy. Imagine it's a real dialog that shows some number-entry
96 class wxExpectModal
<MyDialog
> : public wxExpectModalBase
<MyDialog
>
99 wxExpectModal(int valueToSet
) : m_valueToSet(valueToSet
) {}
102 virtual int OnInvoked(MyDialog
*dlg
) const
104 // Simulate the user entering the expected number:
105 dlg
->m_value
= m_valueToSet
;
112 void ModalDialogsTestCase::CustomDialog()
119 wxExpectModal
<MyDialog
>(42)
122 CPPUNIT_ASSERT_EQUAL( 42, dlg
.m_value
);
125 #endif // HAVE_VARIADIC_MACROS