mclose("all") showed a warning when it was executed in scinotes. 35/17035/2
Charlotte HECQUET [Fri, 14 Aug 2015 09:15:37 +0000 (11:15 +0200)]
test_run functions exec

Change-Id: I546eb195b2823bfa7552609e1c036ca768b7000c

scilab/modules/functions/sci_gateway/cpp/sci_exec.cpp
scilab/modules/functions/tests/unit_tests/exec.dia.ref
scilab/modules/functions/tests/unit_tests/exec.tst

index 9e078f2..d8c9005 100644 (file)
@@ -27,6 +27,7 @@
 #include "threadmanagement.hxx"
 #include "macro.hxx"
 #include "macrofile.hxx"
+#include "filemanager.hxx"
 
 #include <iostream>
 #include <fstream>
@@ -173,7 +174,11 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
                 ConfigVariable::setLastErrorMessage(parser.getErrorMessage());
                 ConfigVariable::setLastErrorNumber(999);
                 delete parser.getTree();
-                mclose(iID);
+                // Check if file has not already been closed (for ex mclose('all') in function)
+                if (FileManager::isOpened(pwstFile) == true)
+                {
+                    mclose(iID);
+                }
                 ThreadManagement::UnlockParser();
                 return Function::OK;
             }
@@ -183,7 +188,11 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
             FREE(pst);
 
             delete parser.getTree();
-            mclose(iID);
+            // Check if file has not already been closed (for ex mclose('all') in function)
+            if (FileManager::isOpened(pwstFile) == true)
+            {
+                mclose(iID);
+            }
             ThreadManagement::UnlockParser();
             return Function::Error;
         }
@@ -363,7 +372,11 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
                     if (file)
                     {
                         delete pExp;
-                        mclose(iID);
+                        // Check if file has not already been closed (for ex mclose('all') in function)
+                        if (FileManager::isOpened(pwstFile) == true)
+                        {
+                            mclose(iID);
+                        }
                         file->close();
                         delete file;
                         FREE(pstFile);
@@ -416,7 +429,11 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
     if (file)
     {
         delete pExp;
-        mclose(iID);
+        // Check if file has not already been closed (for ex mclose('all') in function)
+        if (FileManager::isOpened(pwstFile) == true)
+        {
+            mclose(iID);
+        }
         file->close();
         delete file;
         FREE(pstFile);
index 7201e1c..ca76bea 100644 (file)
@@ -56,3 +56,8 @@ y  =
 if isdef("y")<> %t then bugmes();quit;end
 if isdef("a")<> %t then bugmes();quit;end
 assert_checkequal(y, 25);
+// no warning must be displayed when
+// exec a file with mclose("all") inside
+filename = TMPDIR + filesep() + "testmclose.sce";
+mputl("mclose(""all"");",filename);
+exec(filename);
index 45caeeb..90c9cbc 100644 (file)
@@ -53,3 +53,8 @@ if isdef("y")<> %t then pause,end
 if isdef("a")<> %t then pause,end
 assert_checkequal(y, 25);
 
+// no warning must be displayed when
+// exec a file with mclose("all") inside
+filename = TMPDIR + filesep() + "testmclose.sce";
+mputl("mclose(""all"");",filename);
+exec(filename);