lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master e832bf1 3/4: Clean up extra files created dur


From: Greg Chicares
Subject: [lmi-commits] [lmi] master e832bf1 3/4: Clean up extra files created during MEC and GPT UI tests
Date: Mon, 30 Jul 2018 10:36:23 -0400 (EDT)

branch: master
commit e832bf15f614c059e831e19917ef1c2a24e26ffe
Author: Vadim Zeitlin <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Clean up extra files created during MEC and GPT UI tests
    
    Creating a new MEC or GPT document results in creation of 2 or 1 extra
    file in the current directory, which were not checked for nor cleaned up
    by the testing code.
    
    Do add both the checks (that might be unnecessary) and cleanup for them
    now.
    
    To simplify the new code, make output_file_existence_checker class
    movable and add path() accessor to it.
---
 wx_test_create_open.cpp | 37 +++++++++++++++++++++++++++++++++++++
 wx_test_output.hpp      | 12 +++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/wx_test_create_open.cpp b/wx_test_create_open.cpp
index 81812e5..3131ddc 100644
--- a/wx_test_create_open.cpp
+++ b/wx_test_create_open.cpp
@@ -22,6 +22,7 @@
 #include "pchfile_wx.hpp"
 
 #include "assert_lmi.hpp"
+#include "configurable_settings.hpp"
 #include "mvc_controller.hpp"
 #include "version.hpp"
 #include "wx_test_case.hpp"
@@ -145,12 +146,48 @@ LMI_WX_TEST_CASE(create_open_strata)
 
 LMI_WX_TEST_CASE(create_open_mec)
 {
+    auto const& tsv_ext = 
configurable_settings::instance().spreadsheet_file_extension();
+    std::string const xml_ext = ".xml"; // define for consistency with tsv_ext
+
+    // The generic function only tests for testfile.mec existence and only
+    // removes it at the end, but saving a MEC document creates 2 other files
+    // with the extra suffixes that we deal with here. Notice that these files
+    // are created in the current directory and not in the directory normally
+    // used for the test files.
+    //
+    // Additionally, just creating, without saving, a MEC document currently
+    // creates 2 other files as a side-effect, so deal with them here as well.
+    auto const number_of_extra_files = 4;
+    output_file_existence_checker extra_output_files[number_of_extra_files] =
+        {output_file_existence_checker{"testfile.mec" + tsv_ext}
+        ,output_file_existence_checker{"testfile.mec" + xml_ext}
+        ,output_file_existence_checker{"unnamed.mec" + tsv_ext}
+        ,output_file_existence_checker{"unnamed.mec" + xml_ext}
+        };
+
     do_test_create_open(*this, 'm', "testfile.mec", true);
+
+    for(int n = 0; n < number_of_extra_files; ++n)
+        {
+        LMI_ASSERT_WITH_MSG
+            (extra_output_files[n].exists()
+            ,"file \"" << extra_output_files[n].path() << "\""
+            );
+        }
 }
 
 LMI_WX_TEST_CASE(create_open_gpt)
 {
+    // Similarly to MEC files above, creating and saving GPT documents creates
+    // extra files in the current directory, but here there are only 2 of them,
+    // so don't bother with using an array.
+    output_file_existence_checker output_unnamed_gpt_xml{"unnamed.gpt.xml"};
+    output_file_existence_checker output_testfile_gpt_xml{"testfile.gpt.xml"};
+
     do_test_create_open(*this, 'g', "testfile.gpt", true);
+
+    LMI_ASSERT(output_unnamed_gpt_xml.exists());
+    LMI_ASSERT(output_testfile_gpt_xml.exists());
 }
 
 LMI_WX_TEST_CASE(create_open_text)
diff --git a/wx_test_output.hpp b/wx_test_output.hpp
index 6981880..6b430f3 100644
--- a/wx_test_output.hpp
+++ b/wx_test_output.hpp
@@ -57,10 +57,20 @@ class output_file_existence_checker
         return fs::exists(path_);
         }
 
-  private:
+    std::string const& path() const
+        {
+        return path_.string();
+        }
+
+    // Objects of this class can't be copied, because of side effects of its
+    // dtor, but can be moved.
+    output_file_existence_checker(output_file_existence_checker&&) = default;
+    output_file_existence_checker& operator=(output_file_existence_checker&&) 
= default;
+
     output_file_existence_checker(output_file_existence_checker const&) = 
delete;
     output_file_existence_checker& operator=(output_file_existence_checker 
const&) = delete;
 
+  private:
     fs::path path_;
 };
 



reply via email to

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