>From 4dc7745cfc09677f4d8c9e019aed8a356deca427 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 27 Nov 2014 01:42:13 +0100 Subject: [PATCH] Don't send wxEVT_UPDATE_UI events manually in the automatic tests. With the latest wxWidgets version, wxYield() does generate these events itself, even in wxMSW port, so it is not necessary to send them explicitly. This makes the code slightly simpler but, more importantly, ensures that the code is being tested in the same conditions as in which it is being actually used as wxYield(), as implemented inside wxWidgets, behaves in the same way as normal event handling loop. --- wx_test_calculation_summary.cpp | 15 ++++--- wx_test_default_update.cpp | 11 ++++- wx_test_mvc_dialog.hpp | 82 --------------------------------------- wx_test_paste_census.cpp | 11 ++++- wx_test_validate_output.cpp | 10 +++- 5 files changed, 32 insertions(+), 97 deletions(-) delete mode 100644 wx_test_mvc_dialog.hpp diff --git a/wx_test_calculation_summary.cpp b/wx_test_calculation_summary.cpp index dcf383f..7e43d3d 100644 --- a/wx_test_calculation_summary.cpp +++ b/wx_test_calculation_summary.cpp @@ -28,8 +28,8 @@ #include "assert_lmi.hpp" #include "configurable_settings.hpp" +#include "mvc_controller.hpp" #include "wx_test_case.hpp" -#include "wx_test_mvc_dialog.hpp" #include "wx_test_new.hpp" #include "wx_utility.hpp" @@ -93,7 +93,7 @@ void use_builtin_calculation_summary(bool b) ui.Char('f', wxMOD_CONTROL); // "File|Preferences" class ChangeCalculationSummaryInPreferencesDialog - :public ExpectMvcDialog + :public wxExpectModalBase { public: ChangeCalculationSummaryInPreferencesDialog @@ -102,8 +102,11 @@ void use_builtin_calculation_summary(bool b) { } - virtual void DoRunDialog(MvcController* dialog) const + virtual int OnInvoked(MvcController* dialog) const { + dialog->Show(); + wxYield(); + wxUIActionSimulator ui; // Go to the "Use built-in calculation summary" checkbox. @@ -115,8 +118,6 @@ void use_builtin_calculation_summary(bool b) ui.Char('-'); wxYield(); - DoUpdateDialogUI(dialog); - // Update the columns controls when using them. for(std::size_t n = 0; n < number_of_custom_columns; ++n) { @@ -131,7 +132,7 @@ void use_builtin_calculation_summary(bool b) LMI_ASSERT(ui.Select(column_name)); - DoUpdateDialogUI(dialog); + wxYield(); } // Finally return to the initial checkbox. @@ -145,6 +146,8 @@ void use_builtin_calculation_summary(bool b) // And set it to the desired value. ui.Char(use_builtin_summary_ ? '+' : '-'); wxYield(); + + return wxID_OK; } private: diff --git a/wx_test_default_update.cpp b/wx_test_default_update.cpp index 78ed138..ddf51c7 100644 --- a/wx_test_default_update.cpp +++ b/wx_test_default_update.cpp @@ -28,8 +28,8 @@ #include "assert_lmi.hpp" #include "configurable_settings.hpp" +#include "mvc_controller.hpp" #include "wx_test_case.hpp" -#include "wx_test_mvc_dialog.hpp" #include "wx_test_statusbar.hpp" #include @@ -64,10 +64,13 @@ ui.Char('t', wxMOD_CONTROL); // "File|Default" struct change_mac_in_defaults_dialog - :public ExpectMvcDialog + :public wxExpectModalBase { - virtual void DoRunDialog(MvcController* dialog) const + virtual int OnInvoked(MvcController* dialog) const { + dialog->Show(); + wxYield(); + wxUIActionSimulator ui; // Go to the first page: as the dialog remembers its last opened @@ -85,6 +88,8 @@ // radio box with two buttons. ui.Char(WXK_DOWN); wxYield(); + + return wxID_OK; } }; diff --git a/wx_test_mvc_dialog.hpp b/wx_test_mvc_dialog.hpp deleted file mode 100644 index c0884ad..0000000 --- a/wx_test_mvc_dialog.hpp +++ /dev/null @@ -1,82 +0,0 @@ -// Helper for testing MvcController dialogs. -// -// Copyright (C) 2014 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA -// -// http://savannah.nongnu.org/projects/lmi -// email: -// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA - -// $Id$ - -#ifndef wx_test_mvc_dialog_hpp -#define wx_test_mvc_dialog_hpp - -#include "config.hpp" - -#include "mvc_controller.hpp" - -#include -#include - -/// Abstract base class for the concrete expectations defining the actions to -/// perform when a given MvcController-derived dialog is shown. -/// -/// The main reason for this class existence is the unusual reliance of -/// MvcController on wxEVT_UPDATE_UI events for its functionality. As these -/// events are not sent from inside wxYield(), which is used throughout the -/// automatic tests, the dialog is not updated (i.e. the controls inside it -/// are not enabled when they should be, the corresponding program variables -/// are not updated when GUI controls change, and so on) unless we send these -/// events ourselves and this class helps with doing it. - -class ExpectMvcDialog - :public wxExpectModalBase -{ - public: - virtual int OnInvoked(MvcController* dialog) const - { - // Bring the dialog up. - dialog->Show(); - wxYield(); - - // Perform whichever actions are needed. - DoRunDialog(dialog); - - // And ensure that the model data is updated at the end. - DoUpdateDialogUI(dialog); - - return wxID_OK; - } - - protected: - // The method to be implemented in the derived classes for simulating the - // user actions that need to be performed in this dialog. - // - // DoUpdateDialogUI() should be used after simulating any action updating - // the state of the dialog. - virtual void DoRunDialog(MvcController* dialog) const = 0; - - // Ensure that the dialog state takes into account all the events simulated - // so far by explicitly letting it process a wxUpdateUIEvent. - void DoUpdateDialogUI(MvcController* dialog) const - { - wxUpdateUIEvent event(dialog->GetId()); - event.SetEventObject(dialog); - dialog->ProcessWindowEvent(event); - } -}; - -#endif // wx_test_mvc_dialog_hpp diff --git a/wx_test_paste_census.cpp b/wx_test_paste_census.cpp index d4b7b5a..e166f1f 100644 --- a/wx_test_paste_census.cpp +++ b/wx_test_paste_census.cpp @@ -28,8 +28,8 @@ #include "assert_lmi.hpp" #include "data_directory.hpp" +#include "mvc_controller.hpp" #include "wx_test_case.hpp" -#include "wx_test_mvc_dialog.hpp" #include "wx_test_new.hpp" #include "wx_utility.hpp" @@ -211,10 +211,13 @@ bool does_list_have_column(wxDataViewCtrl* dvc, wxString const& name) ui.Char('e', wxMOD_CONTROL | wxMOD_SHIFT); // "Census|Edit case defaults" struct change_class_in_case_defaults_dialog - :public ExpectMvcDialog + :public wxExpectModalBase { - virtual void DoRunDialog(MvcController* dialog) const + virtual int OnInvoked(MvcController* dialog) const { + dialog->Show(); + wxYield(); + wxUIActionSimulator ui; // Go to the third page: as the dialog remembers its last opened @@ -249,6 +252,8 @@ bool does_list_have_column(wxDataViewCtrl* dvc, wxString const& name) wxYield(); LMI_ASSERT_EQUAL(class_radiobox->GetSelection(), 0); + + return wxID_OK; } }; diff --git a/wx_test_validate_output.cpp b/wx_test_validate_output.cpp index 2ed3ac5..a814090 100644 --- a/wx_test_validate_output.cpp +++ b/wx_test_validate_output.cpp @@ -31,7 +31,6 @@ #include "mvc_controller.hpp" #include "uncopyable_lmi.hpp" #include "wx_test_case.hpp" -#include "wx_test_mvc_dialog.hpp" #include "wx_test_new.hpp" #include @@ -120,10 +119,13 @@ class output_file_existence_checker output_file_existence_checker unnamed_trace("unnamed.monthly_trace" + ext); struct enter_comment_in_illustration_dialog - :public ExpectMvcDialog + :public wxExpectModalBase { - virtual void DoRunDialog(MvcController* dialog) const + virtual int OnInvoked(MvcController* dialog) const { + dialog->Show(); + wxYield(); + wxUIActionSimulator ui; // Go to the first page: as the dialog remembers its last opened @@ -145,6 +147,8 @@ class output_file_existence_checker ui.Text("idiosyncrasyZ"); wxYield(); + + return wxID_OK; } }; -- 1.7.9