Skip to content

Commit

Permalink
Clean jsinterop tests.
Browse files Browse the repository at this point in the history
Change-Id: I3c6fb99c1fecc29c2a33b92bc2ce47323d553e72
Review-Link: https://gwt-review.googlesource.com/#/c/18740/
  • Loading branch information
gkdn committed Jun 26, 2017
1 parent d987899 commit 26f46d6
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 223 deletions.
Expand Up @@ -1604,19 +1604,35 @@ public boolean f() {
} }


@JsFunction @JsFunction
interface JsFunctionInterface { interface MyJsFunctionInterface {
int foo(int a);
}

public void testJsFunction_lambda() {
MyJsFunctionInterface jsFunctionInterface = a -> a + 2;
assertEquals(12, callAsFunction(jsFunctionInterface, 10));
assertEquals(12, jsFunctionInterface.foo(10));
}

private static native int callAsFunction(Object fn, int arg) /*-{
return fn(arg);
}-*/;

@JsFunction
interface MyJsFunctionInterfaceWithOverlay {
Double m(); Double m();
@JsOverlay @JsOverlay
default Double callM() { default Double callM() {
return this.m(); return this.m();
} }
} }


private static native JsFunctionInterface createNative() /*-{ private static native MyJsFunctionInterfaceWithOverlay createNative() /*-{
return function () { return 5; }; return function () { return 5; };
}-*/; }-*/;

