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