summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhbehrens2008-11-14 09:56:35 (EST)
committer sefftinge2008-11-14 09:56:35 (EST)
commit6ce0162385625a3e0ee5cb691871c00be1d7e85c (patch)
tree0ef0845d8c244628a49cedf6cd13375f64da0b2c
parent3b3e804e7c3cc319f2e5c56d78c991d2400b3026 (diff)
downloadorg.eclipse.xtext-6ce0162385625a3e0ee5cb691871c00be1d7e85c.zip
org.eclipse.xtext-6ce0162385625a3e0ee5cb691871c00be1d7e85c.tar.gz
org.eclipse.xtext-6ce0162385625a3e0ee5cb691871c00be1d7e85c.tar.bz2
Further performance improvements during linker phase (Bug 254829) provided by Sebastian
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/AutoTestSuite.java1
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/XtextResourcePerformanceTest.java39
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/FilteringIteratorTest.java97
3 files changed, 118 insertions, 19 deletions
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/AutoTestSuite.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/AutoTestSuite.java
index 233ddbb..fbbf415 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/AutoTestSuite.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/AutoTestSuite.java
@@ -47,6 +47,7 @@ public class AutoTestSuite {
suite.addTestSuite(org.eclipse.xtext.crossrefs.CrossRefTest.class);
suite.addTestSuite(org.eclipse.xtext.crossrefs.LinkingErrorTest.class);
suite.addTestSuite(org.eclipse.xtext.util.SimpleCacheTest.class);
+ suite.addTestSuite(org.eclipse.xtext.util.FilteringIteratorTest.class);
suite.addTestSuite(org.eclipse.xtext.parser.XtextParserBugsTest.class);
return suite;
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/XtextResourcePerformanceTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/XtextResourcePerformanceTest.java
index d6758b1..d51cced 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/XtextResourcePerformanceTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/XtextResourcePerformanceTest.java
@@ -15,40 +15,41 @@ import org.eclipse.xtext.tests.AbstractGeneratorTest;
*/
public class XtextResourcePerformanceTest extends AbstractGeneratorTest {
- private static final int NUM_ELEMENTS = 100;
+ private static final int NUM_ELEMENTS = 190;
private String model;
-
+
protected void setUp() throws Exception {
super.setUp();
with(ReferenceGrammarStandaloneSetup.class);
StringBuilder modelBuilder = new StringBuilder(NUM_ELEMENTS * 64);
- modelBuilder.append("spielplatz " + NUM_ELEMENTS + " {\r\n");
- for(int i = 1; i <= NUM_ELEMENTS; i++ ) {
- modelBuilder.append(" kind (Bob" + i + " " + i + ")\r\n");
- modelBuilder.append(" kind (Joe" + i + " " + i + ")\r\n");
- modelBuilder.append(" erwachsener (Mutter" + i + " " + i + ")\r\n");
- modelBuilder.append(" erwachsener (Vater" + i + " " + i + ")\r\n");
- modelBuilder.append(" familie(Familie" + i + " Vater" + i + " Mutter" + i + " Bob" + i + ", Joe" + i + ")\r\n");
+ modelBuilder.append("spielplatz " + NUM_ELEMENTS + " {\n");
+ for (int i = 1; i <= NUM_ELEMENTS; i++) {
+ modelBuilder.append(" kind (Bob" + i + " " + i + ")\n");
+ modelBuilder.append(" kind (Joe" + i + " " + i + ")\n");
+ modelBuilder.append(" erwachsener (Mutter" + i + " " + i + ")\n");
+ modelBuilder.append(" erwachsener (Vater" + i + " " + i + ")\n");
+ modelBuilder.append(" familie(Familie" + i + " Vater" + i + " Mutter" + i + " Bob" + i + ", Joe" + i
+ + ")\n");
}
modelBuilder.append('}');
model = modelBuilder.toString();
}
-
+
public void testLoad() throws Exception {
XtextResource resource = getResourceFromString(model);
assertNotNull(resource);
assertTrue(resource.getParseResult().getParseErrors().isEmpty());
}
-
+
public void testLoadModelWithLinkingErrors() throws Exception {
StringBuilder modelBuilder = new StringBuilder(NUM_ELEMENTS * 64);
- modelBuilder.append("spielplatz " + NUM_ELEMENTS + " {\r\n");
- for(int i = 1; i <= NUM_ELEMENTS; i++ ) {
- modelBuilder.append(" kind (Bob " + i + ")\r\n");
- modelBuilder.append(" kind (Joe " + i + ")\r\n");
- modelBuilder.append(" erwachsener (Mutter " + i + ")\r\n");
- modelBuilder.append(" erwachsener (Vater " + i + ")\r\n");
- modelBuilder.append(" familie(Familie" + i + " Vater Mutter Bob, Joe)\r\n");
+ modelBuilder.append("spielplatz " + NUM_ELEMENTS + " {\n");
+ for (int i = 1; i <= NUM_ELEMENTS; i++) {
+ modelBuilder.append(" kind (Bob " + i + ")\n");
+ modelBuilder.append(" kind (Joe " + i + ")\n");
+ modelBuilder.append(" erwachsener (Mutter " + i + ")\n");
+ modelBuilder.append(" erwachsener (Vater " + i + ")\n");
+ modelBuilder.append(" familie(Familie" + i + " Vater Mutter Bob, Joe)\n");
}
modelBuilder.append('}');
model = modelBuilder.toString();
@@ -57,5 +58,5 @@ public class XtextResourcePerformanceTest extends AbstractGeneratorTest {
assertTrue(resource.getParseResult().getParseErrors().isEmpty());
assertEquals(2 * NUM_ELEMENTS, resource.getErrors().size());
}
-
+
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/FilteringIteratorTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/FilteringIteratorTest.java
new file mode 100644
index 0000000..33c1dad
--- /dev/null
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/FilteringIteratorTest.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.xtext.util;
+
+import java.util.ArrayList;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Sebastian Zarnekow - Initial contribution and API
+ */
+public class FilteringIteratorTest extends TestCase implements Filter<String> {
+
+ private String matchMe;
+
+ private List<String> list;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ matchMe = "matchMe";
+ list = new ArrayList<String>();
+ }
+
+ public boolean matches(String param) {
+ return param.equals(matchMe);
+ }
+
+ public void testEmptyList() {
+ Iterator<String> iter = new FilteringIterator<String>(list, this);
+ assertFalse(iter.hasNext());
+ }
+
+ public void testConcurrentModificationException() {
+ Iterator<String> iter = new FilteringIterator<String>(list, this);
+ list.add("null");
+ try {
+ iter.hasNext();
+ fail("expected exception");
+ } catch (ConcurrentModificationException ex) {
+ }
+ }
+
+ public void testRemove() {
+ list.add(matchMe);
+ Iterator<String> iter = new FilteringIterator<String>(list, this);
+ iter.next();
+ try {
+ iter.remove();
+ fail("expected exception");
+ } catch (UnsupportedOperationException ex) {
+ }
+ }
+
+ public void testHasNext() {
+ list.add("null");
+ list.add(matchMe);
+ list.add("null");
+ Iterator<String> iter = new FilteringIterator<String>(list, this);
+ assertTrue(iter.hasNext());
+ assertTrue(iter.hasNext());
+ assertEquals(matchMe, iter.next());
+ assertFalse(iter.hasNext());
+ }
+
+ public void testNext() {
+ list.add("null");
+ list.add(matchMe);
+ list.add("null");
+ list.add(matchMe);
+ Iterator<String> iter = new FilteringIterator<String>(list, this);
+ assertTrue(iter.hasNext());
+ assertEquals(matchMe, iter.next());
+ assertTrue(iter.hasNext());
+ assertEquals(matchMe, iter.next());
+ assertFalse(iter.hasNext());
+ }
+
+ public void testNextCallsHasNext() {
+ list.add("null");
+ list.add(matchMe);
+ list.add("null");
+ list.add(matchMe);
+ Iterator<String> iter = new FilteringIterator<String>(list, this);
+ assertEquals(matchMe, iter.next());
+ assertEquals(matchMe, iter.next());
+ assertFalse(iter.hasNext());
+ }
+
+}