Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ project(':sbe-tool') {
'sbe.java.precedence.checks.property.name': 'sbe.enable.test.precedence.checks')
args = ['src/test/resources/json-printer-test-schema.xml',
'src/test/resources/composite-elements-schema.xml',
'src/test/resources/field-order-check-schema.xml']
'src/test/resources/field-order-check-schema.xml',
'src/test/resources/floating-point-infinity-schema.xml']
}

tasks.register('generateTestDtos', JavaExec) {
Expand All @@ -354,7 +355,9 @@ project(':sbe-tool') {
'sbe.java.precedence.checks.property.name': 'sbe.enable.test.precedence.checks',
'sbe.keyword.append.token': '$',
'sbe.java.generate.dtos': 'true')
args = ['src/test/resources/example-extension-schema.xml', 'src/test/resources/dto-test-schema.xml']
args = ['src/test/resources/example-extension-schema.xml',
'src/test/resources/dto-test-schema.xml',
'src/test/resources/floating-point-infinity-schema.xml']
}

jar {
Expand Down Expand Up @@ -684,6 +687,7 @@ tasks.register('generateRustTestCodecs', JavaExec) {
'sbe-tool/src/test/resources/issue1066.xml',
'sbe-tool/src/test/resources/issue1116.xml',
'sbe-tool/src/test/resources/issue1118.xml',
'sbe-tool/src/test/resources/floating-point-infinity-schema.xml',
'sbe-tool/src/test/resources/optional_enum_nullify.xml',
'sbe-tool/src/test/resources/basic-variable-length-schema.xml',
'sbe-tool/src/test/resources/example-bigendian-test-schema.xml',
Expand Down Expand Up @@ -805,6 +809,7 @@ tasks.register('generateGolangCodecsWithXSD', JavaExec) {
'sbe-tool/src/test/resources/issue847.xml',
'sbe-tool/src/test/resources/issue848.xml',
'sbe-tool/src/test/resources/issue849.xml',
'sbe-tool/src/test/resources/floating-point-infinity-schema.xml',
'sbe-tool/src/test/resources/since-deprecated-test-schema.xml',
'sbe-tool/src/test/resources/example-bigendian-test-schema.xml',
'gocode/resources/example-composite.xml',
Expand Down Expand Up @@ -891,6 +896,7 @@ tasks.register('generateGolangFlyweightCodecsWithXSD', JavaExec) {
'sbe-tool/src/test/resources/issue847.xml',
'sbe-tool/src/test/resources/issue848.xml',
'sbe-tool/src/test/resources/issue849.xml',
'sbe-tool/src/test/resources/floating-point-infinity-schema.xml',
'sbe-tool/src/test/resources/since-deprecated-test-schema.xml',
'sbe-tool/src/test/resources/example-bigendian-test-schema.xml',
'sbe-tool/src/test/resources/value-ref-with-lower-case-enum.xml',
Expand Down Expand Up @@ -953,6 +959,7 @@ tasks.register('generateCSharpTestCodecs', JavaExec) {
'sbe-tool/src/test/resources/since-deprecated-test-schema.xml',
'sbe-tool/src/test/resources/example-bigendian-test-schema.xml',
'sbe-tool/src/test/resources/field-order-check-schema.xml',
'sbe-tool/src/test/resources/floating-point-infinity-schema.xml',
'sbe-benchmarks/src/main/resources/fix-message-samples.xml']
}

Expand All @@ -966,7 +973,8 @@ tasks.register('generateCSharpTestDtos', JavaExec) {
'sbe.xinclude.aware': 'true',
'sbe.validation.xsd': validationXsdPath,
'sbe.types.package.override': 'true')
args = ['sbe-samples/src/main/resources/example-extension-schema.xml']
args = ['sbe-samples/src/main/resources/example-extension-schema.xml',
'sbe-tool/src/test/resources/floating-point-infinity-schema.xml']
}

tasks.register('generateCSharpExplicitPackageOverrideCodecs', JavaExec) {
Expand Down
62 changes: 62 additions & 0 deletions csharp/sbe-tests/InfinityTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Org.SbeTool.Sbe.Dll;
using Infinity_test;

namespace Org.SbeTool.Sbe.Tests
{
[TestClass]
public class InfinityTests
{
[TestMethod]
public void ShouldRenderWidthAndSignCorrectInfinityConstants()
{
var buffer = new DirectBuffer(new byte[24]);
var values = new InfinityValues();
values.WrapForEncode(buffer, 0);

Assert.AreEqual(0x7f800000, BitConverter.SingleToInt32Bits(values.FloatPositiveInfinity));
Assert.AreEqual(unchecked((int)0xff800000), BitConverter.SingleToInt32Bits(values.FloatNegativeInfinity));
Assert.AreEqual(0x7ff0000000000000L, BitConverter.DoubleToInt64Bits(values.DoublePositiveInfinity));
Assert.AreEqual(unchecked((long)0xfff0000000000000UL), BitConverter.DoubleToInt64Bits(values.DoubleNegativeInfinity));

Assert.AreEqual(0x7f800000, BitConverter.SingleToInt32Bits(InfinityValuesDto.FloatPositiveInfinity));
Assert.AreEqual(unchecked((int)0xff800000), BitConverter.SingleToInt32Bits(InfinityValuesDto.FloatNegativeInfinity));
Assert.AreEqual(0x7ff0000000000000L, BitConverter.DoubleToInt64Bits(InfinityValuesDto.DoublePositiveInfinity));
Assert.AreEqual(unchecked((long)0xfff0000000000000UL), BitConverter.DoubleToInt64Bits(InfinityValuesDto.DoubleNegativeInfinity));
Assert.AreEqual(0x7f800000, BitConverter.SingleToInt32Bits(FloatConstantsDto.Positive));
Assert.AreEqual(unchecked((int)0xff800000), BitConverter.SingleToInt32Bits(FloatConstantsDto.Negative));

Assert.AreEqual(unchecked((int)0xff800000), BitConverter.SingleToInt32Bits(InfinityValues.FloatPositiveNullMinValue));
Assert.AreEqual(1.5f, InfinityValues.FloatPositiveNullMaxValue);
Assert.AreEqual(-1.5f, InfinityValues.FloatNegativeNullMinValue);
Assert.AreEqual(0x7f800000, BitConverter.SingleToInt32Bits(InfinityValues.FloatNegativeNullMaxValue));
Assert.AreEqual(unchecked((long)0xfff0000000000000UL), BitConverter.DoubleToInt64Bits(InfinityValues.DoublePositiveNullMinValue));
Assert.AreEqual(1.5d, InfinityValues.DoublePositiveNullMaxValue);
Assert.AreEqual(-1.5d, InfinityValues.DoubleNegativeNullMinValue);
Assert.AreEqual(0x7ff0000000000000L, BitConverter.DoubleToInt64Bits(InfinityValues.DoubleNegativeNullMaxValue));

var constants = new FloatConstants();
constants.WrapForEncode(buffer, 0);
Assert.AreEqual(0x7f800000, BitConverter.SingleToInt32Bits(constants.Positive));
Assert.AreEqual(unchecked((int)0xff800000), BitConverter.SingleToInt32Bits(constants.Negative));
}

[TestMethod]
public void ShouldEncodeWidthAndSignCorrectOptionalNullValues()
{
var buffer = new DirectBuffer(new byte[24]);
var values = new InfinityValues();
values.WrapForEncode(buffer, 0);
values.FloatPositiveNull = InfinityValues.FloatPositiveNullNullValue;
values.FloatNegativeNull = InfinityValues.FloatNegativeNullNullValue;
values.DoublePositiveNull = InfinityValues.DoublePositiveNullNullValue;
values.DoubleNegativeNull = InfinityValues.DoubleNegativeNullNullValue;

Assert.AreEqual(0x7f800000, BitConverter.SingleToInt32Bits(values.FloatPositiveNull));
Assert.AreEqual(unchecked((int)0xff800000), BitConverter.SingleToInt32Bits(values.FloatNegativeNull));
Assert.AreEqual(0x7ff0000000000000L, BitConverter.DoubleToInt64Bits(values.DoublePositiveNull));
Assert.AreEqual(unchecked((long)0xfff0000000000000UL), BitConverter.DoubleToInt64Bits(values.DoubleNegativeNull));
}
}
}
4 changes: 2 additions & 2 deletions gocode/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ test: $(DEP)
go install \
;done))
(export GOPATH=$(GOPATH)/struct && \
(for t in baseline-bigendian mktdata group_with_data group_with_data_extension composite_elements composite since-deprecated simple issue435 issue472 issue483 issue488 issue560 issue847 issue848 issue849 issue505 test973; do \
(for t in baseline-bigendian mktdata group_with_data group_with_data_extension composite_elements composite since-deprecated simple issue435 issue472 issue483 issue488 issue560 issue847 issue848 issue849 issue505 test973 infinity_test; do \
cd $(GOPATH)/struct/src/$$t && \
go build && \
go fmt && \
Expand All @@ -95,7 +95,7 @@ test: $(DEP)
go install \
;done))
(export GOPATH=$(GOPATH)/flyweight && \
(for t in baseline-bigendian mktdata group_with_data group_with_data_extension composite_elements composite since-deprecated simple issue435 issue472 issue483 issue488 issue560 issue847 issue848 issue849; do \
(for t in baseline-bigendian mktdata group_with_data group_with_data_extension composite_elements composite since-deprecated simple issue435 issue472 issue483 issue488 issue560 issue847 issue848 issue849 infinity_test; do \
cd $(GOPATH)/flyweight/src/$$t && \
go build && \
go fmt && \
Expand Down
95 changes: 95 additions & 0 deletions gocode/flyweight/src/infinity_test/infinity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package infinity_test

import (
"math"
"testing"
)

func TestInfinityConstantsAndNullValues(t *testing.T) {
var values InfinityValues

if got := math.Float32bits(values.FloatPositiveInfinity()); got != 0x7f800000 {
t.Fatalf("unexpected FLOAT positive infinity bits: %#x", got)
}
if got := math.Float32bits(values.FloatNegativeInfinity()); got != 0xff800000 {
t.Fatalf("unexpected FLOAT negative infinity bits: %#x", got)
}
if got := math.Float64bits(values.DoublePositiveInfinity()); got != 0x7ff0000000000000 {
t.Fatalf("unexpected DOUBLE positive infinity bits: %#x", got)
}
if got := math.Float64bits(values.DoubleNegativeInfinity()); got != 0xfff0000000000000 {
t.Fatalf("unexpected DOUBLE negative infinity bits: %#x", got)
}

if got := math.Float32bits(values.FloatPositiveNullNullValue()); got != 0x7f800000 {
t.Fatalf("unexpected FLOAT positive null bits: %#x", got)
}
if got := math.Float32bits(values.FloatNegativeNullNullValue()); got != 0xff800000 {
t.Fatalf("unexpected FLOAT negative null bits: %#x", got)
}
if got := math.Float64bits(values.DoublePositiveNullNullValue()); got != 0x7ff0000000000000 {
t.Fatalf("unexpected DOUBLE positive null bits: %#x", got)
}
if got := math.Float64bits(values.DoubleNegativeNullNullValue()); got != 0xfff0000000000000 {
t.Fatalf("unexpected DOUBLE negative null bits: %#x", got)
}

if got := math.Float32bits(values.FloatPositiveNullMinValue()); got != 0xff800000 {
t.Fatalf("unexpected FLOAT positive null minimum bits: %#x", got)
}
if got := values.FloatPositiveNullMaxValue(); got != 1.5 {
t.Fatalf("unexpected FLOAT positive null maximum: %v", got)
}
if got := values.FloatNegativeNullMinValue(); got != -1.5 {
t.Fatalf("unexpected FLOAT negative null minimum: %v", got)
}
if got := math.Float32bits(values.FloatNegativeNullMaxValue()); got != 0x7f800000 {
t.Fatalf("unexpected FLOAT negative null maximum bits: %#x", got)
}
if got := math.Float64bits(values.DoublePositiveNullMinValue()); got != 0xfff0000000000000 {
t.Fatalf("unexpected DOUBLE positive null minimum bits: %#x", got)
}
if got := values.DoublePositiveNullMaxValue(); got != 1.5 {
t.Fatalf("unexpected DOUBLE positive null maximum: %v", got)
}
if got := values.DoubleNegativeNullMinValue(); got != -1.5 {
t.Fatalf("unexpected DOUBLE negative null minimum: %v", got)
}
if got := math.Float64bits(values.DoubleNegativeNullMaxValue()); got != 0x7ff0000000000000 {
t.Fatalf("unexpected DOUBLE negative null maximum bits: %#x", got)
}
}

func TestFloatConstants(t *testing.T) {
var values FloatConstants

if got := math.Float32bits(values.Positive()); got != 0x7f800000 {
t.Fatalf("unexpected FLOAT positive constant bits: %#x", got)
}
if got := math.Float32bits(values.Negative()); got != 0xff800000 {
t.Fatalf("unexpected FLOAT negative constant bits: %#x", got)
}
}

func TestInfinityValuesEncodeNulls(t *testing.T) {
var data [24]byte
var values InfinityValues
values.WrapForEncode(data[:], 0, uint64(len(data)))
values.SetFloatPositiveNull(values.FloatPositiveNullNullValue())
values.SetFloatNegativeNull(values.FloatNegativeNullNullValue())
values.SetDoublePositiveNull(values.DoublePositiveNullNullValue())
values.SetDoubleNegativeNull(values.DoubleNegativeNullNullValue())

if got := math.Float32bits(values.FloatPositiveNull()); got != 0x7f800000 {
t.Fatalf("unexpected encoded FLOAT positive null bits: %#x", got)
}
if got := math.Float32bits(values.FloatNegativeNull()); got != 0xff800000 {
t.Fatalf("unexpected encoded FLOAT negative null bits: %#x", got)
}
if got := math.Float64bits(values.DoublePositiveNull()); got != 0x7ff0000000000000 {
t.Fatalf("unexpected encoded DOUBLE positive null bits: %#x", got)
}
if got := math.Float64bits(values.DoubleNegativeNull()); got != 0xfff0000000000000 {
t.Fatalf("unexpected encoded DOUBLE negative null bits: %#x", got)
}
}
74 changes: 74 additions & 0 deletions gocode/struct/src/infinity_test/infinity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package infinity_test

import (
"math"
"testing"
)

func TestInfinityConstantsAndNullValues(t *testing.T) {
var values InfinityValues
InfinityValuesInit(&values)

if got := math.Float32bits(values.FloatPositiveInfinity); got != 0x7f800000 {
t.Fatalf("unexpected FLOAT positive infinity bits: %#x", got)
}
if got := math.Float32bits(values.FloatNegativeInfinity); got != 0xff800000 {
t.Fatalf("unexpected FLOAT negative infinity bits: %#x", got)
}
if got := math.Float64bits(values.DoublePositiveInfinity); got != 0x7ff0000000000000 {
t.Fatalf("unexpected DOUBLE positive infinity bits: %#x", got)
}
if got := math.Float64bits(values.DoubleNegativeInfinity); got != 0xfff0000000000000 {
t.Fatalf("unexpected DOUBLE negative infinity bits: %#x", got)
}

if got := math.Float32bits(values.FloatPositiveNull); got != 0x7f800000 {
t.Fatalf("unexpected FLOAT positive null bits: %#x", got)
}
if got := math.Float32bits(values.FloatNegativeNull); got != 0xff800000 {
t.Fatalf("unexpected FLOAT negative null bits: %#x", got)
}
if got := math.Float64bits(values.DoublePositiveNull); got != 0x7ff0000000000000 {
t.Fatalf("unexpected DOUBLE positive null bits: %#x", got)
}
if got := math.Float64bits(values.DoubleNegativeNull); got != 0xfff0000000000000 {
t.Fatalf("unexpected DOUBLE negative null bits: %#x", got)
}

if got := math.Float32bits(values.FloatPositiveNullMinValue()); got != 0xff800000 {
t.Fatalf("unexpected FLOAT positive null minimum bits: %#x", got)
}
if got := values.FloatPositiveNullMaxValue(); got != 1.5 {
t.Fatalf("unexpected FLOAT positive null maximum: %v", got)
}
if got := values.FloatNegativeNullMinValue(); got != -1.5 {
t.Fatalf("unexpected FLOAT negative null minimum: %v", got)
}
if got := math.Float32bits(values.FloatNegativeNullMaxValue()); got != 0x7f800000 {
t.Fatalf("unexpected FLOAT negative null maximum bits: %#x", got)
}
if got := math.Float64bits(values.DoublePositiveNullMinValue()); got != 0xfff0000000000000 {
t.Fatalf("unexpected DOUBLE positive null minimum bits: %#x", got)
}
if got := values.DoublePositiveNullMaxValue(); got != 1.5 {
t.Fatalf("unexpected DOUBLE positive null maximum: %v", got)
}
if got := values.DoubleNegativeNullMinValue(); got != -1.5 {
t.Fatalf("unexpected DOUBLE negative null minimum: %v", got)
}
if got := math.Float64bits(values.DoubleNegativeNullMaxValue()); got != 0x7ff0000000000000 {
t.Fatalf("unexpected DOUBLE negative null maximum bits: %#x", got)
}
}

func TestFloatConstants(t *testing.T) {
var values FloatConstants
FloatConstantsInit(&values)

if got := math.Float32bits(values.Positive); got != 0x7f800000 {
t.Fatalf("unexpected FLOAT positive constant bits: %#x", got)
}
if got := math.Float32bits(values.Negative); got != 0xff800000 {
t.Fatalf("unexpected FLOAT negative constant bits: %#x", got)
}
}
1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ issue_1057 = { path = "../generated/rust/issue1057" }
issue_1066 = { path = "../generated/rust/issue1066" }
issue_1116 = { path = "../generated/rust/issue1116" }
issue_1118 = { path = "../generated/rust/issue1118" }
infinity_test = { path = "../generated/rust/infinity_test" }
baseline_bigendian = { path = "../generated/rust/baseline_bigendian" }
nested_composite_name = { path = "../generated/rust/nested_composite_name" }
sbe_tests = { path = "../generated/rust/sbe_tests" }
Expand Down
49 changes: 49 additions & 0 deletions rust/tests/infinity_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use infinity_test::{
float_constants_codec::FloatConstantsDecoder,
infinity_values_codec::{self, InfinityValuesDecoder, InfinityValuesEncoder},
ReadBuf, WriteBuf,
};

#[test]
fn should_render_width_and_sign_correct_constants() {
let constants = FloatConstantsDecoder::default();
assert_eq!(constants.positive().to_bits(), 0x7f800000);
assert_eq!(constants.negative().to_bits(), 0xff800000);

let values = InfinityValuesDecoder::default();
assert_eq!(values.float_positive_infinity().to_bits(), 0x7f800000);
assert_eq!(values.float_negative_infinity().to_bits(), 0xff800000);
assert_eq!(
values.double_positive_infinity().to_bits(),
0x7ff0000000000000
);
assert_eq!(
values.double_negative_infinity().to_bits(),
0xfff0000000000000
);
}

#[test]
fn should_encode_and_decode_width_and_sign_correct_optional_null_values() {
let mut buffer = vec![0u8; infinity_values_codec::SBE_BLOCK_LENGTH as usize];
{
let mut encoder =
InfinityValuesEncoder::default().wrap(WriteBuf::new(buffer.as_mut_slice()), 0);
encoder
.float_positive_null_opt(None)
.float_negative_null_opt(None)
.double_positive_null_opt(None)
.double_negative_null_opt(None);
}

let decoder = InfinityValuesDecoder::default().wrap(
ReadBuf::new(&buffer),
0,
infinity_values_codec::SBE_BLOCK_LENGTH,
0,
);
assert!(decoder.float_positive_null().is_none());
assert!(decoder.float_negative_null().is_none());
assert!(decoder.double_positive_null().is_none());
assert!(decoder.double_negative_null().is_none());
}
Loading
Loading