mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-23 12:27:56 +08:00
add specs for basic java types argument/return values calling pure-java / overridden methods
This commit is contained in:
64
test/test-android/app/rubymotion/java_methods_spec.rb
Normal file
64
test/test-android/app/rubymotion/java_methods_spec.rb
Normal file
@@ -0,0 +1,64 @@
|
||||
class TestJavaMethodsOverride < Com::RubyMotion::Test::TestJavaMethods
|
||||
def booleanMethod(arg); arg; end
|
||||
def byteMethod(arg); arg; end
|
||||
def shortMethod(arg); arg; end
|
||||
def intMethod(arg); arg; end
|
||||
def longMethod(arg); arg; end
|
||||
def floatMethod(arg); arg; end
|
||||
def doubleMethod(arg); arg; end
|
||||
def objectMethod(arg); arg; end
|
||||
end
|
||||
|
||||
2.times do |spec_n|
|
||||
describe "Java methods" + (spec_n == 0 ? "" : " overriden in Ruby") + " can be called when accepting/returning" do
|
||||
before :each do
|
||||
@obj = spec_n == 0 ? Com::RubyMotion::Test::TestJavaMethods.new : TestJavaMethodsOverride.new
|
||||
end
|
||||
|
||||
it "'boolean'" do
|
||||
@obj.booleanMethod(true).should == true
|
||||
@obj.booleanMethod(42).should == true
|
||||
@obj.booleanMethod(false).should == false
|
||||
@obj.booleanMethod(nil).should == false
|
||||
end
|
||||
|
||||
it "'byte'" do
|
||||
ret = @obj.byteMethod(42)
|
||||
ret.should be_an_instance_of(Java::Lang::Byte)
|
||||
ret.intValue.should == 42
|
||||
end
|
||||
|
||||
it "'short'" do
|
||||
ret = @obj.shortMethod(42)
|
||||
ret.should be_an_instance_of(Java::Lang::Short)
|
||||
ret.intValue.should == 42
|
||||
end
|
||||
|
||||
it "'int'" do
|
||||
@obj.intMethod(42).should == 42
|
||||
end
|
||||
|
||||
it "'long'" do
|
||||
ret = @obj.longMethod(42)
|
||||
ret.should be_an_instance_of(Java::Lang::Long)
|
||||
ret.intValue.should == 42
|
||||
end
|
||||
|
||||
it "'float'" do
|
||||
@obj.floatMethod(3.14).should == 3.14
|
||||
end
|
||||
|
||||
it "'double'" do
|
||||
ret = @obj.doubleMethod(3.14)
|
||||
ret.should be_an_instance_of(Java::Lang::Double)
|
||||
ret.floatValue.should == 3.14
|
||||
end
|
||||
|
||||
it "'java.lang.Object'" do
|
||||
obj = Java::Lang::Object.new
|
||||
ret = @obj.objectMethod(obj)
|
||||
obj.should == ret
|
||||
obj.should equal(ret)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user