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