fix string module tests 57/17657/3
Antoine ELIAS [Sun, 10 Jan 2016 09:52:18 +0000 (10:52 +0100)]
Change-Id: I507494bb3599c1e4e0a7bc579e80e6984a627105

34 files changed:
scilab/modules/ast/src/cpp/symbol/context.cpp
scilab/modules/data_structures/help/en_US/setfield.xml
scilab/modules/data_structures/sci_gateway/cpp/sci_setfield.cpp
scilab/modules/io/macros/%_sodload.sci
scilab/modules/io/src/cpp/loadlib.cpp
scilab/modules/m2sci/macros/kernel/%infer_i_s.sci
scilab/modules/overloading/macros/%0_i_st.sci
scilab/modules/overloading/macros/%b_i_s.sci
scilab/modules/overloading/macros/%c_i_s.sci
scilab/modules/overloading/macros/%cblock_c_cblock.sci
scilab/modules/overloading/macros/%cblock_c_s.sci
scilab/modules/overloading/macros/%cblock_e.sci
scilab/modules/overloading/macros/%cblock_f_cblock.sci
scilab/modules/overloading/macros/%ce_6.sci
scilab/modules/overloading/macros/%ce_e.sci
scilab/modules/overloading/macros/%ce_i_ce.sci
scilab/modules/overloading/macros/%i_i_s.sci
scilab/modules/overloading/macros/%lss_i_s.sci
scilab/modules/overloading/macros/%msp_i_s.sci
scilab/modules/overloading/macros/%p_i_s.sci
scilab/modules/overloading/macros/%r_i_s.sci
scilab/modules/overloading/macros/%s_c_cblock.sci
scilab/modules/overloading/macros/%s_i_s.sci
scilab/modules/overloading/macros/%sp_i_s.sci
scilab/modules/overloading/macros/%st_6.sci
scilab/modules/overloading/macros/%st_e.sci
scilab/modules/overloading/macros/%st_i_st.sci
scilab/modules/overloading/macros/%st_t.sci
scilab/modules/overloading/macros/createstruct.sci
scilab/modules/overloading/macros/generic_i_s.sci
scilab/modules/overloading/macros/generic_i_st.sci
scilab/modules/parameters/macros/add_param.sci
scilab/modules/string/tests/nonreg_tests/bug_10816.dia.ref [deleted file]
scilab/modules/string/tests/nonreg_tests/bug_10816.tst [deleted file]

index e5bcce8..de445b6 100644 (file)
@@ -276,7 +276,7 @@ int Context::getConsoleVarsName(std::list<std::wstring>& lst)
 {
     if (console)
     {
-        for (const auto& var : *console)
+        for (const auto & var : *console)
         {
             lst.push_back(var.first.getName());
         }
@@ -353,6 +353,19 @@ bool Context::put(Variable* _var, types::InternalType* _pIT)
 bool Context::put(const Symbol& _key, types::InternalType* _pIT)
 {
     Variable* var = variables.getOrCreate(_key);
+
+    if (var->empty())
+    {
+        //box is empty, check if a macro from a library have this name.
+        //in this case, add it to context before set new value.
+        types::InternalType* pIT = get(_key);
+        if (pIT && (pIT->isMacroFile() || pIT->isMacro()))
+        {
+            put(var, pIT);
+            return put(var, _pIT);
+        }
+    }
+
     return put(var, _pIT);
 }
 
index fe691c1..e82154e 100644 (file)
@@ -17,7 +17,7 @@
     </refnamediv>
     <refsynopsisdiv>
         <title>Calling Sequence</title>
-        <synopsis>setfield(i, x, l)</synopsis>
+        <synopsis>a = setfield(i, x, l)</synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Arguments</title>
                     </para>
                 </listitem>
             </varlistentry>
+            <varlistentry>
+                <term>a</term>
+                <listitem>
+                    <para>
+                        Updated variable.
+                    </para>
+                </listitem>
+            </varlistentry>
         </variablelist>
     </refsection>
     <refsection>
@@ -61,9 +69,7 @@ l=list(1,'qwerw',%s)
 l(1)='Changed'
 l(0)='Added'
 l(6)=['one more';'added']
-a=hypermat([2,2,2],rand(1:2^3));// hypermatrices are coded using mlists
-setfield(3,1:8,a);a // set the field value to 1:8
+l=setfield(5,"added by setfield", l)
  ]]></programlisting>
     </refsection>
     <refsection role="see also">
