Skip to content

Commit 28c481a

Browse files
committed
[C#] Add a test that checks generation succeeds when using a constrained uint32 as the group size representation.
1 parent 6d1c731 commit 28c481a

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
public class Issue567GroupSizeTest
1515
{
16-
17-
@Test(expected = Exception.class)
16+
@Test(expected = IllegalArgumentException.class)
1817
public void shouldThrowWhenUsingATypeThatIsNotConstrainedToFitInAnIntAsTheGroupSize() throws Exception
1918
{
2019
// Arrange
@@ -27,8 +26,24 @@ public void shouldThrowWhenUsingATypeThatIsNotConstrainedToFitInAnIntAsTheGroupS
2726
outputManager.setPackageName(ir.applicableNamespace());
2827
final CSharpGenerator generator = new CSharpGenerator(ir, outputManager);
2928

30-
// Act + Assert
29+
// Act + Assert (exception thrown)
3130
generator.generate();
3231
}
3332

33+
@Test
34+
public void shouldGenerateWhenUsingATypeThatIsConstrainedToFitInAnIntAsTheGroupSize() throws Exception
35+
{
36+
// Arrange
37+
final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
38+
final MessageSchema schema = parse(TestUtil.getLocalResource("issue567-valid.xml"), options);
39+
final IrGenerator irg = new IrGenerator();
40+
final Ir ir = irg.generate(schema);
41+
42+
final StringWriterOutputManager outputManager = new StringWriterOutputManager();
43+
outputManager.setPackageName(ir.applicableNamespace());
44+
final CSharpGenerator generator = new CSharpGenerator(ir, outputManager);
45+
46+
// Act + Assert (no exception)
47+
generator.generate();
48+
}
3449
}

sbe-tool/src/test/resources/issue567-invalid.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
22
<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe"
3-
package="issue567"
3+
package="issue567Invalid"
44
id="567"
55
version="0"
66
semanticVersion="5.2"
@@ -31,7 +31,9 @@
3131
<type name="id" primitiveType="int32" />
3232
</composite>
3333
</types>
34-
<sbe:message name="issue567" id="1" description="issue 560 test">
35-
<field name="groupField" id="1" type="issue567Element" />
34+
<sbe:message name="issue567" id="1" description="issue 567 test">
35+
<group name="group" id="1">
36+
<field name="groupField" id="2" type="issue567Element" />
37+
</group>
3638
</sbe:message>
3739
</sbe:messageSchema>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe"
3+
package="issue567Valid"
4+
id="567"
5+
version="0"
6+
semanticVersion="5.2"
7+
description="issue 567 example where group size doesn't fit in an int32"
8+
byteOrder="littleEndian">
9+
<types>
10+
<composite name="messageHeader" description="Message identifiers and length of message root">
11+
<type name="blockLength" primitiveType="uint16"/>
12+
<type name="templateId" primitiveType="uint16"/>
13+
<type name="schemaId" primitiveType="uint16"/>
14+
<type name="version" primitiveType="uint16"/>
15+
</composite>
16+
<composite name="groupSizeEncoding" description="Repeating group dimensions">
17+
<type name="blockLength" primitiveType="uint16"/>
18+
<type name="numInGroup" primitiveType="uint32" maxValue="2147483647" />
19+
</composite>
20+
<composite name="varStringEncoding">
21+
<type name="length" primitiveType="uint32" maxValue="1073741824"/>
22+
<type name="varData" primitiveType="uint8" length="0" characterEncoding="UTF-8"/>
23+
</composite>
24+
<composite name="varDataEncoding">
25+
<type name="length" primitiveType="uint32" maxValue="1073741824"/>
26+
<type name="varData" primitiveType="uint8" length="0"/>
27+
</composite>
28+
</types>
29+
<types>
30+
<composite name="issue567Element" description="element for group exposing issue 567">
31+
<type name="id" primitiveType="int32" />
32+
</composite>
33+
</types>
34+
<sbe:message name="issue567" id="1" description="issue 567 test">
35+
<group name="group" id="1">
36+
<field name="groupField" id="2" type="issue567Element" />
37+
</group>
38+
</sbe:message>
39+
</sbe:messageSchema>

0 commit comments

Comments
 (0)