public void testJsFunction_withOverlay() { public void testJsFunction_withOverlay() {
JsFunctionInterface f = new JsFunctionInterface() { MyJsFunctionInterfaceWithOverlay f = new MyJsFunctionInterfaceWithOverlay() {
@Override @Override
public Double m() { public Double m() {
return new Double(2.0); return new Double(2.0);
Expand Down
2 changes: 0 additions & 2 deletions user/test/com/google/gwt/core/CoreJsInteropSuite.java
Expand Up @@ -23,7 +23,6 @@
import com.google.gwt.core.interop.JsTypeArrayTest; import com.google.gwt.core.interop.JsTypeArrayTest;
import com.google.gwt.core.interop.JsTypeBridgeTest; import com.google.gwt.core.interop.JsTypeBridgeTest;
import com.google.gwt.core.interop.JsTypeObjectMethodsTest; import com.google.gwt.core.interop.JsTypeObjectMethodsTest;
import com.google.gwt.core.interop.JsTypeSpecialTypesTest;
import com.google.gwt.core.interop.JsTypeTest; import com.google.gwt.core.interop.JsTypeTest;
import com.google.gwt.core.interop.JsTypeVarargsTest; import com.google.gwt.core.interop.JsTypeVarargsTest;
import com.google.gwt.core.interop.NativeJsTypeTest; import com.google.gwt.core.interop.NativeJsTypeTest;
Expand All @@ -42,7 +41,6 @@ public static Test suite() {
suite.addTestSuite(JsExportOptimizationTest.class); suite.addTestSuite(JsExportOptimizationTest.class);
suite.addTestSuite(JsTypeTest.class); suite.addTestSuite(JsTypeTest.class);
suite.addTestSuite(JsTypeBridgeTest.class); suite.addTestSuite(JsTypeBridgeTest.class);
suite.addTestSuite(JsTypeSpecialTypesTest.class);
suite.addTestSuite(JsTypeObjectMethodsTest.class); suite.addTestSuite(JsTypeObjectMethodsTest.class);
suite.addTestSuite(JsPropertyTest.class); suite.addTestSuite(JsPropertyTest.class);
suite.addTestSuite(JsMethodTest.class); suite.addTestSuite(JsMethodTest.class);
Expand Down
23 changes: 1 addition & 22 deletions user/test/com/google/gwt/core/interop/JsFunctionTest.java
Expand Up @@ -24,6 +24,7 @@


/** /**
* Tests JsFunction functionality. * Tests JsFunction functionality.
* Note that JsOverlay and lambda's are tested in Java8Test.
*/ */
@SuppressWarnings("cast") @SuppressWarnings("cast")
public class JsFunctionTest extends GWTTestCase { public class JsFunctionTest extends GWTTestCase {
Expand Down Expand Up @@ -249,7 +250,6 @@ class JsFuncionProperty {
} }


public void testGetClass() { public void testGetClass() {

MyJsFunctionInterface jsfunctionImplementation = MyJsFunctionInterface jsfunctionImplementation =
new MyJsFunctionInterface() { new MyJsFunctionInterface() {
@Override @Override
Expand All @@ -264,7 +264,6 @@ public int foo(int a) {
} }


public void testInstanceField() { public void testInstanceField() {

MyJsFunctionInterface jsfunctionImplementation = MyJsFunctionInterface jsfunctionImplementation =
new MyJsFunctionInterface() { new MyJsFunctionInterface() {
String hello = new Object().getClass().getName(); String hello = new Object().getClass().getName();
Expand All @@ -276,26 +275,6 @@ public int foo(int a) {
assertEquals(Object.class.getName().length() + 4, jsfunctionImplementation.foo(4)); assertEquals(Object.class.getName().length() + 4, jsfunctionImplementation.foo(4));
} }


// uncomment when Java8 is supported.
// public void testJsFunctionLambda_JS() {
// MyJsFunctionInterface jsFunctionInterface = a -> { return a + 2; };
// assertEquals(12, callAsFunction(jsFunctionInterface, 10));
// assertEquals(12, callAsCallBackFunction(jsFunctionInterface, 10));
// }
//
// public void testJsFunctionLambda_Java() {
// MyJsFunctionInterface jsFunctionInterface = a -> { return a + 2; };
// assertEquals(12, jsFunctionInterface.foo(10));
// }
//
// public void testJsFunctionDefaultMethod() {
// MyJsFunctionSubInterfaceWithDefaultMethod impl =
// new MyJsFunctionSubInterfaceWithDefaultMethod() {
// };
// assertEquals(10, impl.foo(10));
// assertEquals(10, callAsFunction(impl, 10));
// }

private static native Object callAsFunction(Object fn) /*-{ private static native Object callAsFunction(Object fn) /*-{
return fn(); return fn();
}-*/; }-*/;
Expand Down
12 changes: 11 additions & 1 deletion user/test/com/google/gwt/core/interop/JsTypeArrayTest.java
Expand Up @@ -97,7 +97,6 @@ static class SimpleJsTypeAsAFieldHolder {
public SimpleJsTypeAsAField[] arrayField; public SimpleJsTypeAsAField[] arrayField;
} }


// TODO(rluble): Needs fixes in ImlementCastsAndTypeChecks, ArrayNormalizer and maybe type oracle.
public void testJsTypeArray_asAField() { public void testJsTypeArray_asAField() {
SimpleJsTypeAsAFieldHolder holder = new SimpleJsTypeAsAFieldHolder(); SimpleJsTypeAsAFieldHolder holder = new SimpleJsTypeAsAFieldHolder();
fillArrayField(holder); fillArrayField(holder);
Expand Down Expand Up @@ -202,6 +201,17 @@ public void testJsTypeArray_instanceOf() {
assertTrue(array instanceof SimpleJsTypeReturnForMultiDimArray[][][]); assertTrue(array instanceof SimpleJsTypeReturnForMultiDimArray[][][]);
} }


@JsType(isNative = true)
private static class UnreferencedNativeType { }

private static native Object createArray() /*-{
return [];
}-*/;

public void testJsTypeArray_unreferencedNativeArrayInstanceOf() {
assertTrue(createArray() instanceof UnreferencedNativeType[]);
}

@JsFunction @JsFunction
interface SomeFunction { interface SomeFunction {
int m(int i); int m(int i);
Expand Down
153 changes: 0 additions & 153 deletions user/test/com/google/gwt/core/interop/JsTypeSpecialTypesTest.java

This file was deleted.

26 changes: 26 additions & 0 deletions user/test/com/google/gwt/core/interop/JsTypeTest.java
Expand Up @@ -515,6 +515,32 @@ public void testJsMethodWithDifferentVisiblities() {
assertEquals("bar", callFunction(instance, "bar", null)); assertEquals("bar", callFunction(instance, "bar", null));
} }


@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "*")
interface Star {
}

public void testStar() {
Object object = new Object();

assertNotNull((Star) object);

object = Double.valueOf(3.0);
assertNotNull((Star) object);
}

@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "?")
interface Wildcard {
}

public void testWildcard() {
Object object = new Object();

assertNotNull((Wildcard) object);

object = Double.valueOf(3.0);
assertNotNull((Wildcard) object);
}

static class ClassWithJsMethod { static class ClassWithJsMethod {
@JsMethod(name = "name") @JsMethod(name = "name")
public String className() { public String className() {
Expand Down

This file was deleted.

0 comments on commit 26f46d6

Please sign in to comment.