Skip to content

Commit

Permalink
[Xtend] React on missing output for selective broadcast
Browse files Browse the repository at this point in the history
Selective broadcasts without output parameters are not supported by
joynr. That is why the generator should throw an exception in such case
and propose the user to edit the broadcast definiton in the FIDL file.

Change-Id: I41c3bf9b06f9129c2c2d0edd23123210f324a7ef
  • Loading branch information
agegov committed Sep 14, 2018
1 parent 991bec3 commit 8c6f3b8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
Expand Up @@ -36,10 +36,14 @@ public class BroadcastUtil {
private extension NamingUtil

def Iterable<FArgument> getOutputParameters(FBroadcast event) {
if (event === null || event.outArgs.size() == 0){
return new HashSet<FArgument>
}
else{
if (event === null || event.outArgs.size() == 0) {
if (event.isSelective) {
throw new IllegalStateException("Selective broadcast without output parameters is not supported. " +
"Please edit the definition of the selective broadcast \"" + event.name + "\"")
} else {
return new HashSet<FArgument>
}
} else {
return event.outArgs.filterNull
}
}
Expand Down
Expand Up @@ -27,8 +27,10 @@
import java.util.ArrayList;

import org.eclipse.emf.ecore.resource.Resource;
import org.franca.core.franca.FArgument;
import org.franca.core.franca.FBroadcast;
import org.franca.core.franca.FModel;
import org.junit.Before;
import org.junit.Test;

import com.google.inject.AbstractModule;
Expand All @@ -37,27 +39,59 @@

public class BroadcastUtilTest {

@Test
public void testFilterParameters() throws Exception {
URL fixtureURL = BroadcastUtilTest.class.getResource("FilterParameters.fidl");
ModelLoader loader = new ModelLoader(fixtureURL.getPath());
Resource fixtureResource = loader.getResources().iterator().next();
BroadcastUtil broadcastUtil = Guice.createInjector(new AbstractModule() {
private BroadcastUtil broadcastUtil;
private FModel model;

@Before
public void setUp() {
broadcastUtil = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Names.named(NamingUtil.JOYNR_GENERATOR_INTERFACENAMEWITHVERSION))
.to(false);
}
}).getInstance(BroadcastUtil.class);

FModel model = (FModel) fixtureResource.getContents().get(0);
URL fidlURL = BroadcastUtilTest.class.getResource("SelectiveBroadcastTest.fidl");
ModelLoader loader = new ModelLoader(fidlURL.getPath());
Resource fidlResource = loader.getResources().iterator().next();
model = (FModel) fidlResource.getContents().get(0);
}

@Test
public void testFilterParameters() {
FBroadcast fixture = model.getInterfaces().get(0).getBroadcasts().get(0);

assertEquals("fixture", fixture.getName());
ArrayList<String> result = broadcastUtil.getFilterParameters(fixture);
assertEquals(result.size(), 2);
assertTrue(result.contains("genre"));
assertTrue(result.contains("language"));
}

@Test
public void testOutputParameters() {
FBroadcast fixture = model.getInterfaces().get(0).getBroadcasts().get(0);

assertEquals("fixture", fixture.getName());
Iterable<FArgument> result = broadcastUtil.getOutputParameters(fixture);
assertTrue(result.iterator().hasNext());
assertEquals("station", result.iterator().next().getName());
}

@Test(expected = IllegalStateException.class)
public void testEmptyOutputParametersIsNotSupportedForSelectiveBroadcast() {
FBroadcast emptyOutput = model.getInterfaces().get(0).getBroadcasts().get(1);

assertEquals("emptyOutput", emptyOutput.getName());
broadcastUtil.getOutputParameters(emptyOutput);
}

@Test(expected = IllegalStateException.class)
public void testNoOutputParametersIsNotSupportedForSelectiveBroadcast() {
FBroadcast noOutput = model.getInterfaces().get(0).getBroadcasts().get(2);

assertEquals("noOutput", noOutput.getName());
broadcastUtil.getOutputParameters(noOutput);
}
}
Expand Up @@ -18,7 +18,7 @@
*/
package vehicle

interface BroadcastTest {
interface SelectiveBroadcastTest {
<**
@description: Selective broadcast with predefined filter parameters.
@param: genre Restrict on stations of this music genre
Expand All @@ -29,4 +29,18 @@ interface BroadcastTest {
String station
}
}
}

<**
@description: Selective broadcast with empty output parameters.
**>
broadcast emptyOutput selective {
out {
}
}

<**
@description: Selective broadcast with no output section.
**>
broadcast noOutput selective {
}
}

0 comments on commit 8c6f3b8

Please sign in to comment.