File: 13_handles.t

package info (click to toggle)
libinline-java-perl 0.58~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 964 kB
  • ctags: 684
  • sloc: perl: 4,717; java: 2,844; makefile: 35
file content (95 lines) | stat: -rwxr-xr-x 2,128 bytes parent folder | download
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
use strict ;
use Test ;

use Inline Config => 
           DIRECTORY => './_Inline_test';

use Inline(
	Java => 'DATA',
) ;

use Inline::Java qw(caught) ;


BEGIN {
	# Leave previous server enough time to die...
	sleep(1) ;
	plan(tests => 12) ;
}


my $t = new t13() ;

{
	my $f = File::Spec->catfile("t", "t13.txt") ;
	my $o = t13->getWriter($f) ;
	my $h = new Inline::Java::Handle($o) ;
	for (my $i = 1 ; $i <= 10 ; $i++){
	 	print $h "$i\n" ;
	}
	close($h) ;	
	ok(1) ;

	$o = t13->getReader($f) ;
	$h = new Inline::Java::Handle($o) ;
	for (my $i = 1 ; $i <= 10 ; $i++){
		my $l = <$h> ;
		ok($l, $i) ;
	}
	ok(! defined(<$h>)) ;
}


# It seems that filehandle destruction leaks on certain version
# of Perl. We will change this test to a warning.
if ($t->__get_private()->{proto}->ObjectCount() != 1){
	warn "\nWARNING: Your Perl version ($]) seems to leak tied filehandles. Using\n" .
		"Inline::Java::Handle objects will result in memory leaks both in Perl\n" .
		"and in Java\n" ;
} 


__END__

__Java__


import java.io.* ;

class t13 {
	public t13(){
	}

	public static Reader getReader(String file) throws FileNotFoundException {
		return new FileReader(file) ;
	}

	public static Reader getBufferedReader(String file) throws FileNotFoundException {
		return new BufferedReader(new FileReader(file)) ;
	}

	public static InputStream getInputStream(String file) throws FileNotFoundException {
		return new FileInputStream(file) ;
	}

	public static InputStream getBufferedInputStream(String file) throws FileNotFoundException {
		return new BufferedInputStream(new FileInputStream(file)) ;
	}

	public static Writer getWriter(String file) throws IOException {
		return new FileWriter(file) ;
	}

	public static Writer getBufferedWriter(String file) throws IOException {
		return new BufferedWriter(new FileWriter(file)) ;
	}

	public static OutputStream getOutputStream(String file) throws FileNotFoundException {
		return new FileOutputStream(file) ;
	}

	public static OutputStream getBufferedOutputStream(String file) throws FileNotFoundException {
		return new BufferedOutputStream(new FileOutputStream(file)) ;
	}
}