test/test.rb in rjb-1.5.4 vs test/test.rb in rjb-1.5.5

- old
+ new

@@ -2,12 +2,12 @@ # encoding: utf-8 # $Id: test.rb 199 2012-12-17 13:31:18Z arton $ begin require 'rjb' -rescue LoadError - require 'rubygems' +rescue LoadError + require 'rubygems' require 'rjb' end require 'test/unit' require 'fileutils' @@ -137,12 +137,12 @@ a.add(@jInteger.new_with_sig('I', 2)) a.add(@jInteger.new_with_sig('I', 3)) oa = a.toArray assert_equal(3, oa.size) assert_equal(1, oa[0].intValue) - assert_equal(2, oa[1].intValue) - assert_equal(3, oa[2].intValue) + assert_equal(2, oa[1].intValue) + assert_equal(3, oa[2].intValue) end def test_kjconv() if Object::const_defined?(:Encoding) test = import('jp.co.infoseek.hp.arton.rjb.Test').new @@ -636,11 +636,11 @@ assert_equal "THREE", t.THREE.toString end #rjb-bugs-15430 rebported by Bryan Duxbury def test_generics_map - + ctest = import('jp.co.infoseek.hp.arton.rjb.Test') test = ctest.new map = test.sorted_map assert_equal "\0\x1\x2\x3\x4", map.get('abc') assert_equal "\x5\x6\x7\x8\x9", map.get('def') @@ -648,11 +648,11 @@ cmap = import('java.util.TreeMap') map = cmap.new map.put('abc', @jString.new('abc').bytes) map.put('012', @jString.new('012').bytes) - Rjb::primitive_conversion = true + Rjb::primitive_conversion = true map2 = test.throughSortedMap(map) assert_equal '012', map2.get('012') assert_equal 'abc', map2.get('abc') end @@ -664,11 +664,11 @@ fail 'no exception' rescue assert_equal "can't create Java VM", $!.message end end - + module TestMixin def test_hello(s) 'hello ' + s end end @@ -684,28 +684,28 @@ point.class_eval do include TestRjb::TestMixin end p = point.new(11, 12) assert_equal(11, p.x) - assert_equal(12, p.y) + assert_equal(12, p.y) assert_equal('hello world', p.test_hello('world')) p = p.location assert_equal(11, p.x) - assert_equal(12, p.y) + assert_equal(12, p.y) assert_equal('hello world', p.test_hello('world')) end def test_fetch_method_signature expected = ['I', 'II', 'Ljava.lang.String;', 'Ljava.lang.String;I'] sig = @jString.sigs('indexOf').sort assert_equal(expected, sig) end def test_fetch_method_without_signature - sig = + sig = assert_equal([nil], @jString.sigs('toString')) end def test_fetch_static_method_signature - expected = ['Ljava.lang.String;[Ljava.lang.Object;', + expected = ['Ljava.lang.String;[Ljava.lang.Object;', 'Ljava.util.Locale;Ljava.lang.String;[Ljava.lang.Object;'] sig = @jString.static_sigs('format').sort assert_equal(expected, sig) end def test_fetch_ctor_signature @@ -732,11 +732,11 @@ def test_java_methods indexof = @jString.new('').java_methods.find do |m| m =~ /^indexOf/ end args = indexof.match(/\[([^\]]+)\]/)[1] - assert_equal('Ljava.lang.String;I, II, I, Ljava.lang.String;'.split(/,\s*/).sort, + assert_equal('Ljava.lang.String;I, II, I, Ljava.lang.String;'.split(/,\s*/).sort, args.split(/,\s*/).sort) end def test_java_class_methods format = @jString.java_methods.find do |m| m =~ /^format/ @@ -783,13 +783,13 @@ o1.abs - o2.abs end assert_equal -5, index end def test_impl - two = import('Two') + two = import('jp.co.infoseek.hp.arton.rjb.Two') t = two.impl { |m| m.to_s } - a = import('TwoCaller').new + a = import('jp.co.infoseek.hp.arton.rjb.TwoCaller').new ret = a.foo(t) assert_equal 'method1', ret[0] assert_equal 'method2', ret[1] end @@ -820,22 +820,22 @@ ia = e.cause assert_equal('bad argument', ia.message) assert_equal('java.lang.IllegalArgumentException', ia._classname) end end - + class CbTest def method(l, s, i, d, str) "test_ok:#{l}-#{s}-#{i}-#{d}-#{str}" end end def test_longcallback() cb = bind(CbTest.new, 'jp.co.infoseek.hp.arton.rjb.CallbackTest$Callback') test = import('jp.co.infoseek.hp.arton.rjb.CallbackTest') assert_equal 'test_ok:1234-1234-1234-1234.5-1234', test.callCallback(cb) end - + class TestIterEx < TestIter def initialize() super @strattr = 'strattr' @numattr = 32 @@ -850,29 +850,29 @@ it = bind(it, 'java.util.Iterator') test = import('jp.co.infoseek.hp.arton.rjb.Test') a = test.new assert_equal("43210", a.concat(it)) assert(it.respond_to?(:numattr)) - assert(it.respond_to?(:multargs)) + assert(it.respond_to?(:multargs)) assert_equal(32, it.numattr) assert_equal('strattr', it.strattr) it.numattr += 1 assert_equal(33, it.numattr) assert_equal(5, it.multargs(3, 2)) end def test_noarg_invoke() str = @jString.new('abc') assert_equal('abc', str._invoke('toString', '')) - assert_equal('abc', str._invoke('toString', nil)) - assert_equal('abc', str._invoke('toString')) + assert_equal('abc', str._invoke('toString', nil)) + assert_equal('abc', str._invoke('toString')) end def test_noarg_sinvoke() - sys = import('java.lang.System') - cons = sys.console - assert_equal(cons._classname, sys._invoke('console', '')._classname) - assert_equal(cons._classname, sys._invoke('console', nil)._classname) - assert_equal(cons._classname, sys._invoke('console')._classname) + loader= import('java.lang.ClassLoader') + sloader = loader.system_class_loader + assert_equal(sloader._classname, loader._invoke('getSystemClassLoader', '')._classname) + assert_equal(sloader._classname, loader._invoke('getSystemClassLoader', nil)._classname) + assert_equal(sloader._classname, loader._invoke('getSystemClassLoader')._classname) end def test_longarg skip('rbx can handle 64bits long') if RUBY_ENGINE == 'rbx' assert_equal(597899502607411822, @jLong.reverse(0x7654321076543210)) begin @@ -895,11 +895,11 @@ test = import('jp.co.infoseek.hp.arton.rjb.Test').new uri = import('java.net.URI') ret = test.java_typed_array(['a', 'b', 'c'], [1, 2, 3], [uri.new('http://www.artonx.org')]) assert_equal '[Ljava.lang.String;', ret[0] assert_equal '[Ljava.lang.Integer;', ret[1] - assert_equal '[Ljava.net.URI;', ret[2] + assert_equal '[Ljava.net.URI;', ret[2] end SJIS_STR = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67" EUCJP_STR = "\xb4\xc1\xbb\xfa\xa5\xc6\xa5\xad\xa5\xb9\xa5\xc8" UTF8_STR = "\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88" @@ -921,10 +921,10 @@ end assert_equal s1.toString, s.toString assert_equal s1.toString, e.toString assert_equal s1.toString, u.toString end - + def test_bothdirection_chararray charArrayReader = import('java.io.CharArrayReader') org = [48, 49, 50, 51, 52, 53] reader = charArrayReader.new(org) buffer = Array.new(32, 0)