Atoms: fix tests after https://codereview.scilab.org/#/c/13899/ 15/13915/1
Calixte DENIZET [Wed, 5 Mar 2014 15:41:51 +0000 (16:41 +0100)]
Change-Id: I7ec7af4f4638380d4b6331585d048e0893580763

scilab/modules/atoms/macros/atomsGetConfig.sci
scilab/modules/atoms/macros/atomsRestoreConfig.sci
scilab/modules/atoms/macros/atomsSaveConfig.sci
scilab/modules/atoms/macros/atomsSetConfig.sci
scilab/modules/atoms/tests/unit_tests/atomsSetConfig.dia.ref
scilab/modules/atoms/tests/unit_tests/atomsSetConfig.tst
scilab/modules/gui/etc/XConfiguration-web.xml
scilab/modules/preferences/etc/XConfiguration.xml
scilab/modules/preferences/macros/setPrefValues.sci

index cf6234f..920a4af 100644 (file)
@@ -82,7 +82,14 @@ function result = atomsGetConfig(field)
         if (rhs == 0)
             values = getPrefValues("//web/body/proxy", pref_attrs(2, :));
             for i = 1:size(pref_attrs, "c")
-                result(pref_attrs(1, i)) = values(i);
+                if ~isempty(values(i)) then
+                    if values(i) == "true" then
+                        values(i) = "True";
+                    elseif values(i) == "false" then
+                        values(i) = "False";
+                    end
+                    result(pref_attrs(1, i)) = values(i);
+                end
             end
         end
         return;
@@ -116,7 +123,14 @@ function result = atomsGetConfig(field)
     if (rhs == 0)
         values = getPrefValues("//web/body/proxy", pref_attrs(2, :));
         for i = 1:size(pref_attrs, "c")
-            result(pref_attrs(1, i)) = values(i);
+            if ~isempty(values(i)) then
+                if values(i) == "true" then
+                    values(i) = "True";
+                elseif values(i) == "false" then
+                    values(i) = "False";
+                end
+                result(pref_attrs(1, i)) = values(i);
+            end
         end
     end
 
index c90b024..6e4880f 100644 (file)
@@ -23,6 +23,9 @@ function atomsRestoreConfig(quiet)
         quiet = %F;
     end
 
+    proxy_attrs = ["enabled", "host", "port", "user", "password"];
+    setPrefValues("//web/body/proxy", [proxy_attrs ; getPrefValues("//web/body/previous-proxy", proxy_attrs)]);
+
     pathsystemuser = atomsPath("system", "user");
 
     if isfile(pathsystemuser + "config.bak") then
index 8be0a67..388e142 100644 (file)
@@ -25,6 +25,9 @@ function atomsSaveConfig(force)
 
     pathsystemuser = atomsPath("system", "user");
 
+    proxy_attrs = ["enabled", "host", "port", "user", "password"];
+    setPrefValues("//web/body/previous-proxy", [proxy_attrs ; getPrefValues("//web/body/proxy", proxy_attrs)]);
+
     if isfile(pathsystemuser + "config.bak") then
         if ~force then
             error(msprintf("The file config.bak already exists, aborting.\n"));
index 20cb023..e2e8eec 100644 (file)
@@ -117,6 +117,7 @@ function nbChanges = atomsSetConfig(field, value)
     // =========================================================================
 
     prefs_kv = [];
+    proxy_changes = 0;
 
     for i=1:size(field, "*")
 
@@ -137,6 +138,7 @@ function nbChanges = atomsSetConfig(field, value)
             end
             prefs_kv = [prefs_kv [pref_attrs(2, k) ; value(i)]];
             nbChanges = nbChanges - 1;
+            proxy_changes = proxy_changes + 1;
         else
             config_struct(field(i)) = value(i);
         end;
@@ -149,6 +151,7 @@ function nbChanges = atomsSetConfig(field, value)
     // Shortcut
     // =========================================================================
     if nbChanges == 0 then
+        nbChanges = proxy_changes;
         return;
     end
 
@@ -174,4 +177,5 @@ function nbChanges = atomsSetConfig(field, value)
         atomsSystemUpdate();
     end
 
+    nbChanges = nbChanges + proxy_changes;
 endfunction
index 8833a31..0a09ac5 100644 (file)
@@ -15,11 +15,11 @@ atomsSetConfig("Verbose" ,"False");
 config_downloadTool = atomsGetConfig("downloadTool");
 // Start config
 // =============================================================================
