>From 2b4a4dc8ed0a1720619977bc36371d9b0badf001 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 4 Mar 2015 18:14:46 +0100 Subject: [PATCH] Implement the updated input sequences test specification. Hard code the test input sequences in the test itself instead of taking them from the InputSequences.cns file. Test sequences validation in their entry dialog and also by running the illustration using them. Add another sequence in addition to those present in the manual and InputSequences.cns. --- wx_test_input_sequences.cpp | 120 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 98 insertions(+), 22 deletions(-) diff --git a/wx_test_input_sequences.cpp b/wx_test_input_sequences.cpp index d8b756f..99034ad 100644 --- a/wx_test_input_sequences.cpp +++ b/wx_test_input_sequences.cpp @@ -29,22 +29,16 @@ #include "assert_lmi.hpp" #include "configurable_settings.hpp" #include "wx_test_case.hpp" +#include "wx_test_new.hpp" #include #include -// ERASE THIS BLOCK COMMENT WHEN IMPLEMENTATION COMPLETE. The block -// comment below changes the original specification, and does not -// yet describe the present code. Desired changes: -// - Hard code the sequences; get rid of 'InputSequences.cns'. -// - Paste each test sequence into a temporary input dialog. -// - Validate with ellipsis button and then with OK. - /// Validate a variety of input sequences in the GUI input dialog. /// /// Test a broad variety of input sequences. For now, use the set in /// the user manual: -/// file:///C:/lmi/src/web/lmi/sequence_input.html +/// http://www.nongnu.org/lmi/sequence_input.html /// but hard code them here--later they might differ, e.g. if we /// decide to add extra tests here. /// @@ -58,25 +52,107 @@ /// Reopen the tabbed dialog for each subsequent test. When done, /// close the illustration without saving it. +namespace +{ + +// Combine the input sequence itself with the field it should be entered into. +struct input_sequence_test_data +{ + char const* field; + char const* sequence; +}; + +input_sequence_test_data const test_cases[] = +{ + // These sequences correspond to the examples from the manual. + { "SpecifiedAmount" ,"sevenpay 7; 250000 retirement; 100000 #10; 75000 @95; 50000" }, + { "SpecifiedAmount" ,"100000; 110000; 120000; 130000; 140000; 150000" }, + { "PaymentMode" ,"annual; monthly" }, + { "Payment" ,"10000 20; 0" }, + { "Payment" ,"10000 10; 5000 15; 0" }, + { "Payment" ,"10000 @70; 0" }, + { "Payment" ,"10000 retirement; 0" }, + { "Payment" ,"0 retirement; 5000" }, + { "Payment" ,"0 retirement; 5000 maturity" }, + { "Withdrawal" ,"0 retirement; 5000 #10; 0" }, + { "Withdrawal" ,"0,[0,retirement);10000,[retirement,#10);0" }, + + // This is an additional sequence used solely for testing. + { "ProjectedSalary" ,"100000; 105000; 110000 retirement; 0" }, +}; + +} // anonymous namespace + LMI_WX_TEST_CASE(input_sequences) { - wxUIActionSimulator ui; + wx_test_new_illustration ill; - ui.Char('o', wxMOD_CONTROL); // "File|Open" - wxTEST_DIALOG - (wxYield() - ,wxExpectModal(get_test_file_path_for("InputSequences.cns")) - ); + struct test_sequence_dialog : public wxExpectModalBase + { + explicit test_sequence_dialog(input_sequence_test_data const& test_data) + :test_data_(test_data) + {} - ui.Char('r', wxMOD_CONTROL | wxMOD_SHIFT); // "Census|Run case" - wxYield(); + virtual int OnInvoked(MvcController* dialog) const + { + dialog->Show(); + wxYield(); - // Close the illustration opened by "Run case". - ui.Char('l', wxMOD_CONTROL); // "File|Close" - wxYield(); + if(!wxWindow::FindWindowByName(test_data_.field, dialog)) + { + // If the field for this input sequence doesn't exist in the + // currently used skin at all, skip this particular sequence + // silently -- but continue testing the other ones. + return wxID_CANCEL; + } + + // Focus the field in which the sequence should be entered. + wx_test_focus_controller_child(*dialog, test_data_.field); + + // Do type the sequence into it. + wxUIActionSimulator ui; + ui.Text(test_data_.sequence); + wxYield(); + + // Switch to the ellipsis button which should be next to it. + ui.Char(WXK_TAB); + wxYield(); + + // Show the dialog for sequence entry and dismiss it immediately. + ui.Char(WXK_SPACE); + wxTEST_DIALOG + (wxYield() + ,wxExpectDismissableModal(wxOK). + Describe("sequence entry dialog" + sequence_describe()) + ); + + return wxID_OK; + } + + virtual wxString GetDefaultDescription() const + { + return "cell properties dialog" + sequence_describe(); + } + + // Helper providing the description of the sequence tested by this + // particular dialog, including it in the various descriptions should + // make it easier to find the exact failing test if anything goes + // wrong. + wxString sequence_describe() const + { + return wxString::Format(" for sequence \"%s\"" ,test_data_.sequence); + } + + input_sequence_test_data const& test_data_; + }; + + wxUIActionSimulator ui; + for(std::size_t n = 0; n < sizeof test_cases / sizeof(test_cases[0]); n++) + { + ui.Char('e', wxMOD_CONTROL); // "Illustration|Edit Cell" + wxTEST_DIALOG(wxYield(), test_sequence_dialog(test_cases[n])); + } - // And the census itself as well. - ui.Char('l', wxMOD_CONTROL); // "File|Close" - wxYield(); + ill.close_discard_changes(); } -- 2.1.0