lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [6126] Implement rectified test specification


From: Greg Chicares
Subject: [lmi-commits] [6126] Implement rectified test specification
Date: Sun, 08 Mar 2015 23:06:16 +0000

Revision: 6126
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=6126
Author:   chicares
Date:     2015-03-08 23:06:15 +0000 (Sun, 08 Mar 2015)
Log Message:
-----------
Implement rectified test specification

Modified Paths:
--------------
    lmi/trunk/ChangeLog
    lmi/trunk/wx_test_calculation_summary.cpp

Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2015-03-08 23:01:12 UTC (rev 6125)
+++ lmi/trunk/ChangeLog 2015-03-08 23:06:15 UTC (rev 6126)
@@ -35767,3 +35767,9 @@
 Implement rectified test specification. See:
   http://lists.nongnu.org/archive/html/lmi/2015-03/msg00009.html
 
+20150308T2306Z <address@hidden> [516]
+
+  wx_test_calculation_summary.cpp
+Implement rectified test specification. See:
+  http://lists.nongnu.org/archive/html/lmi/2015-03/msg00017.html
+

Modified: lmi/trunk/wx_test_calculation_summary.cpp
===================================================================
--- lmi/trunk/wx_test_calculation_summary.cpp   2015-03-08 23:01:12 UTC (rev 
6125)
+++ lmi/trunk/wx_test_calculation_summary.cpp   2015-03-08 23:06:15 UTC (rev 
6126)
@@ -33,6 +33,8 @@
 #include "wx_test_new.hpp"
 #include "wx_utility.hpp"
 
+#include <wx/checkbox.h>
+#include <wx/combobox.h>
 #include <wx/ffile.h>
 #include <wx/html/htmlpars.h>
 #include <wx/html/htmlwin.h>
@@ -66,105 +68,116 @@
 // summary.
 name_and_title const custom_columns_info[] =
     {{ "PolicyYear"             , "Policy Year"                 }
-    ,{ "AttainedAge"            , "Attained Age"                }
-    ,{ "Outlay"                 , "Net Outlay"                  }
-    ,{ "CSVNet_Current"         , "Curr Net Cash Surr Value"    }
-    ,{ "AcctVal_Current"        , "Curr Account Value"          }
-    ,{ "CSVNet_Guaranteed"      , "Guar Net Cash Surr Value"    }
-    ,{ "AcctVal_Guaranteed"     , "Guar Account Value"          }
-    ,{ "EOYDeathBft_Current"    , "Curr EOY Death Benefit"      }
-    ,{ "EOYDeathBft_Guaranteed" , "Guar EOY Death Benefit"      }
-    ,{ "NetWD"                  , "Withdrawal"                  }
     ,{ "NewCashLoan"            , "Annual Loan"                 }
-    ,{ "LoanIntAccrued_Current" , "Curr Loan Int Accrued"       }
     };
 
 std::size_t const number_of_custom_columns
     = sizeof custom_columns_info / sizeof(custom_columns_info[0]);
 
-// Special name used when the column is not used at all.
+// Special name used when the column is not used at all. This is the same
+// string used in preferences_model.cpp, but we duplicate it here as we don't
+// have access to it.
 char const* const magic_null_column_name = "[none]";
 
