mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-01 09:31:20 +08:00
add specs for basic java types argument/return values calling pure-java / overridden methods
This commit is contained in:
@@ -9,6 +9,23 @@ Motion::Project::App.setup do |app|
|
||||
app.sdk_path = File.expand_path('~/src/android-sdk-macosx')
|
||||
app.ndk_path = File.expand_path('~/src/android-ndk-r9d')
|
||||
|
||||
# Build the vendor jar if needed.
|
||||
testjava_jar = 'vendor/testjava.jar'
|
||||
if !File.exist?(testjava_jar) \
|
||||
or Dir.glob('vendor/java/**/*.java').any? { |x| File.mtime(x) > File.mtime(testjava_jar) }
|
||||
FileUtils.rm_rf('vendor/classes')
|
||||
FileUtils.mkdir('vendor/classes')
|
||||
Dir.chdir('vendor/java') do
|
||||
Dir.glob('**/*.java').each do |java|
|
||||
sh "/usr/bin/javac -d ../classes \"#{java}\""
|
||||
end
|
||||
end
|
||||
Dir.chdir('vendor/classes') do
|
||||
sh "/usr/bin/jar cvf ../testjava.jar ."
|
||||
end
|
||||
end
|
||||
app.vendor_project :jar => testjava_jar
|
||||
|
||||
# Make sure the main file is compiled and executed first.
|
||||
ary = app.files
|
||||
ary.delete('./app/main.rb')
|
||||
|
||||
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
|
||||
38
test/test-android/vendor/java/com/rubymotion/test/TestJavaMethods.java
vendored
Normal file
38
test/test-android/vendor/java/com/rubymotion/test/TestJavaMethods.java
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.rubymotion.test;
|
||||
|
||||
public class TestJavaMethods extends java.lang.Object {
|
||||
public TestJavaMethods() {
|
||||
}
|
||||
|
||||
public boolean booleanMethod(boolean arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public byte byteMethod(byte arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public short shortMethod(short arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public long longMethod(long arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public int intMethod(int arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public float floatMethod(float arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public double doubleMethod(double arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public java.lang.Object objectMethod(java.lang.Object arg) {
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user