Search in sources :

Example 21 with Enum

use of com.spectralogic.ds3autogen.c.models.Enum in project ds3_autogen by SpectraLogic.

the class CCodeGenerator_Test method testEnumTypesContainsTargetReadPreferenceType.

@Test
public void testEnumTypesContainsTargetReadPreferenceType() throws IOException, ParseException {
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec = parser.getSpec(CCodeGenerator_Test.class.getResourceAsStream("/input/3_2_2_contract.xml"));
    final ImmutableList<Enum> allEnums = CCodeGenerator.getAllEnums(spec);
    final ImmutableSet<String> enumNames = EnumHelper.getEnumNamesSet(allEnums);
    assertTrue(enumNames.contains("ds3_target_read_preference_type"));
}
Also used : Enum(com.spectralogic.ds3autogen.c.models.Enum) Ds3SpecParser(com.spectralogic.ds3autogen.api.Ds3SpecParser) Ds3SpecParserImpl(com.spectralogic.ds3autogen.Ds3SpecParserImpl) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec) Test(org.junit.Test)

Example 22 with Enum

use of com.spectralogic.ds3autogen.c.models.Enum in project ds3_autogen by SpectraLogic.

the class EnumHelper_Test method testRequiresMatcher.

@Test
public void testRequiresMatcher() {
    final Ds3EnumConstant alpha = new Ds3EnumConstant("Alpha", null);
    final Ds3EnumConstant bravo = new Ds3EnumConstant("Bravo", null);
    final ImmutableList<Ds3EnumConstant> enumConstants = ImmutableList.of(alpha, bravo);
    final Ds3Type testDs3Type = new Ds3Type("TypePrefix", null, null, enumConstants);
    final Enum testEnum = EnumConverter.toEnum(testDs3Type);
    assertTrue(testEnum.requiresMatcher());
}
Also used : Enum(com.spectralogic.ds3autogen.c.models.Enum) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3EnumConstant(com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant) Test(org.junit.Test)

Example 23 with Enum

use of com.spectralogic.ds3autogen.c.models.Enum in project ds3_autogen by SpectraLogic.

the class EnumHelper_Test method testEnumToString.

@Test
public void testEnumToString() {
    final Ds3EnumConstant alpha = new Ds3EnumConstant("Charlie", null);
    final Ds3EnumConstant bravo = new Ds3EnumConstant("Delta", null);
    final ImmutableList<Ds3EnumConstant> enumConstants = ImmutableList.of(alpha, bravo);
    final Ds3Type testDs3Type = new Ds3Type("TypePrefix", null, null, enumConstants);
    final Enum testEnum = EnumConverter.toEnum(testDs3Type);
    final String expectedOutput = "    if (input == DS3_TYPE_PREFIX_CHARLIE) {" + "\n" + "        return \"CHARLIE\";" + "\n" + "    } else if (input == DS3_TYPE_PREFIX_DELTA) {" + "\n" + "        return \"DELTA\";" + "\n" + "    } else {" + "\n" + "        return \"\";" + "\n" + "    }" + "\n";
    assertThat(EnumHelper.generateToString(testEnum), is(expectedOutput));
}
Also used : Enum(com.spectralogic.ds3autogen.c.models.Enum) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3EnumConstant(com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant) Test(org.junit.Test)

Example 24 with Enum

use of com.spectralogic.ds3autogen.c.models.Enum in project ds3_autogen by SpectraLogic.

the class HeaderConverter_Test method testToHeader.

@Test
public void testToHeader() throws ParseException {
    final Ds3DocSpec testDocSpec = new Ds3DocSpecEmptyImpl();
    final ImmutableList<Request> allRequests = ImmutableList.of(RequestConverter.toRequest(Ds3ModelFixtures.createBucketRequest(), testDocSpec), RequestConverter.toRequest(Ds3ModelFixtures.deleteBucketRequest(), testDocSpec), RequestConverter.toRequest(Ds3ModelFixtures.getBucketsRequest(), testDocSpec));
    final ImmutableList<Enum> allEnums = ImmutableList.of(new Enum("TestEnum", ImmutableList.of("TestEnumValue1", "TestEnumValue2")), new Enum("TestEnum2", ImmutableList.of("TestEnumValue3", "TestEnumValue4")));
    final ImmutableList<Struct> allStructs = ImmutableList.of(new Struct("testStruct1", ImmutableList.of(new StructMember(new PrimitiveType("int", false), "structMember1"), new StructMember(new PrimitiveType("ds3_str", true), "structMember2"))), new Struct("testStruct2", "marshallStruct2", ImmutableList.of(new StructMember(new PrimitiveType("int", false), "structMember3")), false, true, false, false));
    final Header testHeader = HeaderConverter.toHeader(allEnums, allStructs, allRequests);
    assertEquals(testHeader.getEnums(), allEnums);
    assertEquals(testHeader.getRequests(), allRequests);
    assertEquals(testHeader.getStructs(), allStructs);
}
Also used : Enum(com.spectralogic.ds3autogen.c.models.Enum) Ds3DocSpec(com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec) Ds3DocSpecEmptyImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl) Test(org.junit.Test)

Aggregations

Enum (com.spectralogic.ds3autogen.c.models.Enum)24 Test (org.junit.Test)24 TestFileUtilsImpl (com.spectralogic.ds3autogen.utils.TestFileUtilsImpl)16 Ds3SpecParserImpl (com.spectralogic.ds3autogen.Ds3SpecParserImpl)15 Ds3SpecParser (com.spectralogic.ds3autogen.api.Ds3SpecParser)15 Ds3ApiSpec (com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 Ds3DocSpecEmptyImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl)13 Ds3EnumConstant (com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant)5 Ds3Type (com.spectralogic.ds3autogen.api.models.apispec.Ds3Type)5 Ds3DocSpec (com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec)4 NameMapper (com.spectralogic.ds3autogen.NameMapper)3 Ds3DocSpecParser (com.spectralogic.ds3autogen.api.Ds3DocSpecParser)3 Ds3DocSpecParserImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecParserImpl)3 HashMap (java.util.HashMap)3 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1