lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [6072] Add '--gui_test_path'


From: Greg Chicares
Subject: [lmi-commits] [6072] Add '--gui_test_path'
Date: Mon, 15 Dec 2014 12:39:27 +0000

Revision: 6072
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=6072
Author:   chicares
Date:     2014-12-15 12:39:27 +0000 (Mon, 15 Dec 2014)
Log Message:
-----------
Add '--gui_test_path'

Modified Paths:
--------------
    lmi/trunk/ChangeLog
    lmi/trunk/main_wx_test.cpp
    lmi/trunk/wx_test_case.hpp
    lmi/trunk/wx_test_create_open.cpp
    lmi/trunk/wx_test_input_sequences.cpp
    lmi/trunk/wx_test_input_validation.cpp
    lmi/trunk/wx_test_paste_census.cpp
    lmi/trunk/wx_test_validate_output.cpp

Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2014-12-15 12:20:13 UTC (rev 6071)
+++ lmi/trunk/ChangeLog 2014-12-15 12:39:27 UTC (rev 6072)
@@ -34875,3 +34875,15 @@
 Improve failure reporting. See:
   http://lists.nongnu.org/archive/html/lmi/2014-12/msg00068.html
 
+20141215T1239Z <address@hidden> [516]
+
+  main_wx_test.cpp
+  wx_test_case.hpp
+  wx_test_create_open.cpp
+  wx_test_input_sequences.cpp
+  wx_test_input_validation.cpp
+  wx_test_paste_census.cpp
+  wx_test_validate_output.cpp
+Add '--gui_test_path'. See:
+  http://lists.nongnu.org/archive/html/lmi/2014-12/msg00068.html
+

Modified: lmi/trunk/main_wx_test.cpp
===================================================================
--- lmi/trunk/main_wx_test.cpp  2014-12-15 12:20:13 UTC (rev 6071)
+++ lmi/trunk/main_wx_test.cpp  2014-12-15 12:39:27 UTC (rev 6072)
@@ -48,6 +48,8 @@
 #include <wx/uiaction.h>
 #include <wx/wfstream.h>
 
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
 #include <boost/scoped_ptr.hpp>
 
 #include <algorithm>                    // std::sort()
@@ -177,6 +179,10 @@
     // Used by tests to retrieve their configuration parameters.
     wxConfigBase const& get_config_for(char const* name);
 
+    // Return the configured directory (current one by default) to use for the
+    // test files.
+    fs::path const& get_test_files_path() const { return test_files_path_; }
+
     // Used to check if distribution tests should be enabled.
     bool is_distribution_test() const { return is_distribution_test_; }
 
@@ -231,6 +237,8 @@
 
     boost::scoped_ptr<wxFileConfig> config_;
 
+    fs::path test_files_path_;
+
     bool run_all_;
 
     bool is_distribution_test_;
@@ -302,11 +310,20 @@
 
 bool application_test::process_command_line(int& argc, char* argv[])
 {
+    // THIRD_PARTY !! We have this long and error-prone code to parse the
+    // command line manually here only because getopt_long() is not composable
+    // and so we can't use it with our own options here while still leaving the
+    // standard options for the base class to handle. It would be better to use
+    // a standard command line parsing mechanism if it ever becomes possible.
+
     // This variable is used both as a flag indicating that the last option was
     // the one selecting the test to run and so must be followed by the test
     // name, but also for the diagnostic message at the end of this function.
     char const* last_test_option = 0;
 
+    char const* opt_gui_test_path = "--gui_test_path";
+    int const opt_gui_test_path_length = strlen(opt_gui_test_path);
+
     for(int n = 1; n < argc; )
         {
         char const* const arg = argv[n];
@@ -339,6 +356,32 @@
             is_distribution_test_ = true;
             remove_arg(n, argc, argv);
             }
+        else if(0 == std::strncmp(arg, opt_gui_test_path, 
opt_gui_test_path_length))
+            {
+            if (arg[opt_gui_test_path_length]=='=')
+                {
+                test_files_path_ = arg + opt_gui_test_path_length + 1;
+                }
+            else
+                {
+                if (n == argc - 1)
+                    {
+                    warning()
+                        << "Option '"
+                        << opt_gui_test_path
+                        << "' must be followed by the path to use."
+                        << std::flush
+                        ;
+                    }
+                else
+                    {
+                    remove_arg(n, argc, argv);
+                    test_files_path_ = argv[n];
+                    }
+                }
+
+            remove_arg(n, argc, argv);
+            }
         else if
             (
                0 == std::strcmp(arg, "-h")
@@ -352,11 +395,12 @@
                    "Usage: "
                 << argv[0]
                 << "\n"
-                   "  -h,\t--help     \tdisplay this help and exit\n"
-                   "  -l,\t--list     \tlist all available tests and exit\n"
-                   "  -t <name> or    \trun only the specified test (may 
occur\n"
-                   "  --test <name>   \tmultiple times); default: run all 
tests\n"
-                   "  --distribution  \tenable distribution-specific tests\n"
+                   "  -h,\t--help           \tdisplay this help and exit\n"
+                   "  -l,\t--list           \tlist all available tests and 
exit\n"
+                   "  -t <name> or          \trun only the specified test (may 
occur\n"
+                   "  --test <name>         \tmultiple times); default: run 
all tests\n"
+                   "  --gui_test_path <path>\tpath to use for test files\n"
+                   "  --distribution        \tenable distribution-specific 
tests\n"
                    "\n"
                    "Additionally, all command line options supported by the\n"
                    "main lmi executable are also supported."
@@ -380,6 +424,27 @@
             ;
         }
 
+    // Ensure that the path used for the test files is always valid and
+    // absolute, so that it doesn't change even if the program current
+    // directory changes for whatever reason.
+    if(test_files_path_.empty() || !fs::exists(test_files_path_))
+        {
+        if(!test_files_path_.empty())
+            {
+            warning()
+                << "Test files path '"
+                << test_files_path_.native_file_string()
+                << "' doesn't exist."
+                << std::flush
+                ;
+            }
+        test_files_path_ = fs::current_path();
+        }
+    else
+        {
+        test_files_path_ = fs::system_complete(test_files_path_);
+        }
+
     return true;
 }
 
