Skip to content

Commit f72be51

Browse files
committed
[C#] Add a broken test for issue #564.
1 parent abdc9d3 commit f72be51

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

csharp/sbe-tests/Issue564Tests.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using Baseline;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using Org.SbeTool.Sbe.Dll;
5+
6+
namespace Org.SbeTool.Sbe.Tests
7+
{
8+
[TestClass]
9+
public class Issue564Tests
10+
{
11+
[TestMethod]
12+
public void ShouldFailToEncodeGroupsThatExceedTheMaximumRepresentableSize()
13+
{
14+
// Arrange
15+
var expectedSize = 1024 + (8 + 8 + 8 + 20) * ushort.MaxValue;
16+
var buffer = new DirectBuffer(new byte[expectedSize]);
17+
var car = new Car();
18+
car.WrapForEncode(buffer, 0);
19+
car.SerialNumber = 1234;
20+
car.ModelYear = 2013;
21+
car.Available = BooleanType.T;
22+
car.Code = Model.A;
23+
for (int i = 0, size = Car.SomeNumbersLength; i < size; i++)
24+
{
25+
car.SetSomeNumbers(i, (uint)i);
26+
}
27+
car.SetVehicleCode(System.Text.Encoding.ASCII.GetBytes("abcdef"), 0);
28+
car.Extras = OptionalExtras.CruiseControl | OptionalExtras.SportsPack;
29+
30+
car.Engine.Capacity = 2000;
31+
car.Engine.NumCylinders = 4;
32+
car.Engine.SetManufacturerCode(System.Text.Encoding.ASCII.GetBytes("123"), 0);
33+
car.Engine.Efficiency = 35;
34+
car.Engine.BoosterEnabled = BooleanType.T;
35+
car.Engine.Booster.BoostType = BoostType.NITROUS;
36+
car.Engine.Booster.HorsePower = 200;
37+
38+
// Act + Assert
39+
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
40+
{
41+
int countUnrepresentableByGroupSizeEncoding = 1 + ushort.MaxValue;
42+
var fuelFigures = car.FuelFiguresCount(countUnrepresentableByGroupSizeEncoding);
43+
for (int i = 0; i < countUnrepresentableByGroupSizeEncoding; i++)
44+
{
45+
fuelFigures.Next();
46+
fuelFigures.Speed = 30;
47+
fuelFigures.Mpg = 35.9f;
48+
var description = System.Text.Encoding.ASCII.GetBytes($"i={i}");
49+
fuelFigures.SetUsageDescription(description, 0, description.Length);
50+
}
51+
});
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)