-// Change the calculation summary settings in the preferences dialog to use, or
-// not use, the built-in defaults.
-void use_builtin_calculation_summary(bool b)
+// Total number of configurable summary columns. This, again, duplicates the
+// number [implicitly] used in preferences_model.cpp.
+std::size_t const total_number_of_columns = 12;
+
+// Base class for all the tests working with the preferences dialog. It
+// defines both a simpler interface for the derived classes to define the
+// tests with the preferences dialog, and also provides a helper run() method
+// which shows the preferences dialog and performs these checks.
+class expect_preferences_dialog_base
+    :public wxExpectModalBase<MvcController>
 {
-    wxUIActionSimulator ui;
-    ui.Char('f', wxMOD_CONTROL);    // "File|Preferences"
+  public:
+    expect_preferences_dialog_base()
+        :dialog_(NULL)
+        ,use_checkbox_(NULL)
+        {
+        }
 
-    class ChangeCalculationSummaryInPreferencesDialog
-        :public wxExpectModalBase<MvcController>
-    {
-      public:
-        ChangeCalculationSummaryInPreferencesDialog
-            (bool use_builtin_summary)
-            :use_builtin_summary_(use_builtin_summary)
-            {
-            }
+    void run() const
+        {
+        wxUIActionSimulator ui;
+        ui.Char('f', wxMOD_CONTROL);    // "File|Preferences"
 
-        virtual int OnInvoked(MvcController* dialog) const
-            {
-            dialog->Show();
-            wxYield();
+        wxTEST_DIALOG(wxYield(), *this);
+        }
 
-            wxUIActionSimulator ui;
+    virtual int OnInvoked(MvcController* dialog) const
+        {
+        // OnInvoked() is const but it doesn't make much sense for
+        // OnPreferencesInvoked() to be const as it is going to modify the
+        // dialog, so cast away this constness once and for all.
+        expect_preferences_dialog_base* const
+            self = const_cast<expect_preferences_dialog_base*>(this);
 
-            // Go to the "Use built-in calculation summary" checkbox.
-            ui.Char(WXK_TAB);
-            wxYield();
+        self->dialog_ = dialog;
 
-            // Disable the checkbox initially as we need it to be disabled to
-            // change the values of the column controls.
-            ui.Char('-');
-            wxYield();
+        dialog->Show();
+        wxYield();
 
-            // Update the columns controls when using them.
-            for(std::size_t n = 0; n < number_of_custom_columns; ++n)
-                {
-                ui.Char(WXK_TAB);
-                wxYield();
+        wxWindow* const use_window = wx_test_focus_controller_child
+            (*dialog
+            ,"UseBuiltinCalculationSummary"
+            );
 
-                wxString const column_name
-                    (use_builtin_summary_
-                    ? magic_null_column_name
-                    : custom_columns_info[n].name
-                    );
+        self->use_checkbox_ = dynamic_cast<wxCheckBox*>(use_window);
+        LMI_ASSERT(use_checkbox_);
 
-                LMI_ASSERT(ui.Select(column_name));
+        return self->OnPreferencesInvoked();
+        }
 
-                wxYield();
-                }
+    virtual wxString GetDefaultDescription() const
+        {
+        return "preferences dialog";
+        }
 
-            // Finally return to the initial checkbox.
-            for(std::size_t n = 0; n < number_of_custom_columns; ++n)
-                {
-                ui.Char(WXK_TAB, wxMOD_SHIFT);
-                }
+  protected:
+    virtual int OnPreferencesInvoked() = 0;
 
-            wxYield();
+    // Helpers for the derived classes OnPreferencesInvoked().
+    void set_use_builtin_summary(bool use)
+        {
+        // Under MSW we could use "+" and "-" keys to set the checkbox value
+        // unconditionally, but these keys don't work under the other
+        // platforms, so it's simpler to use the space key which can be used on
+        // all platforms to toggle the checkbox -- but then we must do it only
+        // if really needed.
+        if(use_checkbox_->GetValue() != use)
+            {
+            use_checkbox_->SetFocus();
 
-            // And set it to the desired value.
-            ui.Char(use_builtin_summary_ ? '+' : '-');
+            wxUIActionSimulator ui;
+            ui.Char(WXK_SPACE);
             wxYield();
-
-            return wxID_OK;
             }
+        }
 
-        virtual wxString GetDefaultDescription() const
-            {
-            return "preferences dialog";
-            }
+    wxComboBox* focus_column_combobox(unsigned n)
+        {
+            wxWindow* const column_window = wx_test_focus_controller_child
+                (*dialog_
+                ,wxString::Format("CalculationSummaryColumn%02u", n).c_str()
+                );
 
-      private:
-        bool const use_builtin_summary_;
-    };
+            wxComboBox* const
+                column_combobox = dynamic_cast<wxComboBox*>(column_window);
+            LMI_ASSERT_WITH_MSG
+                (column_combobox
+                ,"control for column #" << n << "is not a wxComboBox"
+                );
 
-    wxTEST_DIALOG
-        (wxYield()
-        ,ChangeCalculationSummaryInPreferencesDialog(b)
-        );
-}
+            return column_combobox;
+        }
 
+    // These variables are only valid inside the overridden
+    // OnPreferencesInvoked() method.
+    MvcController* dialog_;
+    wxCheckBox* use_checkbox_;
+};
+
 void check_calculation_summary_columns
     (std::size_t number_of_columns
     ,name_and_title const columns_info[]
@@ -225,109 +238,8 @@
     LMI_ASSERT_EQUAL(wxString(html, pos, 5), "</tr>");
 }
 
-// Save the current clipboard contents to a file with the given name,
-// overwriting it if necessary.
-void save_clipboard(wxString const& filename)
-{
-    wxFFile f(filename, "w");
-    LMI_ASSERT(f.IsOpened());
-    LMI_ASSERT(f.Write(wxString(ClipboardEx::GetText())));
-    LMI_ASSERT(f.Close());
-}
-
-// Save the illustration calculation summary and full data to files with the
-// given prefix.
-void save_illustration_data(wxString const& prefix)
-{
-    wxUIActionSimulator ui;
-    ui.Char('c', wxMOD_CONTROL); // "Illustration|Copy calculation summary"
-    wxYield();
-    save_clipboard(prefix + "IllSummary.txt");
-
-    ui.Char('d', wxMOD_CONTROL); // "Illustration|Copy full illustration data"
-    wxYield();
-    save_clipboard(prefix + "IllFull.txt");
-}
-
 } // Unnamed namespace.
 