@@ -508,6 +573,17 @@
         }
 }
 
+fs::path wx_base_test_case::get_test_files_path() const
+{
+    return application_test::instance().get_test_files_path();
+}
+
+std::string
+wx_base_test_case::get_test_file_path_for(std::string const& basename) const
+{
+    return (get_test_files_path() / basename).native_file_string();
+}
+
 bool wx_base_test_case::is_distribution_test() const
 {
     return application_test::instance().is_distribution_test();

Modified: lmi/trunk/wx_test_case.hpp
===================================================================
--- lmi/trunk/wx_test_case.hpp  2014-12-15 12:20:13 UTC (rev 6071)
+++ lmi/trunk/wx_test_case.hpp  2014-12-15 12:39:27 UTC (rev 6072)
@@ -28,6 +28,8 @@
 
 #include "uncopyable_lmi.hpp"
 
+#include <boost/filesystem/path.hpp>
+
 class wxConfigBase;
 
 /// Base class for the test case objects.
@@ -65,6 +67,19 @@
     /// Throws test_skipped_exception if the file is not supported.
     void skip_if_not_supported(char const* file);
 
+    /// Return the base directory containing the test files.
+    ///
+    /// This is the same directory as is used by get_test_file_path_for(),
+    /// prefer to use that function if possible.
+    fs::path get_test_files_path() const;
+
+    /// Return the full path for the file with the given base name (which
+    /// should include the extension, but no path components).
+    ///
+    /// The directory of the returned path can be changed by using the command
+    /// line --gui_test_path option when running the test.
+    std::string get_test_file_path_for(std::string const& basename) const;
+
     /// Return true if running in distribution testing mode.
     ///
     /// This method is used to restrict execution of the tests that are

Modified: lmi/trunk/wx_test_create_open.cpp
===================================================================
--- lmi/trunk/wx_test_create_open.cpp   2014-12-15 12:20:13 UTC (rev 6071)
+++ lmi/trunk/wx_test_create_open.cpp   2014-12-15 12:39:27 UTC (rev 6072)
@@ -49,11 +49,12 @@
 void do_test_create_open
         (wx_base_test_case& test
         ,int key
-        ,wxString const& file
+        ,char const* basename
         ,bool uses_dialog)
 {
-    test.skip_if_not_supported(file.c_str());
+    test.skip_if_not_supported(basename);
 
+    wxString const file = test.get_test_file_path_for(basename);
     LMI_ASSERT(!wxFileExists(file));
 
     wxUIActionSimulator z;
@@ -104,11 +105,6 @@
     wxYield();
 }
 
-// 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:
-//  - Put all files in 'gui_test_path'.
-
 /// Create, save, and reopen a file of each available type.
 ///
 /// Validate each tested operation, then erase the file.

Modified: lmi/trunk/wx_test_input_sequences.cpp
===================================================================
--- lmi/trunk/wx_test_input_sequences.cpp       2014-12-15 12:20:13 UTC (rev 
6071)
+++ lmi/trunk/wx_test_input_sequences.cpp       2014-12-15 12:39:27 UTC (rev 
6072)
@@ -30,7 +30,6 @@
 #include "configurable_settings.hpp"
 #include "wx_test_case.hpp"
 
-#include <wx/filename.h>
 #include <wx/testing.h>
 #include <wx/uiaction.h>
 
@@ -61,17 +60,12 @@
 
 LMI_WX_TEST_CASE(input_sequences)
 {
-    // Construct the path of the file to open, it's supposed to be in the same
-    // directory as the default input filename.
-    wxFileName fn(configurable_settings::instance().default_input_filename()); 
// Instead use '--gui_test_path'.
-    fn.SetFullName("InputSequences.cns");
-
     wxUIActionSimulator ui;
 
     ui.Char('o', wxMOD_CONTROL);    // "File|Open"
     wxTEST_DIALOG
         (wxYield()
-        ,wxExpectModal<wxFileDialog>(fn.GetFullPath())
+        
,wxExpectModal<wxFileDialog>(get_test_file_path_for("InputSequences.cns"))
         );
 
     ui.Char('r', wxMOD_CONTROL | wxMOD_SHIFT); // "Census|Run case"

Modified: lmi/trunk/wx_test_input_validation.cpp
===================================================================
--- lmi/trunk/wx_test_input_validation.cpp      2014-12-15 12:20:13 UTC (rev 
6071)
+++ lmi/trunk/wx_test_input_validation.cpp      2014-12-15 12:39:27 UTC (rev 
6072)
@@ -30,7 +30,6 @@
 #include "configurable_settings.hpp"
 #include "wx_test_case.hpp"
 
-#include <wx/filename.h>
 #include <wx/testing.h>
 #include <wx/uiaction.h>
 
@@ -63,11 +62,9 @@
     wxUIActionSimulator ui;
     ui.Char('o', wxMOD_CONTROL);    // "File|Open"
 
-    wxFileName fn(configurable_settings::instance().default_input_filename()); 
// Instead use '--gui_test_path'.
-    fn.SetFullName("CoiMultiplier.cns");
     wxTEST_DIALOG
         (wxYield()
-         ,wxExpectModal<wxFileDialog>(fn.GetFullPath())
+         
,wxExpectModal<wxFileDialog>(get_test_file_path_for("CoiMultiplier.cns"))
         );
 
     ui.Char('r', wxMOD_CONTROL | wxMOD_SHIFT);  // "Census|Run case"

Modified: lmi/trunk/wx_test_paste_census.cpp
===================================================================
--- lmi/trunk/wx_test_paste_census.cpp  2014-12-15 12:20:13 UTC (rev 6071)
+++ lmi/trunk/wx_test_paste_census.cpp  2014-12-15 12:39:27 UTC (rev 6072)
@@ -141,7 +141,6 @@
 //  - Save pastable data inline; don't extract from user manual.
 //  - Validate all columns after each step (after initial pasting).
 //  - Test change in class defaults (in addition to case defaults).
-//  - Place the saved file in 'gui_test_path'.
 
 /// Test pasting spreadsheet data into a census.
 ///
@@ -268,7 +267,7 @@
     LMI_ASSERT(!does_list_have_column(list_window, column_title));
 
     // Finally save the census with the pasted data for later inspection.
-    static char const* census_file_name = "PasteCensus.cns";
+    wxString const census_file_name = 
get_test_file_path_for("PasteCensus.cns");
 
     ui.Char('a', wxMOD_CONTROL);    // "File|Save as"
     wxTEST_DIALOG

Modified: lmi/trunk/wx_test_validate_output.cpp
===================================================================
--- lmi/trunk/wx_test_validate_output.cpp       2014-12-15 12:20:13 UTC (rev 
6071)
+++ lmi/trunk/wx_test_validate_output.cpp       2014-12-15 12:39:27 UTC (rev 
6072)
@@ -33,7 +33,6 @@
 #include "wx_test_case.hpp"
 #include "wx_test_new.hpp"
 
-#include <wx/filename.h>
 #include <wx/testing.h>
 #include <wx/uiaction.h>
 
@@ -167,13 +166,10 @@
     output_file_existence_checker
         existing_trace("MonthlyTrace.monthly_trace" + ext);
 
-    wxFileName fn(configurable_settings::instance().default_input_filename()); 
// Instead use '--gui_test_path'.
-    fn.SetFullName("MonthlyTrace.ill");
-
     ui.Char('o', wxMOD_CONTROL);    // "File|Open"
     wxTEST_DIALOG
         (wxYield()
-        ,wxExpectModal<wxFileDialog>(fn.GetFullPath())
+        
,wxExpectModal<wxFileDialog>(get_test_file_path_for("MonthlyTrace.ill"))
         ,wxExpectModal<wxMessageDialog>(wxID_OK)          // Ignore warning.
         ,wxExpectDismissableModal<MvcController>(wxID_OK) // Accept defaults.
         );
@@ -211,13 +207,10 @@
     // And when opening an existing one.
     output_file_existence_checker existing_output("MecTesting.mec" + ext);
 
-    wxFileName fn(configurable_settings::instance().default_input_filename()); 
// Instead use '--gui_test_path'.
-    fn.SetFullName("MecTesting.mec");
-
     ui.Char('o', wxMOD_CONTROL);    // "File|Open"
     wxTEST_DIALOG
         (wxYield()
-         ,wxExpectModal<wxFileDialog>(fn.GetFullPath())
+         ,wxExpectModal<wxFileDialog>(get_test_file_path_for("MecTesting.mec"))
          ,wxExpectDismissableModal<MvcController>(wxID_OK) // Accept defaults.
         );
 




reply via email to

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