1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2009 - DIGITEO - Allan CORNET
4//
5//  This file is distributed under the same license as the Scilab package.
6// =============================================================================
7// <-- CLI SHELL MODE -->
8// <-- ENGLISH IMPOSED -->
9// =============================================================================
10// Unitary tests for movefile function
11// =============================================================================
12tab_ref = [
13"世界您好",
14"азеазея",
15"ハロー・ワールド",
16"เฮลโลเวิลด์",
17"حريات وحقوق",
18"תוכנית"];
19cd TMPDIR;
20mkdir test_copyfile_source;
21mkdir test_copyfile_target;
22cd('test_copyfile_source');
23for i = 1 : size(tab_ref,"*")
24	filename = tab_ref(i) + '.orig';
25	mputl('I am a dummy String : ' + tab_ref(i), filename);
26	if fileinfo(filename) == [] then bugmes();quit;end
27end
28for i = 1 : size(tab_ref,"*")
29	orig = tab_ref(i) + '.orig';
30	dest = tab_ref(i) + '.dest';
31	r = movefile(TMPDIR+'/test_copyfile_source/' + orig, TMPDIR+'/test_copyfile_target/' + dest);
32	if r <> 1 then bugmes();quit;end
33	if fileinfo(TMPDIR+'/test_copyfile_source/' + orig) <> [] then bugmes();quit;end
34	if fileinfo(TMPDIR+'/test_copyfile_target/' + dest) == [] then bugmes();quit;end
35end
36cd TMPDIR;
37rmdir('test_copyfile_source', 's');
38rmdir('test_copyfile_target', 's');
39// =============================================================================
40cd TMPDIR;
41dir1="test dir with space";
42dir2="test dir with space number 2";
43file1='dummyFile.dummy';
44mkdir(dir1);
45mkdir(dir2);
46mputl('I am a dummy String', dir1+'/'+file1);
47movefile(dir1+'/'+file1,dir2);
48lsResult = ls(dir2+'/'+file1);
49if lsResult == [] then bugmes();quit;end
50lsResult = ls(dir1+'/'+file1);
51if lsResult <> [] then bugmes();quit;end
52rmdir(TMPDIR + filesep() + dir1, 's');
53rmdir(TMPDIR + filesep() + dir2, 's');
54// =============================================================================
55removedir(TMPDIR+'/etc');
56removedir: Warning: Directory 'TMPDIR/etc' does not exist.
57ierr = execstr("movefile(TMPDIR+""/etc"",TMPDIR)","errcatch");
58if ierr <> 999 then bugmes();quit;end
59// =============================================================================
60ref_files = ['fileio.start','fileio.quit'];
61// =============================================================================
62// move a directory into a directory
63dest = 'dirtomove1';
64renamedDst = 'renameddir1';
65a = copyfile(SCI+'/modules/fileio/etc',TMPDIR + filesep() + dest);
66if (a <> 1) then bugmes();quit;end
67if fileinfo(TMPDIR + filesep() + dest + filesep() + ref_files(1)) == [] then bugmes();quit;end
68if fileinfo(TMPDIR + filesep() + dest + filesep() + ref_files(2)) == [] then bugmes();quit;end
69a = movefile(TMPDIR + filesep() + dest, TMPDIR + filesep() + renamedDst);
70if (a <> 1) then bugmes();quit;end
71if fileinfo(TMPDIR + filesep() + renamedDst + filesep() + ref_files(1)) == [] then bugmes();quit;end
72if fileinfo(TMPDIR + filesep() + renamedDst + filesep() + ref_files(2)) == [] then bugmes();quit;end
73mdelete(TMPDIR + filesep() + renamedDst + filesep() + ref_files(1));
74mdelete(TMPDIR + filesep() + renamedDst + filesep() + ref_files(2));
75rmdir(TMPDIR + filesep() + renamedDst);
76// =============================================================================
77// move a directory into a directory  with separator(s)
78dest = 'dirtomove2';
79renamedDst = 'renameddir2';
80mkdir(TMPDIR, renamedDst);
81a = copyfile(SCI+'/modules/fileio/etc',TMPDIR + filesep() + dest);
82if (a <> 1) then bugmes();quit;end
83if fileinfo(TMPDIR + filesep() + dest + filesep() + ref_files(1)) == [] then bugmes();quit;end
84if fileinfo(TMPDIR + filesep() + dest + filesep() + ref_files(2)) == [] then bugmes();quit;end
85a = movefile(TMPDIR + filesep() + dest, TMPDIR + filesep() + renamedDst + filesep());
86if (a <> 1) then bugmes();quit;end
87if fileinfo(TMPDIR + filesep() + renamedDst + filesep() + ref_files(1)) == [] then bugmes();quit;end
88if fileinfo(TMPDIR + filesep() + renamedDst + filesep() + ref_files(2)) == [] then bugmes();quit;end
89mdelete(TMPDIR + filesep() + renamedDst + filesep() + ref_files(1));
90mdelete(TMPDIR + filesep() + renamedDst + filesep() + ref_files(2));
91rmdir(TMPDIR + filesep() + renamedDst);
92// =============================================================================
93// move a file into a directory
94dest = 'dirtomove2';
95renamedDst = 'renameddir2';
96mkdir(TMPDIR, dest);
97a = copyfile(SCI+'/modules/fileio/etc/fileio.start',TMPDIR + filesep() + dest);
98if (a <> 1) then bugmes();quit;end
99if fileinfo(TMPDIR + filesep() + dest + '/fileio.start') == [] then bugmes();quit;end
100mkdir(TMPDIR, renamedDst);
101a = movefile(TMPDIR + filesep() + dest + '/fileio.start', TMPDIR + filesep() + renamedDst + filesep());
102if (a <> 1) then bugmes();quit;end
103if fileinfo(TMPDIR + filesep() + renamedDst + filesep() + '/fileio.start') == [] then bugmes();quit;end
104rmdir(TMPDIR + filesep() + renamedDst,'s');
105rmdir(TMPDIR + filesep() + dest,'s');
106// =============================================================================
107// move a file into a file
108mdelete(TMPDIR + '/scilab.quit');
109a = copyfile(SCI+'/etc/scilab.quit', TMPDIR);
110if (a <> 1) then bugmes();quit;end
111a = movefile(TMPDIR + '/scilab.quit', TMPDIR + '/renamed_scilab.quit');
112if fileinfo(TMPDIR + '/scilab.quit') <> [] then bugmes();quit;end
113if fileinfo(TMPDIR + '/renamed_scilab.quit') == [] then bugmes();quit;end
114mdelete(TMPDIR + '/renamed_scilab.quit');
115// =============================================================================
116// move directory with sub-directories
117mkdir(TMPDIR + '/copyfile_test');
118a = copyfile(SCI+'/modules/fileio/tests', TMPDIR + filesep() + 'copyfile_test');
119if (a <> 1) then bugmes();quit;end
120if fileinfo(TMPDIR + '/copyfile_test/unit_tests/copyfile.tst') == [] then bugmes();quit;end
121a = movefile(TMPDIR + filesep() + 'copyfile_test', TMPDIR + filesep() + 'copyfile_test2');
122if (a <> 1) then bugmes();quit;end
123if fileinfo(TMPDIR + '/copyfile_test/unit_tests/copyfile.tst') <> [] then bugmes();quit;end
124if fileinfo(TMPDIR + '/copyfile_test2/unit_tests/copyfile.tst') == [] then bugmes();quit;end
125rmdir(TMPDIR + '/copyfile_test2','s');
126// =============================================================================
127