]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/dialogtest.cpp
cocoa needs a special implementation for read-only combo box
[wxWidgets.git] / tests / controls / dialogtest.cpp
CommitLineData
a96de8a3
VS
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 wxHAS_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.
26class ModalDialogsTestCase : public CppUnit::TestCase
27{
28public:
29 ModalDialogsTestCase() { }
30
31private:
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
46CPPUNIT_TEST_SUITE_REGISTRATION( ModalDialogsTestCase );
47
48// also include in its own registry so that these tests can be run alone
49CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ModalDialogsTestCase, "ModalDialogsTestCase" );
50
51void 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
65void 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
82class MyDialog : public wxDialog
83{
84public:
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
95template<>
96class wxExpectModal<MyDialog> : public wxExpectModalBase<MyDialog>
97{
98public:
99 wxExpectModal(int valueToSet) : m_valueToSet(valueToSet) {}
100
101protected:
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
112void 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 // wxHAS_VARIADIC_MACROS