summaryrefslogtreecommitdiffstats
path: root/tests/java/JavaTests.sce
blob: 33421e4c77e6c0d35e6e01cf1c9bd1ae729ec750 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Allan CORNET 2005
//---------------------------------------------------------------
// Tests Interface Scilab Java
//---------------------------------------------------------------
tests = ['clf.java';'disp.java';'Exec.java';'Real1.java';'Real2.java';'Real3.java';'String1.java';'Strings1.java';'Strings2.java';'Boolean.java';'BooleanArray.java'];
//---------------------------------------------------------------
// Compilation du fichier Java
function ret=BuildJava(filename)
	if MSDOS then
		Command='javac -deprecation -d '+SCI+'\bin -classpath '+SCI+'\bin '+filename;
	else
		Command='javac -deprecation -d '+SCI+'/bin -classpath '+SCI+'/bin '+filename;
	end
	[rep,stat]=unix_g(Command);
	if ~(stat==0) then
		disp('error compilation '+filename);
		ret=%F;
	else
		ret=%T;
	end
endfunction
//---------------------------------------------------------------
// Execution du fichier Java
function ExecJava(filename,buildref)
	currentdir=pwd();
	repfilename='';
	chdir(SCI+'\bin');
	if ~MSDOS then
		setenv('LD_LIBRARY_PATH','$LD_LIBRARY_PATH:'+pwd());
		setenv('CLASSPATH','$CLASSPATH:'+pwd()+':.');
		setenv('SHLIB_PATH','$SHLIB_PATH:'+pwd()+':.');
	end
	[path,fname,extension]=fileparts(filename);
	if (buildref == %T) then
		if MSDOS then
			repfilename=currentdir+'\'+fname+'.dia.ref';
		else
			repfilename=currentdir+'/'+fname+'.dia.ref';
		end
	else
		if MSDOS then
			repfilename=currentdir+'\'+fname+'.dia';
		else
			repfilename=currentdir+'/'+fname+'.dia';
		end
	end

	if MSDOS then
	  commandline='..\modules\jvm\bin\jre\bin\java '+fname +' > '+repfilename;
	else
	  commandline='../modules/jvm/bin/jre/bin/java '+fname +' > '+repfilename;
	end

	unix(commandline);
	chdir(currentdir);
endfunction
//---------------------------------------------------------------
// Nettoyage apres tests du fichier .class généré
function CleanClass(filename)
	currentdir=pwd();
	chdir(SCI+'\bin');
	[path,fname,extension]=fileparts(filename);
	if MSDOS then
		unix_s('del '+fname+'.class');
	else
		unix_s('rm -f '+fname+'.class');
	end
	chdir(currentdir);
endfunction
//---------------------------------------------------------------
// Comparaison avec la reference
function CompareDiary(filename)
	[path,fname,extension]=fileparts(filename);
	fpdia=mopen(fname+'.dia','r');
	fpref=mopen(fname+'.dia.ref','r');
	dia=mgetl(fpdia);
	mclose(fpdia);
	ref=mgetl(fpref);
	mclose(fpref);
	
	dia=strsubst(dia,' ','');
	ref=strsubst(ref,' ','');
	
	if or(ref<>dia) then
		disp('Test Failed SEE : diff -w  '+fname+'.dia '+fname+'.dia.ref ');
	else
		disp('Test '+fname+' passed');
	end
endfunction
//---------------------------------------------------------------
// Construction de la reference
function BuildRef(filename)
  ExecJava(filename,%T);
endfunction
//---------------------------------------------------------------
function maketests()
	Dim=size(tests);
	i=Dim(1);
	lines(0);
	for indice=1:i
		disp('//---------------------------------------------------------------');
		if ( BuildJava(tests(indice)) ) then
			ExecJava(tests(indice),%F);
			CleanClass(tests(indice));
			CompareDiary(tests(indice));
		end
	end
	disp('//---------------------------------------------------------------');
endfunction
//---------------------------------------------------------------
function makeref()
	Dim=size(tests);
	i=Dim(1);
	lines(0);
	for indice=1:i
		if ( BuildJava(tests(indice)) ) then
			ExecJava(tests(indice),%T);
			CleanClass(tests(indice));
		end
	end
endfunction
//---------------------------------------------------------------
// Fonction principale
function main()
	maketests();
	quit
endfunction
//---------------------------------------------------------------
main();
//---------------------------------------------------------------