| /* |
| * Copyright 2008 Google Inc. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| * use this file except in compliance with the License. You may obtain a copy of |
| * the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| * License for the specific language governing permissions and limitations under |
| * the License. |
| */ |
| package com.google.gwt.dev.shell.rewrite.client; |
| |
| import com.google.gwt.junit.client.GWTTestCase; |
| |
| /** |
| * Test-case to check if the jsni blocks are mapped correctly between the |
| * synthetic and anonymous classes generated by the javac and the jdt compiler. |
| * <p> |
| * This issue arises when emma.jar is in the classpath. Gwt then follows the |
| * emma strategy and loads (offline-instrumented) classes from the disk. These |
| * classes could have been generated by any java compiler -- the java compiler |
| * does not have to be jdt and frequently is javac. These class files may |
| * contain references to synthetic classes and anonymous classes that the jdt |
| * does not know about. This testcase checks that gwt handles these cases |
| * correctly. |
| */ |
| public class EmmaClassLoadingTest extends GWTTestCase { |
| |
| enum EnumTest { |
| A, B, C, |
| } |
| |
| interface TestInterface { |
| void foo(); |
| } |
| |
| private static String messages[] = { |
| "a foo", "b foo", "enum A", "d foo", "e foo"}; |
| |
| private static int logCount = 0; |
| |
| private static void log(String msg) { |
| assertEquals(messages[logCount++], msg); |
| } |
| |
| @Override |
| public String getModuleName() { |
| return "com.google.gwt.dev.shell.rewrite.EmmaClassLoadingTest"; |
| } |
| |
| public void test1() { |
| TestInterface a = new TestInterface() { |
| public void foo() { |
| log("a foo"); |
| } |
| }; |
| a.foo(); |
| |
| TestInterface b = new TestInterface() { |
| public native void foo() /*-{ |
| @com.google.gwt.dev.shell.rewrite.client.EmmaClassLoadingTest::log(Ljava/lang/String;)("b foo"); |
| }-*/; |
| }; |
| b.foo(); |
| |
| if (false) { |
| TestInterface c = new TestInterface() { |
| public native void foo() /*-{ |
| @com.google.gwt.dev.shell.rewrite.client.EmmaClassLoadingTest::log(Ljava/lang/String;)("ANY_FOO_1"); |
| }-*/; |
| }; |
| } |
| EnumTest et = EnumTest.A; |
| switch (et) { |
| case A: |
| log("enum A"); |
| break; |
| case B: |
| log("ANY_FOO_2"); |
| break; |
| case C: |
| log("ANY_FOO_3"); |
| break; |
| } |
| |
| TestInterface d = new TestInterface() { |
| public native void foo() /*-{ |
| @com.google.gwt.dev.shell.rewrite.client.EmmaClassLoadingTest::log(Ljava/lang/String;)("d foo"); |
| }-*/; |
| }; |
| d.foo(); |
| |
| /* |
| * jdt generates $1 (a), $2 (b), $3 (d), $4 (e). javac generates $1 (a), $2 |
| * (b), $3 (c), $4 (d), $5 (e), $6 (synthetic). Added e so that the test |
| * fails quickly. Otherwise, it had to wait for a time-out (in looking |
| * through jdt generated code for non-existent jsni methods of $4) to fail. |
| */ |
| TestInterface e = new TestInterface() { |
| public native void foo() /*-{ |
| @com.google.gwt.dev.shell.rewrite.client.EmmaClassLoadingTest::log(Ljava/lang/String;)("e foo"); |
| }-*/; |
| }; |
| } |
| } |