// Model-view-controller test. // // Copyright (C) 2005 Gregory W. Chicares. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // http://savannah.nongnu.org/projects/lmi // email: // snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA // $Id: mvc_test.cpp,v 1.1 2005/11/16 21:49:09 chicares Exp $ #ifdef __BORLANDC__ # include "pchfile.hpp" # pragma hdrstop #endif // __BORLANDC__ #include "mvc_test.hpp" #include "xml_notebook.tpp" #include #include #include #include #include #include #include #include // wxSafeYield() #include #include #include // TODO ?? Development plans: // // Test more features. // // Write any diagnostics to a file. // // Invoke with a command-line switch. mvc_test::mvc_test(wxWindow* frame) :mvc(frame) { } mvc_test::~mvc_test() { } void mvc_test::Test() { // Use Show() instead of ShowModal() so that the dialog can be // manipulated while it's shown. // // TODO ?? Why doesn't Show(false) work here? // Use Show(true) because Show(false) seems to prevent the // 'mvc' notebook window from responding. mvc.Show(true); wxNotebook& notebook = mvc.WindowFromXrcName("input_notebook"); // WX !! There seems to be no way to do this by xrc name, e.g. // notebook.SetSelection(XRCID("ignore_panel")); // But the pages could be enumerated and their names read. notebook.SetSelection(0); // A default-contructed wxUpdateUIEvent is sufficient to invoke // XmlNotebook::OnUpdateGUI(). wxUpdateUIEvent update; wxCheckBox& check0 = mvc.WindowFromXrcName("check0"); wxCheckBox& check1 = mvc.WindowFromXrcName("check1"); wxCheckBox& check2 = mvc.WindowFromXrcName("check2"); wxLogMessage ("Beginning of MVC test. For the moment, many log messages are " "shown, just to demonstrate that things are really happening, " "and some errors are deliberately introduced to show that the " "test identifies them. Ultimately, this test will run " "automatically, e.g., as 'skeleton --selftest', instead of" "running every time the 'Properties' dialog is displayed." ); wxLog::FlushActive(); wxLogMessage("Check checkbox 0."); wxLog::FlushActive(); // Negate the conditions that are to be tested. check1.Enable(false); check2.Enable(false); // Change control values, expecting the framework to react by // enabling other controls. check0.SetValue(true); check1.SetValue(true); // The framework reacts through its EVT_UPDATE_UI handler, which // must be called explicitly. if(!check0.GetValue()) {wxLogMessage("oops 00a"); wxLog::FlushActive();} wxLogMessage("Some of the next few tests will fail."); wxLog::FlushActive(); if(!check1.IsEnabled()) {wxLogMessage("oops 01a"); wxLog::FlushActive();} if(!check2.IsEnabled()) {wxLogMessage("oops 02a"); wxLog::FlushActive();} // Call wxSafeYield() to see whether EVT_UPDATE_UI is handled. wxSafeYield(); if(!check0.GetValue()) {wxLogMessage("oops 00b"); wxLog::FlushActive();} if(!check1.IsEnabled()) {wxLogMessage("oops 01b"); wxLog::FlushActive();} if(!check2.IsEnabled()) {wxLogMessage("oops 02b"); wxLog::FlushActive();} // Call wxSleep(1) to see whether EVT_UPDATE_UI is handled. wxSleep(1); if(!check0.GetValue()) {wxLogMessage("oops 00c"); wxLog::FlushActive();} if(!check1.IsEnabled()) {wxLogMessage("oops 01c"); wxLog::FlushActive();} if(!check2.IsEnabled()) {wxLogMessage("oops 02c"); wxLog::FlushActive();} // Call the EVT_UPDATE_UI handler explicitly and retest. mvc.OnUpdateGUI(update); if(!check0.GetValue()) {wxLogMessage("oops 00d"); wxLog::FlushActive();} if(!check1.IsEnabled()) {wxLogMessage("oops 01d"); wxLog::FlushActive();} if(!check2.IsEnabled()) {wxLogMessage("oops 02d"); wxLog::FlushActive();} // This is the inverse of the preceding test. wxLogMessage("Uncheck checkbox 0."); wxLog::FlushActive(); // Negate the conditions that are to be tested. check1.Enable(true); check2.Enable(true); // Change control values, expecting the framework to react by // enabling other controls. check0.SetValue(false); check1.SetValue(false); // The framework reacts through its EVT_UPDATE_UI handler, which // must be called explicitly. if( check0.GetValue()) {wxLogMessage("oops 10a"); wxLog::FlushActive();} wxLogMessage("Some of the next few tests will fail."); wxLog::FlushActive(); if( check1.IsEnabled()) {wxLogMessage("oops 11a"); wxLog::FlushActive();} if( check2.IsEnabled()) {wxLogMessage("oops 12a"); wxLog::FlushActive();} // Call wxSafeYield() to see whether EVT_UPDATE_UI is handled. wxSafeYield(); if( check0.GetValue()) {wxLogMessage("oops 10b"); wxLog::FlushActive();} if( check1.IsEnabled()) {wxLogMessage("oops 11b"); wxLog::FlushActive();} if( check2.IsEnabled()) {wxLogMessage("oops 12b"); wxLog::FlushActive();} // Call wxSleep(1) to see whether EVT_UPDATE_UI is handled. wxSleep(1); if( check0.GetValue()) {wxLogMessage("oops 10c"); wxLog::FlushActive();} if( check1.IsEnabled()) {wxLogMessage("oops 11c"); wxLog::FlushActive();} if( check2.IsEnabled()) {wxLogMessage("oops 12c"); wxLog::FlushActive();} // Call the EVT_UPDATE_UI handler explicitly and retest. mvc.OnUpdateGUI(update); if( check0.GetValue()) {wxLogMessage("oops 10d"); wxLog::FlushActive();} if( check1.IsEnabled()) {wxLogMessage("oops 11d"); wxLog::FlushActive();} if( check2.IsEnabled()) {wxLogMessage("oops 12d"); wxLog::FlushActive();} wxLogMessage("End of test."); wxLog::FlushActive(); }