Skip to content

Commit 552b447

Browse files
committed
[Java] Add test showing that DTO generator handles constants correctly.
1 parent 7816d6b commit 552b447

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,9 @@ project(':sbe-tool') {
355355
'sbe.validation.xsd': validationXsdPath,
356356
'sbe.generate.precedence.checks': 'true',
357357
'sbe.java.precedence.checks.property.name': 'sbe.enable.test.precedence.checks',
358+
'sbe.keyword.append.token': 'KeywordSuffix',
358359
'sbe.java.generate.dtos': 'true')
359-
args = ['src/test/resources/example-extension-schema.xml']
360+
args = ['src/test/resources/example-extension-schema.xml', 'src/test/resources/dto-test-schema.xml']
360361
}
361362

362363
jar {

sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/DtoTest.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@
1616

1717
package uk.co.real_logic.sbe.generation.java;
1818

19-
import extension.*;
19+
import dto_test.KeywordsDto;
20+
import dto_test.KeywordsEncoder;
21+
import extension.BooleanType;
22+
import extension.BoostType;
23+
import extension.CarDecoder;
24+
import extension.CarDto;
25+
import extension.CarEncoder;
26+
import extension.Model;
2027
import org.agrona.ExpandableArrayBuffer;
2128
import org.agrona.MutableDirectBuffer;
2229
import org.junit.jupiter.api.Test;
2330

2431
import static org.hamcrest.MatcherAssert.assertThat;
2532
import static org.hamcrest.Matchers.equalTo;
33+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2634

2735
public class DtoTest
2836
{
@@ -65,6 +73,31 @@ void shouldRoundTripCar2()
6573
assertThat(outputBuffer.byteArray(), equalTo(inputBuffer.byteArray()));
6674
}
6775

76+
@Test
77+
void dtoWithKeywords()
78+
{
79+
final KeywordsDto dto = new KeywordsDto();
80+
dto.assertKeywordSuffix((short)42);
81+
dto.finalKeywordSuffix((short)7);
82+
final ExpandableArrayBuffer input = new ExpandableArrayBuffer();
83+
final KeywordsEncoder encoder = new KeywordsEncoder();
84+
encoder.wrap(input, 0);
85+
86+
KeywordsDto.encodeWith(encoder, dto);
87+
88+
final byte[] originalBytes = new byte[encoder.encodedLength()];
89+
input.getBytes(0, originalBytes);
90+
91+
final KeywordsDto otherDto =
92+
KeywordsDto.decodeFrom(input, 0, KeywordsEncoder.SCHEMA_VERSION, KeywordsEncoder.BLOCK_LENGTH);
93+
KeywordsDto.encodeWith(encoder, otherDto);
94+
95+
final byte[] otherBytes = new byte[encoder.encodedLength()];
96+
input.getBytes(0, otherBytes);
97+
98+
assertArrayEquals(originalBytes, otherBytes);
99+
}
100+
68101
private static int encodeCar(final MutableDirectBuffer buffer, final int offset)
69102
{
70103
final CarEncoder car = new CarEncoder();

sbe-tool/src/test/resources/dto-test-schema.xml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,61 @@
107107
<data name="activationCode" id="20" type="varDataEncoding"/>
108108
<data name="added5" id="25" type="varStringEncoding" sinceVersion="5"/>
109109
</sbe:message>
110+
111+
<sbe:message name="Keywords" id="3">
112+
<field name="abstract" id="1" type="uint8"/>
113+
<field name="assert" id="2" type="uint8"/>
114+
<field name="boolean" id="3" type="uint8"/>
115+
<field name="break" id="4" type="uint8"/>
116+
<field name="byte" id="5" type="uint8"/>
117+
<field name="case" id="6" type="uint8"/>
118+
<field name="catch" id="7" type="uint8"/>
119+
<field name="char" id="8" type="uint8"/>
120+
<field name="class" id="9" type="uint8"/>
121+
<field name="const" id="10" type="uint8"/>
122+
<field name="continue" id="11" type="uint8"/>
123+
<field name="default" id="12" type="uint8"/>
124+
<field name="do" id="13" type="uint8"/>
125+
<field name="double" id="14" type="uint8"/>
126+
<field name="else" id="15" type="uint8"/>
127+
<field name="enum" id="16" type="uint8"/>
128+
<field name="extends" id="17" type="uint8"/>
129+
<field name="final" id="18" type="uint8"/>
130+
<field name="finally" id="19" type="uint8"/>
131+
<field name="float" id="20" type="uint8"/>
132+
<field name="for" id="21" type="uint8"/>
133+
<field name="goto" id="22" type="uint8"/>
134+
<field name="if" id="23" type="uint8"/>
135+
<field name="implements" id="24" type="uint8"/>
136+
<field name="import" id="25" type="uint8"/>
137+
<field name="instanceof" id="26" type="uint8"/>
138+
<field name="int" id="27" type="uint8"/>
139+
<field name="interface" id="28" type="uint8"/>
140+
<field name="long" id="29" type="uint8"/>
141+
<field name="native" id="30" type="uint8"/>
142+
<field name="new" id="31" type="uint8"/>
143+
<field name="package" id="32" type="uint8"/>
144+
<field name="private" id="33" type="uint8"/>
145+
<field name="protected" id="34" type="uint8"/>
146+
<field name="public" id="35" type="uint8"/>
147+
<field name="return" id="36" type="uint8"/>
148+
<field name="short" id="37" type="uint8"/>
149+
<field name="static" id="38" type="uint8"/>
150+
<field name="strictfp" id="39" type="uint8"/>
151+
<field name="super" id="40" type="uint8"/>
152+
<field name="switch" id="41" type="uint8"/>
153+
<field name="synchronized" id="42" type="uint8"/>
154+
<field name="this" id="43" type="uint8"/>
155+
<field name="throw" id="44" type="uint8"/>
156+
<field name="throws" id="45" type="uint8"/>
157+
<field name="transient" id="46" type="uint8"/>
158+
<field name="try" id="47" type="uint8"/>
159+
<field name="void" id="48" type="uint8"/>
160+
<field name="volatile" id="49" type="uint8"/>
161+
<field name="while" id="50" type="uint8"/>
162+
<field name="null" id="51" type="uint8"/>
163+
<field name="true" id="52" type="uint8"/>
164+
<field name="false" id="53" type="uint8"/>
165+
<field name="_" id="54" type="uint8"/>
166+
</sbe:message>
110167
</sbe:messageSchema>

0 commit comments

Comments
 (0)