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