File: 11_exceptions.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 (160 lines) | stat: -rwxr-xr-x 2,250 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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 => 8) ;
}


my $t = new t9(0) ;

{
	my $msg = '' ;
	eval {
		$t->f() ;
	} ;
	if ($@){
		if (caught("java.io.IOException")){
			$msg = $@->getMessage() . "io" ;
		}
		elsif (caught("java.lang.Exception")){
			$msg = $@->getMessage() ;
		}
		else {
			die $@ ;
		}
	} ;
	ok($msg, "from fio") ;

	$msg = '' ;
	eval {
		$t->f() ;
	} ;
	if ($@){
		if (caught("java.lang.Throwable")){
			$msg = $@->getMessage() ;
		}
		elsif (caught("java.io.IOException")){
			$msg = $@->getMessage() . "io" ;
		}
		else {
			die $@ ;
		}
	}
	ok($msg, "from f") ;


	$msg = '' ;
	eval {
		die("not e\n") ;
	} ;
	if ($@){
		if (caught("java.lang.Exception")){
			$msg = $@->getMessage() ;
		}
		else {
			$msg = $@ ;
		}
	}
	ok($msg, "not e\n") ;


	my $e = $t->f2() ;
	ok($e->getMessage(), "from f2") ;


	$msg = '' ;
	eval {
		my $t2 = new t9(1) ;
	} ;
	if ($@){
		if (caught("java.lang.Exception")){
			$msg = $@->getMessage() ;
		}
		else{
			die $@ ;
		}
	}
	ok($msg, "from const") ;	

	# Undeclared exception, java.lang.NullPointerException
	$msg = '' ;
	eval {
		my $t2 = new t9(0) ;
		$t2->len(undef) ;
	} ;
	if ($@){
		if (caught("java.lang.NullPointerException")){
			$msg = "null" ;
		}
		else {
			die $@ ;
		}
	}
	ok($msg, "null") ;	

	# Undeclared exception, java.lang.NullPointerException
	$msg = '' ;
	eval {
		my $t2 = new t9(0) ;
		$t2->len(undef) ;
	} ;
	if ($@){
		if (caught("java.lang.IOException")){
			$msg = "io" ;
		}
		elsif (caught("java.lang.Exception")){
			$msg = "null" ;
		}
		else{
			die $@ ;
		}
	}
	ok($msg, "null") ;

	# Make sure the last exception is not lying around...
	$@ = undef ;
}

ok($t->__get_private()->{proto}->ObjectCount(), 1) ;


__END__

__Java__


import java.io.* ;

class t9 {
	public t9(boolean t) throws Exception {
		if (t){
			throw new Exception("from const") ;
		}
	}

	public String f() throws IOException {
		throw new IOException("from f") ;
	}

	public IOException f2() {
		return new IOException("from f2") ;
	}

	public int len(String s) {
		return s.length() ;
	}
}