bug 14909: getshortpathname and getlongpathname return values with '\' instead of '/'
[scilab.git] / scilab / modules / io / tests / unit_tests / saveload.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) ????-2008 - INRIA
4 // Copyright (C) 2012 - Scilab Enterprises - Vincent COUVERT
5 //
6 //  This file is distributed under the same license as the Scilab package.
7 // =============================================================================
8 //
9 // <-- TEST WITH GRAPHIC -->
10 //
11
12 funcprot(0);
13
14 function r = Check(a,b,c,d)
15     [lhs,rhs] = argn();
16     r = %t
17     filename = TMPDIR + "/saveloadtst_mysave";
18     select rhs
19     case 1 then
20         a1 = a;
21         save(filename,"a1");
22         a1 = null();
23         load(filename);
24         if or(a1<>a) then
25             r = %f;
26         end
27     case 2 then
28         a1 = a;
29         b1 = b;
30         save(filename,"a1","b1");
31         a1 = null();
32         b1 = null();
33         load(filename);
34         if or(a1<>a)|or(b1<>b) then
35             r = %f;
36         end
37     case 3 then
38         a1 = a;
39         b1 = b;
40         c1 = c;
41         save(filename,"a1","b1","c1");
42         a1 = null();
43         b1 = null();
44         c1 = null();
45         load(filename);
46         if or(a1<>a)|or(b1<>b)|or(c1<>c) then
47             r = %f;
48         end
49     case 4 then
50         a1 = a;
51         b1 = b;
52         c1 = c;
53         d1 = d;
54         save(filename,"a1","b1","c1","d1");
55         a1 = null();
56         b1 = null();
57         c1 = null();
58         d1 = null();
59         load(filename);
60         if or(a1<>a)|or(b1<>b)|or(c1<>c)|or(d1<>d) then
61             r = %f;
62         end
63     end
64 endfunction
65
66 a=[];assert_checktrue(Check(a));
67 a=1;assert_checktrue(Check(a));
68 a=[1 2 3];assert_checktrue(Check(a));
69 a=[1 2 3;4 5 6];assert_checktrue(Check(a));
70 a=1:100000;assert_checktrue(Check(a));
71
72 a=1+%i;assert_checktrue(Check(a));
73 a=[1 2+%i 3];assert_checktrue(Check(a));
74 a=[1 2 3;4 5+%i 6];assert_checktrue(Check(a));
75 a=1:100000;a(35)=%i;assert_checktrue(Check(a));
76
77 a="";assert_checktrue(Check(a));
78 a="123";assert_checktrue(Check(a));
79 a=["1","abcdefgs";"" "ABDCEFGHIJKLMN"];assert_checktrue(Check(a));
80 a=string(1:10000);assert_checktrue(Check(a));
81
82
83 a=1+%s;assert_checktrue(Check(a));
84 a=[1 2+%s 3];assert_checktrue(Check(a));
85 a=[1 2 3;4 5 6+%s];assert_checktrue(Check(a));
86 a=1:10000;a(4)=%s;assert_checktrue(Check(a));
87
88 a=1+%i+%s;assert_checktrue(Check(a));
89 a=[1 2+%i 3+%s];assert_checktrue(Check(a));
90 a=[1 2+%s 3;4 5+%i 6];assert_checktrue(Check(a));
91 a=1:100;a(35)=%i;a(1)=%s;assert_checktrue(Check(a));
92
93
94 a=%t;assert_checktrue(Check(a));
95 a=rand(100,100)>0.5;assert_checktrue(Check(a));
96
97 //a=mtlb_sparse(sparse(1));assert_checktrue(Check(a)); // Deactivated: See bug #11795
98 //a=mtlb_sparse(sprand(100,100,0.1));assert_checktrue(Check(a)); // Deactivated: See bug #11795
99 //a=mtlb_sparse(sparse(zeros(100,100)));assert_checktrue(Check(a)); // Deactivated: See bug #11795
100
101 a=sparse(1)==1;assert_checktrue(Check(a));
102 a=sprand(100,100,0.1)<0.5;assert_checktrue(Check(a));
103 a=sparse(zeros(100,100))==1;assert_checktrue(Check(a));
104
105 //a=1:$;assert_checktrue(Check(a)); // Deactivated: See bug #11796
106 //a=1:3:$;assert_checktrue(Check(a)); // Deactivated: See bug #11796
107
108 a=int8(1);assert_checktrue(Check(a));
109 a=int8(1:9);assert_checktrue(Check(a));
110 a=int8(1:10000);assert_checktrue(Check(a));
111 a=uint8(1);assert_checktrue(Check(a));
112 a=uint8(1:9);assert_checktrue(Check(a));
113 a=uint8(1:10000);assert_checktrue(Check(a));
114
115 a=int16(1);assert_checktrue(Check(a));
116 a=int16(1:9);assert_checktrue(Check(a));
117 a=int16(1:10000);assert_checktrue(Check(a));
118 a=uint16(1);assert_checktrue(Check(a));
119 a=uint16(1:9);assert_checktrue(Check(a));
120 a=uint16(1:10000);assert_checktrue(Check(a));
121
122 a=int32(1);assert_checktrue(Check(a));
123 a=int32(1:9);assert_checktrue(Check(a));
124 a=int32(1:10000);assert_checktrue(Check(a));
125 a=uint32(1);assert_checktrue(Check(a));
126 a=uint32(1:9);assert_checktrue(Check(a));
127 a=uint32(1:10000);assert_checktrue(Check(a));
128
129 a=list();assert_checktrue(Check(a));
130 a=list(1);assert_checktrue(Check(a));
131 a=list(1,rand(10,10),"asdfsf");assert_checktrue(Check(a));
132 a=list(1,rand(10,10),"asdfsf",poly(rand(10,10),"s"));assert_checktrue(Check(a));
133 a=list(1);a(4)="as";assert_checktrue(Check(a));
134 a=list(1,rand(10,10),"asdfsf",poly(rand(1,11),"s","c"));assert_checktrue(Check(a));
135
136 a=list(list());assert_checktrue(Check(a));
137 a=list(list(1));assert_checktrue(Check(a));
138 a=list(list(1,rand(10,10),"asdfsf"));assert_checktrue(Check(a));
139 a=list(list(1,rand(10,10),"asdfsf",poly(rand(10,10),"s")));assert_checktrue(Check(a));
140 a=list(1);a(4)="as";a=list(a);assert_checktrue(Check(a));
141 a=list(list(1,rand(10,10),"asdfsf",poly(rand(1,11),"s","c")));assert_checktrue(Check(a));
142
143
144 a=list(list(),2);assert_checktrue(Check(a));
145 a=list(list(1),rand(3,3));assert_checktrue(Check(a));
146 a=list(list(1,rand(10,10),"asdfsf"),"sdfs");assert_checktrue(Check(a));
147 a=list(list(1,rand(10,10),"asdfsf",poly(rand(10,10),"s")),$);assert_checktrue(Check(a));
148 a=list(1);a(4)="as";a=list(a,[]);assert_checktrue(Check(a));
149 a=list(list(1,rand(10,10),"asdfsf",poly(rand(1,11),"s","c")),list());assert_checktrue(Check(a));
150
151 a = list();
152 a(3) = 3;
153 assert_checktrue(Check(a));
154
155 a=[];b=1;c=[1 2 3];d=[1 2 3;4 5 6];
156 assert_checktrue(Check(a,b));
157 assert_checktrue(Check(a,b,c));
158 assert_checktrue(Check(a,b,c,d));
159
160 a=1+%i;b=[1 2+%i 3];c=[1 2 3;4 5+%i 6];d=1:100000;d(35)=%i;
161 assert_checktrue(Check(a,b));
162 assert_checktrue(Check(a,b,c));
163 assert_checktrue(Check(a,b,c,d));
164
165 a=sprand(100,100,0.1);
166 b=sparse(zeros(100,100))==1;
167 c=list(list(1,rand(10,10),"asdfsf",poly(rand(1,11),"s","c")),list());
168 assert_checktrue(Check(a,b));
169 assert_checktrue(Check(a,b,c));
170
171 //test save/load macro
172 function a = toto(x,y)
173     a = x + y;
174 endfunction
175 l = list(toto);
176
177 ref = toto(3*5, 9*3);
178 save(TMPDIR + "/savemacro.sod", "toto");
179 clear toto;
180 load(TMPDIR + "/savemacro.sod");
181 assert_checkequal(toto(3*5, 9*3), ref);
182 assert_checkequal(type(toto), 13);
183
184 save(TMPDIR + "/savemacro.sod", "l");
185 clear l;
186 load(TMPDIR + "/savemacro.sod");
187 assert_checkequal(l(1)(3*5, 9*3), ref);
188 assert_checkequal(type(l(1)), 13);
189
190 clear toto;
191 deff("a = toto(x,y)", "a = x + y;");
192 save(TMPDIR + "/savemacro.sod", "toto");
193 clear toto;
194 load(TMPDIR + "/savemacro.sod");
195 assert_checkequal(toto(3*5, 9*3), ref);
196 assert_checkequal(type(toto), 13);
197
198
199 //create plot3d with light
200 plot3d();
201 l = light();
202 f = gcf();
203 l.position = [-1, -2, 1];
204
205 //save image in a file
206 xs2png(f, TMPDIR + "/saveplot.png");
207 //compute md5 of saved image
208 md5_1 = getmd5(TMPDIR + "/saveplot.png");
209 //save figure handle in sod format
210 save(TMPDIR + "/saveplot.sod", "f");
211
212 //clear env
213 close();
214 clear f l;
215
216 load(TMPDIR + "/saveplot.sod");
217 l = f.children(1).children(1);
218 assert_checkequal(l.position, [-1, -2, 1]);
219 xs2png(f, TMPDIR + "/saveplot2.png");
220 md5_2 = getmd5(TMPDIR + "/saveplot2.png");
221 assert_checkequal(md5_1, md5_2);
222
223
224 // Scicos objects
225 clear;
226 loadXcosLibs();
227
228 d = scicos_diagram();
229 save(TMPDIR + "/diagram.sod", "d");
230 refD = d;
231 clear d;
232 load(TMPDIR + "/diagram.sod");
233 assert_checktrue(and(d==refD));
234
235 b = scicos_block();
236 save(TMPDIR + "/Block.sod", "b");
237 refB = b;
238 clear b;
239 load(TMPDIR + "/Block.sod");
240 assert_checktrue(and(b==refB));
241
242 t = TEXT_f("define");
243 save(TMPDIR + "/Text.sod", "t");
244 refT = t;
245 clear t;
246 load(TMPDIR + "/Text.sod");
247 assert_checktrue(and(t==refT));
248
249 l = scicos_link();
250 save(TMPDIR + "/Link.sod", "l");
251 refL = l;
252 clear l;
253 load(TMPDIR + "/Link.sod");
254 assert_checktrue(and(l==refL));
255
256 d = scicos_diagram();
257 S = scicos_block();
258 subD = scicos_diagram(objs = list(scicos_link()));
259 S.model.rpar = subD;
260 d.objs(1) = S;
261 save(TMPDIR + "/SuperBlock.sod", "d");
262 refD = d;
263 clear d;
264 load(TMPDIR + "/SuperBlock.sod");
265 assert_checktrue(and(d==refD));