use of io.joynr.generator.loading.ModelLoader in project joynr by bmwcarit.
the class AbstractTypeUtilTest method testMultipleOutParameters.
@Test
public void testMultipleOutParameters() throws Exception {
URL fixtureURL = AbstractTypeUtilTest.class.getResource("MultipleOutParameters.fidl");
ModelLoader loader = new ModelLoader(fixtureURL.getPath());
Resource fixtureResource = loader.getResources().iterator().next();
class MyCallsRealMethods extends CallsRealMethods {
private static final long serialVersionUID = 1L;
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getMethod().getName().equals("getTypeName")) {
Class<?> parameterType0 = invocation.getMethod().getParameterTypes()[0];
if (parameterType0.equals(FBasicTypeId.class)) {
return ((FBasicTypeId) invocation.getArguments()[0]).getName();
} else if (parameterType0.equals(FType.class)) {
return ((FType) invocation.getArguments()[0]).getName();
} else {
return super.answer(invocation);
}
} else {
return super.answer(invocation);
}
}
}
AbstractTypeUtil typeUtil = mock(AbstractTypeUtil.class, new MyCallsRealMethods());
Guice.createInjector().injectMembers(typeUtil);
FModel model = (FModel) fixtureResource.getContents().get(0);
String stringDatatype = FBasicTypeId.STRING.getName();
String numberDatatype = FBasicTypeId.INT16.getName();
String complexDatatype = model.getTypeCollections().get(0).getTypes().get(0).getName();
FMethod fixture = model.getInterfaces().get(0).getMethods().get(0);
Iterator<String> result = typeUtil.getTypeNamesForOutputParameter(fixture).iterator();
assertEquals(result.next(), stringDatatype);
assertEquals(result.next(), numberDatatype);
assertEquals(result.next(), complexDatatype);
assertFalse(result.hasNext());
}
use of io.joynr.generator.loading.ModelLoader in project joynr by bmwcarit.
the class JoynrJavaGeneratorExtensionsTest method testIncludesOfFixture.
private void testIncludesOfFixture(boolean shallIncludeTopLevel, boolean shallIncludeSecondLevel, String model) {
// this test shall check for correct import statements (avoiding
// warnings) in case of hierachical structs
ModelLoader modelLoader = new ModelLoader(model);
Iterator<Resource> modelResourcesIterator = modelLoader.getResources().iterator();
Resource input = modelResourcesIterator.next();
assertFalse(modelResourcesIterator.hasNext());
FModel fModel = (FModel) input.getContents().get(0);
EList<FTypeCollection> typeCollections = fModel.getTypeCollections();
assertEquals(1, typeCollections.size());
boolean typeFound = false;
for (FType type : typeCollections.get(0).getTypes()) {
if (type.getName().equals(FIXTURE_TYPE_NAME)) {
if (type instanceof FCompoundType) {
typeFound = true;
Iterable<String> result = fixture.getRequiredIncludesFor((FCompoundType) type);
boolean topLevelStructAsInclude = false;
boolean secondLevelStructAsInclude = false;
for (String include : result) {
if (include.equals(TOP_LEVEL_STRUCT_INCLUDE)) {
topLevelStructAsInclude = true;
} else if (include.equals(SECOND_LEVEL_STRUCT_TYPE_NAME)) {
secondLevelStructAsInclude = true;
}
}
assertEquals(TOP_LEVEL_STRUCT_INCLUDE + " shall NOT be part of includes", shallIncludeTopLevel, topLevelStructAsInclude);
assertEquals(SECOND_LEVEL_STRUCT_TYPE_NAME + " shall be part of includes", shallIncludeSecondLevel, secondLevelStructAsInclude);
}
}
}
assertTrue(typeFound);
}
use of io.joynr.generator.loading.ModelLoader in project joynr by bmwcarit.
the class CppStdTypeUtilTest method setUp.
@Override
protected void setUp() throws Exception {
URL fixtureURL = CppStdTypeUtilTest.class.getResource("CppStdTypeUtil.fidl");
ModelLoader loader = new ModelLoader(fixtureURL.getPath());
Resource fixtureResource = loader.getResources().iterator().next();
cppStdTypeUtil = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Names.named("generationId")).to("");
bindConstant().annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_CLEAN)).to(false);
bindConstant().annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_GENERATE)).to(true);
install(new FactoryModuleBuilder().build(CppTemplateFactory.class));
}
}).getInstance(CppStdTypeUtil.class);
model = (FModel) fixtureResource.getContents().get(0);
}
use of io.joynr.generator.loading.ModelLoader in project joynr by bmwcarit.
the class Executor method generate.
public void generate() {
ModelLoader modelLoader = prepareGeneratorEnvironment();
for (Resource resource : modelLoader.getResources()) {
if (resource.getErrors().size() > 0) {
StringBuilder errorMsg = new StringBuilder();
errorMsg.append("Error loading model " + resource.getURI().toString() + ". The following errors occured: \n");
for (Diagnostic error : resource.getErrors()) {
errorMsg.append(error.getMessage());
}
logger.log(Level.SEVERE, errorMsg.toString());
System.exit(-1);
} else {
generator.doGenerate(resource, outputFileSystem);
}
}
}
use of io.joynr.generator.loading.ModelLoader in project joynr by bmwcarit.
the class SupportedFrancaFeatureCheckerTest method testIntegerTypeIsUsed_ExceptionIsThrown.
@Test
public void testIntegerTypeIsUsed_ExceptionIsThrown() {
URL fixtureURL = SupportedFrancaFeatureCheckerTest.class.getResource("IntegerTypeUsed.fidl");
ModelLoader loader = new ModelLoader(fixtureURL.getPath());
Resource fixtureResource = loader.getResources().iterator().next();
FModel model = (FModel) fixtureResource.getContents().get(0);
try {
SupportedFrancaFeatureChecker.checkModel(model);
fail("This line should not be reached, as an exception is expected when invoking checkModel");
} catch (Exception e) {
assertTrue(e.getMessage().contains("not supported"));
}
}
Aggregations