/[lmi]/skeleton/mvc_test.cpp
ViewVC logotype

Contents of /skeleton/mvc_test.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Sat Nov 19 16:31:27 2005 UTC (18 years, 4 months ago) by chicares
Branch: MAIN
Changes since 1.2: +53 -42 lines
Experiment unsuccessfully with idle events

1 // Model-view-controller test.
2 //
3 // Copyright (C) 2005 Gregory W. Chicares.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License version 2 as
7 // published by the Free Software Foundation.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 // http://savannah.nongnu.org/projects/lmi
19 // email: <chicares@cox.net>
20 // snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
21
22 // $Id: mvc_test.cpp,v 1.2 2005/11/19 05:26:15 chicares Exp $
23
24 #ifdef __BORLANDC__
25 # include "pchfile.hpp"
26 # pragma hdrstop
27 #endif // __BORLANDC__
28
29 #include "mvc_test.hpp"
30
31 #include "xml_notebook.tpp"
32
33 #include <wx/app.h> // wxPostEvent(), wxTheApp
34 #include <wx/checkbox.h>
35 #include <wx/ctrlsub.h>
36 #include <wx/log.h>
37 #include <wx/msgdlg.h>
38 #include <wx/notebook.h>
39 #include <wx/radiobox.h>
40 #include <wx/textctrl.h>
41 #include <wx/xrc/xmlres.h>
42
43 #include <sstream>
44 #include <stdexcept>
45
46 // TODO ?? Development plans:
47 //
48 // Test more features.
49 //
50 // Write any diagnostics to a file.
51 //
52 // Invoke with a command-line switch.
53
54 mvc_test::mvc_test(wxWindow* frame)
55 :mvc(frame)
56 {
57 }
58
59 mvc_test::~mvc_test()
60 {
61 }
62
63 void mvc_test::Test()
64 {
65 // Use Show() instead of ShowModal() so that the dialog can be
66 // manipulated by the present function while it's shown.
67 mvc.Show();
68
69 wxNotebook& notebook = mvc.WindowFromXrcName<wxNotebook>("input_notebook");
70 // TODO ?? Do this by xrc name. Because wx doesn't support
71 // notebook.SetSelection(XRCID("ignore_panel"));
72 // directly, enumerate the pages and read their names.
73 notebook.SetSelection(0);
74
75 // A default-contructed wxUpdateUIEvent suffices for invoking
76 // XmlNotebook::OnUpdateGUI() downstream.
77 wxUpdateUIEvent update;
78
79 // A default-contructed wxIdleEvent should suffice for invoking
80 // wxPostEvent(wxTheApp, idle_event) downstream.
81 wxIdleEvent idle_event;
82 // TODO ?? Or maybe it's not sufficient. But even this doesn't
83 // seem to make the idle-event technique work:
84 // idle_event.RequestMore();
85
86 wxCheckBox& check0 = mvc.WindowFromXrcName<wxCheckBox>("check0");
87 wxCheckBox& check1 = mvc.WindowFromXrcName<wxCheckBox>("check1");
88 wxCheckBox& check2 = mvc.WindowFromXrcName<wxCheckBox>("check2");
89
90 wxLogMessage
91 ("Beginning of MVC test. For the moment, many log messages are"
92 " shown, just to demonstrate that things are really happening."
93 " Ultimately, this test will run automatically, e.g., as"
94 " './skeleton --selftest', instead of running every time the"
95 " 'Properties' dialog is displayed."
96 );
97 wxLog::FlushActive();
98
99 // Negate the conditions that are to be tested.
100 check1.Enable(false);
101 check2.Enable(false);
102 wxLogMessage
103 ("Check checkboxes 0 and 1. This should force enablement of"
104 " checkboxes 1 and 2."
105 );
106 wxLog::FlushActive();
107 // Change control values, expecting the framework to react by
108 // enabling other controls.
109 check0.SetValue(true);
110 check1.SetValue(true);
111 // The framework reacts through its EVT_UPDATE_UI handler, which
112 // must be called explicitly: just sending idle events doesn't
113 // work. Is this because the notebook isn't modal here?
114 if(!check0.GetValue()) {wxLogMessage("oops 00a"); wxLog::FlushActive();}
115 if(!check1.GetValue()) {wxLogMessage("oops 01a"); wxLog::FlushActive();}
116 // TODO ?? Post a large number of idle events. This doesn't work.
117 for(int j = 0; j < 1000; ++j)
118 {
119 wxPostEvent(wxTheApp, idle_event);
120 }
121 if(!check0.GetValue()) {wxLogMessage("oops 00b"); wxLog::FlushActive();}
122 if(!check1.IsEnabled()) {wxLogMessage("oops 01b"); wxLog::FlushActive();}
123 if(!check2.IsEnabled()) {wxLogMessage("oops 02b"); wxLog::FlushActive();}
124 // TODO ?? Post idle events until either the Controller sets a
125 // semaphore indicating that its EVT_UPDATE_UI handler finds no
126 // more work to do, or 1000 events have proved insufficient.
127 // This doesn't work.
128 for(int j = 0; j < 1000 && !mvc.update_completed_; ++j)
129 {
130 wxPostEvent(wxTheApp, idle_event);
131 if(999 == j)
132 {
133 wxLogMessage("1000 idle events did not suffice.");
134 wxLog::FlushActive();
135 }
136 }
137 if(!check0.GetValue()) {wxLogMessage("oops 00c"); wxLog::FlushActive();}
138 if(!check1.IsEnabled()) {wxLogMessage("oops 01c"); wxLog::FlushActive();}
139 if(!check2.IsEnabled()) {wxLogMessage("oops 02c"); wxLog::FlushActive();}
140 // Call the EVT_UPDATE_UI handler explicitly and retest.
141 mvc.OnUpdateGUI(update);
142 if(!check0.GetValue()) {wxLogMessage("oops 00d"); wxLog::FlushActive();}
143 if(!check1.IsEnabled()) {wxLogMessage("oops 01d"); wxLog::FlushActive();}
144 if(!check2.IsEnabled()) {wxLogMessage("oops 02d"); wxLog::FlushActive();}
145
146 // This is the inverse of the preceding test.
147
148 // Negate the conditions that are to be tested.
149 check1.Enable(true);
150 check2.Enable(true);
151 wxLogMessage
152 ("Uncheck checkboxes 0 and 1. This should force disablement of"
153 " checkboxes 1 and 2."
154 );
155 wxLog::FlushActive();
156 // Change control values, expecting the framework to react by
157 // enabling other controls.
158 check0.SetValue(false);
159 check1.SetValue(false);
160 if( check0.GetValue()) {wxLogMessage("oops 10a"); wxLog::FlushActive();}
161 if( check1.GetValue()) {wxLogMessage("oops 11a"); wxLog::FlushActive();}
162 // The framework reacts through its EVT_UPDATE_UI handler, which
163 // must be called explicitly.
164 mvc.OnUpdateGUI(update);
165 if( check0.GetValue()) {wxLogMessage("oops 10d"); wxLog::FlushActive();}
166 if( check1.IsEnabled()) {wxLogMessage("oops 11d"); wxLog::FlushActive();}
167 if( check2.IsEnabled()) {wxLogMessage("oops 12d"); wxLog::FlushActive();}
168
169 wxLogMessage("End of test."); wxLog::FlushActive();
170 }
171

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26