Skip to content

Commit

Permalink
Tests for getfield/putfield/getstatic/putstatic.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius@cnutter.local committed Nov 22, 2008
1 parent 0b7b57e commit 1b78664
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/jvmscript/bytecode.rb
Expand Up @@ -7,9 +7,11 @@ module Bytecode
include Signature

begin
# try mangled names for the version included with JRuby
import "jruby.objectweb.asm.Opcodes"
import "jruby.objectweb.asm.Label"
rescue Exception
# fall back on standard names
import "org.objectweb.asm.Opcodes"
import "org.objectweb.asm.Label"
end
Expand Down
22 changes: 22 additions & 0 deletions test/test_builder.rb
Expand Up @@ -299,6 +299,28 @@ def test_native_method
assert_raises(NativeException) {obj.yoohoo}
end

def test_fields
cb = @builder.public_class(@class_name, @builder.object);

cb.public_field('inst_field', JString)
cb.public_static_field('static_field', JString)

cb.public_method('set_inst', cb.void) {aload 0; ldc 'instance'; putfield this, 'inst_field', JString; returnvoid}
cb.public_method('set_static', cb.void) {ldc 'static'; putstatic this, 'static_field', JString; returnvoid}
cb.public_method('get_inst', JString) {aload 0; getfield this, 'inst_field', JString; areturn}
cb.public_method('get_static', JString) {getstatic this, 'static_field', JString; areturn}

dummy_constructor(cb)
obj = load_and_construct(@class_name, cb);

assert_equal nil, obj.get_inst
assert_equal nil, obj.get_static
obj.set_inst
obj.set_static
assert_equal 'instance', obj.get_inst
assert_equal 'static', obj.get_static
end

def test_arrays
cb = @builder.public_class(@class_name, @builder.object);

Expand Down

0 comments on commit 1b78664

Please sign in to comment.