@@ -74,4 +80,15 @@ setfield(3,1:8,a);a // set the field value to 1:8
             </member>
         </simplelist>
     </refsection>
+    <refsection>
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0.0</revnumber>
+                <revdescription>
+                    setfield returns variable updated instead of change it "in place".
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 64d6f52..c280b0d 100644 (file)
@@ -45,6 +45,10 @@ types::Function::ReturnValue sci_setfield(types::typed_list &in, int _iRetCount,
     types::InternalType* pIndex = in[0];
     types::InternalType* pData = in[1];
     types::List* pL = in[2]->getAs<types::List>();
+    if (pL->isDeletable() == false)
+    {
+        pL = pL->clone();
+    }
 
     if (pL->isList() == false && pL->isMList() == false && pL->isTList() == false)
     {
@@ -65,18 +69,28 @@ types::Function::ReturnValue sci_setfield(types::typed_list &in, int _iRetCount,
         types::TList* pT = pL->getAs<types::TList>();
 
         std::wstring stField = pS->get(0);
-        if (pT->set(stField, pData) == false)
+        types::TList* pRet = pT->set(stField, pData);
+        if(pRet == nullptr)
         {
             Scierror(999, _("%s: Invalid index.\n"), "setfield");
             return types::Function::Error;
         }
+
+        out.push_back(pRet);
     }
     else
     {
         //insertion by index
         types::typed_list Args;
         Args.push_back(pIndex);
-        pL->insert(&Args, pData);
+        types::InternalType* pRet = pL->insert(&Args, pData);
+        if (pRet == nullptr)
+        {
+            Scierror(999, _("%s: Invalid index.\n"), "setfield");
+            return types::Function::Error;
+        }
+
+        out.push_back(pRet);
     }
 
     return types::Function::OK;
index 5f940f7..b2ffdd4 100644 (file)
@@ -103,7 +103,7 @@ function varargout = %_sodload(%__varnameList__)
                 elseif isList(fieldValue) then
                     fieldValue = parseList(fieldValue);
                 end
-                setfield(kField, fieldValue, varValue);
+                varValue = setfield(kField, fieldValue, varValue);
             end
         end
     endfunction
index f52a622..f9e7f86 100644 (file)
@@ -41,7 +41,7 @@ types::Library* loadlib(const std::wstring& _wstXML, int* err, bool _isFile, boo
     get_full_pathW(pwstTemp, pwstPathLib, PATH_MAX * 2);
     FREE(pwstPathLib);
 
-    std::wstring wstOriginalPath(pwstTemp);
+    std::wstring wstOriginalPath(_wstXML);
     std::wstring wstFile(pwstTemp);
     std::wstring wstPath(pwstTemp);
     FREE(pwstTemp);
index 528cc0f..8df80ab 100644 (file)
@@ -21,14 +21,14 @@ function M=%infer_i_s(varargin)
             if index=="entries" then
                 // change struct to cell
                 f=getfield(1,M);f(1)="ce"
-                setfield(1,f,M)
+                M=setfield(1,f,M)
             end
         else
             M=createstruct(index,N)
             if type(index(1))<>10 & index(2)=="entries" then
                 // change struct to cell
                 f=getfield(1,M);f(1)="ce"
-                setfield(1,f,M)
+                M=setfield(1,f,M)
             end
         end
         return
index 420e3f9..4a0a57e 100644 (file)
@@ -13,8 +13,8 @@ function st=%0_i_st(i,void,st)
         k=find(f(3:$)==i);
         if k<>[] then
             f(k+2)=[];
-            setfield(k+2,null(),st);
-            setfield(1,f,st);
+            st = setfield(k+2,null(),st);
+            st = setfield(1,f,st);
         else
             error(msprintf(_("%s: Invalid index.\n"),"%0_i_st"));
         end
index 26ae99e..1a7c2c6 100644 (file)
@@ -20,7 +20,7 @@ function M=%b_i_s(varargin)
         if type(index(1))<>10 & index(2)=="entries" then
             // change struct to cell
             f=getfield(1,M);f(1)="ce"
-            setfield(1,f,M)
+            M=setfield(1,f,M)
         end
     elseif rhs>4 then //more than 2 indices: insertion of a boolean in a matrix of numbers
         M=varargin($)
index c265fee..a659df2 100644 (file)
@@ -22,7 +22,7 @@ function M=%c_i_s(varargin)
             if index=="entries" then //M.entries=N
                 // change struct to cell
                 f=getfield(1,M);f(1)="ce"
-                setfield(1,f,M)
+                M=setfield(1,f,M)
             end
             return
         elseif type(index)==15 then
@@ -34,7 +34,7 @@ function M=%c_i_s(varargin)
                 if type(index(1))<>10 & index(2)=="entries" then
                     // change struct to cell
                     f=getfield(1,M);f(1)="ce"
-                    setfield(1,f,M)
+                    M=setfield(1,f,M)
                 end
             else
                 M(index(:))=N
index 3becb60..3bb31fc 100644 (file)
@@ -15,13 +15,13 @@ function a=%cblock_c_cblock(a,b)
 
     if size(v1,1)<>size(v2,1) then error(5),end
     if type(v1)==type(v2) then
-        setfield(na,[v1 v2],a)
+        a=setfield(na,[v1 v2],a)
     else
-        setfield(na+1,v2,a);na=na+1
+        a=setfield(na+1,v2,a);na=na+1
     end
 
     for k=3:length(b)
-        setfield(na+1,getfield(k,b),a)
+        a=setfield(na+1,getfield(k,b),a)
         na=na+1
     end
 endfunction
index 875fa71..6b98019 100644 (file)
@@ -12,8 +12,8 @@ function a=%cblock_c_s(a,b)
 
     if size(v,1)<>size(b,1) then error(5),end
     if type(b)==type(v) then
-        setfield($,[v b],a)
+        a=setfield($,[v b],a)
     else
-        setfield($+1,b,a)
+        a=setfield($+1,b,a)
     end
 endfunction
index b59e44e..9dd3636 100644 (file)
@@ -49,7 +49,7 @@ function y=%cblock_e(varargin)
             if type(v)==type(temp) then
                 temp=[temp v(i,jk)]
             else
-                setfield(length(y)+1,temp,y)
+                y=setfield(length(y)+1,temp,y)
                 temp=v(i,jk)
             end
         end
@@ -57,7 +57,7 @@ function y=%cblock_e(varargin)
     if length(y)==1 then
         y=temp
     else
-        setfield(length(y)+1,temp,y)
+        y=setfield(length(y)+1,temp,y)
     end
 
 endfunction
index c6ff505..69e7893 100644 (file)
@@ -12,6 +12,6 @@ function a=%cblock_f_cblock(a,b)
 
     if length(a)<>length(b) then error(6),end
     for k=2:length(a)
-        setfield(k,[getfield(k,a);getfield(k,b)],a)
+        a=setfield(k,[getfield(k,a);getfield(k,b)],a)
     end
 endfunction
index 11c1ffb..feabdda 100644 (file)
@@ -42,7 +42,7 @@ function s=%ce_6(varargin)
                 s.dims=int32([0 0]);
             else
                 // return a 1x1 struct with fields set to []
-                for k=1:size(f,"*"),setfield(k+2,[],s);end
+                for k=1:size(f,"*"),s=setfield(k+2,[],s);end
                 s.dims=int32([1 1]);
             end
         end
index 646d91b..17dba65 100644 (file)
@@ -93,11 +93,11 @@ function s=%ce_e(varargin)
         ww=getfield(k,w);
         if type(ww)~=15 then ww=list(ww);end
         if prod(dims)==1
-            setfield(k,ww(I),s);
+            s=setfield(k,ww(I),s);
         elseif prod(dims)==0 //VC 27/05/2004 after modification in convertindex
-            setfield(k,list(),s);
+            s=setfield(k,list(),s);
         else
-            setfield(k,list(ww(I)),s);
+            s=setfield(k,list(ww(I)),s);
         end
     end
 endfunction
index 5a50083..6739ed7 100644 (file)
@@ -86,7 +86,7 @@ function M=%ce_i_ce(varargin)
             end
         end
         if length(v2)==1 then v2=v2(1);end
-        setfield(3,v2,R);
+        R=setfield(3,v2,R);
     end
 
     //remove trailing unitary dimensions
index 7b30945..53a0c62 100644 (file)
@@ -20,7 +20,7 @@ function M=%i_i_s(varargin)
         if type(index(1))<>10 & index(2)=="entries" then
             // change struct to cell
             f=getfield(1,M);f(1)="ce"
-            setfield(1,f,M)
+            M=setfield(1,f,M)
         end
     elseif rhs>4 then//more than 2 indices: insertion of an integer in a matrix of numbers
         M=varargin($)
index b006ab9..f85a156 100644 (file)
@@ -19,7 +19,7 @@ function s=%lss_i_s(i,j,s1,s2)
             if type(i(1))<>10 & i(2)=="entries" then
                 // change struct to cell
                 f=getfield(1,s);f(1)="ce"
-                setfield(1,f,s)
+                s=setfield(1,f,s)
             end
             return
         end
index 6e8d48e..6347735 100644 (file)
@@ -23,7 +23,7 @@ function M=%msp_i_s(varargin)
         if type(index(1))<>10 & index(2)=="entries" then
             // change struct to cell
             f=getfield(1,M);f(1)="ce"
-            setfield(1,f,M)
+            M=setfield(1,f,M)
         end
     elseif rhs>4 then //more than 2 indices:
 
index 8b5ac0b..811fe68 100644 (file)
@@ -18,7 +18,7 @@ function M=%p_i_s(varargin)
         if type(index(1))<>10 & index(2)=="entries" then
             // change struct to cell
             f=getfield(1,M);f(1)="ce"
-            setfield(1,f,M)
+            M=setfield(1,f,M)
         end
     elseif rhs>4 then //more than 2 indices: insertion of a polynomial in an  matrix of numbers
         M=varargin($)
index 5e87fc7..79e7dc1 100644 (file)
@@ -20,7 +20,7 @@ function f2=%r_i_s(varargin)
             if type(i(1))<>10 & i(2)=="entries" then
                 // change struct to cell
                 f=getfield(1,f2);f(1)="ce"
-                setfield(1,f,f2)
+                f2=setfield(1,f,f2)
             end
             return
         end
index a3f8c42..be9b443 100644 (file)
@@ -13,9 +13,9 @@ function b=%s_c_cblock(a,b)
 
     if size(a,1)<>size(v2,1) then error(5),end
     if type(a)==type(v2) then
-        setfield(2,[a v2],b)
+        b=setfield(2,[a v2],b)
     else
-        setfield(0,"cblock",b)
-        setfield(2,a,b);
+        b=setfield(0,"cblock",b)
+        b=setfield(2,a,b);
     end
 endfunction
index f6e2724..311c3fb 100644 (file)
@@ -24,7 +24,7 @@ function M=%s_i_s(varargin)
 
                 // change struct to cell
                 f=getfield(1,M);f(1)="ce"
-                setfield(1,f,M)
+                M=setfield(1,f,M)
             end
             return
         elseif type(index)==15 then
@@ -36,7 +36,7 @@ function M=%s_i_s(varargin)
                 if type(index(1))<>10 & index(2)=="entries" then
                     // change struct to cell
                     f=getfield(1,M);f(1)="ce"
-                    setfield(1,f,M)
+                    M=setfield(1,f,M)
                 end
             else
                 M(index(:))=N
index 67cef4f..f57fea0 100644 (file)
@@ -23,7 +23,7 @@ function M=%sp_i_s(varargin)
         if type(index(1))<>10 & index(2)=="entries" then
             // change struct to cell
             f=getfield(1,M);f(1)="ce"
-            setfield(1,f,M)
+            M=setfield(1,f,M)
         end
     elseif rhs>4 then //more than 2 indices:
 
index 11cdc3f..82d8a13 100644 (file)
@@ -45,7 +45,7 @@ function s=%st_6(varargin)
                 s.dims=int32([0 0]);
             else
                 // return a 1x1 struct with fields set to []
-                for k=1:size(f,"*"),setfield(k+2,[],s);end
+                for k=1:size(f,"*"),s=setfield(k+2,[],s);end
                 s.dims=int32([1 1]);
             end
         end
index 11e81fd..34a72bc 100644 (file)
@@ -99,9 +99,9 @@ function s=%st_e(varargin)
         if type(ww)~=15 then ww=list(ww);end
         //S(2,3).f1=12  -> k=3;I=6;ww(I)=12;s=mlist(["st","dims","f1"],int32([1;1]));
         if prod(dims)==1 then
-            setfield(k,ww(I),s);
+            s=setfield(k,ww(I),s);
         elseif prod(dims)>1 then
-            setfield(k,list(ww(I)),s);
+            s=setfield(k,list(ww(I)),s);
         end
     end
 endfunction
index ff39000..1bc2d85 100644 (file)
@@ -21,7 +21,7 @@ function M=%st_i_st(varargin)
 
     if type(varargin(1))==10 //addind a new field
         flds=getfield(1,M);flds=[flds,varargin(1)];
-        setfield(1,flds,M);setfield($+1,N,M);
+        M=setfield(1,flds,M);M=setfield($+1,N,M);
         if and(dims==[0 0]) then M.dims=int32([1 1]),end
     else   //Subscripted assignment between structures
         //build resulting struct fields
@@ -65,7 +65,7 @@ function M=%st_i_st(varargin)
             v1=list();for k=1:prod(Ndims),v1(k)=[];end
             // create the resulting matrix
             R=mlist(["st","dims",matrix(FR,1,-1)],int32(Ndims));
-            for k=1:size(FR,"*"),setfield(2+k,v1,R),end
+            for k=1:size(FR,"*"),R=setfield(2+k,v1,R),end
             // populate it with M entries
             for k=1:nFM
                 v2=v1;
@@ -80,17 +80,17 @@ function M=%st_i_st(varargin)
                         v2(I1(i)+1)=[];
                     end
                 end
-                setfield(kf+2,v2,R);
+                R=setfield(kf+2,v2,R);
             end
         else //the dimension agree
             R=M
             //does the fields agree?
             if or(FR<>FM) then //no
                 //add new fields
-                setfield(1,["st","dims",FR],R)
+                R=setfield(1,["st","dims",FR],R)
                 v1=list();for k=1:prod(Ndims),v1(k)=[];end
                 for k=nFM+1:size(FR,"*")
-                    setfield($+1,v1,R)
+                    R=setfield($+1,v1,R)
                 end
             end
         end
@@ -114,7 +114,7 @@ function M=%st_i_st(varargin)
                 end
             end
             if length(v2)==1 then v2=v2(1);end
-            setfield(kf+2,v2,R);
+            R=setfield(kf+2,v2,R);
         end
 
         //remove trailing unitary dimensions
index 0223661..726cee8 100644 (file)
@@ -18,6 +18,6 @@ function R=%st_t(M)
     R=mlist(F,int32([D(2) D(1)]))
     for k=3:size(F,"*")
         v=getfield(k,M)
-        setfield(k,list(v(NewInd)),R)
+        R=setfield(k,list(v(NewInd)),R)
     end
 endfunction
index 0e09268..afbb6dd 100644 (file)
@@ -37,7 +37,7 @@ function  M=createstruct(index,N)
                         Li=list();for kl=1:nmax, Li(kl)=[];end
                         //set fields pointed to by index(1) to N
                         for kl=1:size(I,"*"), Li(I(kl))=N;end
-                        setfield(3,Li,M);
+                        M=setfield(3,Li,M);
                     end
                     return;
                     // First index is a list of numerical values
index cfc0fc9..6ef7f6e 100644 (file)
@@ -24,7 +24,7 @@ function M=generic_i_s(varargin)
         if index($)=="entries" then
             // change struct to cell
             f=getfield(1,M);f(1)="ce"
-            setfield(1,f,M)
+            M=setfield(1,f,M)
         end
         return
     elseif rhs==3 &(type(index)<>10 & type(index)<>15) then
index 42e9b2b..3cf3c8b 100644 (file)
@@ -17,8 +17,8 @@ function out=generic_i_st(i,in,out)
         error(1);
     end
     T=getfield(1,out);
-    T($+1)=i;setfield(1,T,out)
-    setfield($+1,in,out)
+    T($+1)=i;out=setfield(1,T,out)
+    out=setfield($+1,in,out)
     if double(out.dims)==[0 0] then
         out.dims=int32([1 1]);
     end
index 5581dba..630dd89 100644 (file)
@@ -9,8 +9,6 @@
 
 function plist = add_param(list_name, param_name, param_value)
 
-    [nargout, nargin] = argn();
-
     if nargout == 2 then
         warning(sprintf(_("Second output argument of %s is obsolete.\n"), "add_param"))
         warning(sprintf(_("This argument will be permanently removed in Scilab %s"), "5.5.1"))
@@ -22,7 +20,7 @@ function plist = add_param(list_name, param_name, param_value)
 
     if typeof(list_name) == "plist" then
         if ~is_param(list_name, param_name) then
-            setfield(1, [getfield(1, list_name) param_name], list_name);
+            list_name = setfield(1, [getfield(1, list_name) param_name], list_name);
             if nargin == 3 then
                 list_name(param_name) = param_value;
             end
diff --git a/scilab/modules/string/tests/nonreg_tests/bug_10816.dia.ref b/scilab/modules/string/tests/nonreg_tests/bug_10816.dia.ref
deleted file mode 100644 (file)
index 629e5b8..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// =============================================================================
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2014 - Scilab Enterprises - Paul Bignier
-//
-//  This file is distributed under the same license as the Scilab package.
-// =============================================================================
-//
-// <-- CLI SHELL MODE -->
-//
-// <-- Non-regression test for bug 10816 -->
-//
-// <-- Bugzilla URL -->
-// http://bugzilla.scilab.org/show_bug.cgi?id=10816
-//
-// <-- Short Description -->
-// Typo fixed in %ip_part error message.
-refMsg = msprintf(_("%s: Wrong value for input argument #%d: $ expected.\n"), "part", 2);
-s = poly(0, "s");
-assert_checkerror("part(""string"", s:s:s)", refMsg);
diff --git a/scilab/modules/string/tests/nonreg_tests/bug_10816.tst b/scilab/modules/string/tests/nonreg_tests/bug_10816.tst
deleted file mode 100644 (file)
index f24d662..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// =============================================================================
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2014 - Scilab Enterprises - Paul Bignier
-//
-//  This file is distributed under the same license as the Scilab package.
-// =============================================================================
-//
-// <-- CLI SHELL MODE -->
-//
-// <-- Non-regression test for bug 10816 -->
-//
-// <-- Bugzilla URL -->
-// http://bugzilla.scilab.org/show_bug.cgi?id=10816
-//
-// <-- Short Description -->
-// Typo fixed in %ip_part error message.
-
-refMsg = msprintf(_("%s: Wrong value for input argument #%d: $ expected.\n"), "part", 2);
-
-s = poly(0, "s");
-assert_checkerror("part(""string"", s:s:s)", refMsg);