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