diff options
author | Juergen Haug | 2017-08-14 09:39:23 +0000 |
---|---|---|
committer | Juergen Haug | 2017-08-28 15:09:41 +0000 |
commit | 965e852cc5dc0a3a6891c5bd8962d596eb122238 (patch) | |
tree | 34ec02c82941ccb213cd0dd88e66eb5d96c96912 /tests | |
parent | c6148998f6ef8ec40882e70d684208440d8de574 (diff) | |
download | org.eclipse.etrice-965e852cc5dc0a3a6891c5bd8962d596eb122238.tar.gz org.eclipse.etrice-965e852cc5dc0a3a6891c5bd8962d596eb122238.tar.xz org.eclipse.etrice-965e852cc5dc0a3a6891c5bd8962d596eb122238.zip |
[targetLang] migration to formatter2 + added ccstring formatting
Change-Id: I75546335e817478f2835d20801fa142787418080
Diffstat (limited to 'tests')
15 files changed, 1560 insertions, 5 deletions
diff --git a/tests/org.eclipse.etrice.core.common.tests/src-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.xtend b/tests/org.eclipse.etrice.core.common.tests/src-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.xtend new file mode 100644 index 000000000..5446f57c1 --- /dev/null +++ b/tests/org.eclipse.etrice.core.common.tests/src-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.xtend @@ -0,0 +1,187 @@ +/******************************************************************************* + * Copyright (c) 2011 protos software gmbh (http://www.protos.de). + * 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 + * + * CONTRIBUTORS: + * Juergen Haug (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.core.common + +import com.google.inject.Inject +import org.eclipse.etrice.core.common.converter.BaseConverterService +import org.eclipse.etrice.core.common.converter.CC_StringConverter +import org.eclipse.xtext.junit4.InjectWith +import org.eclipse.xtext.junit4.XtextRunner +import org.eclipse.xtext.util.Strings +import org.junit.Test +import org.junit.runner.RunWith + +import static org.junit.Assert.* + +@RunWith(XtextRunner) +@InjectWith(BaseTestInjectorProvider) +class DetailCodeParseTest { + + val NL = Strings.newLine + val DELIM = CC_StringConverter.DELIM + + @Inject + BaseConverterService baseConverterService + + protected def String toValue(String withoutDelim) { + baseConverterService.getCC_StringConverter.toValue(withoutDelim, null) => [ convertedWithoutDelim | + val convertedWithDelim = baseConverterService.getCC_StringConverter.toValue(DELIM + withoutDelim + DELIM, null) + assertEquals(convertedWithoutDelim, convertedWithDelim) + ] + } + + @Test + def void noLineBreak() { + assertEquals('', toValue('''''')) + assertEquals(''''''.toString, toValue('''''')) + + assertEquals(' ', toValue(''' ''')) + assertEquals(''' '''.toString, toValue(''' ''')) + + assertEquals('\t', toValue(''' ''')) + assertEquals(''' '''.toString, toValue(''' ''')) + + assertEquals(' text ', toValue(''' text ''')) + assertEquals(''' text '''.toString, toValue(''' text ''')) + + assertEquals("'", toValue("'")) + assertEquals("''", toValue("''")) + assertEquals('"', toValue('"')) + } + + @Test + def void singleLineBreak() { + assertEquals('', toValue('\r')) + assertEquals('', toValue('\r\n')) + assertEquals('', toValue('\n')) + assertEquals(''' + '''.toString, toValue(NL)) + + '\t' + NL => [ text | + assertEquals('', toValue(text)) + assertEquals(''' + '''.toString, toValue(text)) + ] + + 'text' + NL => [ text | + assertEquals('text' + NL, toValue(text)) + assertEquals('''text + '''.toString, toValue(text)) + ] + + ' text\t' + NL => [ text | + + assertEquals(' text\t' + NL, toValue(text)) + assertEquals(''' text + '''.toString, toValue(text)) + ] + + 'text' + NL + '\t' => [ text | + assertEquals('text' + NL, toValue(text)) + assertEquals('''text + '''.toString, toValue(text)) + ] + + NL + 'text ' => [ text | + assertEquals('text ', toValue(text)) + assertEquals(''' + text '''.toString, toValue(text)) + ] + + ' ' + NL + 'text' => [ text | + assertEquals('text', toValue(text)) + assertEquals(''' + text'''.toString, toValue(text)) + ] + + NL + ' text ' => [ text | + assertEquals('text ', toValue(text)) + assertEquals(''' + text '''.toString, toValue(text)) + ] + + } + + @Test + def void twoLineBreaks() { + NL + NL => [ text | + assertEquals(NL, toValue(text)) + assertEquals(''' + + '''.toString, toValue(text)) + ] + + 'text' + NL + NL => [ text | + assertEquals('text' + NL + NL, toValue(text)) + assertEquals('''text + + '''.toString, toValue(text)) + ] + + 'text' + NL + '\t\t\t\tindent' + NL => [ text | + assertEquals('text' + NL + '\t\t\t\tindent' + NL, toValue(text)) + assertEquals('''text + indent + '''.toString, toValue(text)) + ] + + NL + 'text' + NL => [ text | + assertEquals('text' + NL, toValue(text)) + assertEquals(''' +text + '''.toString, toValue(text)) + ] + + NL + '\t\t\t\ttext\t' + NL => [ text | + assertEquals('text\t' + NL, toValue(text)) + assertEquals(''' + text + '''.toString, toValue(text)) + ] + + NL + 'text' + NL + 'text2 ' => [ text | + assertEquals('text' + NL + 'text2 ', toValue(text)) + assertEquals(''' + text + text2 '''.toString, toValue(text)) + ] + + NL + '\ttext' + NL + 'text2 ' => [ text | + assertEquals('\ttext' + NL + 'text2 ', toValue(text)) + assertEquals(''' + text + text2 '''.toString, toValue(text)) + ] + + NL + 'text' + NL + '\t\t\tindent' => [ text | + assertEquals('text' + NL + '\t\t\tindent', toValue(text)) + assertEquals(''' +text + indent'''.toString, toValue(text)) + ] + } + + @Test + def void multiLineBreaks() { + NL + '\t\t\t ' + NL + NL + '\t\t ' + NL + '\t\t\ttext' + NL => [ text | + assertEquals(' ' + NL + NL + '\t\t ' + NL + 'text' + NL, toValue(text)) + assertEquals(''' + + + + text + '''.toString, toValue(text)) + ] + } + +} diff --git a/tests/org.eclipse.etrice.core.common.tests/xtend-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.java b/tests/org.eclipse.etrice.core.common.tests/xtend-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.java new file mode 100644 index 000000000..c1e083296 --- /dev/null +++ b/tests/org.eclipse.etrice.core.common.tests/xtend-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.java @@ -0,0 +1,326 @@ +/** + * Copyright (c) 2011 protos software gmbh (http://www.protos.de). + * 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 + * + * CONTRIBUTORS: + * Juergen Haug (initial contribution) + */ +package org.eclipse.etrice.core.common; + +import com.google.inject.Inject; +import org.eclipse.etrice.core.common.BaseTestInjectorProvider; +import org.eclipse.etrice.core.common.converter.BaseConverterService; +import org.eclipse.etrice.core.common.converter.CC_StringConverter; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.conversion.IValueConverter; +import org.eclipse.xtext.junit4.InjectWith; +import org.eclipse.xtext.junit4.XtextRunner; +import org.eclipse.xtext.util.Strings; +import org.eclipse.xtext.xbase.lib.ObjectExtensions; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(XtextRunner.class) +@InjectWith(BaseTestInjectorProvider.class) +@SuppressWarnings("all") +public class DetailCodeParseTest { + private final String NL = Strings.newLine(); + + private final String DELIM = CC_StringConverter.DELIM; + + @Inject + private BaseConverterService baseConverterService; + + protected String toValue(final String withoutDelim) { + IValueConverter<String> _cC_StringConverter = this.baseConverterService.getCC_StringConverter(); + String _value = _cC_StringConverter.toValue(withoutDelim, null); + final Procedure1<String> _function = (String convertedWithoutDelim) -> { + IValueConverter<String> _cC_StringConverter_1 = this.baseConverterService.getCC_StringConverter(); + final String convertedWithDelim = _cC_StringConverter_1.toValue(((this.DELIM + withoutDelim) + this.DELIM), null); + Assert.assertEquals(convertedWithoutDelim, convertedWithDelim); + }; + return ObjectExtensions.<String>operator_doubleArrow(_value, _function); + } + + @Test + public void noLineBreak() { + StringConcatenation _builder = new StringConcatenation(); + String _value = this.toValue(_builder.toString()); + Assert.assertEquals("", _value); + StringConcatenation _builder_1 = new StringConcatenation(); + String _string = _builder_1.toString(); + StringConcatenation _builder_2 = new StringConcatenation(); + String _value_1 = this.toValue(_builder_2.toString()); + Assert.assertEquals(_string, _value_1); + StringConcatenation _builder_3 = new StringConcatenation(); + _builder_3.append(" "); + String _value_2 = this.toValue(_builder_3.toString()); + Assert.assertEquals(" ", _value_2); + StringConcatenation _builder_4 = new StringConcatenation(); + _builder_4.append(" "); + String _string_1 = _builder_4.toString(); + StringConcatenation _builder_5 = new StringConcatenation(); + _builder_5.append(" "); + String _value_3 = this.toValue(_builder_5.toString()); + Assert.assertEquals(_string_1, _value_3); + StringConcatenation _builder_6 = new StringConcatenation(); + _builder_6.append("\t"); + String _value_4 = this.toValue(_builder_6.toString()); + Assert.assertEquals("\t", _value_4); + StringConcatenation _builder_7 = new StringConcatenation(); + _builder_7.append("\t"); + String _string_2 = _builder_7.toString(); + StringConcatenation _builder_8 = new StringConcatenation(); + _builder_8.append("\t"); + String _value_5 = this.toValue(_builder_8.toString()); + Assert.assertEquals(_string_2, _value_5); + StringConcatenation _builder_9 = new StringConcatenation(); + _builder_9.append(" "); + _builder_9.append("text "); + String _value_6 = this.toValue(_builder_9.toString()); + Assert.assertEquals(" text ", _value_6); + StringConcatenation _builder_10 = new StringConcatenation(); + _builder_10.append(" "); + _builder_10.append("text "); + String _string_3 = _builder_10.toString(); + StringConcatenation _builder_11 = new StringConcatenation(); + _builder_11.append(" "); + _builder_11.append("text "); + String _value_7 = this.toValue(_builder_11.toString()); + Assert.assertEquals(_string_3, _value_7); + String _value_8 = this.toValue("\'"); + Assert.assertEquals("\'", _value_8); + String _value_9 = this.toValue("\'\'"); + Assert.assertEquals("\'\'", _value_9); + String _value_10 = this.toValue("\""); + Assert.assertEquals("\"", _value_10); + } + + @Test + public void singleLineBreak() { + String _value = this.toValue("\r"); + Assert.assertEquals("", _value); + String _value_1 = this.toValue("\r\n"); + Assert.assertEquals("", _value_1); + String _value_2 = this.toValue("\n"); + Assert.assertEquals("", _value_2); + StringConcatenation _builder = new StringConcatenation(); + String _string = _builder.toString(); + String _value_3 = this.toValue(this.NL); + Assert.assertEquals(_string, _value_3); + final Procedure1<String> _function = (String text) -> { + String _value_4 = this.toValue(text); + Assert.assertEquals("", _value_4); + StringConcatenation _builder_1 = new StringConcatenation(); + String _string_1 = _builder_1.toString(); + String _value_5 = this.toValue(text); + Assert.assertEquals(_string_1, _value_5); + }; + ObjectExtensions.<String>operator_doubleArrow( + ("\t" + this.NL), _function); + final Procedure1<String> _function_1 = (String text) -> { + String _value_4 = this.toValue(text); + Assert.assertEquals(("text" + this.NL), _value_4); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("text"); + _builder_1.newLine(); + String _string_1 = _builder_1.toString(); + String _value_5 = this.toValue(text); + Assert.assertEquals(_string_1, _value_5); + }; + ObjectExtensions.<String>operator_doubleArrow( + ("text" + this.NL), _function_1); + final Procedure1<String> _function_2 = (String text) -> { + String _value_4 = this.toValue(text); + Assert.assertEquals((" text\t" + this.NL), _value_4); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append(" "); + _builder_1.append("text\t"); + _builder_1.newLine(); + String _string_1 = _builder_1.toString(); + String _value_5 = this.toValue(text); + Assert.assertEquals(_string_1, _value_5); + }; + ObjectExtensions.<String>operator_doubleArrow( + (" text\t" + this.NL), _function_2); + final Procedure1<String> _function_3 = (String text) -> { + String _value_4 = this.toValue(text); + Assert.assertEquals(("text" + this.NL), _value_4); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("text"); + _builder_1.newLine(); + String _string_1 = _builder_1.toString(); + String _value_5 = this.toValue(text); + Assert.assertEquals(_string_1, _value_5); + }; + ObjectExtensions.<String>operator_doubleArrow( + (("text" + this.NL) + "\t"), _function_3); + final Procedure1<String> _function_4 = (String text) -> { + String _value_4 = this.toValue(text); + Assert.assertEquals("text ", _value_4); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("text "); + String _string_1 = _builder_1.toString(); + String _value_5 = this.toValue(text); + Assert.assertEquals(_string_1, _value_5); + }; + ObjectExtensions.<String>operator_doubleArrow( + (this.NL + "text "), _function_4); + final Procedure1<String> _function_5 = (String text) -> { + String _value_4 = this.toValue(text); + Assert.assertEquals("text", _value_4); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("text"); + String _string_1 = _builder_1.toString(); + String _value_5 = this.toValue(text); + Assert.assertEquals(_string_1, _value_5); + }; + ObjectExtensions.<String>operator_doubleArrow( + ((" " + this.NL) + "text"), _function_5); + final Procedure1<String> _function_6 = (String text) -> { + String _value_4 = this.toValue(text); + Assert.assertEquals("text ", _value_4); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("text "); + String _string_1 = _builder_1.toString(); + String _value_5 = this.toValue(text); + Assert.assertEquals(_string_1, _value_5); + }; + ObjectExtensions.<String>operator_doubleArrow( + (this.NL + " text "), _function_6); + } + + @Test + public void twoLineBreaks() { + final Procedure1<String> _function = (String text) -> { + String _value = this.toValue(text); + Assert.assertEquals(this.NL, _value); + StringConcatenation _builder = new StringConcatenation(); + _builder.newLine(); + String _string = _builder.toString(); + String _value_1 = this.toValue(text); + Assert.assertEquals(_string, _value_1); + }; + ObjectExtensions.<String>operator_doubleArrow( + (this.NL + this.NL), _function); + final Procedure1<String> _function_1 = (String text) -> { + String _value = this.toValue(text); + Assert.assertEquals((("text" + this.NL) + this.NL), _value); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("text"); + _builder.newLine(); + _builder.newLine(); + String _string = _builder.toString(); + String _value_1 = this.toValue(text); + Assert.assertEquals(_string, _value_1); + }; + ObjectExtensions.<String>operator_doubleArrow( + (("text" + this.NL) + this.NL), _function_1); + final Procedure1<String> _function_2 = (String text) -> { + String _value = this.toValue(text); + Assert.assertEquals(((("text" + this.NL) + "\t\t\t\tindent") + this.NL), _value); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("text"); + _builder.newLine(); + _builder.append("\t\t\t\t"); + _builder.append("indent"); + _builder.newLine(); + String _string = _builder.toString(); + String _value_1 = this.toValue(text); + Assert.assertEquals(_string, _value_1); + }; + ObjectExtensions.<String>operator_doubleArrow( + ((("text" + this.NL) + "\t\t\t\tindent") + this.NL), _function_2); + final Procedure1<String> _function_3 = (String text) -> { + String _value = this.toValue(text); + Assert.assertEquals(("text" + this.NL), _value); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("text"); + _builder.newLine(); + String _string = _builder.toString(); + String _value_1 = this.toValue(text); + Assert.assertEquals(_string, _value_1); + }; + ObjectExtensions.<String>operator_doubleArrow( + ((this.NL + "text") + this.NL), _function_3); + final Procedure1<String> _function_4 = (String text) -> { + String _value = this.toValue(text); + Assert.assertEquals(("text\t" + this.NL), _value); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("text\t"); + _builder.newLine(); + String _string = _builder.toString(); + String _value_1 = this.toValue(text); + Assert.assertEquals(_string, _value_1); + }; + ObjectExtensions.<String>operator_doubleArrow( + ((this.NL + "\t\t\t\ttext\t") + this.NL), _function_4); + final Procedure1<String> _function_5 = (String text) -> { + String _value = this.toValue(text); + Assert.assertEquals((("text" + this.NL) + "text2 "), _value); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("text"); + _builder.newLine(); + _builder.append("text2 "); + String _string = _builder.toString(); + String _value_1 = this.toValue(text); + Assert.assertEquals(_string, _value_1); + }; + ObjectExtensions.<String>operator_doubleArrow( + (((this.NL + "text") + this.NL) + "text2 "), _function_5); + final Procedure1<String> _function_6 = (String text) -> { + String _value = this.toValue(text); + Assert.assertEquals((("\ttext" + this.NL) + "text2 "), _value); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("\t"); + _builder.append("text"); + _builder.newLine(); + _builder.append("text2 "); + String _string = _builder.toString(); + String _value_1 = this.toValue(text); + Assert.assertEquals(_string, _value_1); + }; + ObjectExtensions.<String>operator_doubleArrow( + (((this.NL + "\ttext") + this.NL) + "text2 "), _function_6); + final Procedure1<String> _function_7 = (String text) -> { + String _value = this.toValue(text); + Assert.assertEquals((("text" + this.NL) + "\t\t\tindent"), _value); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("text"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("indent"); + String _string = _builder.toString(); + String _value_1 = this.toValue(text); + Assert.assertEquals(_string, _value_1); + }; + ObjectExtensions.<String>operator_doubleArrow( + (((this.NL + "text") + this.NL) + "\t\t\tindent"), _function_7); + } + + @Test + public void multiLineBreaks() { + final Procedure1<String> _function = (String text) -> { + String _value = this.toValue(text); + Assert.assertEquals(((((((" " + this.NL) + this.NL) + "\t\t ") + this.NL) + "text") + this.NL), _value); + StringConcatenation _builder = new StringConcatenation(); + _builder.append(" "); + _builder.newLine(); + _builder.newLine(); + _builder.append("\t\t "); + _builder.newLine(); + _builder.append("text"); + _builder.newLine(); + String _string = _builder.toString(); + String _value_1 = this.toValue(text); + Assert.assertEquals(_string, _value_1); + }; + ObjectExtensions.<String>operator_doubleArrow( + (((((((this.NL + "\t\t\t ") + this.NL) + this.NL) + "\t\t ") + this.NL) + "\t\t\ttext") + this.NL), _function); + } +} diff --git a/tests/org.eclipse.etrice.core.fsm.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.etrice.core.fsm.tests/META-INF/MANIFEST.MF index 41b0bf1af..596021e5b 100644 --- a/tests/org.eclipse.etrice.core.fsm.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.etrice.core.fsm.tests/META-INF/MANIFEST.MF @@ -5,7 +5,8 @@ Bundle-Vendor: Eclipse eTrice Bundle-Version: 1.1.1.qualifier Bundle-SymbolicName: org.eclipse.etrice.core.fsm.tests; singleton:=true Bundle-ActivationPolicy: lazy -Require-Bundle: org.eclipse.etrice.core.fsm, +Require-Bundle: org.eclipse.etrice.core.common, + org.eclipse.etrice.core.fsm, org.eclipse.etrice.core.fsm.ui, org.eclipse.core.runtime, org.eclipse.xtext.junit4;bundle-version="2.6.0", diff --git a/tests/org.eclipse.etrice.core.room.tests/.classpath b/tests/org.eclipse.etrice.core.room.tests/.classpath index b9247ca72..6f43376b3 100644 --- a/tests/org.eclipse.etrice.core.room.tests/.classpath +++ b/tests/org.eclipse.etrice.core.room.tests/.classpath @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="xtend-gen"/> + <classpathentry kind="src" path="src-gen"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> diff --git a/tests/org.eclipse.etrice.core.room.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.etrice.core.room.tests/META-INF/MANIFEST.MF index 81b087191..c6acb3d89 100644 --- a/tests/org.eclipse.etrice.core.room.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.etrice.core.room.tests/META-INF/MANIFEST.MF @@ -9,10 +9,11 @@ Require-Bundle: org.eclipse.etrice.core.room;bundle-version="1.1.1", org.eclipse.etrice.core.common;bundle-version="1.1.1", org.eclipse.etrice.core.fsm;bundle-version="1.1.1", org.junit;bundle-version="4.8.1", + org.eclipse.xtext.junit4, + org.eclipse.xtext.xbase.junit, org.eclipse.osgi;bundle-version="3.6.0", org.eclipse.xtext;bundle-version="2.6.0", org.eclipse.core.runtime;bundle-version="3.6.0", - org.eclipse.emf.ecore, - org.eclipse.xtend.core;bundle-version="2.7.3" + org.eclipse.emf.ecore Bundle-Activator: org.eclipse.etrice.core.CoreTestsActivator Bundle-ActivationPolicy: lazy diff --git a/tests/org.eclipse.etrice.core.room.tests/models/formatting/expected/DetailCode.room b/tests/org.eclipse.etrice.core.room.tests/models/formatting/expected/DetailCode.room new file mode 100644 index 000000000..76ebd8506 --- /dev/null +++ b/tests/org.eclipse.etrice.core.room.tests/models/formatting/expected/DetailCode.room @@ -0,0 +1,52 @@ +RoomModel DetailCode { + + ActorClass ADetailCode { + Structure { + usercode1 { + "/*uc1*/" + } + usercode2 '''/*uc3*/''' + usercode3 '''/*uc3*/''' + } + Behavior { + Operation op1() '''text\r\n''' + Operation op2() ''' + text\r\n + ''' + StateMachine { + State state { + entry '''dfd''' + exit '''d + ''' + } + + Transition init: initial -> state { + action ''' + /* maintain timers */ + etTimerControlBlock* temp; + etTime t; + + getTimeFromTarget(&t); + while (usedTcbsRoot != 0) { + if (isTimeGreater(&t, &(usedTcbsRoot->expTime))) { + timer_timeout(usedTcbsRoot->portIdx); + temp = usedTcbsRoot; + usedTcbsRoot = usedTcbsRoot->next; + if ((temp->pTime.sec == 0) && (temp->pTime.nSec == 0)) { + /* single shot timer */ + returnTcb(temp); + } else { + /* periodic timer */ + addTime(&temp->expTime, &temp->pTime); + putTcbToUsedList(temp); + } + } else { + break; + } + } + ''' + } + } + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/ActorCommunicationTest.room b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/ActorCommunicationTest.room new file mode 100644 index 000000000..3d43c757c --- /dev/null +++ b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/ActorCommunicationTest.room @@ -0,0 +1,304 @@ +/*removed comments and whitespace from detail code*/RoomModel ActorCommunicationTest { + + import room.basic.types.* from "Types.room" + import room.basic.test.* from "Tests.room" + import room.basic.service.timing.* from "TimingService.room" + + SubSystemClass SubSystem_ActorCommunicationTest { + @TestInstance + ActorRef singleThread_Appl: Appl + ActorRef timing: ATimingService + LayerConnection ref singleThread_Appl satisfied_by timing.timer + } + + ActorClass Appl { + Structure { + ActorRef tester: Tester + ActorRef datadriven_Testee: Datadriven_Testee + ActorRef eventdriven_Testee: Eventdriven_Testee + ActorRef async_Testee: Async_Testee + Binding tester.data_counter and datadriven_Testee.data_counter + Binding tester.data_counter_finish and datadriven_Testee.counter_finish + Binding tester.event_counter and eventdriven_Testee.event_counter + Binding tester.async_counter1 and async_Testee.event_counter + Binding tester.async_counter2 and async_Testee.data_counter + } + Behavior { + } + } + + async ActorClass Tester { + Interface { + conjugated Port event_counter: Eventdriven_PC + conjugated Port data_counter: Datadriven_PC + Port data_counter_finish: Datadriven_PC + conjugated Port async_counter1: Eventdriven_PC + conjugated Port async_counter2: Datadriven_PC + } + Structure { + external Port event_counter + external Port data_counter + external Port data_counter_finish + external Port async_counter1 + external Port async_counter2 + SAP timer: PTimer + Attribute data_caseId: int32 + Attribute event_caseId: int32 + Attribute async_caseId: int32 + Attribute counter: int32 + Attribute finish_counter: int32 + Attribute data_finish_flag: boolean + Attribute data_result [10]: int16 = "{1,2,3,4,5,6,7,8,9,10}" + Attribute event_result [10]: int16 = "{101,102,103,104,105,106,107,108,109,110}" + Attribute async_result [10]: int16 = "{1051,1002,1053,1004,1055,1006,1057,1008,1059,1010}" + } + Behavior { + ctor { + "etUnit_open(\"log/testlog\",\"ActorCommunicationTest\");" + "etUnit_openTestSuite(\"org.eclipse.etrice.generator.common.tests\");" + } + dtor { + "etUnit_closeTestSuite();" + "etUnit_close();" + } + StateMachine { + Transition init: initial -> tester_run { + action { + "data_caseId=etUnit_openTestCase(\"Datadriven ActorCommunicationTest\");" + "event_caseId=etUnit_openTestCase(\"Eventdriven ActorCommunicationTest\");" + "async_caseId=etUnit_openTestCase(\"Async ActorCommunicationTest\");" + "" + "event_counter.caseId(event_caseId);" + "data_counter.caseId(data_caseId);" + "async_counter2.caseId(async_caseId);" + "" + "counter=0;" + "finish_counter=0;" + "data_finish_flag=false;" + "EXPECT_ORDER_START(data_caseId,data_result,10);" + "EXPECT_ORDER_START(event_caseId,event_result,10);" + "EXPECT_ORDER_START(async_caseId,async_result,10);" + "timer.startTimer(400);" + } + } + Transition tr0: tester_run -> tester_run { + triggers { + <timeout: timer guard { + "counter<10" + }> + } + action { + "counter++;" + "event_counter.in1(counter);" + "data_counter.in1(counter);" + "async_counter1.in1(counter);" + "async_counter2.in1(counter);" + } + } + Transition tr1: tester_run -> tester_run { + triggers { + <finish: event_counter> + } + action { + "EXPECT_ORDER_END(event_caseId,\"<|MODEL_LOCATION|>\",110);" + "etUnit_closeTestCase(event_caseId);" + "finish_counter++;" + } + } + Transition tr2: tester_run -> tester_run { + guard { + "data_counter_finish.finish==true&&data_finish_flag==false" + } + action { + "data_finish_flag=true;" + "EXPECT_ORDER_END(data_caseId,\"<|MODEL_LOCATION|>\",10);" + "etUnit_closeTestCase(data_caseId);" + "finish_counter++;" + } + } + Transition tr3: tester_run -> tester_run { + triggers { + <finish: async_counter1> + } + action { + "EXPECT_ORDER_END(async_caseId,\"<|MODEL_LOCATION|>\",1010);" + "etUnit_closeTestCase(async_caseId);" + "finish_counter++;" + } + } + Transition terminate: my tp0 -> my tp0 { + guard { + "finish_counter==3" + } + action { + "etUnit_testFinished(event_caseId);" + } + } + TransitionPoint tp0 + State tester_run + } + } + } + + async ActorClass Async_Testee { + Interface { + Port event_counter: Eventdriven_PC + Port data_counter: Datadriven_PC + } + Structure { + external Port event_counter + external Port data_counter + Attribute counter: int32 + } + Behavior { + StateMachine { + Transition init: initial -> Idle { + action { + "counter=0;" + } + } + Transition tr0: Idle -> Idle { + guard { + "data_counter.in1!=counter&&data_counter.in1%2==1" + } + action { + "counter=data_counter.in1;" + "EXPECT_ORDER(data_counter.caseId,\"<|MODEL_LOCATION|>\",counter+1050);" + } + } + Transition tr1: Idle -> Idle { + triggers { + <in1: event_counter guard { + "data%2==0&&data<10" + }> + } + action { + "counter=data;" + "EXPECT_ORDER(data_counter.caseId,\"<|MODEL_LOCATION|>\",counter+1000);" + } + } + Transition tr2: Idle -> state0 { + triggers { + <in1: event_counter guard { + "data==10" + }> + } + action { + "event_counter.finish();" + } + } + State Idle + State state0 + } + } + } + + ActorClass Eventdriven_Testee { + Interface { + Port event_counter: Eventdriven_PC + } + Structure { + external Port event_counter + Attribute caseId: int32 + Attribute counter: int32 + } + Behavior { + StateMachine { + Transition init: initial -> state0 { + action { + "counter=0;" + } + } + Transition tr0: state0 -> state0 { + triggers { + <in1: event_counter guard { + "data<10" + }> + } + action { + "EXPECT_ORDER(caseId,\"<|MODEL_LOCATION|>\",data+100);" + } + } + Transition tr1: state0 -> state1 { + triggers { + <in1: event_counter guard { + "data==10" + }> + } + action { + "event_counter.finish();" + } + } + Transition tr2: state0 -> state0 { + triggers { + <caseId: event_counter> + } + action { + "caseId=data;" + } + } + State state0 + State state1 + } + } + } + + datadriven ActorClass Datadriven_Testee { + Interface { + Port data_counter: Datadriven_PC + conjugated Port counter_finish: Datadriven_PC + } + Structure { + external Port data_counter + external Port counter_finish + Attribute counter: int32 + } + Behavior { + StateMachine { + Transition init: initial -> state0 { + action { + "counter=0;" + "counter_finish.finish(false);" + } + } + Transition tr0: state0 -> state1 { + guard { + "data_counter.in1==10" + } + action { + "counter_finish.finish(true);" + } + } + Transition tr1: state0 -> state0 { + guard { + "data_counter.in1!=counter&&counter<10" + } + action { + "counter=data_counter.in1;" + "EXPECT_ORDER(data_counter.caseId,\"<|MODEL_LOCATION|>\",counter);" + } + } + State state0 + State state1 + } + } + } + + datadriven ProtocolClass Datadriven_PC { + incoming { + Message caseId(data: int32) + Message in1(data: int32) + Message finish(data: boolean) + } + } + + ProtocolClass Eventdriven_PC { + incoming { + Message caseId(data: int32) + Message in1(data: int32) + } + outgoing { + Message finish() + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Annotations.room b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Annotations.room new file mode 100644 index 000000000..32f0cf8f7 --- /dev/null +++ b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Annotations.room @@ -0,0 +1,30 @@ +RoomModel room.basic.annotations { + + AnnotationType BehaviorManual { + target = ActorBehavior + } + + AnnotationType DataLogging { + target = SubSystemClass + mandatory attribute pathlist: ptCharacter + } + + AnnotationType Gnuplot { + target = SubSystemClass + mandatory attribute format: ptCharacter + mandatory attribute outputfile: ptCharacter + mandatory attribute width: ptInteger + mandatory attribute height: ptInteger + optional attribute fontsize: ptInteger + } + + AnnotationType GnuplotGraph { + target = SubSystemClass + mandatory attribute paths: ptCharacter + optional attribute interval: ptInteger + optional attribute xtics: ptReal + optional attribute mxtics: ptInteger + optional attribute ymin: ptReal + optional attribute ymax: ptReal + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/TimingService.room b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/TimingService.room new file mode 100644 index 000000000..f22cf33df --- /dev/null +++ b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/TimingService.room @@ -0,0 +1,263 @@ +/*removed comments and whitespace from detail code*/RoomModel room.basic.service.timing { + + import room.basic.types.* from "Types.room" + + async ActorClass ATimingService { + Interface { + SPP timer: PTimer + } + Structure { + usercode1 { + "#include\"osal/etTime.h\"" + "#define ET_NB_OF_TCBS 30" + "typedef struct etTCB etTimerControlBlock;" + "struct etTCB{" + "etTime expTime;" + "etTime pTime;" + "int32 portIdx;" + "etTimerControlBlock*next;" + " };" + } + usercode2 { + "/*uc2*/" + } + usercode3 { + "/*uc3*/" + } + ServiceImplementation of timer + Attribute tcbs [30]: tcb + Attribute usedTcbsRoot: tcb ref + Attribute freeTcbsRoot: tcb ref + } + Behavior { + Operation getTcb(): tcb ref { + "etTimerControlBlock*temp=freeTcbsRoot;" + "" + "if(freeTcbsRoot!=0){" + "freeTcbsRoot=freeTcbsRoot->next;" + "temp->next=0;" + " }" + "return temp;" + } + Operation returnTcb(block: tcb ref) { + "block->next=freeTcbsRoot;" + "freeTcbsRoot=block;" + } + Operation removeTcbFromUsedList(idx: int32) { + "etTimerControlBlock*temp=usedTcbsRoot;" + "etTimerControlBlock*temp2=usedTcbsRoot;" + "" + "if(temp==0)return;" + "" + "if(usedTcbsRoot->portIdx==idx){" + " /*element found,the first one*/" + "usedTcbsRoot=usedTcbsRoot->next;" + "returnTcb(temp);" + "return;" + "}" + "" + "temp=temp->next;" + "while(temp!=0){" + "if(temp->portIdx==idx){" + "temp2->next=temp->next;" + "returnTcb(temp);" + "return;" + "}else{" + " /*try next*/" + "temp2=temp;" + "temp=temp->next;" + " }" + "}" + } + Operation putTcbToUsedList(block: tcb ref) { + "etTimerControlBlock*temp=usedTcbsRoot;" + "etTimerControlBlock*temp2=usedTcbsRoot;" + "" + "if(temp==0){" + " /*list empty put new block to root*/" + "block->next=0;" + "usedTcbsRoot=block;" + "return;" + " }" + "" + "while(1){" + "if(temp!=0){" + "if(isTimeGreater(&block->expTime,&temp->expTime)){" + " /*try next position*/" + "temp2=temp;" + "temp=temp->next;" + " }else{" + " /*right position found*/" + "block->next=temp;" + "if(temp==usedTcbsRoot){" + "usedTcbsRoot=block;" + " }else{" + "temp2->next=block;" + " }" + "return;" + " }" + " }else{" + " /*end of list reached*/" + "block->next=0;" + "temp2->next=block;" + "return;" + " }" + "}" + } + Operation isTimeGreater(t1: targetTime ref, t2: targetTime ref): boolean { + "if(t1->sec>t2->sec)return ET_TRUE;" + "if(t1->sec<t2->sec)return ET_FALSE;" + "if(t1->nSec>t2->nSec)return ET_TRUE;" + "return ET_FALSE;" + } + Operation addTime(t1: targetTime ref, t2: targetTime ref) { + "t1->sec+=t2->sec;" + "t1->nSec+=t2->nSec;" + "while(t1->nSec>=1000000000L){" + "t1->sec++;" + "t1->nSec-=1000000000L;" + "}" + } + StateMachine { + Transition tr0: initial -> Operational { + action { + "int i;" + "usedTcbsRoot=0;" + "freeTcbsRoot=&tcbs[0];" + "tcbs[ET_NB_OF_TCBS-1].next=0;" + "for(i=0;i<ET_NB_OF_TCBS-1;i++){" + "\ttcbs[i].next=&tcbs[i+1];" + "\t}" + } + } + Transition tr1: Operational -> Operational { + triggers { + <startTimeout: timer> + } + action { + "etTimerControlBlock*timer=getTcb();" + "etTime t;" + "if(timer!=0){" + "\tt.sec=time/1000;" + "\tt.nSec=(time%1000)*1000000L;" + "\ttimer->pTime.sec=0;" + "\ttimer->pTime.nSec=0;" + "\ttimer->portIdx=((etReplSubPort*)ifitem)->index;" + "\tgetTimeFromTarget(&(timer->expTime));" + "\taddTime(&(timer->expTime),&t);" + "\tputTcbToUsedList(timer);" + "\t}" + } + } + Transition tr3: Operational -> Operational { + triggers { + <startTimer: timer> + } + action { + "etTimerControlBlock*timer=getTcb();" + "etTime t;" + "if(timer!=0){" + "\tt.sec=time/1000;" + "\tt.nSec=(time%1000)*1000000L;" + "\ttimer->pTime=t;" + "\ttimer->portIdx=((etReplSubPort*)ifitem)->index;" + "\tgetTimeFromTarget(&(timer->expTime));" + "\taddTime(&(timer->expTime),&t);" + "\tputTcbToUsedList(timer);" + "\t}" + } + } + Transition tr4: Operational -> Operational { + triggers { + <kill: timer> + } + action { + "removeTcbFromUsedList(((etReplSubPort*)ifitem)->index);" + } + } + State Operational { + entry { + "/*prepare*/" + } + do { + "/*maintain timers*/" + "etTimerControlBlock*temp;" + "etTime t;" + "" + "getTimeFromTarget(&t);" + "while(usedTcbsRoot!=0){" + "\tif(isTimeGreater(&t,&(usedTcbsRoot->expTime))){" + "\t\ttimer[usedTcbsRoot->portIdx].timeout();" + "\t\ttemp=usedTcbsRoot;" + "\t\tusedTcbsRoot=usedTcbsRoot->next;" + "\t\tif((temp->pTime.sec==0)&&(temp->pTime.nSec==0)){" + "\t\t\t/*single shot timer*/" + "\t\t\treturnTcb(temp);" + "\t\t}else{" + "\t\t\t/*periodic timer*/" + "\t\t\taddTime(&temp->expTime,&temp->pTime);" + "\t\t\tputTcbToUsedList(temp);" + "\t\t\t}" + "\t\t}else{" + "\t\t\tbreak;" + "\t\t\t}" + "\t}" + } + } + } + } + } + + ProtocolClass PTimer { + usercode1 { + "#define ET_TIMER_RUNNING 0x01" + "#define ET_TIMER_PERIODIC 0x02" + } + usercode2 { + "/*uc2*/" + } + incoming { + Message startTimer(time: uint32) + Message startTimeout(time: uint32) + Message kill() + } + outgoing { + Message timeout() + } + conjugated PortClass + { + handle incoming startTimer { + "if(status==0){" + "status=ET_TIMER_RUNNING|ET_TIMER_PERIODIC;" + "etPort_sendMessage(self,PTimer_IN_startTimer,sizeof(int32),&data__et);" + "}" + } + handle incoming startTimeout { + "if(status==0){" + "status=ET_TIMER_RUNNING;" + "etPort_sendMessage(self,PTimer_IN_startTimeout,sizeof(int32),&data__et);" + "}" + } + handle outgoing timeout { + "/*TODO:clear active bit in case of single shot timer*/" + "if(status!=0){" + "if(status==ET_TIMER_RUNNING){" + " /*single shot timer*/" + "status=0;" + " }" + " /*msg to fsm*/" + " (*receiveMessageFunc)(actor,self,msg);" + "}" + } + handle incoming kill { + "if(status!=0){" + "status=0;" + "etPort_sendMessage(self,PTimer_IN_kill,0,NULL);" + "}" + } + Attribute status: int8 = "0" + } + } + ExternalType tcb -> "etTimerControlBlock" default "{{0,0},{0,0},0,NULL}" + ExternalType targetTime -> "etTime" default "{0,0}" +}
\ No newline at end of file diff --git a/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Types.room b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Types.room new file mode 100644 index 000000000..79ebd1a75 --- /dev/null +++ b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Types.room @@ -0,0 +1,19 @@ +RoomModel room.basic.types { + + PrimitiveType boolean: ptBoolean -> 'bool' default 'false' + PrimitiveType char: ptCharacter -> 'char' default '0' + PrimitiveType int8: ptInteger -> 'int8' default '0' + PrimitiveType int16: ptInteger -> 'int16' default '0' + PrimitiveType int32: ptInteger -> 'int32' default '0' + PrimitiveType int64: ptInteger -> 'int64' default '0' + PrimitiveType uint8: ptInteger -> 'uint8' default '0' + PrimitiveType uint16: ptInteger -> 'uint16' default '0' + PrimitiveType uint32: ptInteger -> 'uint32' default '0' + PrimitiveType uint64: ptInteger -> 'uint64' default '0' + PrimitiveType float32: ptReal -> 'float32' default '0' + PrimitiveType float64: ptReal -> 'float64' default '0' + PrimitiveType charPtr: ptCharacter -> 'charPtr' default '0' + PrimitiveType string: ptCharacter -> 'charPtr' default '0' + PrimitiveType etAddressId: ptInteger -> 'etAddressId' default '0' + ExternalType voidType -> 'void' default 'NULL' +}
\ No newline at end of file diff --git a/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatted/DetailCode.room b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatted/DetailCode.room new file mode 100644 index 000000000..206e4690a --- /dev/null +++ b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatted/DetailCode.room @@ -0,0 +1,53 @@ +RoomModel DetailCode { + + ActorClass ADetailCode { + Structure { + usercode1 { + "/*uc1*/" + } + usercode2 '''/*uc3*/''' + usercode3 ''' + /*uc3*/''' + } + Behavior { + Operation op1() '''text\r\n''' + Operation op2() ''' + text\r\n + ''' + StateMachine { + State state { + entry '''dfd''' + exit '''d +''' + } + + Transition init : initial -> state { + action ''' + /* maintain timers */ + etTimerControlBlock* temp; + etTime t; + + getTimeFromTarget(&t); + while (usedTcbsRoot != 0) { + if (isTimeGreater(&t, &(usedTcbsRoot->expTime))) { + timer_timeout(usedTcbsRoot->portIdx); + temp = usedTcbsRoot; + usedTcbsRoot = usedTcbsRoot->next; + if ((temp->pTime.sec == 0) && (temp->pTime.nSec == 0)) { + /* single shot timer */ + returnTcb(temp); + } else { + /* periodic timer */ + addTime(&temp->expTime, &temp->pTime); + putTcbToUsedList(temp); + } + } else { + break; + } + } + ''' + } + } + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.etrice.core.room.tests/org.eclipse.etrice.core.room.tests.launch b/tests/org.eclipse.etrice.core.room.tests/org.eclipse.etrice.core.room.tests.launch index 3fabf9600..6cb9c65b8 100644 --- a/tests/org.eclipse.etrice.core.room.tests/org.eclipse.etrice.core.room.tests.launch +++ b/tests/org.eclipse.etrice.core.room.tests/org.eclipse.etrice.core.room.tests.launch @@ -11,7 +11,7 @@ <booleanAttribute key="clearws" value="true"/> <booleanAttribute key="clearwslog" value="false"/> <stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/> -<booleanAttribute key="default" value="false"/> +<booleanAttribute key="default" value="true"/> <booleanAttribute key="includeOptional" value="false"/> <stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> @@ -36,7 +36,7 @@ <stringAttribute key="pde.version" value="3.3"/> <stringAttribute key="product" value="org.eclipse.platform.ide"/> <booleanAttribute key="run_in_ui_thread" value="false"/> -<stringAttribute key="selected_target_plugins" value="com.google.guava@default:default,com.google.inject@default:default,javax.inject@default:default,javax.xml@default:default,org.antlr.runtime@default:default,org.apache.log4j@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.expressions@default:default,org.eclipse.core.filesystem.win32.x86_64@default:false,org.eclipse.core.filesystem@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.resources.win32.x86_64@default:false,org.eclipse.core.resources@default:default,org.eclipse.core.runtime@default:true,org.eclipse.emf.common@default:default,org.eclipse.emf.ecore.xmi@default:default,org.eclipse.emf.ecore@default:default,org.eclipse.equinox.app@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.osgi.compatibility.state@default:false,org.eclipse.osgi@-1:true,org.eclipse.xtend.core@default:default,org.eclipse.xtend.lib.macro@default:default,org.eclipse.xtend.lib@default:default,org.eclipse.xtext.common.types@default:default,org.eclipse.xtext.logging@default:false,org.eclipse.xtext.smap@default:default,org.eclipse.xtext.util@default:default,org.eclipse.xtext.xbase.lib@default:default,org.eclipse.xtext.xbase@default:default,org.eclipse.xtext@default:default,org.hamcrest.core@default:default,org.junit@default:default,org.objectweb.asm@default:default"/> +<stringAttribute key="selected_target_plugins" value="com.google.guava*15.0.0.v201403281430@default:default,com.google.guava*21.0.0.v20170206-1425@default:default,com.google.inject@default:default,javax.inject@default:default,javax.xml@default:default,org.antlr.runtime*3.2.0.v201101311130@default:default,org.antlr.runtime*4.3.0.v201502022030@default:default,org.apache.log4j@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.expressions@default:default,org.eclipse.core.filesystem.win32.x86_64@default:false,org.eclipse.core.filesystem@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.resources.win32.x86_64@default:false,org.eclipse.core.resources@default:default,org.eclipse.core.runtime@default:true,org.eclipse.emf.common@default:default,org.eclipse.emf.ecore.xmi@default:default,org.eclipse.emf.ecore@default:default,org.eclipse.equinox.app@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.osgi.compatibility.state@default:false,org.eclipse.osgi@-1:true,org.eclipse.xtend.core@default:default,org.eclipse.xtend.lib.macro@default:default,org.eclipse.xtend.lib@default:default,org.eclipse.xtext.common.types@default:default,org.eclipse.xtext.logging@default:false,org.eclipse.xtext.smap@default:default,org.eclipse.xtext.util@default:default,org.eclipse.xtext.xbase.lib@default:default,org.eclipse.xtext.xbase@default:default,org.eclipse.xtext@default:default,org.hamcrest.core@default:default,org.junit@default:default,org.objectweb.asm@default:default"/> <stringAttribute key="selected_workspace_plugins" value="org.eclipse.etrice.core.common@default:default,org.eclipse.etrice.core.fsm@default:default,org.eclipse.etrice.core.room.tests@default:default,org.eclipse.etrice.core.room@default:default,org.eclipse.etrice.logging@default:false"/> <booleanAttribute key="show_selected_only" value="true"/> <stringAttribute key="templateConfig" value="${target_home}\configuration\config.ini"/> diff --git a/tests/org.eclipse.etrice.core.room.tests/src-gen/org/eclipse/etrice/core/room/tests/RoomInjectorProvider.java b/tests/org.eclipse.etrice.core.room.tests/src-gen/org/eclipse/etrice/core/room/tests/RoomInjectorProvider.java new file mode 100644 index 000000000..cccecc6f5 --- /dev/null +++ b/tests/org.eclipse.etrice.core.room.tests/src-gen/org/eclipse/etrice/core/room/tests/RoomInjectorProvider.java @@ -0,0 +1,69 @@ +package org.eclipse.etrice.core.room.tests; +/* + * generated by Xtext + */ + + +import org.eclipse.etrice.core.RoomRuntimeModule; +import org.eclipse.etrice.core.RoomStandaloneSetup; +import org.eclipse.xtext.junit4.GlobalRegistries; +import org.eclipse.xtext.junit4.GlobalRegistries.GlobalStateMemento; +import org.eclipse.xtext.junit4.IInjectorProvider; +import org.eclipse.xtext.junit4.IRegistryConfigurator; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +public class RoomInjectorProvider implements IInjectorProvider, IRegistryConfigurator { + + protected GlobalStateMemento stateBeforeInjectorCreation; + protected GlobalStateMemento stateAfterInjectorCreation; + protected Injector injector; + + static { + GlobalRegistries.initializeDefaults(); + } + + @Override + public Injector getInjector() + { + if (injector == null) { + stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState(); + this.injector = internalCreateInjector(); + stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState(); + } + return injector; + } + + protected Injector internalCreateInjector() { + return new RoomStandaloneSetup() { + @Override + public Injector createInjector() { + return Guice.createInjector(createRuntimeModule()); + } + }.createInjectorAndDoEMFRegistration(); + } + + protected RoomRuntimeModule createRuntimeModule() { + // make it work also with Maven/Tycho and OSGI + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=493672 + return new RoomRuntimeModule() { + @Override + public ClassLoader bindClassLoaderToInstance() { + return RoomInjectorProvider.class + .getClassLoader(); + } + }; + } + + @Override + public void restoreRegistry() { + stateBeforeInjectorCreation.restoreGlobalState(); + } + + @Override + public void setupRegistry() { + getInjector(); + stateAfterInjectorCreation.restoreGlobalState(); + } +} diff --git a/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/FormatterTest.xtend b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/FormatterTest.xtend new file mode 100644 index 000000000..2a710a92d --- /dev/null +++ b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/FormatterTest.xtend @@ -0,0 +1,88 @@ + +package org.eclipse.etrice.core + +import com.google.common.io.CharStreams +import java.io.InputStreamReader +import java.util.Map +import java.util.regex.Pattern +import org.eclipse.core.runtime.FileLocator +import org.eclipse.emf.common.util.URI +import org.eclipse.etrice.core.room.tests.RoomInjectorProvider +import org.eclipse.xtext.junit4.InjectWith +import org.eclipse.xtext.junit4.XtextRunner +import org.eclipse.xtext.junit4.formatter.FormatterTester +import org.junit.Test +import org.junit.runner.RunWith + +import static org.junit.Assert.* +import static org.junit.Assert.assertNotEquals + +@RunWith(XtextRunner) +@InjectWith(RoomInjectorProvider) +class FormatterTest extends FormatterTester { + + // does not work with comments or ccstring + val patterns = #[ + Pattern.compile('''([^\w\s])\s+(\w)'''), + Pattern.compile('''([^\w\s])\s+([^\w\s])'''), + Pattern.compile('''(\w)\s+([^\w\s])''') + ] + + @Test + def void unformatEqualsFormat(){ + + val expectedContents = newArrayList => [contents | + val entries = CoreTestsActivator.getInstance().getBundle().findEntries("models/formatting/unformatEqualsFormat/", "*.room", false) + while(entries.hasMoreElements) { + contents += CharStreams.toString(new InputStreamReader(FileLocator.toFileURL(entries.nextElement).openStream)) + } + ] + assertTrue(!expectedContents.empty) + + // expectation == format(unformat(expectation)) + val (String) => String unformatter = [content | + val unformatted = patterns.fold(content, [replaced, pattern |pattern.matcher(replaced).replaceAll('$1$2')]) + assertNotEquals(content, unformatted) + unformatted.replace('\r\n', ' ').replace('\n', ' ') + ] + expectedContents.forEach[expected | + println(unformatter.apply(expected)) + assertFormatted[ + expectation = expected + toBeFormatted = unformatter.apply(expected) + ] + ] + } + + @Test + def void testManual(){ + + val (String) => Map<String, String> collector = [path | + val entries = CoreTestsActivator.getInstance().getBundle().findEntries(path, '*.room', false) + newHashMap => [contentMap | + while(entries.hasMoreElements) { + val entry = entries.nextElement + val name = URI.createURI(entry.toURI.toString).lastSegment + contentMap.put(name, CharStreams.toString(new InputStreamReader(FileLocator.toFileURL(entry).openStream))) + } + ] + ] + + // fileName -> unformattedContent + val unformattedContents = collector.apply('models/formatting/expected/') + // fileName -> expectedContent + val expectedContents = collector.apply('models/formatting/expected/') + + assertTrue(!unformattedContents.empty && expectedContents.keySet == unformattedContents.keySet) + + // expectedContent == format(unformattedContent) + expectedContents.keySet.forEach[fileName | + assertFormatted[ + expectation = expectedContents.get(fileName) + toBeFormatted = unformattedContents.get(fileName) + ] + ] + } + + +} diff --git a/tests/org.eclipse.etrice.core.room.tests/xtend-gen/org/eclipse/etrice/core/FormatterTest.java b/tests/org.eclipse.etrice.core.room.tests/xtend-gen/org/eclipse/etrice/core/FormatterTest.java new file mode 100644 index 000000000..43be83aad --- /dev/null +++ b/tests/org.eclipse.etrice.core.room.tests/xtend-gen/org/eclipse/etrice/core/FormatterTest.java @@ -0,0 +1,161 @@ +package org.eclipse.etrice.core; + +import com.google.common.base.Objects; +import com.google.common.io.CharStreams; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Consumer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.etrice.core.CoreTestsActivator; +import org.eclipse.etrice.core.room.tests.RoomInjectorProvider; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.junit4.InjectWith; +import org.eclipse.xtext.junit4.XtextRunner; +import org.eclipse.xtext.junit4.formatter.FormatterTestRequest; +import org.eclipse.xtext.junit4.formatter.FormatterTester; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Exceptions; +import org.eclipse.xtext.xbase.lib.Functions.Function0; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.Functions.Function2; +import org.eclipse.xtext.xbase.lib.InputOutput; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.ObjectExtensions; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.osgi.framework.Bundle; + +@RunWith(XtextRunner.class) +@InjectWith(RoomInjectorProvider.class) +@SuppressWarnings("all") +public class FormatterTest extends FormatterTester { + private final List<Pattern> patterns = new Function0<List<Pattern>>() { + public List<Pattern> apply() { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("([^\\w\\s])\\s+(\\w)"); + Pattern _compile = Pattern.compile(_builder.toString()); + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("([^\\w\\s])\\s+([^\\w\\s])"); + Pattern _compile_1 = Pattern.compile(_builder_1.toString()); + StringConcatenation _builder_2 = new StringConcatenation(); + _builder_2.append("(\\w)\\s+([^\\w\\s])"); + Pattern _compile_2 = Pattern.compile(_builder_2.toString()); + return Collections.<Pattern>unmodifiableList(CollectionLiterals.<Pattern>newArrayList(_compile, _compile_1, _compile_2)); + } + }.apply(); + + @Test + public void unformatEqualsFormat() { + ArrayList<String> _newArrayList = CollectionLiterals.<String>newArrayList(); + final Procedure1<ArrayList<String>> _function = (ArrayList<String> contents) -> { + try { + CoreTestsActivator _instance = CoreTestsActivator.getInstance(); + Bundle _bundle = _instance.getBundle(); + final Enumeration<URL> entries = _bundle.findEntries("models/formatting/unformatEqualsFormat/", "*.room", false); + while (entries.hasMoreElements()) { + URL _nextElement = entries.nextElement(); + URL _fileURL = FileLocator.toFileURL(_nextElement); + InputStream _openStream = _fileURL.openStream(); + InputStreamReader _inputStreamReader = new InputStreamReader(_openStream); + String _string = CharStreams.toString(_inputStreamReader); + contents.add(_string); + } + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + }; + final ArrayList<String> expectedContents = ObjectExtensions.<ArrayList<String>>operator_doubleArrow(_newArrayList, _function); + boolean _isEmpty = expectedContents.isEmpty(); + boolean _not = (!_isEmpty); + Assert.assertTrue(_not); + final Function1<String, String> _function_1 = (String content) -> { + String _xblockexpression = null; + { + final Function2<String, Pattern, String> _function_2 = (String replaced, Pattern pattern) -> { + Matcher _matcher = pattern.matcher(replaced); + return _matcher.replaceAll("$1$2"); + }; + final String unformatted = IterableExtensions.<Pattern, String>fold(this.patterns, content, _function_2); + Assert.assertNotEquals(content, unformatted); + String _replace = unformatted.replace("\r\n", " "); + _xblockexpression = _replace.replace("\n", " "); + } + return _xblockexpression; + }; + final Function1<? super String, ? extends String> unformatter = _function_1; + final Consumer<String> _function_2 = (String expected) -> { + String _apply = unformatter.apply(expected); + InputOutput.<String>println(_apply); + final Procedure1<FormatterTestRequest> _function_3 = (FormatterTestRequest it) -> { + it.setExpectation(expected); + String _apply_1 = unformatter.apply(expected); + it.setToBeFormatted(_apply_1); + }; + this.assertFormatted(_function_3); + }; + expectedContents.forEach(_function_2); + } + + @Test + public void testManual() { + final Function1<String, Map<String, String>> _function = (String path) -> { + HashMap<String, String> _xblockexpression = null; + { + CoreTestsActivator _instance = CoreTestsActivator.getInstance(); + Bundle _bundle = _instance.getBundle(); + final Enumeration<URL> entries = _bundle.findEntries(path, "*.room", false); + HashMap<String, String> _newHashMap = CollectionLiterals.<String, String>newHashMap(); + final Procedure1<HashMap<String, String>> _function_1 = (HashMap<String, String> contentMap) -> { + try { + while (entries.hasMoreElements()) { + { + final URL entry = entries.nextElement(); + URI _uRI = entry.toURI(); + String _string = _uRI.toString(); + org.eclipse.emf.common.util.URI _createURI = org.eclipse.emf.common.util.URI.createURI(_string); + final String name = _createURI.lastSegment(); + URL _fileURL = FileLocator.toFileURL(entry); + InputStream _openStream = _fileURL.openStream(); + InputStreamReader _inputStreamReader = new InputStreamReader(_openStream); + String _string_1 = CharStreams.toString(_inputStreamReader); + contentMap.put(name, _string_1); + } + } + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + }; + _xblockexpression = ObjectExtensions.<HashMap<String, String>>operator_doubleArrow(_newHashMap, _function_1); + } + return _xblockexpression; + }; + final Function1<? super String, ? extends Map<String, String>> collector = _function; + final Map<String, String> unformattedContents = collector.apply("models/formatting/expected/"); + final Map<String, String> expectedContents = collector.apply("models/formatting/expected/"); + Assert.assertTrue(((!unformattedContents.isEmpty()) && Objects.equal(expectedContents.keySet(), unformattedContents.keySet()))); + Set<String> _keySet = expectedContents.keySet(); + final Consumer<String> _function_1 = (String fileName) -> { + final Procedure1<FormatterTestRequest> _function_2 = (FormatterTestRequest it) -> { + String _get = expectedContents.get(fileName); + it.setExpectation(_get); + String _get_1 = unformattedContents.get(fileName); + it.setToBeFormatted(_get_1); + }; + this.assertFormatted(_function_2); + }; + _keySet.forEach(_function_1); + } +} |