-ref=struct("downloadTool",config_downloadTool,"autoloadAddAfterInstall","False","Verbose","False");
+ref=struct("useProxy", "False", "downloadTool",config_downloadTool,"autoloadAddAfterInstall","False","Verbose","False");
 assert_checkequal(atomsGetConfig(),ref);
 // CamelCase test
 // =============================================================================
-ref=struct("downloadTool",config_downloadTool,"autoloadAddAfterInstall","False","Verbose","True");
+ref=struct("useProxy", "False", "downloadTool",config_downloadTool,"autoloadAddAfterInstall","False","Verbose","True");
 assert_checkequal(string(atomsSetConfig("Verbose","True")),"1");
 assert_checkequal(atomsGetConfig(),ref);
 assert_checkequal(string(atomsSetConfig("verbose","true")),"0");
@@ -48,7 +48,7 @@ ref=struct(   "useProxy","False",..
                "autoloadAddAfterInstall","False",..
                "autoload","True",..
                "Verbose","True");
-assert_checkequal(string(atomsSetConfig("useProxy","False")),"1");
+assert_checkequal(string(atomsSetConfig("useProxy","False")),"0");
 assert_checkequal(string(atomsSetConfig("proxyHost","myproxy")),"1");
 assert_checkequal(string(atomsSetConfig("proxyPort","42")),"1");
 assert_checkequal(string(atomsSetConfig("proxyUser","scilab")),"1");
index 43f92be..d997da2 100644 (file)
@@ -20,12 +20,12 @@ config_downloadTool = atomsGetConfig("downloadTool");
 
 // Start config
 // =============================================================================
-ref=struct("downloadTool",config_downloadTool,"autoloadAddAfterInstall","False","Verbose","False");
+ref=struct("useProxy", "False", "downloadTool",config_downloadTool,"autoloadAddAfterInstall","False","Verbose","False");
 assert_checkequal(atomsGetConfig(),ref);
 
 // CamelCase test
 // =============================================================================
-ref=struct("downloadTool",config_downloadTool,"autoloadAddAfterInstall","False","Verbose","True");
+ref=struct("useProxy", "False", "downloadTool",config_downloadTool,"autoloadAddAfterInstall","False","Verbose","True");
 assert_checkequal(string(atomsSetConfig("Verbose","True")),"1");
 assert_checkequal(atomsGetConfig(),ref);
 assert_checkequal(string(atomsSetConfig("verbose","true")),"0");
@@ -47,17 +47,17 @@ assert_checkequal(atomsGetConfig(),ref);
 // Exhaustive key list test
 // =============================================================================
 ref=struct(    "useProxy","False",..
-               "proxyUser","scilab",..
-               "proxyPort","42",..
-               "proxyPassword","scilab",..
-               "proxyHost","myproxy",..
-               "offline","False",..
-               "downloadTool",config_downloadTool,..
-               "autoloadAddAfterInstall","False",..
-               "autoload","True",..
-               "Verbose","True");
+"proxyUser","scilab",..
+"proxyPort","42",..
+"proxyPassword","scilab",..
+"proxyHost","myproxy",..
+"offline","False",..
+"downloadTool",config_downloadTool,..
+"autoloadAddAfterInstall","False",..
+"autoload","True",..
+"Verbose","True");
 
-assert_checkequal(string(atomsSetConfig("useProxy","False")),"1");
+assert_checkequal(string(atomsSetConfig("useProxy","False")),"0");
 assert_checkequal(string(atomsSetConfig("proxyHost","myproxy")),"1");
 assert_checkequal(string(atomsSetConfig("proxyPort","42")),"1");
 assert_checkequal(string(atomsSetConfig("proxyUser","scilab")),"1");
index 06d5869..daf2e90 100644 (file)
@@ -3,5 +3,6 @@
     <body>
         <web default-browser="true" default-mailer="true" command-browser="" command-mailer=""/>
         <proxy enabled="false" host="" port="" user="" password=""/>
+        <previous-proxy enabled="false" host="" port="" user="" password=""/>
     </body>
 </web>
index e63e392..63ad450 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<interface version="0.16" path="1/" width="800" height="600">
+<interface version="0.17" path="1/" width="800" height="600">
     <general/>
     <web/>
     <preference/>
index 514ee93..6225648 100644 (file)
@@ -66,7 +66,7 @@ function setPrefValues(xpath, kv, doc)
     attr = node.attributes;
     for i = 1:size(kv, "c")
         v = attr(kv(1, i));
-        if ~isempty(v) then
+        if v ~= [] then
             attr(kv(1, i)) = kv(2, i);
         else
             if rhs == 2 then