Search in sources :

Example 1 with FCompoundType

use of org.franca.core.franca.FCompoundType in project joynr by bmwcarit.

the class CppStdTypeUtilTest method testGetRootType.

private void testGetRootType(FInterface francaIntf, Class<? extends FCompoundType> type) {
    FType base = francaIntf.getTypes().get(0);
    FType fixture = francaIntf.getTypes().get(1);
    assertTrue(type.isAssignableFrom(base.getClass()));
    assertTrue(type.isAssignableFrom(base.getClass()));
    /* this test ensures that no runtime exceptions of the generator occur */
    assertEquals(base, cppStdTypeUtil.getRootType((FCompoundType) fixture));
    assertEquals(base, cppStdTypeUtil.getRootType((FCompoundType) base));
}
Also used : FCompoundType(org.franca.core.franca.FCompoundType) FType(org.franca.core.franca.FType)

Example 2 with FCompoundType

use of org.franca.core.franca.FCompoundType 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);
}
Also used : FCompoundType(org.franca.core.franca.FCompoundType) ModelLoader(io.joynr.generator.loading.ModelLoader) FType(org.franca.core.franca.FType) FTypeCollection(org.franca.core.franca.FTypeCollection) FModel(org.franca.core.franca.FModel) Resource(org.eclipse.emf.ecore.resource.Resource)

Example 3 with FCompoundType

use of org.franca.core.franca.FCompoundType in project joynr by bmwcarit.

the class TypeUtilTest method testRecurstiveStruct.

@Test
public void testRecurstiveStruct() throws Exception {
    FStructType structType = FrancaFactory.eINSTANCE.createFStructType();
    structType.setName("TestStruct");
    FField field = FrancaFactory.eINSTANCE.createFField();
    field.setName("exampleField");
    field.setArray(true);
    FTypeRef typeRef = FrancaFactory.eINSTANCE.createFTypeRef();
    typeRef.setDerived(structType);
    field.setType(typeRef);
    structType.getElements().add(field);
    TypeUtil typeUtil = Guice.createInjector().getInstance(TypeUtil.class);
    FCompoundType result = typeUtil.getCompoundType(structType);
    assertEquals(structType, result);
}
Also used : FCompoundType(org.franca.core.franca.FCompoundType) FStructType(org.franca.core.franca.FStructType) FTypeRef(org.franca.core.franca.FTypeRef) FField(org.franca.core.franca.FField) Test(org.junit.Test)

Aggregations

FCompoundType (org.franca.core.franca.FCompoundType)3 FType (org.franca.core.franca.FType)2 ModelLoader (io.joynr.generator.loading.ModelLoader)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 FField (org.franca.core.franca.FField)1 FModel (org.franca.core.franca.FModel)1 FStructType (org.franca.core.franca.FStructType)1 FTypeCollection (org.franca.core.franca.FTypeCollection)1 FTypeRef (org.franca.core.franca.FTypeRef)1 Test (org.junit.Test)1