Revision: 6789 Author: sco...@google.com Date: Tue Nov 10 08:11:52 2009 Log: Shuffles some test classes around; adds missing tests to JavaCompilationSuite convenience test suite.
Review by: bobv http://code.google.com/p/google-web-toolkit/source/detail?r=6789 Added: /trunk/dev/core/test/com/google/gwt/dev/jjs/ast /trunk/dev/core/test/com/google/gwt/dev/jjs/ast/JProgramLastFragmentLoadingBeforeTest.java /trunk/dev/core/test/com/google/gwt/dev/jjs/impl/RunAsyncNameTest.java Deleted: /trunk/dev/core/test/com/google/gwt/dev/javac/JProgramLastFragmentLoadingBeforeTest.java /trunk/dev/core/test/com/google/gwt/dev/javac/RunAsyncNameTest.java Modified: /trunk/dev/core/test/com/google/gwt/dev/javac/JavaCompilationSuite.java /trunk/dev/core/test/com/google/gwt/dev/jjs/impl/OptimizerTestBase.java ======================================= --- /dev/null +++ /trunk/dev/core/test/com/google/gwt/dev/jjs/ast/JProgramLastFragmentLoadingBeforeTest.java Tue Nov 10 08:11:52 2009 @@ -0,0 +1,128 @@ +/* + * Copyright 2009 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.jjs.ast; + +import com.google.gwt.dev.util.collect.Lists; + +import junit.framework.TestCase; + +import java.util.List; + +/** + * Tests {...@link JProgram#lastFragmentLoadingBefore(int, int...)}. + */ +public class JProgramLastFragmentLoadingBeforeTest extends TestCase { + + public void testBasics() { + List<Integer> initialSeq = Lists.create(4, 3, 2); + int numSps = 10; + + // Very simple + assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0, + 1, 2, 3)); + + // Equal fragments load at the same time + assertEquals(0, + JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0, 0)); + assertEquals(1, + JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 1, 1)); + assertEquals(3, + JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 3, 3)); + assertEquals(6, + JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 6, 6)); + assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 11, + 11)); + + // Zero loads first + assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 11, + 0)); + assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 10, + 0)); + assertEquals(0, + JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 3, 0)); + + // Initial sequence fragments load before all others + assertEquals(3, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 3, + 10)); + assertEquals(3, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 10, + 3)); + + // Earlier initial sequence fragments load before the others + assertEquals(4, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 2, + 3, 4)); + assertEquals(3, + JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 2, 3)); + assertEquals(4, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 4, + 3, 2)); + + // For non-equal exclusive fragments, leftovers is the common predecessor + assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 1, + 7)); + + // Leftovers is before any exclusive + assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 7, + 11)); + } + + public void testWithEmptyInitial() { + List<Integer> initialSeq = Lists.create(); + int numSps = 10; + + // Simple case + assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0, + 1, 2, 3)); + + // Equal fragments load at the same time + assertEquals(0, + JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0, 0)); + assertEquals(6, + JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 6, 6)); + assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 11, + 11)); + + // Zero loads first + assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 11, + 0)); + assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 10, + 0)); + assertEquals(0, + JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 3, 0)); + + // For non-equal exclusive fragments, leftovers is the common predecessor + assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 1, + 7)); + + // Leftovers is before any exclusive + assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 7, + 11)); + + // With just one argument, return it + assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0)); + assertEquals(3, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 3)); + assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 11)); + } + + public void testWithNoSplitPoints() { + List<Integer> initialSeq = Lists.create(); + int numSps = 0; + + assertEquals(0, + JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0, 0)); + assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0, + 0, 0)); + assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0)); + } +} ======================================= --- /dev/null +++ /trunk/dev/core/test/com/google/gwt/dev/jjs/impl/RunAsyncNameTest.java Tue Nov 10 08:11:52 2009 @@ -0,0 +1,80 @@ +/* + * Copyright 2009 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.jjs.impl; + +import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.UnableToCompleteException; +import com.google.gwt.dev.javac.impl.MockJavaResource; +import com.google.gwt.dev.util.UnitTestTreeLogger; + +/** + * This class tests naming of runAsync calls. Mostly it tests names that are + * invalid. + */ +public class RunAsyncNameTest extends OptimizerTestBase { + @Override + public void setUp() { + sourceOracle.addOrReplace(new MockJavaResource("test.CallRunAsync") { + @Override + protected CharSequence getContent() { + StringBuffer code = new StringBuffer(); + code.append("package test;\n"); + code.append("import com.google.gwt.core.client.GWT;\n"); + code.append("public class CallRunAsync {\n"); + code.append(" public static int notAmethod;"); + code.append(" public static void call0() { }\n"); + code.append(" public static void call1() {\n"); + code.append(" GWT.runAsync(null);\n"); + code.append(" }\n"); + code.append(" public static void call2() {\n"); + code.append(" GWT.runAsync(null);\n"); + code.append(" GWT.runAsync(null);\n"); + code.append(" }\n"); + code.append("}\n"); + return code; + } + }); + } + + /** + * Tests that it's an error to call the 2-argument version of GWT.runAsync + * with anything but a class literal. + */ + public void testNonLiteralInCall() { + UnitTestTreeLogger logger; + { + UnitTestTreeLogger.Builder builder = new UnitTestTreeLogger.Builder(); + builder.setLowestLogLevel(TreeLogger.ERROR); + builder.expectError("Errors in /mock/test/EntryPoint.java", null); + builder.expectError( + "Line 5: Only class literals may be used to name a call to GWT.runAsync()", + null); + builder.expectError("Cannot proceed due to previous errors", null); + logger = builder.createLogger(); + this.logger = logger; + } + + addSnippetImport("com.google.gwt.core.client.GWT"); + try { + compileSnippet("void", "GWT.runAsync((new Object()).getClass(), null);"); + fail("Expected compilation to fail"); + } catch (UnableToCompleteException e) { + // expected + } + + logger.assertCorrectLogEntries(); + } +} ======================================= --- /trunk/dev/core/test/com/google/gwt/dev/javac/JProgramLastFragmentLoadingBeforeTest.java Wed Oct 28 09:10:53 2009 +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2009 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.javac; - -import com.google.gwt.dev.jjs.ast.JProgram; -import com.google.gwt.dev.util.collect.Lists; - -import junit.framework.TestCase; - -import java.util.List; - -/** - * Tests {...@link JProgram#lastFragmentLoadingBefore(int, int...)}. - */ -public class JProgramLastFragmentLoadingBeforeTest extends TestCase { - - public void testBasics() { - List<Integer> initialSeq = Lists.create(4, 3, 2); - int numSps = 10; - - // Very simple - assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0, - 1, 2, 3)); - - // Equal fragments load at the same time - assertEquals(0, - JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0, 0)); - assertEquals(1, - JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 1, 1)); - assertEquals(3, - JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 3, 3)); - assertEquals(6, - JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 6, 6)); - assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 11, - 11)); - - // Zero loads first - assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 11, - 0)); - assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 10, - 0)); - assertEquals(0, - JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 3, 0)); - - // Initial sequence fragments load before all others - assertEquals(3, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 3, - 10)); - assertEquals(3, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 10, - 3)); - - // Earlier initial sequence fragments load before the others - assertEquals(4, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 2, - 3, 4)); - assertEquals(3, - JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 2, 3)); - assertEquals(4, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 4, - 3, 2)); - - // For non-equal exclusive fragments, leftovers is the common predecessor - assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 1, - 7)); - - // Leftovers is before any exclusive - assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 7, - 11)); - } - - public void testWithEmptyInitial() { - List<Integer> initialSeq = Lists.create(); - int numSps = 10; - - // Simple case - assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0, - 1, 2, 3)); - - // Equal fragments load at the same time - assertEquals(0, - JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0, 0)); - assertEquals(6, - JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 6, 6)); - assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 11, - 11)); - - // Zero loads first - assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 11, - 0)); - assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 10, - 0)); - assertEquals(0, - JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 3, 0)); - - // For non-equal exclusive fragments, leftovers is the common predecessor - assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 1, - 7)); - - // Leftovers is before any exclusive - assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 7, - 11)); - - // With just one argument, return it - assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0)); - assertEquals(3, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 3)); - assertEquals(11, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 11)); - } - - public void testWithNoSplitPoints() { - List<Integer> initialSeq = Lists.create(); - int numSps = 0; - - assertEquals(0, - JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0, 0)); - assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0, - 0, 0)); - assertEquals(0, JProgram.lastFragmentLoadingBefore(initialSeq, numSps, 0)); - } -} ======================================= --- /trunk/dev/core/test/com/google/gwt/dev/javac/RunAsyncNameTest.java Tue Sep 8 11:07:39 2009 +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2009 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.javac; - -import com.google.gwt.core.ext.TreeLogger; -import com.google.gwt.core.ext.UnableToCompleteException; -import com.google.gwt.dev.javac.impl.MockJavaResource; -import com.google.gwt.dev.jjs.impl.OptimizerTestBase; -import com.google.gwt.dev.util.UnitTestTreeLogger; - -/** - * This class tests naming of runAsync calls. Mostly it tests names that are - * invalid. - */ -public class RunAsyncNameTest extends OptimizerTestBase { - @Override - public void setUp() { - sourceOracle.addOrReplace(new MockJavaResource("test.CallRunAsync") { - @Override - protected CharSequence getContent() { - StringBuffer code = new StringBuffer(); - code.append("package test;\n"); - code.append("import com.google.gwt.core.client.GWT;\n"); - code.append("public class CallRunAsync {\n"); - code.append(" public static int notAmethod;"); - code.append(" public static void call0() { }\n"); - code.append(" public static void call1() {\n"); - code.append(" GWT.runAsync(null);\n"); - code.append(" }\n"); - code.append(" public static void call2() {\n"); - code.append(" GWT.runAsync(null);\n"); - code.append(" GWT.runAsync(null);\n"); - code.append(" }\n"); - code.append("}\n"); - return code; - } - }); - } - - /** - * Tests that it's an error to call the 2-argument version of GWT.runAsync - * with anything but a class literal. - */ - public void testNonLiteralInCall() throws UnableToCompleteException { - UnitTestTreeLogger logger; - { - UnitTestTreeLogger.Builder builder = new UnitTestTreeLogger.Builder(); - builder.setLowestLogLevel(TreeLogger.ERROR); - builder.expectError("Errors in /mock/test/EntryPoint.java", null); - builder.expectError( - "Line 5: Only class literals may be used to name a call to GWT.runAsync()", - null); - builder.expectError("Cannot proceed due to previous errors", null); - logger = builder.createLogger(); - this.logger = logger; - } - - addSnippetImport("com.google.gwt.core.client.GWT"); - try { - compileSnippet("void", "GWT.runAsync((new Object()).getClass(), null);"); - fail("Expected compilation to fail"); - } catch (UnableToCompleteException e) { - // expected - } - - logger.assertCorrectLogEntries(); - } -} ======================================= --- /trunk/dev/core/test/com/google/gwt/dev/javac/JavaCompilationSuite.java Mon Nov 9 20:50:50 2009 +++ /trunk/dev/core/test/com/google/gwt/dev/javac/JavaCompilationSuite.java Tue Nov 10 08:11:52 2009 @@ -15,6 +15,9 @@ */ package com.google.gwt.dev.javac; +import com.google.gwt.dev.javac.asm.CollectClassDataTest; +import com.google.gwt.dev.javac.asm.CollectReferencesVisitorTest; +import com.google.gwt.dev.javac.asm.ResolveGenericsTest; import com.google.gwt.dev.javac.impl.JdtBehaviorTest; import junit.framework.Test; @@ -27,18 +30,28 @@ public static Test suite() { TestSuite suite = new TestSuite(JavaCompilationSuite.class.getName()); + suite.addTestSuite(ArtificialRescueCheckerTest.class); suite.addTestSuite(BinaryTypeReferenceRestrictionsCheckerTest.class); suite.addTestSuite(CompilationStateTest.class); suite.addTestSuite(CompilationUnitFileReferenceTest.class); suite.addTestSuite(GWTProblemTest.class); suite.addTestSuite(JavaSourceParserTest.class); - suite.addTestSuite(JdtBehaviorTest.class); suite.addTestSuite(JdtCompilerTest.class); - suite.addTestSuite(JProgramLastFragmentLoadingBeforeTest.class); suite.addTestSuite(JSORestrictionsTest.class); suite.addTestSuite(JsniCheckerTest.class); suite.addTestSuite(TypeOracleMediatorTest.class); + suite.addTestSuite(CollectClassDataTest.class); + suite.addTestSuite(CollectReferencesVisitorTest.class); + suite.addTestSuite(ResolveGenericsTest.class); + + suite.addTestSuite(JdtBehaviorTest.class); + + // TODO: Move these to another package. + suite.addTestSuite(GeneratedClassnameComparatorTest.class); + suite.addTestSuite(GeneratedClassnameFinderTest.class); + suite.addTestSuite(GeneratedClassnameTest.class); + return suite; } } ======================================= --- /trunk/dev/core/test/com/google/gwt/dev/jjs/impl/OptimizerTestBase.java Mon Nov 9 19:37:01 2009 +++ /trunk/dev/core/test/com/google/gwt/dev/jjs/impl/OptimizerTestBase.java Tue Nov 10 08:11:52 2009 @@ -35,7 +35,7 @@ import java.util.TreeSet; /** - * Tests {...@link DeadCodeElimination}. + * A useful base class for tests that build JJS ASTs. */ public abstract class OptimizerTestBase extends TestCase { --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---