@ -38,11 +38,10 @@ using System;
using System.Collections.Generic ;
using System.IO ;
using Google.ProtocolBuffers.TestProtos ;
using Microsoft.VisualStudio.TestTools.UnitTesting ;
using Xunit ;
namespace Google.ProtocolBuffers
{
[TestClass]
public class CodedOutputStreamTest
{
/// <summary>
@ -58,9 +57,9 @@ namespace Google.ProtocolBuffers
CodedOutputStream output = CodedOutputStream . CreateInstance ( rawOutput ) ;
output . WriteRawVarint32 ( ( uint ) value ) ;
output . Flush ( ) ;
TestUtil . AssertBytes Equal( data , rawOutput . ToArray ( ) ) ;
Assert . Equal ( data , rawOutput . ToArray ( ) ) ;
// Also try computing size.
Assert . Are Equal( data . Length , CodedOutputStream . ComputeRawVarint32Size ( ( uint ) value ) ) ;
Assert . Equal ( data . Length , CodedOutputStream . ComputeRawVarint32Size ( ( uint ) value ) ) ;
}
{
@ -68,10 +67,10 @@ namespace Google.ProtocolBuffers
CodedOutputStream output = CodedOutputStream . CreateInstance ( rawOutput ) ;
output . WriteRawVarint64 ( value ) ;
output . Flush ( ) ;
TestUtil . AssertBytes Equal( data , rawOutput . ToArray ( ) ) ;
Assert . Equal ( data , rawOutput . ToArray ( ) ) ;
// Also try computing size.
Assert . Are Equal( data . Length , CodedOutputStream . ComputeRawVarint64Size ( value ) ) ;
Assert . Equal ( data . Length , CodedOutputStream . ComputeRawVarint64Size ( value ) ) ;
}
// Try different buffer sizes.
@ -85,7 +84,7 @@ namespace Google.ProtocolBuffers
CodedOutputStream . CreateInstance ( rawOutput , bufferSize ) ;
output . WriteRawVarint32 ( ( uint ) value ) ;
output . Flush ( ) ;
TestUtil . AssertBytes Equal( data , rawOutput . ToArray ( ) ) ;
Assert . Equal ( data , rawOutput . ToArray ( ) ) ;
}
{
@ -93,7 +92,7 @@ namespace Google.ProtocolBuffers
CodedOutputStream output = CodedOutputStream . CreateInstance ( rawOutput , bufferSize ) ;
output . WriteRawVarint64 ( value ) ;
output . Flush ( ) ;
TestUtil . AssertBytes Equal( data , rawOutput . ToArray ( ) ) ;
Assert . Equal ( data , rawOutput . ToArray ( ) ) ;
}
}
}
@ -101,7 +100,7 @@ namespace Google.ProtocolBuffers
/// <summary>
/// Tests WriteRawVarint32() and WriteRawVarint64()
/// </summary>
[TestMethod ]
[Fact ]
public void WriteVarint ( )
{
AssertWriteVarint ( new byte [ ] { 0x00 } , 0 ) ;
@ -143,7 +142,7 @@ namespace Google.ProtocolBuffers
CodedOutputStream output = CodedOutputStream . CreateInstance ( rawOutput ) ;
output . WriteRawLittleEndian32 ( value ) ;
output . Flush ( ) ;
TestUtil . AssertBytes Equal( data , rawOutput . ToArray ( ) ) ;
Assert . Equal ( data , rawOutput . ToArray ( ) ) ;
// Try different buffer sizes.
for ( int bufferSize = 1 ; bufferSize < = 1 6 ; bufferSize * = 2 )
@ -152,7 +151,7 @@ namespace Google.ProtocolBuffers
output = CodedOutputStream . CreateInstance ( rawOutput , bufferSize ) ;
output . WriteRawLittleEndian32 ( value ) ;
output . Flush ( ) ;
TestUtil . AssertBytes Equal( data , rawOutput . ToArray ( ) ) ;
Assert . Equal ( data , rawOutput . ToArray ( ) ) ;
}
}
@ -166,7 +165,7 @@ namespace Google.ProtocolBuffers
CodedOutputStream output = CodedOutputStream . CreateInstance ( rawOutput ) ;
output . WriteRawLittleEndian64 ( value ) ;
output . Flush ( ) ;
TestUtil . AssertBytes Equal( data , rawOutput . ToArray ( ) ) ;
Assert . Equal ( data , rawOutput . ToArray ( ) ) ;
// Try different block sizes.
for ( int blockSize = 1 ; blockSize < = 1 6 ; blockSize * = 2 )
@ -175,14 +174,14 @@ namespace Google.ProtocolBuffers
output = CodedOutputStream . CreateInstance ( rawOutput , blockSize ) ;
output . WriteRawLittleEndian64 ( value ) ;
output . Flush ( ) ;
TestUtil . AssertBytes Equal( data , rawOutput . ToArray ( ) ) ;
Assert . Equal ( data , rawOutput . ToArray ( ) ) ;
}
}
/// <summary>
/// Tests writeRawLittleEndian32() and writeRawLittleEndian64().
/// </summary>
[TestMethod ]
[Fact ]
public void WriteLittleEndian ( )
{
AssertWriteLittleEndian32 ( new byte [ ] { 0x78 , 0x56 , 0x34 , 0x12 } , 0x12345678 ) ;
@ -196,7 +195,7 @@ namespace Google.ProtocolBuffers
0x9abcdef012345678 UL ) ;
}
[TestMethod ]
[Fact ]
public void WriteWholeMessage ( )
{
TestAllTypes message = TestUtil . GetAllSet ( ) ;
@ -220,7 +219,7 @@ namespace Google.ProtocolBuffers
/// Tests writing a whole message with every packed field type. Ensures the
/// wire format of packed fields is compatible with C++.
/// </summary>
[TestMethod ]
[Fact ]
public void WriteWholePackedFieldsMessage ( )
{
TestPackedTypes message = TestUtil . GetPackedSet ( ) ;
@ -230,97 +229,97 @@ namespace Google.ProtocolBuffers
rawBytes ) ;
}
[TestMethod ]
[Fact ]
public void EncodeZigZag32 ( )
{
Assert . Are Equal( 0 u , CodedOutputStream . EncodeZigZag32 ( 0 ) ) ;
Assert . Are Equal( 1 u , CodedOutputStream . EncodeZigZag32 ( - 1 ) ) ;
Assert . Are Equal( 2 u , CodedOutputStream . EncodeZigZag32 ( 1 ) ) ;
Assert . Are Equal( 3 u , CodedOutputStream . EncodeZigZag32 ( - 2 ) ) ;
Assert . Are Equal( 0x7FFFFFFE u , CodedOutputStream . EncodeZigZag32 ( 0x3FFFFFFF ) ) ;
Assert . Are Equal( 0x7FFFFFFF u , CodedOutputStream . EncodeZigZag32 ( unchecked ( ( int ) 0xC0000000 ) ) ) ;
Assert . Are Equal( 0xFFFFFFFE u , CodedOutputStream . EncodeZigZag32 ( 0x7FFFFFFF ) ) ;
Assert . Are Equal( 0xFFFFFFFF u , CodedOutputStream . EncodeZigZag32 ( unchecked ( ( int ) 0x80000000 ) ) ) ;
Assert . Equal ( 0 u , CodedOutputStream . EncodeZigZag32 ( 0 ) ) ;
Assert . Equal ( 1 u , CodedOutputStream . EncodeZigZag32 ( - 1 ) ) ;
Assert . Equal ( 2 u , CodedOutputStream . EncodeZigZag32 ( 1 ) ) ;
Assert . Equal ( 3 u , CodedOutputStream . EncodeZigZag32 ( - 2 ) ) ;
Assert . Equal ( 0x7FFFFFFE u , CodedOutputStream . EncodeZigZag32 ( 0x3FFFFFFF ) ) ;
Assert . Equal ( 0x7FFFFFFF u , CodedOutputStream . EncodeZigZag32 ( unchecked ( ( int ) 0xC0000000 ) ) ) ;
Assert . Equal ( 0xFFFFFFFE u , CodedOutputStream . EncodeZigZag32 ( 0x7FFFFFFF ) ) ;
Assert . Equal ( 0xFFFFFFFF u , CodedOutputStream . EncodeZigZag32 ( unchecked ( ( int ) 0x80000000 ) ) ) ;
}
[TestMethod ]
[Fact ]
public void EncodeZigZag64 ( )
{
Assert . Are Equal( 0 u , CodedOutputStream . EncodeZigZag64 ( 0 ) ) ;
Assert . Are Equal( 1 u , CodedOutputStream . EncodeZigZag64 ( - 1 ) ) ;
Assert . Are Equal( 2 u , CodedOutputStream . EncodeZigZag64 ( 1 ) ) ;
Assert . Are Equal( 3 u , CodedOutputStream . EncodeZigZag64 ( - 2 ) ) ;
Assert . Are Equal( 0x000000007FFFFFFE uL ,
Assert . Equal ( 0 u , CodedOutputStream . EncodeZigZag64 ( 0 ) ) ;
Assert . Equal ( 1 u , CodedOutputStream . EncodeZigZag64 ( - 1 ) ) ;
Assert . Equal ( 2 u , CodedOutputStream . EncodeZigZag64 ( 1 ) ) ;
Assert . Equal ( 3 u , CodedOutputStream . EncodeZigZag64 ( - 2 ) ) ;
Assert . Equal ( 0x000000007FFFFFFE uL ,
CodedOutputStream . EncodeZigZag64 ( unchecked ( ( long ) 0x000000003FFFFFFF UL ) ) ) ;
Assert . Are Equal( 0x000000007FFFFFFF uL ,
Assert . Equal ( 0x000000007FFFFFFF uL ,
CodedOutputStream . EncodeZigZag64 ( unchecked ( ( long ) 0xFFFFFFFFC0000000 UL ) ) ) ;
Assert . Are Equal( 0x00000000FFFFFFFE uL ,
Assert . Equal ( 0x00000000FFFFFFFE uL ,
CodedOutputStream . EncodeZigZag64 ( unchecked ( ( long ) 0x000000007FFFFFFF UL ) ) ) ;
Assert . Are Equal( 0x00000000FFFFFFFF uL ,
Assert . Equal ( 0x00000000FFFFFFFF uL ,
CodedOutputStream . EncodeZigZag64 ( unchecked ( ( long ) 0xFFFFFFFF80000000 UL ) ) ) ;
Assert . Are Equal( 0xFFFFFFFFFFFFFFFEL ,
Assert . Equal ( 0xFFFFFFFFFFFFFFFEL ,
CodedOutputStream . EncodeZigZag64 ( unchecked ( ( long ) 0x7FFFFFFFFFFFFFFF UL ) ) ) ;
Assert . Are Equal( 0xFFFFFFFFFFFFFFFFL ,
Assert . Equal ( 0xFFFFFFFFFFFFFFFFL ,
CodedOutputStream . EncodeZigZag64 ( unchecked ( ( long ) 0x8000000000000000 UL ) ) ) ;
}
[TestMethod ]
[Fact ]
public void RoundTripZigZag32 ( )
{
// Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1)
// were chosen semi-randomly via keyboard bashing.
Assert . Are Equal( 0 , CodedInputStream . DecodeZigZag32 ( CodedOutputStream . EncodeZigZag32 ( 0 ) ) ) ;
Assert . Are Equal( 1 , CodedInputStream . DecodeZigZag32 ( CodedOutputStream . EncodeZigZag32 ( 1 ) ) ) ;
Assert . Are Equal( - 1 , CodedInputStream . DecodeZigZag32 ( CodedOutputStream . EncodeZigZag32 ( - 1 ) ) ) ;
Assert . Are Equal( 1 4 9 2 7 , CodedInputStream . DecodeZigZag32 ( CodedOutputStream . EncodeZigZag32 ( 1 4 9 2 7 ) ) ) ;
Assert . Are Equal( - 3 6 1 2 , CodedInputStream . DecodeZigZag32 ( CodedOutputStream . EncodeZigZag32 ( - 3 6 1 2 ) ) ) ;
Assert . Equal ( 0 , CodedInputStream . DecodeZigZag32 ( CodedOutputStream . EncodeZigZag32 ( 0 ) ) ) ;
Assert . Equal ( 1 , CodedInputStream . DecodeZigZag32 ( CodedOutputStream . EncodeZigZag32 ( 1 ) ) ) ;
Assert . Equal ( - 1 , CodedInputStream . DecodeZigZag32 ( CodedOutputStream . EncodeZigZag32 ( - 1 ) ) ) ;
Assert . Equal ( 1 4 9 2 7 , CodedInputStream . DecodeZigZag32 ( CodedOutputStream . EncodeZigZag32 ( 1 4 9 2 7 ) ) ) ;
Assert . Equal ( - 3 6 1 2 , CodedInputStream . DecodeZigZag32 ( CodedOutputStream . EncodeZigZag32 ( - 3 6 1 2 ) ) ) ;
}
[TestMethod ]
[Fact ]
public void RoundTripZigZag64 ( )
{
Assert . Are Equal( 0 , CodedInputStream . DecodeZigZag64 ( CodedOutputStream . EncodeZigZag64 ( 0 ) ) ) ;
Assert . Are Equal( 1 , CodedInputStream . DecodeZigZag64 ( CodedOutputStream . EncodeZigZag64 ( 1 ) ) ) ;
Assert . Are Equal( - 1 , CodedInputStream . DecodeZigZag64 ( CodedOutputStream . EncodeZigZag64 ( - 1 ) ) ) ;
Assert . Are Equal( 1 4 9 2 7 , CodedInputStream . DecodeZigZag64 ( CodedOutputStream . EncodeZigZag64 ( 1 4 9 2 7 ) ) ) ;
Assert . Are Equal( - 3 6 1 2 , CodedInputStream . DecodeZigZag64 ( CodedOutputStream . EncodeZigZag64 ( - 3 6 1 2 ) ) ) ;
Assert . Equal ( 0 , CodedInputStream . DecodeZigZag64 ( CodedOutputStream . EncodeZigZag64 ( 0 ) ) ) ;
Assert . Equal ( 1 , CodedInputStream . DecodeZigZag64 ( CodedOutputStream . EncodeZigZag64 ( 1 ) ) ) ;
Assert . Equal ( - 1 , CodedInputStream . DecodeZigZag64 ( CodedOutputStream . EncodeZigZag64 ( - 1 ) ) ) ;
Assert . Equal ( 1 4 9 2 7 , CodedInputStream . DecodeZigZag64 ( CodedOutputStream . EncodeZigZag64 ( 1 4 9 2 7 ) ) ) ;
Assert . Equal ( - 3 6 1 2 , CodedInputStream . DecodeZigZag64 ( CodedOutputStream . EncodeZigZag64 ( - 3 6 1 2 ) ) ) ;
Assert . Are Equal( 8 5 6 9 1 2 3 0 4 8 0 1 4 1 6L ,
Assert . Equal ( 8 5 6 9 1 2 3 0 4 8 0 1 4 1 6L ,
CodedInputStream . DecodeZigZag64 ( CodedOutputStream . EncodeZigZag64 ( 8 5 6 9 1 2 3 0 4 8 0 1 4 1 6L ) ) ) ;
Assert . Are Equal( - 7 5 1 2 3 9 0 5 4 3 9 5 7 1 2 5 6L ,
Assert . Equal ( - 7 5 1 2 3 9 0 5 4 3 9 5 7 1 2 5 6L ,
CodedInputStream . DecodeZigZag64 ( CodedOutputStream . EncodeZigZag64 ( - 7 5 1 2 3 9 0 5 4 3 9 5 7 1 2 5 6L ) ) ) ;
}
[TestMethod ]
[Fact ]
public void TestNegativeEnumNoTag ( )
{
Assert . Are Equal( 1 0 , CodedOutputStream . ComputeInt32SizeNoTag ( - 2 ) ) ;
Assert . Are Equal( 1 0 , CodedOutputStream . ComputeEnumSizeNoTag ( - 2 ) ) ;
Assert . Equal ( 1 0 , CodedOutputStream . ComputeInt32SizeNoTag ( - 2 ) ) ;
Assert . Equal ( 1 0 , CodedOutputStream . ComputeEnumSizeNoTag ( - 2 ) ) ;
byte [ ] bytes = new byte [ 1 0 ] ;
CodedOutputStream output = CodedOutputStream . CreateInstance ( bytes ) ;
output . WriteEnumNoTag ( - 2 ) ;
Assert . Are Equal( 0 , output . SpaceLeft ) ;
Assert . Are Equal( "FE-FF-FF-FF-FF-FF-FF-FF-FF-01" , BitConverter . ToString ( bytes ) ) ;
Assert . Equal ( 0 , output . SpaceLeft ) ;
Assert . Equal ( "FE-FF-FF-FF-FF-FF-FF-FF-FF-01" , BitConverter . ToString ( bytes ) ) ;
}
[TestMethod ]
[Fact ]
public void TestNegativeEnumWithTag ( )
{
Assert . Are Equal( 1 1 , CodedOutputStream . ComputeInt32Size ( 8 , - 2 ) ) ;
Assert . Are Equal( 1 1 , CodedOutputStream . ComputeEnumSize ( 8 , - 2 ) ) ;
Assert . Equal ( 1 1 , CodedOutputStream . ComputeInt32Size ( 8 , - 2 ) ) ;
Assert . Equal ( 1 1 , CodedOutputStream . ComputeEnumSize ( 8 , - 2 ) ) ;
byte [ ] bytes = new byte [ 1 1 ] ;
CodedOutputStream output = CodedOutputStream . CreateInstance ( bytes ) ;
output . WriteEnum ( 8 , "" , - 2 , - 2 ) ;
Assert . Are Equal( 0 , output . SpaceLeft ) ;
Assert . Equal ( 0 , output . SpaceLeft ) ;
//fyi, 0x40 == 0x08 << 3 + 0, field num + wire format shift
Assert . Are Equal( "40-FE-FF-FF-FF-FF-FF-FF-FF-FF-01" , BitConverter . ToString ( bytes ) ) ;
Assert . Equal ( "40-FE-FF-FF-FF-FF-FF-FF-FF-FF-01" , BitConverter . ToString ( bytes ) ) ;
}
[TestMethod ]
[Fact ]
public void TestNegativeEnumArrayPacked ( )
{
int arraySize = 1 + ( 1 0 * 5 ) ;
@ -329,22 +328,22 @@ namespace Google.ProtocolBuffers
CodedOutputStream output = CodedOutputStream . CreateInstance ( bytes ) ;
output . WritePackedEnumArray ( 8 , "" , arraySize , new int [ ] { 0 , - 1 , - 2 , - 3 , - 4 , - 5 } ) ;
Assert . Are Equal( 0 , output . SpaceLeft ) ;
Assert . Equal ( 0 , output . SpaceLeft ) ;
CodedInputStream input = CodedInputStream . CreateInstance ( bytes ) ;
uint tag ;
string name ;
Assert . Is True( input . ReadTag ( out tag , out name ) ) ;
Assert . True ( input . ReadTag ( out tag , out name ) ) ;
List < int > values = new List < int > ( ) ;
input . ReadInt32Array ( tag , name , values ) ;
Assert . Are Equal( 6 , values . Count ) ;
Assert . Equal ( 6 , values . Count ) ;
for ( int i = 0 ; i > - 6 ; i - - )
Assert . Are Equal( i , values [ Math . Abs ( i ) ] ) ;
Assert . Equal ( i , values [ Math . Abs ( i ) ] ) ;
}
[TestMethod ]
[Fact ]
public void TestNegativeEnumArray ( )
{
int arraySize = 1 + 1 + ( 1 1 * 5 ) ;
@ -353,22 +352,22 @@ namespace Google.ProtocolBuffers
CodedOutputStream output = CodedOutputStream . CreateInstance ( bytes ) ;
output . WriteEnumArray ( 8 , "" , new int [ ] { 0 , - 1 , - 2 , - 3 , - 4 , - 5 } ) ;
Assert . Are Equal( 0 , output . SpaceLeft ) ;
Assert . Equal ( 0 , output . SpaceLeft ) ;
CodedInputStream input = CodedInputStream . CreateInstance ( bytes ) ;
uint tag ;
string name ;
Assert . Is True( input . ReadTag ( out tag , out name ) ) ;
Assert . True ( input . ReadTag ( out tag , out name ) ) ;
List < int > values = new List < int > ( ) ;
input . ReadInt32Array ( tag , name , values ) ;
Assert . Are Equal( 6 , values . Count ) ;
Assert . Equal ( 6 , values . Count ) ;
for ( int i = 0 ; i > - 6 ; i - - )
Assert . Are Equal( i , values [ Math . Abs ( i ) ] ) ;
Assert . Equal ( i , values [ Math . Abs ( i ) ] ) ;
}
[TestMethod ]
[Fact ]
public void TestCodedInputOutputPosition ( )
{
byte [ ] content = new byte [ 1 1 0 ] ;
@ -381,19 +380,19 @@ namespace Google.ProtocolBuffers
CodedOutputStream cout = CodedOutputStream . CreateInstance ( ms , 2 0 ) ;
// Field 11: numeric value: 500
cout . WriteTag ( 1 1 , WireFormat . WireType . Varint ) ;
Assert . Are Equal( 1 , cout . Position ) ;
Assert . Equal ( 1 , cout . Position ) ;
cout . WriteInt32NoTag ( 5 0 0 ) ;
Assert . Are Equal( 3 , cout . Position ) ;
Assert . Equal ( 3 , cout . Position ) ;
//Field 12: length delimited 120 bytes
cout . WriteTag ( 1 2 , WireFormat . WireType . LengthDelimited ) ;
Assert . Are Equal( 4 , cout . Position ) ;
Assert . Equal ( 4 , cout . Position ) ;
cout . WriteBytesNoTag ( ByteString . CopyFrom ( content ) ) ;
Assert . Are Equal( 1 1 5 , cout . Position ) ;
Assert . Equal ( 1 1 5 , cout . Position ) ;
// Field 13: fixed numeric value: 501
cout . WriteTag ( 1 3 , WireFormat . WireType . Fixed32 ) ;
Assert . Are Equal( 1 1 6 , cout . Position ) ;
Assert . Equal ( 1 1 6 , cout . Position ) ;
cout . WriteSFixed32NoTag ( 5 0 1 ) ;
Assert . Are Equal( 1 2 0 , cout . Position ) ;
Assert . Equal ( 1 2 0 , cout . Position ) ;
cout . Flush ( ) ;
}
@ -402,19 +401,19 @@ namespace Google.ProtocolBuffers
CodedOutputStream cout = CodedOutputStream . CreateInstance ( bytes ) ;
// Field 1: numeric value: 500
cout . WriteTag ( 1 , WireFormat . WireType . Varint ) ;
Assert . Are Equal( 1 , cout . Position ) ;
Assert . Equal ( 1 , cout . Position ) ;
cout . WriteInt32NoTag ( 5 0 0 ) ;
Assert . Are Equal( 3 , cout . Position ) ;
Assert . Equal ( 3 , cout . Position ) ;
//Field 2: length delimited 120 bytes
cout . WriteTag ( 2 , WireFormat . WireType . LengthDelimited ) ;
Assert . Are Equal( 4 , cout . Position ) ;
Assert . Equal ( 4 , cout . Position ) ;
cout . WriteBytesNoTag ( ByteString . CopyFrom ( child ) ) ;
Assert . Are Equal( 1 2 5 , cout . Position ) ;
Assert . Equal ( 1 2 5 , cout . Position ) ;
// Field 3: fixed numeric value: 500
cout . WriteTag ( 3 , WireFormat . WireType . Fixed32 ) ;
Assert . Are Equal( 1 2 6 , cout . Position ) ;
Assert . Equal ( 1 2 6 , cout . Position ) ;
cout . WriteSFixed32NoTag ( 5 0 1 ) ;
Assert . Are Equal( 1 3 0 , cout . Position ) ;
Assert . Equal ( 1 3 0 , cout . Position ) ;
cout . Flush ( ) ;
}
//Now test Input stream:
@ -423,49 +422,49 @@ namespace Google.ProtocolBuffers
uint tag ;
int intValue = 0 ;
string ignore ;
Assert . Are Equal( 0 , cin . Position ) ;
Assert . Equal ( 0 , cin . Position ) ;
// Field 1:
Assert . Is True( cin . ReadTag ( out tag , out ignore ) & & tag > > 3 = = 1 ) ;
Assert . Are Equal( 1 , cin . Position ) ;
Assert . Is True( cin . ReadInt32 ( ref intValue ) & & intValue = = 5 0 0 ) ;
Assert . Are Equal( 3 , cin . Position ) ;
Assert . True ( cin . ReadTag ( out tag , out ignore ) & & tag > > 3 = = 1 ) ;
Assert . Equal ( 1 , cin . Position ) ;
Assert . True ( cin . ReadInt32 ( ref intValue ) & & intValue = = 5 0 0 ) ;
Assert . Equal ( 3 , cin . Position ) ;
//Field 2:
Assert . Is True( cin . ReadTag ( out tag , out ignore ) & & tag > > 3 = = 2 ) ;
Assert . Are Equal( 4 , cin . Position ) ;
Assert . True ( cin . ReadTag ( out tag , out ignore ) & & tag > > 3 = = 2 ) ;
Assert . Equal ( 4 , cin . Position ) ;
uint childlen = cin . ReadRawVarint32 ( ) ;
Assert . Are Equal( 1 2 0 u , childlen ) ;
Assert . Are Equal( 5 , cin . Position ) ;
Assert . Equal ( 1 2 0 u , childlen ) ;
Assert . Equal ( 5 , cin . Position ) ;
int oldlimit = cin . PushLimit ( ( int ) childlen ) ;
Assert . Are Equal( 5 , cin . Position ) ;
Assert . Equal ( 5 , cin . Position ) ;
// Now we are reading child message
{
// Field 11: numeric value: 500
Assert . Is True( cin . ReadTag ( out tag , out ignore ) & & tag > > 3 = = 1 1 ) ;
Assert . Are Equal( 6 , cin . Position ) ;
Assert . Is True( cin . ReadInt32 ( ref intValue ) & & intValue = = 5 0 0 ) ;
Assert . Are Equal( 8 , cin . Position ) ;
Assert . True ( cin . ReadTag ( out tag , out ignore ) & & tag > > 3 = = 1 1 ) ;
Assert . Equal ( 6 , cin . Position ) ;
Assert . True ( cin . ReadInt32 ( ref intValue ) & & intValue = = 5 0 0 ) ;
Assert . Equal ( 8 , cin . Position ) ;
//Field 12: length delimited 120 bytes
Assert . Is True( cin . ReadTag ( out tag , out ignore ) & & tag > > 3 = = 1 2 ) ;
Assert . Are Equal( 9 , cin . Position ) ;
Assert . True ( cin . ReadTag ( out tag , out ignore ) & & tag > > 3 = = 1 2 ) ;
Assert . Equal ( 9 , cin . Position ) ;
ByteString bstr = null ;
Assert . Is True( cin . ReadBytes ( ref bstr ) & & bstr . Length = = 1 1 0 & & bstr . ToByteArray ( ) [ 1 0 9 ] = = 1 0 9 ) ;
Assert . Are Equal( 1 2 0 , cin . Position ) ;
Assert . True ( cin . ReadBytes ( ref bstr ) & & bstr . Length = = 1 1 0 & & bstr . ToByteArray ( ) [ 1 0 9 ] = = 1 0 9 ) ;
Assert . Equal ( 1 2 0 , cin . Position ) ;
// Field 13: fixed numeric value: 501
Assert . Is True( cin . ReadTag ( out tag , out ignore ) & & tag > > 3 = = 1 3 ) ;
Assert . True ( cin . ReadTag ( out tag , out ignore ) & & tag > > 3 = = 1 3 ) ;
// ROK - Previously broken here, this returned 126 failing to account for bufferSizeAfterLimit
Assert . Are Equal( 1 2 1 , cin . Position ) ;
Assert . Is True( cin . ReadSFixed32 ( ref intValue ) & & intValue = = 5 0 1 ) ;
Assert . Are Equal( 1 2 5 , cin . Position ) ;
Assert . Is True( cin . IsAtEnd ) ;
Assert . Equal ( 1 2 1 , cin . Position ) ;
Assert . True ( cin . ReadSFixed32 ( ref intValue ) & & intValue = = 5 0 1 ) ;
Assert . Equal ( 1 2 5 , cin . Position ) ;
Assert . True ( cin . IsAtEnd ) ;
}
cin . PopLimit ( oldlimit ) ;
Assert . Are Equal( 1 2 5 , cin . Position ) ;
Assert . Equal ( 1 2 5 , cin . Position ) ;
// Field 3: fixed numeric value: 501
Assert . Is True( cin . ReadTag ( out tag , out ignore ) & & tag > > 3 = = 3 ) ;
Assert . Are Equal( 1 2 6 , cin . Position ) ;
Assert . Is True( cin . ReadSFixed32 ( ref intValue ) & & intValue = = 5 0 1 ) ;
Assert . Are Equal( 1 3 0 , cin . Position ) ;
Assert . Is True( cin . IsAtEnd ) ;
Assert . True ( cin . ReadTag ( out tag , out ignore ) & & tag > > 3 = = 3 ) ;
Assert . Equal ( 1 2 6 , cin . Position ) ;
Assert . True ( cin . ReadSFixed32 ( ref intValue ) & & intValue = = 5 0 1 ) ;
Assert . Equal ( 1 3 0 , cin . Position ) ;
Assert . True ( cin . IsAtEnd ) ;
}
}
}