fix trouble on atoms tests since 5.4.0 without libscilab
[scilab.git] / scilab / modules / atoms / tests / unit_tests / atomsRemove.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2011 - DIGITEO - Simon GARESTE <simon.gareste@scilab.org>
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7
8 // <-- CLI SHELL MODE -->
9
10
11 //detect scilab arch
12 [version, opts] = getversion();
13 if opts(2) == "x64" & getos() == "Windows" then
14     arch = "x64/";
15 else
16     arch = "";
17 end
18
19 load("SCI/modules/atoms/macros/atoms_internals/lib");
20
21 // If previous test did not end properly, restore, else backup config file
22 atomsRestoreConfig(%T);
23 atomsSaveConfig();
24
25 // Do not use the autoload system
26 atomsSetConfig("autoloadAddAfterInstall","False");
27 atomsSetConfig("Verbose" ,"False");
28
29 // Load the 1st scenario : See scene1.test.atoms.scilab.org.txt
30 // =============================================================================
31 atomsRepositorySetOfl("http://scene1.test.atoms.scilab.org");
32 if atomsIsInstalled("toolbox_1") then
33     atomsRemove("toolbox_1");
34 end
35 if atomsIsInstalled("toolbox_2") then
36     atomsRemove("toolbox_2");
37 end
38 if atomsIsInstalled("toolbox_3") then
39     atomsRemove("toolbox_3");
40 end
41 if atomsIsInstalled("toolbox_4") then
42     atomsRemove("toolbox_4");
43 end
44 if atomsIsInstalled("toolbox_5") then
45     atomsRemove("toolbox_5");
46 end
47 if atomsIsInstalled("toolbox_6") then
48     atomsRemove("toolbox_6");
49 end
50 // REMOVING PART
51
52 // REMOVING an Automatic installed toolbox deletes the toolbox it has been 
53 // installed by
54 // -----------------------------------------------------------------------------
55 atomsInstall(["toolbox_5" "1.0"],"user");
56 ref = [ "toolbox_1"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_1/1.0-1"  "A" ;
57         "toolbox_2"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_2/1.0-1"  "A" ;
58         "toolbox_4"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_4/1.0-1"  "A" ;
59         "toolbox_5"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_5/1.0-1"  "I" ];
60         
61 if getos()=="Windows" then
62    ref=strsubst(ref,"/","\");
63 end
64 removed=atomsRemove(["toolbox_2" "1.0"],"user");
65 [a,b]=gsort(removed(:,1),'r','i');
66 assert_checkequal(removed(b,:),ref);
67
68 // REMOVING an Automatic toolbox deletes all the toolboxes depending on it
69 // -----------------------------------------------------------------------------
70 atomsInstall(["toolbox_5" "1.0"],"user");
71 atomsInstall(["toolbox_3" "1.0"],"user");
72 ref = [ "toolbox_1"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_1/1.0-1"  "A" ;
73         "toolbox_2"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_2/1.0-1"  "A" ;
74         "toolbox_2"  "2.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_2/2.0-1"  "A" ;
75         "toolbox_3"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_3/1.0-1"  "I" ;
76         "toolbox_4"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_4/1.0-1"  "A" ;
77         "toolbox_5"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_5/1.0-1"  "I" ];
78 if getos()=="Windows" then
79    ref=strsubst(ref,"/","\");
80 end
81 removed=atomsRemove(["toolbox_1"],"user");
82 [a,b]=gsort(removed(:,1),'r','i');
83 assert_checkequal(removed(b,:),ref);
84 //assert_checkequal(atomsRemove(["toolbox_1"]      ,"user"),ref);
85
86 // REMOVING an Intentionnaly installed toolbox won't delete an Automatically
87 // installed toolbox if it is needed by another toolbox
88 // -----------------------------------------------------------------------------
89 atomsInstall(["toolbox_5" "1.0"],"user");
90 atomsInstall(["toolbox_3" "1.0"],"user");
91 ref = [ "toolbox_2"  "2.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_2/2.0-1"  "A" ;
92         "toolbox_3"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_3/1.0-1"  "I" ];
93         
94 if getos()=="Windows" then
95    ref=strsubst(ref,"/","\");
96 end
97 removed=atomsRemove(["toolbox_3" "1.0"],"user");
98 [a,b]=gsort(removed(:,1),'r','i');
99 assert_checkequal(removed(b,:),ref);
100
101 // REMOVING a toolbox in a section won't delete it in other sections
102 // -----------------------------------------------------------------------------
103 atomsInstall(["toolbox_5" "1.0"],"user");
104 atomsInstall(["toolbox_5" "1.0"],"allusers");
105 ref = [ "toolbox_1"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_1/1.0-1"  "A" ;
106         "toolbox_2"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_2/1.0-1"  "A" ;
107         "toolbox_4"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_4/1.0-1"  "A" ;
108         "toolbox_5"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_5/1.0-1"  "I" ];
109 if getos()=="Windows" then
110    ref=strsubst(ref,"/","\");
111 end
112 ref_all = [ "toolbox_1"  "1.0-1"  "allusers"  "SCI/contrib/toolbox_1/1.0-1"  "A" ;
113             "toolbox_2"  "1.0-1"  "allusers"  "SCI/contrib/toolbox_2/1.0-1"  "A" ;
114             "toolbox_4"  "1.0-1"  "allusers"  "SCI/contrib/toolbox_4/1.0-1"  "A" ;
115             "toolbox_5"  "1.0-1"  "allusers"  "SCI/contrib/toolbox_5/1.0-1"  "I" ];
116 if getos()=="Windows" then
117    ref_all=strsubst(ref_all,"/","\");
118 end
119 removed=atomsRemove(["toolbox_5" "1.0"],"user");
120 [a,b]=gsort(removed(:,1),'r','i');
121 assert_checkequal(removed(b,:),ref);
122 removed=atomsRemove(["toolbox_5" "1.0"],"allusers");
123 [a,b]=gsort(removed(:,1),'r','i');
124 assert_checkequal(removed(b,:),ref_all);
125
126 // REMOVING a toolbox with section "all" will remove this toolbox in sections 
127 // "alluser" AND "user"
128 // -----------------------------------------------------------------------------
129 atomsInstall(["toolbox_5" "1.0"],"user");
130 atomsInstall(["toolbox_5" "1.0"],"allusers");
131 ref = [ "toolbox_1"  "1.0-1"  "allusers"  "SCI/contrib/toolbox_1/1.0-1"  "A" ;
132         "toolbox_1"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_1/1.0-1"  "A" ;
133         "toolbox_2"  "1.0-1"  "allusers"  "SCI/contrib/toolbox_2/1.0-1"  "A" ;
134         "toolbox_2"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_2/1.0-1"  "A" ;
135         "toolbox_4"  "1.0-1"  "allusers"  "SCI/contrib/toolbox_4/1.0-1"  "A" ;
136         "toolbox_4"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_4/1.0-1"  "A" ;
137         "toolbox_5"  "1.0-1"  "allusers"  "SCI/contrib/toolbox_5/1.0-1"  "I" ;
138         "toolbox_5"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_5/1.0-1"  "I" ];
139 if getos()=="Windows" then
140    ref=strsubst(ref,"/","\");
141 end
142 removed=atomsRemove(["toolbox_5" "1.0"],"all");
143 [a,b]=gsort(removed(:,1),'r','i');
144 assert_checkequal(removed(b,:),ref);
145
146 // REMOVING a toolbox from a section where it doesn't exist won't remove it from
147 // its existing section
148 // REMOVING an Intentionnaly installed toolbox deletes all the Automatically
149 // installed toolbox that were installed for this.
150 // -----------------------------------------------------------------------------
151 atomsInstall(["toolbox_5" "1.0"],"user");
152 ref_empty = [];
153 ref = [ "toolbox_1"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_1/1.0-1"  "A" ;
154         "toolbox_2"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_2/1.0-1"  "A" ;
155         "toolbox_4"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_4/1.0-1"  "A" ;
156         "toolbox_5"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_5/1.0-1"  "I" ];
157 if getos()=="Windows" then
158    ref=strsubst(ref,"/","\");
159 end
160 assert_checkequal(atomsRemove(["toolbox_5" "1.0"],"allusers"),ref_empty);
161 removed=atomsRemove(["toolbox_5" "1.0"],"user");
162 [a,b]=gsort(removed(:,1),'r','i');
163 assert_checkequal(removed(b,:),ref);
164
165 // ============================================================================
166 // DELETING PART
167 rmdir(atomsPath("install","user")+'archives/','s');
168 mkdir(atomsPath("install","user")+'archives/');
169 rmdir(atomsPath("install","allusers")+'archives/','s');
170 mkdir(atomsPath("install","allusers")+'archives/');
171 // ============================================================================
172
173 // REMOVING AND DELETING a toolbox will delete its archives and archives of the
174 // toolboxes it depends on
175 // -----------------------------------------------------------------------------
176 atomsInstall(["toolbox_5" "1.0"],"user");
177 ref = [ "toolbox_1"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_1/1.0-1"  "A" ;
178         "toolbox_2"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_2/1.0-1"  "A" ;
179         "toolbox_4"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_4/1.0-1"  "A" ;
180         "toolbox_5"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_5/1.0-1"  "I" ];
181 if getos()=="Windows" then
182    ref=strsubst(ref,"/","\");
183 end
184 ref_empty = [];
185 removed=atomsRemove(["toolbox_5" "1.0"],"user",%T);
186 [a,b]=gsort(removed(:,1),'r','i');
187 assert_checkequal(removed(b,:),ref);
188 if getos()=="Windows" then
189     assert_checkequal(ls(atomsPath("install","user")+'archives\'),ref_empty);
190 else
191     assert_checkequal(ls(atomsPath("install","user")+'archives/'),ref_empty);
192 end
193 rmdir(atomsPath("install","user")+'archives/','s');
194 mkdir(atomsPath("install","user")+'archives/');
195 rmdir(atomsPath("install","allusers")+'archives/','s');
196 mkdir(atomsPath("install","allusers")+'archives/');
197
198 // REMOVING AND DELETING a toolbox will not delete other archives than the ones
199 // it depends on
200 // -----------------------------------------------------------------------------
201 atomsInstall(["toolbox_5" "1.0"],"user");
202 atomsInstall(["toolbox_6" "1.0"],"user");
203 ref = [ "toolbox_2"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_2/1.0-1"  "A" ;
204         "toolbox_4"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_4/1.0-1"  "A" ;
205         "toolbox_5"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_5/1.0-1"  "I" ];
206 [version, opts] = getversion();
207
208 if getos()=="Windows" then
209     ref=strsubst(ref,"/","\");
210         if opts(2) == "x86" then
211 ref_ls = [ "toolbox_1_1.0-1.bin.windows.zip";
212            "toolbox_2_2.0-1.bin.windows.zip";
213            "toolbox_6_1.0-1.bin.windows.zip"];
214         else
215 ref_ls = [ "toolbox_1_1.0-1.bin.x64.windows.zip";
216            "toolbox_2_2.0-1.bin.x64.windows.zip";
217            "toolbox_6_1.0-1.bin.x64.windows.zip"];
218         end
219 elseif getos()=="Linux" then
220         if opts(2) == "x86" then
221 ref_ls = [ "toolbox_1_1.0-1.bin.i686.linux.tar.gz";
222            "toolbox_2_2.0-1.bin.i686.linux.tar.gz";
223            "toolbox_6_1.0-1.bin.i686.linux.tar.gz"];    
224         else
225 ref_ls = [ "toolbox_1_1.0-1.bin.x86_64.linux.tar.gz";
226            "toolbox_2_2.0-1.bin.x86_64.linux.tar.gz";
227            "toolbox_6_1.0-1.bin.x86_64.linux.tar.gz"];  
228         end
229 elseif getos()=="Darwin" then
230 ref_ls = [ "toolbox_1_1.0-1.bin.x86_64.darwin.tar.gz";
231            "toolbox_2_2.0-1.bin.x86_64.darwin.tar.gz";
232            "toolbox_6_1.0-1.bin.x86_64.darwin.tar.gz"]; 
233 end
234 ref_rem_6 = [ "toolbox_1"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_1/1.0-1"  "A" ;
235               "toolbox_2"  "2.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_2/2.0-1"  "A" ;
236               "toolbox_6"  "1.0-1"  "user"  "SCIHOME/atoms/" + arch + "toolbox_6/1.0-1"  "I" ];
237 if getos()=="Windows" then
238    ref_rem_6=strsubst(ref_rem_6,"/","\");
239 end
240 removed=atomsRemove(["toolbox_5" "1.0"],"user",%T);
241 [a,b]=gsort(removed(:,1),'r','i');
242 assert_checkequal(removed(b,:),ref);
243
244 left=ls(atomsPath("install","user")+'archives/');
245 [a,b]=gsort(left(:,1),'r','i');
246 assert_checkequal(left(b,:),ref_ls);
247
248 // cleaning
249 allremoved=atomsRemove(["toolbox_6" "1.0"],"user",%T);
250 [a,b]=gsort(allremoved(:,1),'r','i');
251 assert_checkequal(allremoved(b,:),ref_rem_6);
252
253 //assert_checkequal(atomsRemove(["toolbox_6" "1.0"],"user",%T),ref_rem_6);
254 rmdir(atomsPath("install","user")+'archives/','s');
255 mkdir(atomsPath("install","user")+'archives/');
256 rmdir(atomsPath("install","allusers")+'archives/','s');
257 mkdir(atomsPath("install","allusers")+'archives/');
258
259 // no module should be installed
260 assert_checktrue(isempty(atomsGetInstalled()));
261
262
263 // Restore original values
264 // =============================================================================
265 atomsRestoreConfig(%T);
266
267 atomsRepositorySetOfl(mgetl(SCI+"/modules/atoms/tests/unit_tests/repositories.orig"));