mirror of
https://github.com/netbirdio/gomobile-tvos-fork.git
synced 2026-05-22 18:43:29 -07:00
cmd/gobind: implement interface method binding.
This change makes gobind to generate proper Go-side proxy code to handle interface methods that have parameters and return values. It allows gobind to accept struct pointer types as parameters or a return value of a method. Fixes golang/go#9487, golang/go#9488. Change-Id: Id243c42ee0701d40e3871e392140368c2f8f9bc6 Reviewed-on: https://go-review.googlesource.com/2348 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
+76
-6
@@ -96,16 +96,87 @@ public class SeqTest extends TestCase {
|
||||
boolean finalizedAnI;
|
||||
|
||||
private class AnI extends Testpkg.I.Stub {
|
||||
boolean called;
|
||||
public void F() {
|
||||
called = true;
|
||||
public void E() throws Exception {
|
||||
throw new Exception("my exception from E");
|
||||
}
|
||||
|
||||
boolean calledF;
|
||||
public void F() {
|
||||
calledF = true;
|
||||
}
|
||||
|
||||
public Testpkg.I I() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Testpkg.S S() {
|
||||
return Testpkg.New();
|
||||
}
|
||||
|
||||
public long V() {
|
||||
return 1234;
|
||||
}
|
||||
|
||||
public long VE() throws Exception {
|
||||
throw new Exception("my exception from VE");
|
||||
}
|
||||
|
||||
public String name;
|
||||
|
||||
public String String() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finalize() throws Throwable {
|
||||
finalizedAnI = true;
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
// TODO(hyangah): add tests for methods that take parameters.
|
||||
|
||||
public void testInterfaceMethodReturnsError() {
|
||||
final AnI obj = new AnI();
|
||||
try {
|
||||
Testpkg.CallE(obj);
|
||||
fail("Expecting exception but none was thrown.");
|
||||
} catch (Exception e) {
|
||||
assertEquals("Error messages should match", "my exception from E", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testInterfaceMethodVoid() {
|
||||
final AnI obj = new AnI();
|
||||
Testpkg.CallF(obj);
|
||||
assertTrue("Want AnI.F to be called", obj.calledF);
|
||||
}
|
||||
|
||||
public void testInterfaceMethodReturnsInterface() {
|
||||
AnI obj = new AnI();
|
||||
obj.name = "testing AnI.I";
|
||||
Testpkg.I i = Testpkg.CallI(obj);
|
||||
assertEquals("Want AnI.I to return itself", i.String(), obj.String());
|
||||
}
|
||||
|
||||
public void testInterfaceMethodReturnsStructPointer() {
|
||||
final AnI obj = new AnI();
|
||||
Testpkg.S s = Testpkg.CallS(obj);
|
||||
}
|
||||
|
||||
public void testInterfaceMethodReturnsInt() {
|
||||
final AnI obj = new AnI();
|
||||
assertEquals("Values must match", 1234, Testpkg.CallV(obj));
|
||||
}
|
||||
|
||||
public void testInterfaceMethodReturnsIntOrError() {
|
||||
final AnI obj = new AnI();
|
||||
try {
|
||||
long v = Testpkg.CallVE(obj);
|
||||
fail("Expecting exception but none was thrown and got value " + v);
|
||||
} catch (Exception e) {
|
||||
assertEquals("Error messages should match", "my exception from VE", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/* Suppress this test for now; it's flaky or broken. */
|
||||
@Suppress
|
||||
@@ -113,8 +184,8 @@ public class SeqTest extends TestCase {
|
||||
finalizedAnI = false;
|
||||
AnI obj = new AnI();
|
||||
runGC();
|
||||
Testpkg.Call(obj);
|
||||
assertTrue("want F to be called", obj.called);
|
||||
Testpkg.CallF(obj);
|
||||
assertTrue("want F to be called", obj.calledF);
|
||||
obj = null;
|
||||
runGC();
|
||||
assertTrue("want obj to be collected", finalizedAnI);
|
||||
@@ -137,4 +208,3 @@ public class SeqTest extends TestCase {
|
||||
System.runFinalization();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user