Search in sources :

Example 1 with ParserOptions

use of uk.co.real_logic.sbe.xml.ParserOptions in project simple-binary-encoding by real-logic.

the class GenerateFixBinaryTest method shouldGenerateValidJava.

@Test
public void shouldGenerateValidJava() throws Exception {
    System.setProperty(SbeTool.KEYWORD_APPEND_TOKEN, "_");
    final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
    final MessageSchema schema = parse(TestUtil.getLocalResource("FixBinary.xml"), options);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    final JavaGenerator generator = new JavaGenerator(ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, outputManager);
    outputManager.setPackageName(ir.applicableNamespace());
    generator.generateMessageHeaderStub();
    generator.generateTypeStubs();
    generator.generate();
    final Map<String, CharSequence> sources = outputManager.getSources();
    final String className = "MDIncrementalRefreshTradeSummary42Decoder";
    final String fqClassName = ir.applicableNamespace() + "." + className;
    final Class<?> aClass = CompilerUtil.compileInMemory(fqClassName, sources);
    assertNotNull(aClass);
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) ParserOptions(uk.co.real_logic.sbe.xml.ParserOptions) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) Ir(uk.co.real_logic.sbe.ir.Ir) Test(org.junit.Test)

Example 2 with ParserOptions

use of uk.co.real_logic.sbe.xml.ParserOptions in project simple-binary-encoding by real-logic.

the class SchemaExtensionTest method setup.

@Before
public void setup() throws Exception {
    final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
    final MessageSchema schema = parse(TestUtil.getLocalResource("extension-schema.xml"), options);
    final IrGenerator irg = new IrGenerator();
    ir = irg.generate(schema);
    outputManager.clear();
    outputManager.setPackageName(ir.applicableNamespace());
    generator().generate();
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) ParserOptions(uk.co.real_logic.sbe.xml.ParserOptions) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) Before(org.junit.Before)

Example 3 with ParserOptions

use of uk.co.real_logic.sbe.xml.ParserOptions in project simple-binary-encoding by real-logic.

the class JavaGeneratorTest method setUp.

@Before
public void setUp() throws Exception {
    final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
    final MessageSchema schema = parse(TestUtil.getLocalResource("code-generation-schema.xml"), options);
    final IrGenerator irg = new IrGenerator();
    ir = irg.generate(schema);
    outputManager.clear();
    outputManager.setPackageName(ir.applicableNamespace());
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) ParserOptions(uk.co.real_logic.sbe.xml.ParserOptions) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) Before(org.junit.Before)

Example 4 with ParserOptions

use of uk.co.real_logic.sbe.xml.ParserOptions in project simple-binary-encoding by real-logic.

the class ConstantCharArrayTest method shouldGenerateConstCharArrayMethods.

@Test
public void shouldGenerateConstCharArrayMethods() throws Exception {
    final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
    final MessageSchema schema = parse(TestUtil.getLocalResource("issue505.xml"), options);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    final StringWriterOutputManager outputManager = new StringWriterOutputManager();
    outputManager.setPackageName(ir.applicableNamespace());
    final JavaGenerator generator = new JavaGenerator(ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, outputManager);
    generator.generate();
    final String sources = outputManager.getSources().toString();
    final String expectedOne = "    public byte sourceOne()\n" + "    {\n" + "        return (byte)67;\n" + "    }";
    assertThat(sources, containsString(expectedOne));
    final String expectedTwo = "    public byte sourceTwo()\n" + "    {\n" + "        return (byte)68;\n" + "    }";
    assertThat(sources, containsString(expectedTwo));
    final String expectedThree = "    public String sourceThree()\n" + "    {\n" + "        return \"EF\";\n" + "    }";
    assertThat(sources, containsString(expectedThree));
    final String expectedFour = "    public String sourceFour()\n" + "    {\n" + "        return \"GH\";\n" + "    }";
    assertThat(sources, containsString(expectedFour));
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) ParserOptions(uk.co.real_logic.sbe.xml.ParserOptions) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) StringWriterOutputManager(org.agrona.generation.StringWriterOutputManager) Ir(uk.co.real_logic.sbe.ir.Ir) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 5 with ParserOptions

use of uk.co.real_logic.sbe.xml.ParserOptions in project simple-binary-encoding by real-logic.

the class GenerateFixBinaryTest method shouldGenerateAndEncodeIr.

@Test
public void shouldGenerateAndEncodeIr() throws Exception {
    System.setProperty(SbeTool.KEYWORD_APPEND_TOKEN, "_");
    final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
    final MessageSchema schema = parse(TestUtil.getLocalResource("FixBinary.xml"), options);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    final ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
    final IrEncoder irEncoder = new IrEncoder(buffer, ir);
    irEncoder.encode();
    buffer.flip();
    final IrDecoder irDecoder = new IrDecoder(buffer);
    final Ir decodedIr = irDecoder.decode();
    assertEquals(ir.id(), decodedIr.id());
    assertEquals(ir.version(), decodedIr.version());
    assertEquals(ir.byteOrder(), decodedIr.byteOrder());
    assertEquals(ir.applicableNamespace(), decodedIr.applicableNamespace());
    assertEquals(ir.packageName(), decodedIr.packageName());
    assertEquals(ir.types().size(), decodedIr.types().size());
    assertEquals(ir.messages().size(), decodedIr.messages().size());
}
Also used : IrEncoder(uk.co.real_logic.sbe.ir.IrEncoder) IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) ParserOptions(uk.co.real_logic.sbe.xml.ParserOptions) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) Ir(uk.co.real_logic.sbe.ir.Ir) IrDecoder(uk.co.real_logic.sbe.ir.IrDecoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

IrGenerator (uk.co.real_logic.sbe.xml.IrGenerator)6 MessageSchema (uk.co.real_logic.sbe.xml.MessageSchema)6 ParserOptions (uk.co.real_logic.sbe.xml.ParserOptions)6 Test (org.junit.Test)3 Ir (uk.co.real_logic.sbe.ir.Ir)3 Before (org.junit.Before)2 ByteBuffer (java.nio.ByteBuffer)1 StringWriterOutputManager (org.agrona.generation.StringWriterOutputManager)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 IrDecoder (uk.co.real_logic.sbe.ir.IrDecoder)1 IrEncoder (uk.co.real_logic.sbe.ir.IrEncoder)1