rjb 1.4.5 → 1.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +504 -504
- data/ChangeLog +6 -1
- data/data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class +0 -0
- data/ext/RBridge.java +39 -39
- data/ext/depend +23 -23
- data/ext/extconf.h +1 -0
- data/ext/extconf.rb +77 -77
- data/ext/jp_co_infoseek_hp_arton_rjb_RBridge.h +21 -21
- data/ext/load.c +408 -408
- data/ext/riconv.c +218 -218
- data/ext/riconv.h +24 -24
- data/ext/rjb.c +3317 -3317
- data/ext/rjb.h +164 -164
- data/ext/rjbexception.c +167 -167
- data/lib/rjb.rb +122 -122
- data/readme.txt +35 -35
- data/samples/filechooser.rb +35 -35
- data/samples/unzip.rb +66 -66
- data/test/gctest.rb +24 -24
- data/test/listtest.rb +56 -56
- data/test/osx_jvmcheck.rb +9 -9
- data/test/rjbtest.jar +0 -0
- data/test/test.rb +873 -873
- data/test/test_osxjvm.rb +23 -23
- data/test/test_osxload.rb +64 -64
- data/test/test_unload.rb +0 -0
- metadata +15 -17
- data/lib/rjbcore.so +0 -0
data/test/gctest.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'rjb'
|
3
|
-
|
4
|
-
class TestRjbGC < Test::Unit::TestCase
|
5
|
-
include Rjb
|
6
|
-
def setup
|
7
|
-
load(nil, ['-verbose:gc'])
|
8
|
-
end
|
9
|
-
|
10
|
-
def tearDown
|
11
|
-
unload
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_gc
|
15
|
-
stringBuffer = import('java.lang.StringBuffer')
|
16
|
-
(0..1000).each do |i|
|
17
|
-
sb = stringBuffer.new
|
18
|
-
(0..1000).each do |j|
|
19
|
-
sb.append(' ')
|
20
|
-
end
|
21
|
-
GC.start
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rjb'
|
3
|
+
|
4
|
+
class TestRjbGC < Test::Unit::TestCase
|
5
|
+
include Rjb
|
6
|
+
def setup
|
7
|
+
load(nil, ['-verbose:gc'])
|
8
|
+
end
|
9
|
+
|
10
|
+
def tearDown
|
11
|
+
unload
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_gc
|
15
|
+
stringBuffer = import('java.lang.StringBuffer')
|
16
|
+
(0..1000).each do |i|
|
17
|
+
sb = stringBuffer.new
|
18
|
+
(0..1000).each do |j|
|
19
|
+
sb.append(' ')
|
20
|
+
end
|
21
|
+
GC.start
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/test/listtest.rb
CHANGED
@@ -1,56 +1,56 @@
|
|
1
|
-
#!/usr/local/env ruby -Ku
|
2
|
-
# encoding: utf-8
|
3
|
-
=begin
|
4
|
-
Copyright(c) 2012 arton
|
5
|
-
=end
|
6
|
-
|
7
|
-
begin
|
8
|
-
require 'rjb/list'
|
9
|
-
rescue LoadError
|
10
|
-
require 'rubygems'
|
11
|
-
require 'rjb/list'
|
12
|
-
end
|
13
|
-
require 'test/unit'
|
14
|
-
require 'fileutils'
|
15
|
-
|
16
|
-
class ListTest < Test::Unit::TestCase
|
17
|
-
include Rjb
|
18
|
-
def test_create
|
19
|
-
ja = import('java.util.ArrayList')
|
20
|
-
a = ja.new
|
21
|
-
a.add(1)
|
22
|
-
a.add(2)
|
23
|
-
a.add(3)
|
24
|
-
n = 1
|
25
|
-
a.each do |x|
|
26
|
-
assert_equal n, x.intValue
|
27
|
-
n += 1
|
28
|
-
end
|
29
|
-
assert_equal 4, n
|
30
|
-
end
|
31
|
-
def test_returned_proxy
|
32
|
-
ja = import('java.util.Arrays')
|
33
|
-
a = ja.as_list([1, 2, 3])
|
34
|
-
n = 1
|
35
|
-
a.each do |x|
|
36
|
-
assert_equal n, x.intValue
|
37
|
-
n += 1
|
38
|
-
end
|
39
|
-
assert_equal 4, n
|
40
|
-
end
|
41
|
-
def test_iterator
|
42
|
-
ja = import('java.util.Arrays')
|
43
|
-
it = ja.as_list([1, 2, 3]).iterator
|
44
|
-
n = 1
|
45
|
-
it.each do |x|
|
46
|
-
assert_equal n, x.intValue
|
47
|
-
n += 1
|
48
|
-
end
|
49
|
-
assert_equal 4, n
|
50
|
-
end
|
51
|
-
def test_enumerable
|
52
|
-
ja = import('java.util.Arrays')
|
53
|
-
assert_equal 55, ja.as_list((1..10).to_a).inject(0) {|r, e| r + e.intValue}
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
1
|
+
#!/usr/local/env ruby -Ku
|
2
|
+
# encoding: utf-8
|
3
|
+
=begin
|
4
|
+
Copyright(c) 2012 arton
|
5
|
+
=end
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'rjb/list'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rubygems'
|
11
|
+
require 'rjb/list'
|
12
|
+
end
|
13
|
+
require 'test/unit'
|
14
|
+
require 'fileutils'
|
15
|
+
|
16
|
+
class ListTest < Test::Unit::TestCase
|
17
|
+
include Rjb
|
18
|
+
def test_create
|
19
|
+
ja = import('java.util.ArrayList')
|
20
|
+
a = ja.new
|
21
|
+
a.add(1)
|
22
|
+
a.add(2)
|
23
|
+
a.add(3)
|
24
|
+
n = 1
|
25
|
+
a.each do |x|
|
26
|
+
assert_equal n, x.intValue
|
27
|
+
n += 1
|
28
|
+
end
|
29
|
+
assert_equal 4, n
|
30
|
+
end
|
31
|
+
def test_returned_proxy
|
32
|
+
ja = import('java.util.Arrays')
|
33
|
+
a = ja.as_list([1, 2, 3])
|
34
|
+
n = 1
|
35
|
+
a.each do |x|
|
36
|
+
assert_equal n, x.intValue
|
37
|
+
n += 1
|
38
|
+
end
|
39
|
+
assert_equal 4, n
|
40
|
+
end
|
41
|
+
def test_iterator
|
42
|
+
ja = import('java.util.Arrays')
|
43
|
+
it = ja.as_list([1, 2, 3]).iterator
|
44
|
+
n = 1
|
45
|
+
it.each do |x|
|
46
|
+
assert_equal n, x.intValue
|
47
|
+
n += 1
|
48
|
+
end
|
49
|
+
assert_equal 4, n
|
50
|
+
end
|
51
|
+
def test_enumerable
|
52
|
+
ja = import('java.util.Arrays')
|
53
|
+
assert_equal 55, ja.as_list((1..10).to_a).inject(0) {|r, e| r + e.intValue}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
data/test/osx_jvmcheck.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
begin
|
3
|
-
require 'rjb'
|
4
|
-
rescue LoadError
|
5
|
-
require 'rubygems'
|
6
|
-
require 'rjb'
|
7
|
-
end
|
8
|
-
S = Rjb::import('java.lang.System')
|
9
|
-
puts "#{S.property('java.vendor')} #{S.property('java.version')}"
|
1
|
+
# coding: utf-8
|
2
|
+
begin
|
3
|
+
require 'rjb'
|
4
|
+
rescue LoadError
|
5
|
+
require 'rubygems'
|
6
|
+
require 'rjb'
|
7
|
+
end
|
8
|
+
S = Rjb::import('java.lang.System')
|
9
|
+
puts "#{S.property('java.vendor')} #{S.property('java.version')}"
|
data/test/rjbtest.jar
CHANGED
File without changes
|
data/test/test.rb
CHANGED
@@ -1,873 +1,873 @@
|
|
1
|
-
#!/usr/local/env ruby -Ku
|
2
|
-
# encoding: utf-8
|
3
|
-
# $Id: test.rb 199 2012-12-17 13:31:18Z arton $
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'rjb'
|
7
|
-
rescue LoadError
|
8
|
-
require 'rubygems'
|
9
|
-
require 'rjb'
|
10
|
-
end
|
11
|
-
require 'test/unit'
|
12
|
-
require 'fileutils'
|
13
|
-
|
14
|
-
FileUtils.rm_f 'jp/co/infoseek/hp/arton/rjb/Base.class'
|
15
|
-
FileUtils.rm_f 'jp/co/infoseek/hp/arton/rjb/ExtBase.class'
|
16
|
-
|
17
|
-
puts "start RJB(#{Rjb::VERSION}) test"
|
18
|
-
class TestRjb < Test::Unit::TestCase
|
19
|
-
include Rjb
|
20
|
-
def setup
|
21
|
-
Rjb::load('.')
|
22
|
-
Rjb::add_jar(File.expand_path('rjbtest.jar'))
|
23
|
-
Rjb::primitive_conversion = false
|
24
|
-
|
25
|
-
@jString = import('java.lang.String')
|
26
|
-
@jInteger = import('java.lang.Integer')
|
27
|
-
@jShort = import('java.lang.Short')
|
28
|
-
@jDouble = import('java.lang.Double')
|
29
|
-
@jFloat = import('java.lang.Float')
|
30
|
-
@jBoolean = import('java.lang.Boolean')
|
31
|
-
@jByte = import('java.lang.Byte')
|
32
|
-
@jLong = import('java.lang.Long')
|
33
|
-
@jChar = import('java.lang.Character')
|
34
|
-
end
|
35
|
-
|
36
|
-
def teardown
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_metaclass
|
40
|
-
cls = import('java.lang.Class')
|
41
|
-
assert_equal('java.lang.Class', cls._classname)
|
42
|
-
assert_equal('java.lang.Class', cls.getName)
|
43
|
-
assert_equal(17, cls.getModifiers)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_scalar
|
47
|
-
assert_equal('java.lang.Class', @jString._classname)
|
48
|
-
assert_equal('class java.lang.String', @jString.toString)
|
49
|
-
str = @jString.new
|
50
|
-
assert_equal('java.lang.String', str._classname)
|
51
|
-
assert_equal(0, str.length)
|
52
|
-
assert_equal('', str.toString)
|
53
|
-
str = @jString.new_with_sig('Ljava.lang.String;', "abcde")
|
54
|
-
# result integer
|
55
|
-
assert_equal(5, str.length)
|
56
|
-
# result string
|
57
|
-
assert_equal('abcde', str.toString)
|
58
|
-
# argument test
|
59
|
-
# char
|
60
|
-
assert_equal('abxde', str.replace("c".sum, "x".sum))
|
61
|
-
# string
|
62
|
-
assert_equal('abdxe', str.replaceAll('cd', 'dx'))
|
63
|
-
# int
|
64
|
-
assert_equal('bc', str.substring(1, 3))
|
65
|
-
assert_equal('e', str.substring(4))
|
66
|
-
# float with static
|
67
|
-
assert_equal('5.23', @jString._invoke('valueOf', 'F', 5.23))
|
68
|
-
assert_equal('25.233', @jString._invoke('valueOf', 'D', 25.233))
|
69
|
-
# rjb object (String)
|
70
|
-
str2 = @jString.new_with_sig('Ljava.lang.String;', 'fghijk')
|
71
|
-
assert_equal('abcdefghijk', str.concat(str2))
|
72
|
-
# rjb object other (implicit toString call is Rjb feature)
|
73
|
-
i = @jInteger.new_with_sig('I', 35901)
|
74
|
-
assert_equal('abcde35901', str.concat(i))
|
75
|
-
# result boolean and argument is rjb object
|
76
|
-
assert_equal(false, i.equals(str))
|
77
|
-
assert_equal(false, str.equals(i))
|
78
|
-
assert_equal(true, str.equals("abcde"))
|
79
|
-
assert_equal(true, str.equals(str))
|
80
|
-
# long
|
81
|
-
l = @jLong.new_with_sig('J', -9223372036854775808)
|
82
|
-
assert_equal(-9223372036854775808, l.longValue)
|
83
|
-
l = @jLong.new_with_sig('J', 9223372036854775807)
|
84
|
-
assert_equal(9223372036854775807, l.longValue)
|
85
|
-
# double
|
86
|
-
d = @jDouble.new_with_sig('D', 1234.5678901234567890)
|
87
|
-
assert_equal(1234.5678901234567890, d.doubleValue)
|
88
|
-
# byte
|
89
|
-
b = @jByte.new_with_sig('B', 13)
|
90
|
-
assert_equal(13, b.byteValue)
|
91
|
-
# float
|
92
|
-
f = @jFloat.new_with_sig('F', 13.5)
|
93
|
-
assert_equal(13.5, f.floatValue)
|
94
|
-
# short
|
95
|
-
s = @jShort.new_with_sig('S', 1532)
|
96
|
-
assert_equal(1532, s.shortValue)
|
97
|
-
c = @jChar.new_with_sig('C', "A".sum)
|
98
|
-
assert_equal("A".sum, c.charValue)
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_array
|
102
|
-
str = @jString.new_with_sig('[C', ["a".sum, "b".sum, "c".sum, "d".sum, "e".sum, "c".sum, "f".sum, "c".sum, "g".sum])
|
103
|
-
assert_equal('abcdecfcg', str.toString)
|
104
|
-
# conv string array
|
105
|
-
splt = str.split('c')
|
106
|
-
assert(Array === splt)
|
107
|
-
assert_equal(4, splt.size)
|
108
|
-
assert_equal('ab', splt[0])
|
109
|
-
assert_equal('g', splt[3])
|
110
|
-
# conv byte array to (ruby)string
|
111
|
-
ba = str.getBytes
|
112
|
-
assert_equal('abcdecfcg', ba)
|
113
|
-
# conv char array to array(int)
|
114
|
-
ca = str.toCharArray
|
115
|
-
assert_equal(["a".sum, "b".sum, "c".sum, "d".sum, "e".sum, "c".sum, "f".sum, "c".sum, "g".sum], ca)
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_importobj()
|
119
|
-
sys = import('java.lang.System')
|
120
|
-
props = sys.getProperties
|
121
|
-
assert_equal('java.util.Properties', props._classname)
|
122
|
-
if /cygwin/ =~ RUBY_PLATFORM # patch for dirty environment
|
123
|
-
assert_equal(Dir::pwd, %x[cygpath -u #{props.getProperty('user.dir').gsub('\\', '/')}].chop)
|
124
|
-
else
|
125
|
-
assert_equal(Dir::pwd, props.getProperty('user.dir').gsub('\\', '/'))
|
126
|
-
end
|
127
|
-
assert_equal(@jBoolean.valueOf(true).booleanValue(), true)
|
128
|
-
assert_equal(@jBoolean.valueOf(false).booleanValue(), false)
|
129
|
-
assert_equal(@jBoolean.valueOf('true').booleanValue(), true)
|
130
|
-
assert_equal(@jBoolean.valueOf('false').booleanValue(), false)
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_importobjarray()
|
134
|
-
jarray = import('java.util.ArrayList')
|
135
|
-
a = jarray.new()
|
136
|
-
a.add(@jInteger.new_with_sig('I', 1))
|
137
|
-
a.add(@jInteger.new_with_sig('I', 2))
|
138
|
-
a.add(@jInteger.new_with_sig('I', 3))
|
139
|
-
oa = a.toArray
|
140
|
-
assert_equal(3, oa.size)
|
141
|
-
assert_equal(1, oa[0].intValue)
|
142
|
-
assert_equal(2, oa[1].intValue)
|
143
|
-
assert_equal(3, oa[2].intValue)
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_kjconv()
|
147
|
-
if Object::const_defined?(:Encoding)
|
148
|
-
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
149
|
-
euc_kj = "\xb4\xc1\xbb\xfa\xa5\xc6\xa5\xad\xa5\xb9\xa5\xc8".force_encoding Encoding::EUC_JP
|
150
|
-
s = @jString.new(euc_kj)
|
151
|
-
assert_equal(s.toString().encoding, Encoding::UTF_8)
|
152
|
-
assert(test.isSameString(s))
|
153
|
-
assert(test.isSameString(euc_kj))
|
154
|
-
assert_equal(s.toString().encode(Encoding::EUC_JP), euc_kj)
|
155
|
-
sjis_kj = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67".force_encoding Encoding::SHIFT_JIS
|
156
|
-
s = @jString.new(sjis_kj)
|
157
|
-
assert_equal(s.toString().encoding, Encoding::UTF_8)
|
158
|
-
assert(test.isSameString(s))
|
159
|
-
assert(test.isSameString(sjis_kj))
|
160
|
-
assert_equal(s.toString().encode(Encoding::SHIFT_JIS), sjis_kj)
|
161
|
-
utf8_kj = "\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88".force_encoding Encoding::UTF_8
|
162
|
-
s = @jString.new(utf8_kj)
|
163
|
-
assert_equal(s.toString().encoding, Encoding::UTF_8)
|
164
|
-
assert(test.isSameString(s))
|
165
|
-
assert(test.isSameString(utf8_kj))
|
166
|
-
assert_equal(s.toString().encode(Encoding::UTF_8), utf8_kj)
|
167
|
-
iso2022jp_kj = "\x1b\x24\x42\x34\x41\x3b\x7a\x25\x46\x25\x2d\x25\x39\x25\x48\x1b\x28\x42".force_encoding Encoding::ISO_2022_JP
|
168
|
-
s = @jString.new(iso2022jp_kj)
|
169
|
-
assert_equal(s.toString().encoding, Encoding::UTF_8)
|
170
|
-
assert(test.isSameString(s))
|
171
|
-
assert(test.isSameString(iso2022jp_kj))
|
172
|
-
assert_equal(s.toString().encode(Encoding::ISO_2022_JP), iso2022jp_kj)
|
173
|
-
assert_equal(@jString.new("abcdef".force_encoding(Encoding::ASCII_8BIT)).toString(), "abcdef")
|
174
|
-
assert_equal(@jString.new("abcdef".force_encoding(Encoding::find("us-ascii"))).toString(), "abcdef")
|
175
|
-
else
|
176
|
-
default_kcode = $KCODE
|
177
|
-
begin
|
178
|
-
$KCODE = 'euc'
|
179
|
-
euc_kj = "\xb4\xc1\xbb\xfa\xa5\xc6\xa5\xad\xa5\xb9\xa5\xc8"
|
180
|
-
s = @jString.new(euc_kj)
|
181
|
-
assert_equal(s.toString(), euc_kj)
|
182
|
-
$KCODE = 'sjis'
|
183
|
-
sjis_kj = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67"
|
184
|
-
s = @jString.new(sjis_kj)
|
185
|
-
assert_equal(s.toString(), sjis_kj)
|
186
|
-
$KCODE = 'utf8'
|
187
|
-
utf8_kj = "\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88"
|
188
|
-
s = @jString.new(utf8_kj)
|
189
|
-
assert_equal(s.toString(), utf8_kj)
|
190
|
-
$KCODE = 'none'
|
191
|
-
if /mswin(?!ce)|mingw|cygwin|bccwin/ =~ RUBY_PLATFORM
|
192
|
-
#expecting shift_jis on windows
|
193
|
-
none_kj = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67"
|
194
|
-
else
|
195
|
-
#expecting utf-8 unless windows
|
196
|
-
none_kj = "\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88"
|
197
|
-
end
|
198
|
-
s = @jString.new(none_kj)
|
199
|
-
assert_equal(s.toString(), none_kj)
|
200
|
-
$KCODE = 'utf8'
|
201
|
-
utf8_kj = "\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88"
|
202
|
-
s = @jString.new(utf8_kj)
|
203
|
-
assert_equal(s.toString(), utf8_kj)
|
204
|
-
$KCODE = 'sjis'
|
205
|
-
sjis_kj = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67"
|
206
|
-
s = @jString.new(sjis_kj)
|
207
|
-
assert_equal(s.toString(), sjis_kj)
|
208
|
-
$KCODE = 'euc'
|
209
|
-
euc_kj = "\xb4\xc1\xbb\xfa\xa5\xc6\xa5\xad\xa5\xb9\xa5\xc8"
|
210
|
-
s = @jString.new(euc_kj)
|
211
|
-
assert_equal(s.toString(), euc_kj)
|
212
|
-
ensure
|
213
|
-
$KCODE = default_kcode
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_combination_charcters
|
219
|
-
teststr = "\xc7\x96\xc3\xbc\xcc\x84\x75\xcc\x88\xcc\x84\xed\xa1\xa9\xed\xba\xb2\xe3\x81\x8b\xe3\x82\x9a"
|
220
|
-
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
221
|
-
s = test.getUmlaut()
|
222
|
-
if Object::const_defined?(:Encoding) #>=1.9
|
223
|
-
teststr = teststr.force_encoding(Encoding::UTF_8)
|
224
|
-
assert_equal(s, teststr)
|
225
|
-
else
|
226
|
-
default_kcode = $KCODE
|
227
|
-
begin
|
228
|
-
$KCODE = "utf8"
|
229
|
-
assert_equal(s, teststr)
|
230
|
-
ensure
|
231
|
-
$KCODE = default_kcode
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
def test_constants()
|
237
|
-
assert_equal(0x7fffffffffffffff, @jLong.MAX_VALUE)
|
238
|
-
assert_equal(-9223372036854775808, @jLong.MIN_VALUE)
|
239
|
-
end
|
240
|
-
|
241
|
-
class TestIter
|
242
|
-
def initialize()
|
243
|
-
@i = 5
|
244
|
-
end
|
245
|
-
def hasNext()
|
246
|
-
@i > 0
|
247
|
-
end
|
248
|
-
def next()
|
249
|
-
@i -= 1
|
250
|
-
@i.to_s
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
def test_newobject()
|
255
|
-
it = TestIter.new
|
256
|
-
it = bind(it, 'java.util.Iterator')
|
257
|
-
test = import('jp.co.infoseek.hp.arton.rjb.Test')
|
258
|
-
a = test.new
|
259
|
-
assert_equal("43210", a.concat(it))
|
260
|
-
end
|
261
|
-
|
262
|
-
def test_unbind()
|
263
|
-
it = TestIter.new
|
264
|
-
it = bind(it, 'java.util.Iterator')
|
265
|
-
assert_equal(it, unbind(it))
|
266
|
-
end
|
267
|
-
|
268
|
-
class TestComparator
|
269
|
-
def compare(o1, o2)
|
270
|
-
o1.to_i - o2.to_i
|
271
|
-
end
|
272
|
-
def equals(o)
|
273
|
-
o == self
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_comparator
|
278
|
-
cp = TestComparator.new
|
279
|
-
cp = bind(cp, 'java.util.Comparator')
|
280
|
-
test = import('jp.co.infoseek.hp.arton.rjb.Test')
|
281
|
-
a = test.new
|
282
|
-
assert_equal(0, a.check(cp, 123, 123))
|
283
|
-
assert_equal(5, a.check(cp, 81, 76))
|
284
|
-
assert_equal(-5, a.check(cp, 76, 81))
|
285
|
-
end
|
286
|
-
|
287
|
-
# assert_raise is useless in this test, because NumberFormatException may be defined in
|
288
|
-
# its block.
|
289
|
-
def test_exception()
|
290
|
-
begin
|
291
|
-
@jInteger.parseInt('blabla')
|
292
|
-
flunk('no exception')
|
293
|
-
rescue NumberFormatException => e
|
294
|
-
assert_nil(e.cause)
|
295
|
-
# OK
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
class TestIterator
|
300
|
-
def initialize(tp)
|
301
|
-
@type = tp
|
302
|
-
end
|
303
|
-
def hasNext()
|
304
|
-
true
|
305
|
-
end
|
306
|
-
def next()
|
307
|
-
if @type == 0
|
308
|
-
Rjb::throw('java.util.NoSuchElementException', 'test exception')
|
309
|
-
elsif @type == 1
|
310
|
-
Rjb::throw(Rjb::import('java.util.NoSuchElementException').new('instance test'))
|
311
|
-
end
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
def test_throw()
|
316
|
-
it = TestIterator.new(0)
|
317
|
-
it = bind(it, 'java.util.Iterator')
|
318
|
-
test = import('jp.co.infoseek.hp.arton.rjb.Test')
|
319
|
-
a = test.new
|
320
|
-
begin
|
321
|
-
a.concat(it)
|
322
|
-
flunk('no exception')
|
323
|
-
rescue NoSuchElementException => e
|
324
|
-
assert_equal('test exception', e.message)
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
def test_instance_throw()
|
329
|
-
it = TestIterator.new(1)
|
330
|
-
it = bind(it, 'java.util.Iterator')
|
331
|
-
test = import('jp.co.infoseek.hp.arton.rjb.Test')
|
332
|
-
a = test.new
|
333
|
-
begin
|
334
|
-
a.concat(it)
|
335
|
-
flunk('no exception')
|
336
|
-
rescue NoSuchElementException => e
|
337
|
-
assert_equal('instance test', e.message)
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
def test_null_string()
|
342
|
-
sys = import('java.lang.System')
|
343
|
-
begin
|
344
|
-
sys.getProperty(nil)
|
345
|
-
flunk('no exception')
|
346
|
-
rescue NullPointerException => e
|
347
|
-
assert(true)
|
348
|
-
rescue RuntimeError => e
|
349
|
-
flunk(e.message)
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
def test_throw_error()
|
354
|
-
begin
|
355
|
-
throw(self)
|
356
|
-
flunk('no exception')
|
357
|
-
rescue TypeError => e
|
358
|
-
end
|
359
|
-
begin
|
360
|
-
throw(@jString.new('a'))
|
361
|
-
flunk('no exception')
|
362
|
-
rescue RuntimeError => e
|
363
|
-
assert_equal('arg1 must be a throwable', e.message)
|
364
|
-
end
|
365
|
-
begin
|
366
|
-
throw('java.lang.NoSuchException', 'test')
|
367
|
-
flunk('no excpetion')
|
368
|
-
rescue RuntimeError => e
|
369
|
-
assert_equal("`java.lang.NoSuchException' not found", e.message)
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
def test_throw_clear()
|
374
|
-
assert_nothing_raised {
|
375
|
-
begin
|
376
|
-
Rjb::throw('java.util.NoSuchElementException', 'test exception')
|
377
|
-
rescue #drop ruby exception
|
378
|
-
end
|
379
|
-
test = import('jp.co.infoseek.hp.arton.rjb.Test')
|
380
|
-
begin
|
381
|
-
Rjb::throw('java.util.NoSuchElementException', 'test exception')
|
382
|
-
rescue #drop ruby exception
|
383
|
-
end
|
384
|
-
test.new
|
385
|
-
begin
|
386
|
-
Rjb::throw('java.util.NoSuchElementException', 'test exception')
|
387
|
-
rescue #drop ruby exception
|
388
|
-
end
|
389
|
-
@jString.new_with_sig('Ljava.lang.String;', "abcde")
|
390
|
-
begin
|
391
|
-
Rjb::throw('java.util.NoSuchElementException', 'test exception')
|
392
|
-
rescue #drop ruby exception
|
393
|
-
end
|
394
|
-
it = TestIterator.new(0)
|
395
|
-
it = bind(it, 'java.util.Iterator')
|
396
|
-
begin
|
397
|
-
Rjb::throw('java.util.NoSuchElementException', 'test exception')
|
398
|
-
rescue NoSuchElementException
|
399
|
-
end
|
400
|
-
begin
|
401
|
-
Rjb::throw('java.lang.IllegalAccessException', 'test exception')
|
402
|
-
rescue IllegalAccessException
|
403
|
-
end
|
404
|
-
unbind(it)
|
405
|
-
}
|
406
|
-
end
|
407
|
-
|
408
|
-
def test_field()
|
409
|
-
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
410
|
-
assert_equal('Hello World !!', test.helloData)
|
411
|
-
test.helloData = 'Goodby World !'
|
412
|
-
assert_equal('Goodby World !', test.helloData)
|
413
|
-
end
|
414
|
-
|
415
|
-
def test_instancemethod_from_class()
|
416
|
-
begin
|
417
|
-
assert_equal('true', @jString.valueOf(true))
|
418
|
-
@jString.length
|
419
|
-
flunk('no exception')
|
420
|
-
rescue RuntimeError => e
|
421
|
-
assert_equal('instance method `length\' for class', e.message)
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
|
-
def test_instancefield_from_class()
|
426
|
-
point = import('java.awt.Point')
|
427
|
-
begin
|
428
|
-
point.x
|
429
|
-
flunk('no exception')
|
430
|
-
rescue RuntimeError => e
|
431
|
-
assert_equal('instance field `x\' for class', e.message)
|
432
|
-
end
|
433
|
-
begin
|
434
|
-
point.x = 30
|
435
|
-
rescue RuntimeError => e
|
436
|
-
assert_equal('instance field `x\' for class', e.message)
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
def test_static_derived_method()
|
441
|
-
ext = import('jp.co.infoseek.hp.arton.rjb.ExtBase')
|
442
|
-
assert_equal("sVal", ext.getSVal)
|
443
|
-
end
|
444
|
-
|
445
|
-
def test_capitalized_method()
|
446
|
-
bs = import('jp.co.infoseek.hp.arton.rjb.Base')
|
447
|
-
assert_equal("val", bs.val)
|
448
|
-
assert_equal("Val", bs.Val)
|
449
|
-
end
|
450
|
-
|
451
|
-
def test_underscored_constant()
|
452
|
-
bs = import('jp.co.infoseek.hp.arton.rjb.Base')
|
453
|
-
assert_equal(5, bs._NUMBER_FIVE)
|
454
|
-
end
|
455
|
-
|
456
|
-
def test_passingclass()
|
457
|
-
ibs = import('jp.co.infoseek.hp.arton.rjb.IBase')
|
458
|
-
bs = import('jp.co.infoseek.hp.arton.rjb.Base')
|
459
|
-
assert_equal('interface jp.co.infoseek.hp.arton.rjb.IBase', bs.intf(ibs))
|
460
|
-
end
|
461
|
-
|
462
|
-
def test_fornamehook()
|
463
|
-
# j2se class
|
464
|
-
cls = import('java.lang.Class')
|
465
|
-
c = cls.forName('java.lang.Class')
|
466
|
-
assert_equal(cls, c)
|
467
|
-
# user class
|
468
|
-
bs = import('jp.co.infoseek.hp.arton.rjb.Base')
|
469
|
-
b = cls.forName('jp.co.infoseek.hp.arton.rjb.Base')
|
470
|
-
assert_equal(bs, b)
|
471
|
-
# check class that was loaded from classpath
|
472
|
-
loader = Rjb::import('java.lang.ClassLoader')
|
473
|
-
b = cls.forName('jp.co.infoseek.hp.arton.rjb.IBase', true, loader.getSystemClassLoader)
|
474
|
-
assert(b.isInterface)
|
475
|
-
end
|
476
|
-
|
477
|
-
def test_send_array_of_arrays()
|
478
|
-
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
479
|
-
a = test.joinStringArray([['ab', 'cd'], ['ef', 'gh']])
|
480
|
-
assert_equal(['ab', 'cd', 'ef', 'gh'], a)
|
481
|
-
a = test.joinIntArray([[1, 2, 3], [4, 5, 6]])
|
482
|
-
a.collect! {|e| e.intValue }
|
483
|
-
assert_equal([1, 2, 3, 4, 5, 6], a)
|
484
|
-
r = [[[ 1, 2], [2, 3] ], [[ 3, 4], [5, 6]], [[7, 8], [1, 3]]]
|
485
|
-
a = test.throughIntArray(r)
|
486
|
-
assert_equal(a, r)
|
487
|
-
end
|
488
|
-
|
489
|
-
def test_import_and_instanciate()
|
490
|
-
b = import('jp.co.infoseek.hp.arton.rjb.Base')
|
491
|
-
assert_equal('hello', b.new.getInstanceVar())
|
492
|
-
end
|
493
|
-
|
494
|
-
def test_array_of_arrays()
|
495
|
-
jversion = import('java.lang.System').getProperty('java.version')
|
496
|
-
if /^1\.5/ =~ jversion
|
497
|
-
method = import('java.lang.reflect.Method')
|
498
|
-
end
|
499
|
-
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
500
|
-
a = test.getStringArrayOfArrays()
|
501
|
-
assert_equal("abc", a[0][0])
|
502
|
-
assert_equal("def", a[0][1])
|
503
|
-
assert_equal("123", a[1][0])
|
504
|
-
assert_equal("456", a[1][1])
|
505
|
-
|
506
|
-
ints = test.getIntArrayOfArrays()
|
507
|
-
assert_equal(2, ints.size )
|
508
|
-
assert_equal([1,2,3], ints[0] )
|
509
|
-
assert_equal([[1,2,3],[4,5,6]], ints )
|
510
|
-
|
511
|
-
sized = test.getSizedArray()
|
512
|
-
assert_equal("find me",sized[0][1][2][3])
|
513
|
-
|
514
|
-
mixed = test.getMixedArray()
|
515
|
-
assert_equal(12,mixed[0][0][0].intValue)
|
516
|
-
assert_equal("another string",mixed[1][0][1].toString)
|
517
|
-
assert_equal([],mixed[2])
|
518
|
-
end
|
519
|
-
|
520
|
-
def test_CastObjectArray()
|
521
|
-
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
522
|
-
a = test.getObjectArray()
|
523
|
-
assert_equal(1, a[0].intValue)
|
524
|
-
assert_equal('Hello World !', a[1].toString)
|
525
|
-
a = test.getObjectArrayOfArray()
|
526
|
-
assert_equal(1, a[0][0].intValue)
|
527
|
-
assert_equal('Hello World !', a[0][1].toString)
|
528
|
-
assert_equal(2, a[1][0].intValue)
|
529
|
-
assert_equal('Hello World !!', a[1][1].toString)
|
530
|
-
end
|
531
|
-
|
532
|
-
def test_CallByNullForArrays()
|
533
|
-
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
534
|
-
assert_equal(nil, test.callWithArrays(nil, nil, nil, nil, nil, nil,
|
535
|
-
nil, nil))
|
536
|
-
end
|
537
|
-
|
538
|
-
def test_failed_constructor_call()
|
539
|
-
begin
|
540
|
-
s = @jString.new('a', 'b', 'c')
|
541
|
-
flunk('no exception')
|
542
|
-
rescue RuntimeError => e
|
543
|
-
assert(e)
|
544
|
-
end
|
545
|
-
end
|
546
|
-
|
547
|
-
def test_rubyize
|
548
|
-
loader = Rjb::import('java.lang.ClassLoader')
|
549
|
-
cls = import('java.lang.Class')
|
550
|
-
b = cls.for_name('jp.co.infoseek.hp.arton.rjb.IBase', true, loader.system_class_loader)
|
551
|
-
assert(b.interface?)
|
552
|
-
stringbuffer = Rjb::import('java.lang.StringBuffer')
|
553
|
-
sb = stringbuffer.new('abc')
|
554
|
-
assert_equal(1, sb.index_of('bc'))
|
555
|
-
sb.set_char_at(1, "B".sum)
|
556
|
-
assert_equal('aBc', sb.to_string)
|
557
|
-
sb.length = 2
|
558
|
-
assert_equal('aB', sb.to_string)
|
559
|
-
end
|
560
|
-
|
561
|
-
def test_auto_conv
|
562
|
-
assert_equal(false, Rjb::primitive_conversion)
|
563
|
-
Rjb::primitive_conversion = true
|
564
|
-
assert_equal(true, Rjb::primitive_conversion)
|
565
|
-
assert_equal(1, @jInteger.valueOf('1'))
|
566
|
-
assert_equal(-1, @jInteger.valueOf('-1'))
|
567
|
-
assert_equal(2, @jShort.valueOf('2'))
|
568
|
-
assert_equal(-2, @jShort.valueOf('-2'))
|
569
|
-
assert_equal(3.1, @jDouble.valueOf('3.1'))
|
570
|
-
assert_equal(4.5, @jFloat.valueOf('4.5'))
|
571
|
-
assert(@jBoolean.TRUE)
|
572
|
-
assert_equal(5, @jByte.valueOf('5'))
|
573
|
-
assert_equal(-6, @jByte.valueOf('-6'))
|
574
|
-
assert_equal(0x7000000000000000, @jLong.valueOf('8070450532247928832'))
|
575
|
-
assert_equal(-9223372036854775807, @jLong.valueOf('-9223372036854775807'))
|
576
|
-
assert_equal("A".sum, @jChar.valueOf("A".sum))
|
577
|
-
end
|
578
|
-
|
579
|
-
def test_obj_to_primitive
|
580
|
-
ar = Rjb::import('java.util.ArrayList')
|
581
|
-
a = ar.new
|
582
|
-
a.add @jString.new('abcdef')
|
583
|
-
a.add @jInteger.valueOf('1')
|
584
|
-
a.add @jShort.valueOf('2')
|
585
|
-
a.add @jDouble.valueOf('3.1')
|
586
|
-
a.add @jFloat.valueOf('4.5')
|
587
|
-
a.add @jBoolean.TRUE
|
588
|
-
a.add @jByte.valueOf('5')
|
589
|
-
a.add @jLong.valueOf('8070450532247928832')
|
590
|
-
a.add @jChar.valueOf("A".sum)
|
591
|
-
|
592
|
-
Rjb::primitive_conversion = true
|
593
|
-
|
594
|
-
assert_equal 'abcdef', a.get(0)
|
595
|
-
assert_equal 1, a.get(1)
|
596
|
-
assert_equal 2, a.get(2)
|
597
|
-
assert_equal 3.1, a.get(3)
|
598
|
-
assert_equal 4.5, a.get(4)
|
599
|
-
assert a.get(5)
|
600
|
-
assert_equal 5, a.get(6)
|
601
|
-
assert_equal 8070450532247928832, a.get(7)
|
602
|
-
assert_equal "A".sum, a.get(8)
|
603
|
-
end
|
604
|
-
|
605
|
-
def test_primitive_to_obj
|
606
|
-
Rjb::primitive_conversion = true
|
607
|
-
|
608
|
-
ar = Rjb::import('java.util.ArrayList')
|
609
|
-
a = ar.new
|
610
|
-
a.add @jString.new('abcdef')
|
611
|
-
a.add @jInteger.valueOf('1')
|
612
|
-
a.add @jShort.valueOf('2')
|
613
|
-
a.add @jDouble.valueOf('3.1')
|
614
|
-
a.add @jFloat.valueOf('4.5')
|
615
|
-
a.add @jBoolean.TRUE
|
616
|
-
a.add @jByte.valueOf('5')
|
617
|
-
a.add @jLong.valueOf('8070450532247928832')
|
618
|
-
a.add @jChar.valueOf("A".sum)
|
619
|
-
assert_equal 'abcdef', a.get(0)
|
620
|
-
assert_equal 1, a.get(1)
|
621
|
-
assert_equal 2, a.get(2)
|
622
|
-
assert_equal 3.1, a.get(3)
|
623
|
-
assert_equal 4.5, a.get(4)
|
624
|
-
assert a.get(5)
|
625
|
-
assert_equal 5, a.get(6)
|
626
|
-
assert_equal 8070450532247928832, a.get(7)
|
627
|
-
assert_equal "A".sum, a.get(8)
|
628
|
-
end
|
629
|
-
|
630
|
-
def test_enum
|
631
|
-
t = Rjb::import('jp.co.infoseek.hp.arton.rjb.Test$TestTypes')
|
632
|
-
assert t.ONE.equals(t.values()[0])
|
633
|
-
assert_equal 3, t.values().size
|
634
|
-
assert_equal 2, t.THREE.ordinal
|
635
|
-
assert_equal "TWO", t.TWO.name
|
636
|
-
assert_equal "THREE", t.THREE.toString
|
637
|
-
end
|
638
|
-
|
639
|
-
#rjb-bugs-15430 rebported by Bryan Duxbury
|
640
|
-
def test_generics_map
|
641
|
-
|
642
|
-
ctest = import('jp.co.infoseek.hp.arton.rjb.Test')
|
643
|
-
test = ctest.new
|
644
|
-
map = test.sorted_map
|
645
|
-
assert_equal "\0\x1\x2\x3\x4", map.get('abc')
|
646
|
-
assert_equal "\x5\x6\x7\x8\x9", map.get('def')
|
647
|
-
|
648
|
-
cmap = import('java.util.TreeMap')
|
649
|
-
map = cmap.new
|
650
|
-
map.put('abc', @jString.new('abc').bytes)
|
651
|
-
map.put('012', @jString.new('012').bytes)
|
652
|
-
|
653
|
-
Rjb::primitive_conversion = true
|
654
|
-
map2 = test.throughSortedMap(map)
|
655
|
-
assert_equal '012', map2.get('012')
|
656
|
-
assert_equal 'abc', map2.get('abc')
|
657
|
-
end
|
658
|
-
|
659
|
-
def x_test_zzunload
|
660
|
-
# this test should run at the last
|
661
|
-
unload
|
662
|
-
begin
|
663
|
-
load('.')
|
664
|
-
fail 'no exception'
|
665
|
-
rescue
|
666
|
-
assert_equal "can't create Java VM", $!.message
|
667
|
-
end
|
668
|
-
end
|
669
|
-
|
670
|
-
module TestMixin
|
671
|
-
def test_hello(s)
|
672
|
-
'hello ' + s
|
673
|
-
end
|
674
|
-
end
|
675
|
-
def test_extend
|
676
|
-
@jString.class_eval do
|
677
|
-
include TestRjb::TestMixin
|
678
|
-
end
|
679
|
-
s = @jString.new
|
680
|
-
assert_equal('hello world', s.test_hello('world'))
|
681
|
-
end
|
682
|
-
def test_extend_with_factory
|
683
|
-
point = import('java.awt.Point')
|
684
|
-
point.class_eval do
|
685
|
-
include TestRjb::TestMixin
|
686
|
-
end
|
687
|
-
p = point.new(11, 12)
|
688
|
-
assert_equal(11, p.x)
|
689
|
-
assert_equal(12, p.y)
|
690
|
-
assert_equal('hello world', p.test_hello('world'))
|
691
|
-
p = p.location
|
692
|
-
assert_equal(11, p.x)
|
693
|
-
assert_equal(12, p.y)
|
694
|
-
assert_equal('hello world', p.test_hello('world'))
|
695
|
-
end
|
696
|
-
def test_fetch_method_signature
|
697
|
-
expected = ['I', 'II', 'Ljava.lang.String;', 'Ljava.lang.String;I']
|
698
|
-
sig = @jString.sigs('indexOf').sort
|
699
|
-
assert_equal(expected, sig)
|
700
|
-
end
|
701
|
-
def test_fetch_method_without_signature
|
702
|
-
sig =
|
703
|
-
assert_equal([nil], @jString.sigs('toString'))
|
704
|
-
end
|
705
|
-
def test_fetch_static_method_signature
|
706
|
-
expected = ['Ljava.lang.String;[Ljava.lang.Object;',
|
707
|
-
'Ljava.util.Locale;Ljava.lang.String;[Ljava.lang.Object;']
|
708
|
-
sig = @jString.static_sigs('format').sort
|
709
|
-
assert_equal(expected, sig)
|
710
|
-
end
|
711
|
-
def test_fetch_ctor_signature
|
712
|
-
expected = ['I', 'Ljava.lang.String;']
|
713
|
-
sig = @jInteger.ctor_sigs.sort
|
714
|
-
assert_equal(expected, sig)
|
715
|
-
end
|
716
|
-
def test_methods_extension
|
717
|
-
m = @jString.new('').methods
|
718
|
-
assert m.include?('indexOf')
|
719
|
-
end
|
720
|
-
def test_class_methods_extension
|
721
|
-
m = @jString.methods
|
722
|
-
assert m.include?('format')
|
723
|
-
end
|
724
|
-
def test_pmethods_extension
|
725
|
-
m = @jString.new('').public_methods
|
726
|
-
assert m.include?('indexOf')
|
727
|
-
end
|
728
|
-
def test_class_pmethods_extension
|
729
|
-
m = @jString.public_methods
|
730
|
-
assert m.include?('format')
|
731
|
-
end
|
732
|
-
def test_java_methods
|
733
|
-
indexof = @jString.new('').java_methods.find do |m|
|
734
|
-
m =~ /^indexOf/
|
735
|
-
end
|
736
|
-
args = indexof.match(/\[([^\]]+)\]/)[1]
|
737
|
-
assert_equal('Ljava.lang.String;I, II, I, Ljava.lang.String;'.split(/,\s*/).sort,
|
738
|
-
args.split(/,\s*/).sort)
|
739
|
-
end
|
740
|
-
def test_java_class_methods
|
741
|
-
format = @jString.java_methods.find do |m|
|
742
|
-
m =~ /^format/
|
743
|
-
end
|
744
|
-
args = format.match(/\[([^\]]+)\]/)[1]
|
745
|
-
assert_equal('Ljava.lang.String;[Ljava.lang.Object;, Ljava.util.Locale;Ljava.lang.String;[Ljava.lang.Object;'.split(/,\s*/).sort, args.split(/,\s*/).sort)
|
746
|
-
end
|
747
|
-
def test_64fixnum
|
748
|
-
big = @jLong.new_with_sig('J', 1230918239495)
|
749
|
-
assert_equal 1230918239495, big.long_value
|
750
|
-
end
|
751
|
-
def test_add_jar
|
752
|
-
add_jar(File.expand_path('./jartest.jar'))
|
753
|
-
jt = import('jp.co.infoseek.hp.arton.rjb.JarTest')
|
754
|
-
assert jt
|
755
|
-
assert_equal 'abcd', jt.new.add('ab', 'cd')
|
756
|
-
end
|
757
|
-
def test_add_jars
|
758
|
-
arg = ['./jartest.jar', './jartest.jar'].map do |e|
|
759
|
-
File.expand_path(e)
|
760
|
-
end
|
761
|
-
add_jar(arg)
|
762
|
-
jt = import('jp.co.infoseek.hp.arton.rjb.JarTest')
|
763
|
-
assert_equal 'abcd', jt.new.add('ab', 'cd')
|
764
|
-
end
|
765
|
-
def test_bothdirection_buffer
|
766
|
-
org = "abcdefghijklmn"
|
767
|
-
baip = import('java.io.ByteArrayInputStream')
|
768
|
-
ba = baip.new(org)
|
769
|
-
buff = "\0" * org.size
|
770
|
-
assert_equal org.size, ba.read(buff)
|
771
|
-
assert_equal -1, ba.read(buff)
|
772
|
-
ba.close
|
773
|
-
assert_equal org, buff
|
774
|
-
end
|
775
|
-
def test_anoninterface
|
776
|
-
arrays = import('java.util.Arrays')
|
777
|
-
a = [3, -4, 5, -6, 8, -10, -14]
|
778
|
-
index = arrays.binary_search(a, 6) do |m, o1, o2|
|
779
|
-
o1.abs - o2.abs
|
780
|
-
end
|
781
|
-
assert_equal 3, index
|
782
|
-
index = arrays.binary_search(a, 7) do |m, o1, o2|
|
783
|
-
o1.abs - o2.abs
|
784
|
-
end
|
785
|
-
assert_equal -5, index
|
786
|
-
end
|
787
|
-
def test_impl
|
788
|
-
two = import('Two')
|
789
|
-
t = two.impl { |m| m.to_s }
|
790
|
-
a = import('TwoCaller').new
|
791
|
-
ret = a.foo(t)
|
792
|
-
assert_equal 'method1', ret[0]
|
793
|
-
assert_equal 'method2', ret[1]
|
794
|
-
end
|
795
|
-
|
796
|
-
def cause_exception
|
797
|
-
begin
|
798
|
-
@jInteger.parseInt('blabla')
|
799
|
-
rescue NumberFormatException => e
|
800
|
-
raise
|
801
|
-
end
|
802
|
-
end
|
803
|
-
|
804
|
-
def test_reraise_exception()
|
805
|
-
unless /^1\.8/ =~ RUBY_VERSION
|
806
|
-
begin
|
807
|
-
cause_exception
|
808
|
-
rescue
|
809
|
-
assert($!.to_s =~ /NumberFormatException/)
|
810
|
-
end
|
811
|
-
end
|
812
|
-
end
|
813
|
-
|
814
|
-
class CbTest
|
815
|
-
def method(l, s, i, d, str)
|
816
|
-
"test_ok:#{l}-#{s}-#{i}-#{d}-#{str}"
|
817
|
-
end
|
818
|
-
end
|
819
|
-
def test_longcallback()
|
820
|
-
cb = bind(CbTest.new, 'jp.co.infoseek.hp.arton.rjb.CallbackTest$Callback')
|
821
|
-
test = import('jp.co.infoseek.hp.arton.rjb.CallbackTest')
|
822
|
-
assert_equal 'test_ok:1234-1234-1234-1234.5-1234', test.callCallback(cb)
|
823
|
-
end
|
824
|
-
|
825
|
-
class TestIterEx < TestIter
|
826
|
-
def initialize()
|
827
|
-
super
|
828
|
-
@strattr = 'strattr'
|
829
|
-
@numattr = 32
|
830
|
-
end
|
831
|
-
attr_accessor :strattr, :numattr
|
832
|
-
def multargs(a, b)
|
833
|
-
a + b
|
834
|
-
end
|
835
|
-
end
|
836
|
-
def test_method_otherthan_bound()
|
837
|
-
it = TestIterEx.new
|
838
|
-
it = bind(it, 'java.util.Iterator')
|
839
|
-
test = import('jp.co.infoseek.hp.arton.rjb.Test')
|
840
|
-
a = test.new
|
841
|
-
assert_equal("43210", a.concat(it))
|
842
|
-
assert(it.respond_to?(:numattr))
|
843
|
-
assert(it.respond_to?(:multargs))
|
844
|
-
assert_equal(32, it.numattr)
|
845
|
-
assert_equal('strattr', it.strattr)
|
846
|
-
it.numattr += 1
|
847
|
-
assert_equal(33, it.numattr)
|
848
|
-
assert_equal(5, it.multargs(3, 2))
|
849
|
-
end
|
850
|
-
def test_noarg_invoke()
|
851
|
-
str = @jString.new('abc')
|
852
|
-
assert_equal('abc', str._invoke('toString', ''))
|
853
|
-
assert_equal('abc', str._invoke('toString', nil))
|
854
|
-
assert_equal('abc', str._invoke('toString'))
|
855
|
-
end
|
856
|
-
def test_noarg_sinvoke()
|
857
|
-
sys = import('java.lang.System')
|
858
|
-
cons = sys.console
|
859
|
-
assert_equal(cons._classname, sys._invoke('console', '')._classname)
|
860
|
-
assert_equal(cons._classname, sys._invoke('console', nil)._classname)
|
861
|
-
assert_equal(cons._classname, sys._invoke('console')._classname)
|
862
|
-
end
|
863
|
-
def test_longarg
|
864
|
-
assert_equal(597899502607411822, @jLong.reverse(0x7654321076543210))
|
865
|
-
begin
|
866
|
-
@jLong.reverse(0x76543210765432101)
|
867
|
-
fail 'no exception for gibnum it doesn\'t convert Java long'
|
868
|
-
rescue RangeError
|
869
|
-
assert true
|
870
|
-
end
|
871
|
-
end
|
872
|
-
end
|
873
|
-
|
1
|
+
#!/usr/local/env ruby -Ku
|
2
|
+
# encoding: utf-8
|
3
|
+
# $Id: test.rb 199 2012-12-17 13:31:18Z arton $
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'rjb'
|
7
|
+
rescue LoadError
|
8
|
+
require 'rubygems'
|
9
|
+
require 'rjb'
|
10
|
+
end
|
11
|
+
require 'test/unit'
|
12
|
+
require 'fileutils'
|
13
|
+
|
14
|
+
FileUtils.rm_f 'jp/co/infoseek/hp/arton/rjb/Base.class'
|
15
|
+
FileUtils.rm_f 'jp/co/infoseek/hp/arton/rjb/ExtBase.class'
|
16
|
+
|
17
|
+
puts "start RJB(#{Rjb::VERSION}) test"
|
18
|
+
class TestRjb < Test::Unit::TestCase
|
19
|
+
include Rjb
|
20
|
+
def setup
|
21
|
+
Rjb::load('.')
|
22
|
+
Rjb::add_jar(File.expand_path('rjbtest.jar'))
|
23
|
+
Rjb::primitive_conversion = false
|
24
|
+
|
25
|
+
@jString = import('java.lang.String')
|
26
|
+
@jInteger = import('java.lang.Integer')
|
27
|
+
@jShort = import('java.lang.Short')
|
28
|
+
@jDouble = import('java.lang.Double')
|
29
|
+
@jFloat = import('java.lang.Float')
|
30
|
+
@jBoolean = import('java.lang.Boolean')
|
31
|
+
@jByte = import('java.lang.Byte')
|
32
|
+
@jLong = import('java.lang.Long')
|
33
|
+
@jChar = import('java.lang.Character')
|
34
|
+
end
|
35
|
+
|
36
|
+
def teardown
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_metaclass
|
40
|
+
cls = import('java.lang.Class')
|
41
|
+
assert_equal('java.lang.Class', cls._classname)
|
42
|
+
assert_equal('java.lang.Class', cls.getName)
|
43
|
+
assert_equal(17, cls.getModifiers)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_scalar
|
47
|
+
assert_equal('java.lang.Class', @jString._classname)
|
48
|
+
assert_equal('class java.lang.String', @jString.toString)
|
49
|
+
str = @jString.new
|
50
|
+
assert_equal('java.lang.String', str._classname)
|
51
|
+
assert_equal(0, str.length)
|
52
|
+
assert_equal('', str.toString)
|
53
|
+
str = @jString.new_with_sig('Ljava.lang.String;', "abcde")
|
54
|
+
# result integer
|
55
|
+
assert_equal(5, str.length)
|
56
|
+
# result string
|
57
|
+
assert_equal('abcde', str.toString)
|
58
|
+
# argument test
|
59
|
+
# char
|
60
|
+
assert_equal('abxde', str.replace("c".sum, "x".sum))
|
61
|
+
# string
|
62
|
+
assert_equal('abdxe', str.replaceAll('cd', 'dx'))
|
63
|
+
# int
|
64
|
+
assert_equal('bc', str.substring(1, 3))
|
65
|
+
assert_equal('e', str.substring(4))
|
66
|
+
# float with static
|
67
|
+
assert_equal('5.23', @jString._invoke('valueOf', 'F', 5.23))
|
68
|
+
assert_equal('25.233', @jString._invoke('valueOf', 'D', 25.233))
|
69
|
+
# rjb object (String)
|
70
|
+
str2 = @jString.new_with_sig('Ljava.lang.String;', 'fghijk')
|
71
|
+
assert_equal('abcdefghijk', str.concat(str2))
|
72
|
+
# rjb object other (implicit toString call is Rjb feature)
|
73
|
+
i = @jInteger.new_with_sig('I', 35901)
|
74
|
+
assert_equal('abcde35901', str.concat(i))
|
75
|
+
# result boolean and argument is rjb object
|
76
|
+
assert_equal(false, i.equals(str))
|
77
|
+
assert_equal(false, str.equals(i))
|
78
|
+
assert_equal(true, str.equals("abcde"))
|
79
|
+
assert_equal(true, str.equals(str))
|
80
|
+
# long
|
81
|
+
l = @jLong.new_with_sig('J', -9223372036854775808)
|
82
|
+
assert_equal(-9223372036854775808, l.longValue)
|
83
|
+
l = @jLong.new_with_sig('J', 9223372036854775807)
|
84
|
+
assert_equal(9223372036854775807, l.longValue)
|
85
|
+
# double
|
86
|
+
d = @jDouble.new_with_sig('D', 1234.5678901234567890)
|
87
|
+
assert_equal(1234.5678901234567890, d.doubleValue)
|
88
|
+
# byte
|
89
|
+
b = @jByte.new_with_sig('B', 13)
|
90
|
+
assert_equal(13, b.byteValue)
|
91
|
+
# float
|
92
|
+
f = @jFloat.new_with_sig('F', 13.5)
|
93
|
+
assert_equal(13.5, f.floatValue)
|
94
|
+
# short
|
95
|
+
s = @jShort.new_with_sig('S', 1532)
|
96
|
+
assert_equal(1532, s.shortValue)
|
97
|
+
c = @jChar.new_with_sig('C', "A".sum)
|
98
|
+
assert_equal("A".sum, c.charValue)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_array
|
102
|
+
str = @jString.new_with_sig('[C', ["a".sum, "b".sum, "c".sum, "d".sum, "e".sum, "c".sum, "f".sum, "c".sum, "g".sum])
|
103
|
+
assert_equal('abcdecfcg', str.toString)
|
104
|
+
# conv string array
|
105
|
+
splt = str.split('c')
|
106
|
+
assert(Array === splt)
|
107
|
+
assert_equal(4, splt.size)
|
108
|
+
assert_equal('ab', splt[0])
|
109
|
+
assert_equal('g', splt[3])
|
110
|
+
# conv byte array to (ruby)string
|
111
|
+
ba = str.getBytes
|
112
|
+
assert_equal('abcdecfcg', ba)
|
113
|
+
# conv char array to array(int)
|
114
|
+
ca = str.toCharArray
|
115
|
+
assert_equal(["a".sum, "b".sum, "c".sum, "d".sum, "e".sum, "c".sum, "f".sum, "c".sum, "g".sum], ca)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_importobj()
|
119
|
+
sys = import('java.lang.System')
|
120
|
+
props = sys.getProperties
|
121
|
+
assert_equal('java.util.Properties', props._classname)
|
122
|
+
if /cygwin/ =~ RUBY_PLATFORM # patch for dirty environment
|
123
|
+
assert_equal(Dir::pwd, %x[cygpath -u #{props.getProperty('user.dir').gsub('\\', '/')}].chop)
|
124
|
+
else
|
125
|
+
assert_equal(Dir::pwd, props.getProperty('user.dir').gsub('\\', '/'))
|
126
|
+
end
|
127
|
+
assert_equal(@jBoolean.valueOf(true).booleanValue(), true)
|
128
|
+
assert_equal(@jBoolean.valueOf(false).booleanValue(), false)
|
129
|
+
assert_equal(@jBoolean.valueOf('true').booleanValue(), true)
|
130
|
+
assert_equal(@jBoolean.valueOf('false').booleanValue(), false)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_importobjarray()
|
134
|
+
jarray = import('java.util.ArrayList')
|
135
|
+
a = jarray.new()
|
136
|
+
a.add(@jInteger.new_with_sig('I', 1))
|
137
|
+
a.add(@jInteger.new_with_sig('I', 2))
|
138
|
+
a.add(@jInteger.new_with_sig('I', 3))
|
139
|
+
oa = a.toArray
|
140
|
+
assert_equal(3, oa.size)
|
141
|
+
assert_equal(1, oa[0].intValue)
|
142
|
+
assert_equal(2, oa[1].intValue)
|
143
|
+
assert_equal(3, oa[2].intValue)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_kjconv()
|
147
|
+
if Object::const_defined?(:Encoding)
|
148
|
+
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
149
|
+
euc_kj = "\xb4\xc1\xbb\xfa\xa5\xc6\xa5\xad\xa5\xb9\xa5\xc8".force_encoding Encoding::EUC_JP
|
150
|
+
s = @jString.new(euc_kj)
|
151
|
+
assert_equal(s.toString().encoding, Encoding::UTF_8)
|
152
|
+
assert(test.isSameString(s))
|
153
|
+
assert(test.isSameString(euc_kj))
|
154
|
+
assert_equal(s.toString().encode(Encoding::EUC_JP), euc_kj)
|
155
|
+
sjis_kj = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67".force_encoding Encoding::SHIFT_JIS
|
156
|
+
s = @jString.new(sjis_kj)
|
157
|
+
assert_equal(s.toString().encoding, Encoding::UTF_8)
|
158
|
+
assert(test.isSameString(s))
|
159
|
+
assert(test.isSameString(sjis_kj))
|
160
|
+
assert_equal(s.toString().encode(Encoding::SHIFT_JIS), sjis_kj)
|
161
|
+
utf8_kj = "\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88".force_encoding Encoding::UTF_8
|
162
|
+
s = @jString.new(utf8_kj)
|
163
|
+
assert_equal(s.toString().encoding, Encoding::UTF_8)
|
164
|
+
assert(test.isSameString(s))
|
165
|
+
assert(test.isSameString(utf8_kj))
|
166
|
+
assert_equal(s.toString().encode(Encoding::UTF_8), utf8_kj)
|
167
|
+
iso2022jp_kj = "\x1b\x24\x42\x34\x41\x3b\x7a\x25\x46\x25\x2d\x25\x39\x25\x48\x1b\x28\x42".force_encoding Encoding::ISO_2022_JP
|
168
|
+
s = @jString.new(iso2022jp_kj)
|
169
|
+
assert_equal(s.toString().encoding, Encoding::UTF_8)
|
170
|
+
assert(test.isSameString(s))
|
171
|
+
assert(test.isSameString(iso2022jp_kj))
|
172
|
+
assert_equal(s.toString().encode(Encoding::ISO_2022_JP), iso2022jp_kj)
|
173
|
+
assert_equal(@jString.new("abcdef".force_encoding(Encoding::ASCII_8BIT)).toString(), "abcdef")
|
174
|
+
assert_equal(@jString.new("abcdef".force_encoding(Encoding::find("us-ascii"))).toString(), "abcdef")
|
175
|
+
else
|
176
|
+
default_kcode = $KCODE
|
177
|
+
begin
|
178
|
+
$KCODE = 'euc'
|
179
|
+
euc_kj = "\xb4\xc1\xbb\xfa\xa5\xc6\xa5\xad\xa5\xb9\xa5\xc8"
|
180
|
+
s = @jString.new(euc_kj)
|
181
|
+
assert_equal(s.toString(), euc_kj)
|
182
|
+
$KCODE = 'sjis'
|
183
|
+
sjis_kj = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67"
|
184
|
+
s = @jString.new(sjis_kj)
|
185
|
+
assert_equal(s.toString(), sjis_kj)
|
186
|
+
$KCODE = 'utf8'
|
187
|
+
utf8_kj = "\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88"
|
188
|
+
s = @jString.new(utf8_kj)
|
189
|
+
assert_equal(s.toString(), utf8_kj)
|
190
|
+
$KCODE = 'none'
|
191
|
+
if /mswin(?!ce)|mingw|cygwin|bccwin/ =~ RUBY_PLATFORM
|
192
|
+
#expecting shift_jis on windows
|
193
|
+
none_kj = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67"
|
194
|
+
else
|
195
|
+
#expecting utf-8 unless windows
|
196
|
+
none_kj = "\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88"
|
197
|
+
end
|
198
|
+
s = @jString.new(none_kj)
|
199
|
+
assert_equal(s.toString(), none_kj)
|
200
|
+
$KCODE = 'utf8'
|
201
|
+
utf8_kj = "\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88"
|
202
|
+
s = @jString.new(utf8_kj)
|
203
|
+
assert_equal(s.toString(), utf8_kj)
|
204
|
+
$KCODE = 'sjis'
|
205
|
+
sjis_kj = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67"
|
206
|
+
s = @jString.new(sjis_kj)
|
207
|
+
assert_equal(s.toString(), sjis_kj)
|
208
|
+
$KCODE = 'euc'
|
209
|
+
euc_kj = "\xb4\xc1\xbb\xfa\xa5\xc6\xa5\xad\xa5\xb9\xa5\xc8"
|
210
|
+
s = @jString.new(euc_kj)
|
211
|
+
assert_equal(s.toString(), euc_kj)
|
212
|
+
ensure
|
213
|
+
$KCODE = default_kcode
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_combination_charcters
|
219
|
+
teststr = "\xc7\x96\xc3\xbc\xcc\x84\x75\xcc\x88\xcc\x84\xed\xa1\xa9\xed\xba\xb2\xe3\x81\x8b\xe3\x82\x9a"
|
220
|
+
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
221
|
+
s = test.getUmlaut()
|
222
|
+
if Object::const_defined?(:Encoding) #>=1.9
|
223
|
+
teststr = teststr.force_encoding(Encoding::UTF_8)
|
224
|
+
assert_equal(s, teststr)
|
225
|
+
else
|
226
|
+
default_kcode = $KCODE
|
227
|
+
begin
|
228
|
+
$KCODE = "utf8"
|
229
|
+
assert_equal(s, teststr)
|
230
|
+
ensure
|
231
|
+
$KCODE = default_kcode
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_constants()
|
237
|
+
assert_equal(0x7fffffffffffffff, @jLong.MAX_VALUE)
|
238
|
+
assert_equal(-9223372036854775808, @jLong.MIN_VALUE)
|
239
|
+
end
|
240
|
+
|
241
|
+
class TestIter
|
242
|
+
def initialize()
|
243
|
+
@i = 5
|
244
|
+
end
|
245
|
+
def hasNext()
|
246
|
+
@i > 0
|
247
|
+
end
|
248
|
+
def next()
|
249
|
+
@i -= 1
|
250
|
+
@i.to_s
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_newobject()
|
255
|
+
it = TestIter.new
|
256
|
+
it = bind(it, 'java.util.Iterator')
|
257
|
+
test = import('jp.co.infoseek.hp.arton.rjb.Test')
|
258
|
+
a = test.new
|
259
|
+
assert_equal("43210", a.concat(it))
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_unbind()
|
263
|
+
it = TestIter.new
|
264
|
+
it = bind(it, 'java.util.Iterator')
|
265
|
+
assert_equal(it, unbind(it))
|
266
|
+
end
|
267
|
+
|
268
|
+
class TestComparator
|
269
|
+
def compare(o1, o2)
|
270
|
+
o1.to_i - o2.to_i
|
271
|
+
end
|
272
|
+
def equals(o)
|
273
|
+
o == self
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
def test_comparator
|
278
|
+
cp = TestComparator.new
|
279
|
+
cp = bind(cp, 'java.util.Comparator')
|
280
|
+
test = import('jp.co.infoseek.hp.arton.rjb.Test')
|
281
|
+
a = test.new
|
282
|
+
assert_equal(0, a.check(cp, 123, 123))
|
283
|
+
assert_equal(5, a.check(cp, 81, 76))
|
284
|
+
assert_equal(-5, a.check(cp, 76, 81))
|
285
|
+
end
|
286
|
+
|
287
|
+
# assert_raise is useless in this test, because NumberFormatException may be defined in
|
288
|
+
# its block.
|
289
|
+
def test_exception()
|
290
|
+
begin
|
291
|
+
@jInteger.parseInt('blabla')
|
292
|
+
flunk('no exception')
|
293
|
+
rescue NumberFormatException => e
|
294
|
+
assert_nil(e.cause)
|
295
|
+
# OK
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
class TestIterator
|
300
|
+
def initialize(tp)
|
301
|
+
@type = tp
|
302
|
+
end
|
303
|
+
def hasNext()
|
304
|
+
true
|
305
|
+
end
|
306
|
+
def next()
|
307
|
+
if @type == 0
|
308
|
+
Rjb::throw('java.util.NoSuchElementException', 'test exception')
|
309
|
+
elsif @type == 1
|
310
|
+
Rjb::throw(Rjb::import('java.util.NoSuchElementException').new('instance test'))
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_throw()
|
316
|
+
it = TestIterator.new(0)
|
317
|
+
it = bind(it, 'java.util.Iterator')
|
318
|
+
test = import('jp.co.infoseek.hp.arton.rjb.Test')
|
319
|
+
a = test.new
|
320
|
+
begin
|
321
|
+
a.concat(it)
|
322
|
+
flunk('no exception')
|
323
|
+
rescue NoSuchElementException => e
|
324
|
+
assert_equal('test exception', e.message)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
def test_instance_throw()
|
329
|
+
it = TestIterator.new(1)
|
330
|
+
it = bind(it, 'java.util.Iterator')
|
331
|
+
test = import('jp.co.infoseek.hp.arton.rjb.Test')
|
332
|
+
a = test.new
|
333
|
+
begin
|
334
|
+
a.concat(it)
|
335
|
+
flunk('no exception')
|
336
|
+
rescue NoSuchElementException => e
|
337
|
+
assert_equal('instance test', e.message)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_null_string()
|
342
|
+
sys = import('java.lang.System')
|
343
|
+
begin
|
344
|
+
sys.getProperty(nil)
|
345
|
+
flunk('no exception')
|
346
|
+
rescue NullPointerException => e
|
347
|
+
assert(true)
|
348
|
+
rescue RuntimeError => e
|
349
|
+
flunk(e.message)
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
def test_throw_error()
|
354
|
+
begin
|
355
|
+
throw(self)
|
356
|
+
flunk('no exception')
|
357
|
+
rescue TypeError => e
|
358
|
+
end
|
359
|
+
begin
|
360
|
+
throw(@jString.new('a'))
|
361
|
+
flunk('no exception')
|
362
|
+
rescue RuntimeError => e
|
363
|
+
assert_equal('arg1 must be a throwable', e.message)
|
364
|
+
end
|
365
|
+
begin
|
366
|
+
throw('java.lang.NoSuchException', 'test')
|
367
|
+
flunk('no excpetion')
|
368
|
+
rescue RuntimeError => e
|
369
|
+
assert_equal("`java.lang.NoSuchException' not found", e.message)
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
def test_throw_clear()
|
374
|
+
assert_nothing_raised {
|
375
|
+
begin
|
376
|
+
Rjb::throw('java.util.NoSuchElementException', 'test exception')
|
377
|
+
rescue #drop ruby exception
|
378
|
+
end
|
379
|
+
test = import('jp.co.infoseek.hp.arton.rjb.Test')
|
380
|
+
begin
|
381
|
+
Rjb::throw('java.util.NoSuchElementException', 'test exception')
|
382
|
+
rescue #drop ruby exception
|
383
|
+
end
|
384
|
+
test.new
|
385
|
+
begin
|
386
|
+
Rjb::throw('java.util.NoSuchElementException', 'test exception')
|
387
|
+
rescue #drop ruby exception
|
388
|
+
end
|
389
|
+
@jString.new_with_sig('Ljava.lang.String;', "abcde")
|
390
|
+
begin
|
391
|
+
Rjb::throw('java.util.NoSuchElementException', 'test exception')
|
392
|
+
rescue #drop ruby exception
|
393
|
+
end
|
394
|
+
it = TestIterator.new(0)
|
395
|
+
it = bind(it, 'java.util.Iterator')
|
396
|
+
begin
|
397
|
+
Rjb::throw('java.util.NoSuchElementException', 'test exception')
|
398
|
+
rescue NoSuchElementException
|
399
|
+
end
|
400
|
+
begin
|
401
|
+
Rjb::throw('java.lang.IllegalAccessException', 'test exception')
|
402
|
+
rescue IllegalAccessException
|
403
|
+
end
|
404
|
+
unbind(it)
|
405
|
+
}
|
406
|
+
end
|
407
|
+
|
408
|
+
def test_field()
|
409
|
+
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
410
|
+
assert_equal('Hello World !!', test.helloData)
|
411
|
+
test.helloData = 'Goodby World !'
|
412
|
+
assert_equal('Goodby World !', test.helloData)
|
413
|
+
end
|
414
|
+
|
415
|
+
def test_instancemethod_from_class()
|
416
|
+
begin
|
417
|
+
assert_equal('true', @jString.valueOf(true))
|
418
|
+
@jString.length
|
419
|
+
flunk('no exception')
|
420
|
+
rescue RuntimeError => e
|
421
|
+
assert_equal('instance method `length\' for class', e.message)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
def test_instancefield_from_class()
|
426
|
+
point = import('java.awt.Point')
|
427
|
+
begin
|
428
|
+
point.x
|
429
|
+
flunk('no exception')
|
430
|
+
rescue RuntimeError => e
|
431
|
+
assert_equal('instance field `x\' for class', e.message)
|
432
|
+
end
|
433
|
+
begin
|
434
|
+
point.x = 30
|
435
|
+
rescue RuntimeError => e
|
436
|
+
assert_equal('instance field `x\' for class', e.message)
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
def test_static_derived_method()
|
441
|
+
ext = import('jp.co.infoseek.hp.arton.rjb.ExtBase')
|
442
|
+
assert_equal("sVal", ext.getSVal)
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_capitalized_method()
|
446
|
+
bs = import('jp.co.infoseek.hp.arton.rjb.Base')
|
447
|
+
assert_equal("val", bs.val)
|
448
|
+
assert_equal("Val", bs.Val)
|
449
|
+
end
|
450
|
+
|
451
|
+
def test_underscored_constant()
|
452
|
+
bs = import('jp.co.infoseek.hp.arton.rjb.Base')
|
453
|
+
assert_equal(5, bs._NUMBER_FIVE)
|
454
|
+
end
|
455
|
+
|
456
|
+
def test_passingclass()
|
457
|
+
ibs = import('jp.co.infoseek.hp.arton.rjb.IBase')
|
458
|
+
bs = import('jp.co.infoseek.hp.arton.rjb.Base')
|
459
|
+
assert_equal('interface jp.co.infoseek.hp.arton.rjb.IBase', bs.intf(ibs))
|
460
|
+
end
|
461
|
+
|
462
|
+
def test_fornamehook()
|
463
|
+
# j2se class
|
464
|
+
cls = import('java.lang.Class')
|
465
|
+
c = cls.forName('java.lang.Class')
|
466
|
+
assert_equal(cls, c)
|
467
|
+
# user class
|
468
|
+
bs = import('jp.co.infoseek.hp.arton.rjb.Base')
|
469
|
+
b = cls.forName('jp.co.infoseek.hp.arton.rjb.Base')
|
470
|
+
assert_equal(bs, b)
|
471
|
+
# check class that was loaded from classpath
|
472
|
+
loader = Rjb::import('java.lang.ClassLoader')
|
473
|
+
b = cls.forName('jp.co.infoseek.hp.arton.rjb.IBase', true, loader.getSystemClassLoader)
|
474
|
+
assert(b.isInterface)
|
475
|
+
end
|
476
|
+
|
477
|
+
def test_send_array_of_arrays()
|
478
|
+
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
479
|
+
a = test.joinStringArray([['ab', 'cd'], ['ef', 'gh']])
|
480
|
+
assert_equal(['ab', 'cd', 'ef', 'gh'], a)
|
481
|
+
a = test.joinIntArray([[1, 2, 3], [4, 5, 6]])
|
482
|
+
a.collect! {|e| e.intValue }
|
483
|
+
assert_equal([1, 2, 3, 4, 5, 6], a)
|
484
|
+
r = [[[ 1, 2], [2, 3] ], [[ 3, 4], [5, 6]], [[7, 8], [1, 3]]]
|
485
|
+
a = test.throughIntArray(r)
|
486
|
+
assert_equal(a, r)
|
487
|
+
end
|
488
|
+
|
489
|
+
def test_import_and_instanciate()
|
490
|
+
b = import('jp.co.infoseek.hp.arton.rjb.Base')
|
491
|
+
assert_equal('hello', b.new.getInstanceVar())
|
492
|
+
end
|
493
|
+
|
494
|
+
def test_array_of_arrays()
|
495
|
+
jversion = import('java.lang.System').getProperty('java.version')
|
496
|
+
if /^1\.5/ =~ jversion
|
497
|
+
method = import('java.lang.reflect.Method')
|
498
|
+
end
|
499
|
+
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
500
|
+
a = test.getStringArrayOfArrays()
|
501
|
+
assert_equal("abc", a[0][0])
|
502
|
+
assert_equal("def", a[0][1])
|
503
|
+
assert_equal("123", a[1][0])
|
504
|
+
assert_equal("456", a[1][1])
|
505
|
+
|
506
|
+
ints = test.getIntArrayOfArrays()
|
507
|
+
assert_equal(2, ints.size )
|
508
|
+
assert_equal([1,2,3], ints[0] )
|
509
|
+
assert_equal([[1,2,3],[4,5,6]], ints )
|
510
|
+
|
511
|
+
sized = test.getSizedArray()
|
512
|
+
assert_equal("find me",sized[0][1][2][3])
|
513
|
+
|
514
|
+
mixed = test.getMixedArray()
|
515
|
+
assert_equal(12,mixed[0][0][0].intValue)
|
516
|
+
assert_equal("another string",mixed[1][0][1].toString)
|
517
|
+
assert_equal([],mixed[2])
|
518
|
+
end
|
519
|
+
|
520
|
+
def test_CastObjectArray()
|
521
|
+
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
522
|
+
a = test.getObjectArray()
|
523
|
+
assert_equal(1, a[0].intValue)
|
524
|
+
assert_equal('Hello World !', a[1].toString)
|
525
|
+
a = test.getObjectArrayOfArray()
|
526
|
+
assert_equal(1, a[0][0].intValue)
|
527
|
+
assert_equal('Hello World !', a[0][1].toString)
|
528
|
+
assert_equal(2, a[1][0].intValue)
|
529
|
+
assert_equal('Hello World !!', a[1][1].toString)
|
530
|
+
end
|
531
|
+
|
532
|
+
def test_CallByNullForArrays()
|
533
|
+
test = import('jp.co.infoseek.hp.arton.rjb.Test').new
|
534
|
+
assert_equal(nil, test.callWithArrays(nil, nil, nil, nil, nil, nil,
|
535
|
+
nil, nil))
|
536
|
+
end
|
537
|
+
|
538
|
+
def test_failed_constructor_call()
|
539
|
+
begin
|
540
|
+
s = @jString.new('a', 'b', 'c')
|
541
|
+
flunk('no exception')
|
542
|
+
rescue RuntimeError => e
|
543
|
+
assert(e)
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
def test_rubyize
|
548
|
+
loader = Rjb::import('java.lang.ClassLoader')
|
549
|
+
cls = import('java.lang.Class')
|
550
|
+
b = cls.for_name('jp.co.infoseek.hp.arton.rjb.IBase', true, loader.system_class_loader)
|
551
|
+
assert(b.interface?)
|
552
|
+
stringbuffer = Rjb::import('java.lang.StringBuffer')
|
553
|
+
sb = stringbuffer.new('abc')
|
554
|
+
assert_equal(1, sb.index_of('bc'))
|
555
|
+
sb.set_char_at(1, "B".sum)
|
556
|
+
assert_equal('aBc', sb.to_string)
|
557
|
+
sb.length = 2
|
558
|
+
assert_equal('aB', sb.to_string)
|
559
|
+
end
|
560
|
+
|
561
|
+
def test_auto_conv
|
562
|
+
assert_equal(false, Rjb::primitive_conversion)
|
563
|
+
Rjb::primitive_conversion = true
|
564
|
+
assert_equal(true, Rjb::primitive_conversion)
|
565
|
+
assert_equal(1, @jInteger.valueOf('1'))
|
566
|
+
assert_equal(-1, @jInteger.valueOf('-1'))
|
567
|
+
assert_equal(2, @jShort.valueOf('2'))
|
568
|
+
assert_equal(-2, @jShort.valueOf('-2'))
|
569
|
+
assert_equal(3.1, @jDouble.valueOf('3.1'))
|
570
|
+
assert_equal(4.5, @jFloat.valueOf('4.5'))
|
571
|
+
assert(@jBoolean.TRUE)
|
572
|
+
assert_equal(5, @jByte.valueOf('5'))
|
573
|
+
assert_equal(-6, @jByte.valueOf('-6'))
|
574
|
+
assert_equal(0x7000000000000000, @jLong.valueOf('8070450532247928832'))
|
575
|
+
assert_equal(-9223372036854775807, @jLong.valueOf('-9223372036854775807'))
|
576
|
+
assert_equal("A".sum, @jChar.valueOf("A".sum))
|
577
|
+
end
|
578
|
+
|
579
|
+
def test_obj_to_primitive
|
580
|
+
ar = Rjb::import('java.util.ArrayList')
|
581
|
+
a = ar.new
|
582
|
+
a.add @jString.new('abcdef')
|
583
|
+
a.add @jInteger.valueOf('1')
|
584
|
+
a.add @jShort.valueOf('2')
|
585
|
+
a.add @jDouble.valueOf('3.1')
|
586
|
+
a.add @jFloat.valueOf('4.5')
|
587
|
+
a.add @jBoolean.TRUE
|
588
|
+
a.add @jByte.valueOf('5')
|
589
|
+
a.add @jLong.valueOf('8070450532247928832')
|
590
|
+
a.add @jChar.valueOf("A".sum)
|
591
|
+
|
592
|
+
Rjb::primitive_conversion = true
|
593
|
+
|
594
|
+
assert_equal 'abcdef', a.get(0)
|
595
|
+
assert_equal 1, a.get(1)
|
596
|
+
assert_equal 2, a.get(2)
|
597
|
+
assert_equal 3.1, a.get(3)
|
598
|
+
assert_equal 4.5, a.get(4)
|
599
|
+
assert a.get(5)
|
600
|
+
assert_equal 5, a.get(6)
|
601
|
+
assert_equal 8070450532247928832, a.get(7)
|
602
|
+
assert_equal "A".sum, a.get(8)
|
603
|
+
end
|
604
|
+
|
605
|
+
def test_primitive_to_obj
|
606
|
+
Rjb::primitive_conversion = true
|
607
|
+
|
608
|
+
ar = Rjb::import('java.util.ArrayList')
|
609
|
+
a = ar.new
|
610
|
+
a.add @jString.new('abcdef')
|
611
|
+
a.add @jInteger.valueOf('1')
|
612
|
+
a.add @jShort.valueOf('2')
|
613
|
+
a.add @jDouble.valueOf('3.1')
|
614
|
+
a.add @jFloat.valueOf('4.5')
|
615
|
+
a.add @jBoolean.TRUE
|
616
|
+
a.add @jByte.valueOf('5')
|
617
|
+
a.add @jLong.valueOf('8070450532247928832')
|
618
|
+
a.add @jChar.valueOf("A".sum)
|
619
|
+
assert_equal 'abcdef', a.get(0)
|
620
|
+
assert_equal 1, a.get(1)
|
621
|
+
assert_equal 2, a.get(2)
|
622
|
+
assert_equal 3.1, a.get(3)
|
623
|
+
assert_equal 4.5, a.get(4)
|
624
|
+
assert a.get(5)
|
625
|
+
assert_equal 5, a.get(6)
|
626
|
+
assert_equal 8070450532247928832, a.get(7)
|
627
|
+
assert_equal "A".sum, a.get(8)
|
628
|
+
end
|
629
|
+
|
630
|
+
def test_enum
|
631
|
+
t = Rjb::import('jp.co.infoseek.hp.arton.rjb.Test$TestTypes')
|
632
|
+
assert t.ONE.equals(t.values()[0])
|
633
|
+
assert_equal 3, t.values().size
|
634
|
+
assert_equal 2, t.THREE.ordinal
|
635
|
+
assert_equal "TWO", t.TWO.name
|
636
|
+
assert_equal "THREE", t.THREE.toString
|
637
|
+
end
|
638
|
+
|
639
|
+
#rjb-bugs-15430 rebported by Bryan Duxbury
|
640
|
+
def test_generics_map
|
641
|
+
|
642
|
+
ctest = import('jp.co.infoseek.hp.arton.rjb.Test')
|
643
|
+
test = ctest.new
|
644
|
+
map = test.sorted_map
|
645
|
+
assert_equal "\0\x1\x2\x3\x4", map.get('abc')
|
646
|
+
assert_equal "\x5\x6\x7\x8\x9", map.get('def')
|
647
|
+
|
648
|
+
cmap = import('java.util.TreeMap')
|
649
|
+
map = cmap.new
|
650
|
+
map.put('abc', @jString.new('abc').bytes)
|
651
|
+
map.put('012', @jString.new('012').bytes)
|
652
|
+
|
653
|
+
Rjb::primitive_conversion = true
|
654
|
+
map2 = test.throughSortedMap(map)
|
655
|
+
assert_equal '012', map2.get('012')
|
656
|
+
assert_equal 'abc', map2.get('abc')
|
657
|
+
end
|
658
|
+
|
659
|
+
def x_test_zzunload
|
660
|
+
# this test should run at the last
|
661
|
+
unload
|
662
|
+
begin
|
663
|
+
load('.')
|
664
|
+
fail 'no exception'
|
665
|
+
rescue
|
666
|
+
assert_equal "can't create Java VM", $!.message
|
667
|
+
end
|
668
|
+
end
|
669
|
+
|
670
|
+
module TestMixin
|
671
|
+
def test_hello(s)
|
672
|
+
'hello ' + s
|
673
|
+
end
|
674
|
+
end
|
675
|
+
def test_extend
|
676
|
+
@jString.class_eval do
|
677
|
+
include TestRjb::TestMixin
|
678
|
+
end
|
679
|
+
s = @jString.new
|
680
|
+
assert_equal('hello world', s.test_hello('world'))
|
681
|
+
end
|
682
|
+
def test_extend_with_factory
|
683
|
+
point = import('java.awt.Point')
|
684
|
+
point.class_eval do
|
685
|
+
include TestRjb::TestMixin
|
686
|
+
end
|
687
|
+
p = point.new(11, 12)
|
688
|
+
assert_equal(11, p.x)
|
689
|
+
assert_equal(12, p.y)
|
690
|
+
assert_equal('hello world', p.test_hello('world'))
|
691
|
+
p = p.location
|
692
|
+
assert_equal(11, p.x)
|
693
|
+
assert_equal(12, p.y)
|
694
|
+
assert_equal('hello world', p.test_hello('world'))
|
695
|
+
end
|
696
|
+
def test_fetch_method_signature
|
697
|
+
expected = ['I', 'II', 'Ljava.lang.String;', 'Ljava.lang.String;I']
|
698
|
+
sig = @jString.sigs('indexOf').sort
|
699
|
+
assert_equal(expected, sig)
|
700
|
+
end
|
701
|
+
def test_fetch_method_without_signature
|
702
|
+
sig =
|
703
|
+
assert_equal([nil], @jString.sigs('toString'))
|
704
|
+
end
|
705
|
+
def test_fetch_static_method_signature
|
706
|
+
expected = ['Ljava.lang.String;[Ljava.lang.Object;',
|
707
|
+
'Ljava.util.Locale;Ljava.lang.String;[Ljava.lang.Object;']
|
708
|
+
sig = @jString.static_sigs('format').sort
|
709
|
+
assert_equal(expected, sig)
|
710
|
+
end
|
711
|
+
def test_fetch_ctor_signature
|
712
|
+
expected = ['I', 'Ljava.lang.String;']
|
713
|
+
sig = @jInteger.ctor_sigs.sort
|
714
|
+
assert_equal(expected, sig)
|
715
|
+
end
|
716
|
+
def test_methods_extension
|
717
|
+
m = @jString.new('').methods
|
718
|
+
assert m.include?('indexOf')
|
719
|
+
end
|
720
|
+
def test_class_methods_extension
|
721
|
+
m = @jString.methods
|
722
|
+
assert m.include?('format')
|
723
|
+
end
|
724
|
+
def test_pmethods_extension
|
725
|
+
m = @jString.new('').public_methods
|
726
|
+
assert m.include?('indexOf')
|
727
|
+
end
|
728
|
+
def test_class_pmethods_extension
|
729
|
+
m = @jString.public_methods
|
730
|
+
assert m.include?('format')
|
731
|
+
end
|
732
|
+
def test_java_methods
|
733
|
+
indexof = @jString.new('').java_methods.find do |m|
|
734
|
+
m =~ /^indexOf/
|
735
|
+
end
|
736
|
+
args = indexof.match(/\[([^\]]+)\]/)[1]
|
737
|
+
assert_equal('Ljava.lang.String;I, II, I, Ljava.lang.String;'.split(/,\s*/).sort,
|
738
|
+
args.split(/,\s*/).sort)
|
739
|
+
end
|
740
|
+
def test_java_class_methods
|
741
|
+
format = @jString.java_methods.find do |m|
|
742
|
+
m =~ /^format/
|
743
|
+
end
|
744
|
+
args = format.match(/\[([^\]]+)\]/)[1]
|
745
|
+
assert_equal('Ljava.lang.String;[Ljava.lang.Object;, Ljava.util.Locale;Ljava.lang.String;[Ljava.lang.Object;'.split(/,\s*/).sort, args.split(/,\s*/).sort)
|
746
|
+
end
|
747
|
+
def test_64fixnum
|
748
|
+
big = @jLong.new_with_sig('J', 1230918239495)
|
749
|
+
assert_equal 1230918239495, big.long_value
|
750
|
+
end
|
751
|
+
def test_add_jar
|
752
|
+
add_jar(File.expand_path('./jartest.jar'))
|
753
|
+
jt = import('jp.co.infoseek.hp.arton.rjb.JarTest')
|
754
|
+
assert jt
|
755
|
+
assert_equal 'abcd', jt.new.add('ab', 'cd')
|
756
|
+
end
|
757
|
+
def test_add_jars
|
758
|
+
arg = ['./jartest.jar', './jartest.jar'].map do |e|
|
759
|
+
File.expand_path(e)
|
760
|
+
end
|
761
|
+
add_jar(arg)
|
762
|
+
jt = import('jp.co.infoseek.hp.arton.rjb.JarTest')
|
763
|
+
assert_equal 'abcd', jt.new.add('ab', 'cd')
|
764
|
+
end
|
765
|
+
def test_bothdirection_buffer
|
766
|
+
org = "abcdefghijklmn"
|
767
|
+
baip = import('java.io.ByteArrayInputStream')
|
768
|
+
ba = baip.new(org)
|
769
|
+
buff = "\0" * org.size
|
770
|
+
assert_equal org.size, ba.read(buff)
|
771
|
+
assert_equal -1, ba.read(buff)
|
772
|
+
ba.close
|
773
|
+
assert_equal org, buff
|
774
|
+
end
|
775
|
+
def test_anoninterface
|
776
|
+
arrays = import('java.util.Arrays')
|
777
|
+
a = [3, -4, 5, -6, 8, -10, -14]
|
778
|
+
index = arrays.binary_search(a, 6) do |m, o1, o2|
|
779
|
+
o1.abs - o2.abs
|
780
|
+
end
|
781
|
+
assert_equal 3, index
|
782
|
+
index = arrays.binary_search(a, 7) do |m, o1, o2|
|
783
|
+
o1.abs - o2.abs
|
784
|
+
end
|
785
|
+
assert_equal -5, index
|
786
|
+
end
|
787
|
+
def test_impl
|
788
|
+
two = import('Two')
|
789
|
+
t = two.impl { |m| m.to_s }
|
790
|
+
a = import('TwoCaller').new
|
791
|
+
ret = a.foo(t)
|
792
|
+
assert_equal 'method1', ret[0]
|
793
|
+
assert_equal 'method2', ret[1]
|
794
|
+
end
|
795
|
+
|
796
|
+
def cause_exception
|
797
|
+
begin
|
798
|
+
@jInteger.parseInt('blabla')
|
799
|
+
rescue NumberFormatException => e
|
800
|
+
raise
|
801
|
+
end
|
802
|
+
end
|
803
|
+
|
804
|
+
def test_reraise_exception()
|
805
|
+
unless /^1\.8/ =~ RUBY_VERSION
|
806
|
+
begin
|
807
|
+
cause_exception
|
808
|
+
rescue
|
809
|
+
assert($!.to_s =~ /NumberFormatException/)
|
810
|
+
end
|
811
|
+
end
|
812
|
+
end
|
813
|
+
|
814
|
+
class CbTest
|
815
|
+
def method(l, s, i, d, str)
|
816
|
+
"test_ok:#{l}-#{s}-#{i}-#{d}-#{str}"
|
817
|
+
end
|
818
|
+
end
|
819
|
+
def test_longcallback()
|
820
|
+
cb = bind(CbTest.new, 'jp.co.infoseek.hp.arton.rjb.CallbackTest$Callback')
|
821
|
+
test = import('jp.co.infoseek.hp.arton.rjb.CallbackTest')
|
822
|
+
assert_equal 'test_ok:1234-1234-1234-1234.5-1234', test.callCallback(cb)
|
823
|
+
end
|
824
|
+
|
825
|
+
class TestIterEx < TestIter
|
826
|
+
def initialize()
|
827
|
+
super
|
828
|
+
@strattr = 'strattr'
|
829
|
+
@numattr = 32
|
830
|
+
end
|
831
|
+
attr_accessor :strattr, :numattr
|
832
|
+
def multargs(a, b)
|
833
|
+
a + b
|
834
|
+
end
|
835
|
+
end
|
836
|
+
def test_method_otherthan_bound()
|
837
|
+
it = TestIterEx.new
|
838
|
+
it = bind(it, 'java.util.Iterator')
|
839
|
+
test = import('jp.co.infoseek.hp.arton.rjb.Test')
|
840
|
+
a = test.new
|
841
|
+
assert_equal("43210", a.concat(it))
|
842
|
+
assert(it.respond_to?(:numattr))
|
843
|
+
assert(it.respond_to?(:multargs))
|
844
|
+
assert_equal(32, it.numattr)
|
845
|
+
assert_equal('strattr', it.strattr)
|
846
|
+
it.numattr += 1
|
847
|
+
assert_equal(33, it.numattr)
|
848
|
+
assert_equal(5, it.multargs(3, 2))
|
849
|
+
end
|
850
|
+
def test_noarg_invoke()
|
851
|
+
str = @jString.new('abc')
|
852
|
+
assert_equal('abc', str._invoke('toString', ''))
|
853
|
+
assert_equal('abc', str._invoke('toString', nil))
|
854
|
+
assert_equal('abc', str._invoke('toString'))
|
855
|
+
end
|
856
|
+
def test_noarg_sinvoke()
|
857
|
+
sys = import('java.lang.System')
|
858
|
+
cons = sys.console
|
859
|
+
assert_equal(cons._classname, sys._invoke('console', '')._classname)
|
860
|
+
assert_equal(cons._classname, sys._invoke('console', nil)._classname)
|
861
|
+
assert_equal(cons._classname, sys._invoke('console')._classname)
|
862
|
+
end
|
863
|
+
def test_longarg
|
864
|
+
assert_equal(597899502607411822, @jLong.reverse(0x7654321076543210))
|
865
|
+
begin
|
866
|
+
@jLong.reverse(0x76543210765432101)
|
867
|
+
fail 'no exception for gibnum it doesn\'t convert Java long'
|
868
|
+
rescue RangeError
|
869
|
+
assert true
|
870
|
+
end
|
871
|
+
end
|
872
|
+
end
|
873
|
+
|