-/*
-    Start of the calculation summary unit test.
-
-    This partially implements the first half of the item 8 of the
-    testing specification:
-
-        8. Validate Calculation summary and a few of its features.
-
-          A. File | Preferences | check 'Use built-in calculation summary'
-             File | New | Illustration | Ok
-             Expected results:
-               These columns display in the calculation summary view:
-                 Policy Year
-                 Net Outlay
-                 Curr Account Value
-                 Curr Net Cash Surr Value
-                 Curr EOY Death Benefit
-               Inspect 'configurable_settings.xml' for:
-                 <calculation_summary_columns></calculation_summary_columns>
-
-          B. File | Preferences | uncheck 'Use built-in calculation summary'
-             select twelve different columns | inspect display for those 
columns
-             Expected results:
-               These columns display in the calculation summary view:
-                 Policy Year
-                 Attained Age
-                 Net Outlay
-                 Curr Net Cash Surr Value
-                 Curr Account Value
-                 Guar Net Cash Surr Value
-                 Guar Account Value
-                 Curr EOY Death Benefit
-                 Guar EOY Death Benefit
-                 Withdrawal
-                 Annual Loan
-                 Curr Loan Int Accrued
-               Inspect 'configurable_settings.xml' for:
-                 <calculation_summary_columns>AttainedAge PolicyYear Outlay \
-                  CSVNet_Current AcctVal_Current CSVNet_Guaranteed \
-                  AcctVal_Guaranteed EOYDeathBft_Current 
EOYDeathBft_Guaranteed \
-                  NetWD NewCashLoan LoanIntAccrued_Current 
</calculation_summary_columns>
-
-          C. File | New | Illustration
-             Illustration | Copy calculation summary
-             paste the output for inspection, then
-             Illustration | Copy full illustration data
-             paste the output for inspection
-
-          D. File | New | Census
-             Census | Run case
-             Illustration | Copy calculation summary
-             paste the output for inspection, then
-             Illustration | Copy full illustration data
-             paste the output for inspection
-             [note--apparently this creates a file automatically]
-
-    The output is pasted into 4 files called {New,Calc}Ill{Summary,Full}.txt in
-    the current working directory.
-    [note--we'd rather write them to the gui-test directory; but, as
-    noted above, (D) already writes its own file...and, as noted below,
-    it may be better to remove (C) and (D) from this file altogether.]
- */
-
-// 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:
-//  - Make sure default columns are used with '--distribution'.
-//  - Remove comment block (A) above: it's incorporated below.
-//  - Remove comment block (B) above: it's incorporated below, with
-//    only one column selected (twelve is overkill).
-//  - Remove comment blocks (C) and (D) above and their associated
-//    code: cf. 'wx_test_validate_output.cpp'.
-//  - Code the additional tests specified below.
-//  - Don't bother reading 'configurable_settings' directly: it cannot
-//    be wrong if all columns on the screen are correct.
-// ERASABLE BLOCK COMMENT ENDS.
-
 // Deferred ideas:
 //
 // Someday, test supplemental-report column selections similarly.
@@ -349,8 +261,8 @@
 ///   File | Preferences
 /// make sure that "Use built-in calculation summary" is checked, and
 /// that the saved selections (those that would become active if the
-/// checkbox were unchecked) exactly match the default selctions given
-/// by default_calculation_summary_columns().
+/// checkbox were unchecked) exactly match the default selections
+/// given by default_calculation_summary_columns().
 ///
 /// Display an illustration, to see calculation-summary effects:
 /// File | New | Illustration | OK
@@ -358,8 +270,6 @@
 /// File | Preferences
 /// uncheck "Use built-in calculation summary"
 /// set all "Column" controls to "[none]"
-///   do this by simulating {Tab Home} repeatedly because that is
-///   much faster and is what a smart user does
 /// in "Column 2" (two, not zero), select "NewCashLoan"
 /// OK
 /// Verify that the columns shown in the open illustration are exactly
