Skip to content

Commit 2703c9b

Browse files
committed
Add tests.
1 parent f7b24ab commit 2703c9b

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ tasks.register('generateRustTestCodecs', JavaExec) {
672672
'sbe-tool/src/test/resources/issue984.xml',
673673
'sbe-tool/src/test/resources/issue987.xml',
674674
'sbe-tool/src/test/resources/issue1028.xml',
675+
'sbe-tool/src/test/resources/issue1060.xml',
675676
'sbe-tool/src/test/resources/fixed-sized-primitive-array-types.xml',
676677
'sbe-tool/src/test/resources/example-bigendian-test-schema.xml',
677678
'sbe-tool/src/test/resources/nested-composite-name.xml',

rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ issue_972 = { path = "../generated/rust/issue972" }
1717
issue_984 = { path = "../generated/rust/issue984" }
1818
issue_987 = { path = "../generated/rust/issue987" }
1919
issue_1028 = { path = "../generated/rust/issue1028" }
20+
issue_1060 = { path = "../generated/rust/issue1060" }
2021
baseline_bigendian = { path = "../generated/rust/baseline-bigendian" }
2122
nested_composite_name = { path = "../generated/rust/nested-composite-name" }
2223
fixed_sized_primitive_array = { path = "../generated/rust/fixed_sized_primitive_array" }

rust/tests/issue_1060_test.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use issue_1060::{
2+
issue_1060_codec,
3+
issue_1060_codec::{Issue1060Decoder, Issue1060Encoder},
4+
*,
5+
};
6+
7+
#[test]
8+
fn decode_optional_primitive_field() {
9+
let mut buffer = vec![0u8; 256];
10+
11+
// Create a message with `field` set.
12+
let mut encoder = Issue1060Encoder::default().wrap(
13+
WriteBuf::new(&mut buffer),
14+
message_header_codec::ENCODED_LENGTH,
15+
);
16+
encoder.field(10);
17+
18+
// Drop encoder to drop the mut reference for the buffer.
19+
drop(encoder);
20+
21+
// Create a decoder for the message, but stating that the version is 1, instead of 2
22+
// which is the acting version for `field`. Thus, `field()` must return `None`.
23+
let decoder = Issue1060Decoder::default().wrap(
24+
ReadBuf::new(&mut buffer),
25+
message_header_codec::ENCODED_LENGTH,
26+
issue_1060_codec::SBE_BLOCK_LENGTH,
27+
1,
28+
);
29+
assert!(decoder.field().is_none());
30+
31+
// Create a decoder for the message, but stating that the version is 1, instead of 2
32+
// which is the acting version for `field`. Thus, `field()` must return `None`.
33+
let decoder = Issue1060Decoder::default().wrap(
34+
ReadBuf::new(&mut buffer),
35+
message_header_codec::ENCODED_LENGTH,
36+
issue_1060_codec::SBE_BLOCK_LENGTH,
37+
2,
38+
);
39+
assert_eq!(decoder.field(), Some(10));
40+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe" package="issue1060" id="1060" version="2"
2+
semanticVersion="1.0.0" byteOrder="littleEndian">
3+
<types>
4+
<composite name="messageHeader">
5+
<type name="blockLength" primitiveType="uint16"
6+
description="Length of the root of the FIX message contained before repeating groups or variable/conditions fields." />
7+
<type name="templateId" primitiveType="uint16"
8+
description="Template ID used to encode the message." />
9+
<type name="schemaId" primitiveType="uint16"
10+
description="ID of the system publishing the message." />
11+
<type name="version" primitiveType="uint16" description="Schema version." />
12+
</composite>
13+
</types>
14+
<message name="issue1060" id="1">
15+
<field name="field" id="1" type="uint16" semanticType="Int" sinceVersion="2"
16+
presence="optional" />
17+
</message>
18+
</messageSchema>

0 commit comments

Comments
 (0)