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