@@ -387,53 +297,139 @@
 
 LMI_WX_TEST_CASE(calculation_summary)
 {
-    configurable_settings const& settings = configurable_settings::instance();
+    if(is_distribution_test())
+        {
+        // Not only is this the expected value in the GUI, but we also want to 
be
+        // sure that effective_calculation_summary_columns() returns the 
default
+        // columns in the code below -- and this is only the case when we are 
using
+        // the built-in calculation summary.
+        LMI_ASSERT
+            
(configurable_settings::instance().use_builtin_calculation_summary()
+            );
 
-    use_builtin_calculation_summary(true);
+        struct verify_builtin_calculation_summary : 
expect_preferences_dialog_base
+        {
+            virtual int OnPreferencesInvoked()
+                {
+                LMI_ASSERT_EQUAL(use_checkbox_->GetValue(), true);
 
-    LMI_ASSERT(settings.calculation_summary_columns().empty());
-    LMI_ASSERT(settings.use_builtin_calculation_summary());
+                std::vector<std::string> const&
+                    summary_columns = effective_calculation_summary_columns();
 
-    check_calculation_summary_columns
-        (number_of_default_columns
-        ,default_columns_info
-        );
+                for(unsigned n = 0; n < number_of_custom_columns; ++n)
+                    {
+                    wxString const& column = 
focus_column_combobox(n)->GetValue();
+                    if(n < summary_columns.size())
+                        {
+                        LMI_ASSERT_EQUAL(column, summary_columns[n]);
+                        }
+                    else
+                        {
+                        LMI_ASSERT_EQUAL(column, magic_null_column_name);
+                        }
+                    }
 
-    use_builtin_calculation_summary(false);
+                return wxID_CANCEL;
+                }
+        };
 
-    // Concatenate all the custom column names together. Notice that the
-    // trailing space is intentional as it is present in the configurable
-    // settings file too.
-    std::string all_custom_columns;
-    for(std::size_t n = 0; n < number_of_custom_columns; ++n)
-        {
-        all_custom_columns += custom_columns_info[n].name;
-        all_custom_columns += ' ';
+        verify_builtin_calculation_summary().run();
         }
 
-    LMI_ASSERT_EQUAL(settings.calculation_summary_columns(), 
all_custom_columns);
-    LMI_ASSERT(!settings.use_builtin_calculation_summary());
+    wx_test_new_illustration ill;
 
+    // Use a single "NewCashLoan" custom column in third position.
+    struct set_custom_columns_in_preferences_dialog : 
expect_preferences_dialog_base
+    {
+        virtual int OnPreferencesInvoked()
+            {
+            set_use_builtin_summary(false);
+
+            wxUIActionSimulator ui;
+            for(unsigned n = 0; n < total_number_of_columns; ++n)
+                {
+                focus_column_combobox(n);
+                ui.Select(n == 2 ? "NewCashLoan" : magic_null_column_name);
+                }
+
+            return wxID_OK;
+            }
+    };
+
+    set_custom_columns_in_preferences_dialog().run();
+
     check_calculation_summary_columns
         (number_of_custom_columns
         ,custom_columns_info
         );
 
-    wxUIActionSimulator ui;
+    // Now switch to using the default columns.
+    struct use_builtin_calculation_summary : expect_preferences_dialog_base
+    {
+        virtual int OnPreferencesInvoked()
+            {
+            // Before returning to the built-in summary, check that our custom
+            // value for the column #2 moved into the position #0 (because the
+            // first two columns were left unspecified).
+            LMI_ASSERT_EQUAL
+                (focus_column_combobox(0)->GetValue()
+                ,"NewCashLoan"
+                );
 
-    wx_test_new_illustration ill;
-    save_illustration_data("New");
-    ill.close();
+            // And all the rest of the columns are (still) empty.
+            for(unsigned n = 1; n < total_number_of_columns; ++n)
+                {
+                LMI_ASSERT_EQUAL
+                    (focus_column_combobox(n)->GetValue()
+                    ,magic_null_column_name
+                    );
+                }
 
-    wx_test_new_census census;
-    ui.Char('r', wxMOD_CONTROL | wxMOD_SHIFT); // "Census|Run case"
-    wxYield();
+            set_use_builtin_summary(true);
 
-    save_illustration_data("Calc");
+            return wxID_OK;
+            }
+    };
 
-    // Close the illustration opened by "Run case".
-    ui.Char('l', wxMOD_CONTROL);    // "File|Close"
-    wxYield();
+    use_builtin_calculation_summary().run();
 
-    census.close();
+    check_calculation_summary_columns
+        (number_of_default_columns
+        ,default_columns_info
+        );
+
+    // Finally, switch back to the previously configured custom columns.
+    struct use_custom_calculation_summary : expect_preferences_dialog_base
+    {
+      public:
+        virtual int OnPreferencesInvoked()
+            {
+            set_use_builtin_summary(false);
+
+            // The custom columns shouldn't have changed.
+            LMI_ASSERT_EQUAL
+                (focus_column_combobox(0)->GetValue()
+                ,"NewCashLoan"
+                );
+
+            for(unsigned n = 1; n < total_number_of_columns; ++n)
+                {
+                LMI_ASSERT_EQUAL
+                    (focus_column_combobox(n)->GetValue()
+                    ,magic_null_column_name
+                    );
+                }
+
+            return wxID_OK;
+            }
+    };
+
+    use_custom_calculation_summary().run();
+
+    check_calculation_summary_columns
+        (number_of_custom_columns
+        ,custom_columns_info
+        );
+
+    ill.close();
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]