@ -58,7 +58,7 @@ namespace Google.Protobuf
Assert . AreEqual ( data , rawOutput . ToArray ( ) ) ;
// IBufferWriter
var bufferWriter = new ArrayBufferWriter < byte > ( ) ;
var bufferWriter = new Test ArrayBufferWriter< byte > ( ) ;
WriteContext . Initialize ( bufferWriter , out WriteContext ctx ) ;
ctx . WriteUInt32 ( ( uint ) value ) ;
ctx . Flush ( ) ;
@ -77,7 +77,7 @@ namespace Google.Protobuf
Assert . AreEqual ( data , rawOutput . ToArray ( ) ) ;
// IBufferWriter
var bufferWriter = new ArrayBufferWriter < byte > ( ) ;
var bufferWriter = new Test ArrayBufferWriter< byte > ( ) ;
WriteContext . Initialize ( bufferWriter , out WriteContext ctx ) ;
ctx . WriteUInt64 ( value ) ;
ctx . Flush ( ) ;
@ -100,7 +100,7 @@ namespace Google.Protobuf
output . Flush ( ) ;
Assert . AreEqual ( data , rawOutput . ToArray ( ) ) ;
var bufferWriter = new ArrayBufferWriter < byte > ( ) ;
var bufferWriter = new Test ArrayBufferWriter< byte > ( ) ;
bufferWriter . MaxGrowBy = bufferSize ;
WriteContext . Initialize ( bufferWriter , out WriteContext ctx ) ;
ctx . WriteUInt32 ( ( uint ) value ) ;
@ -115,7 +115,7 @@ namespace Google.Protobuf
output . Flush ( ) ;
Assert . AreEqual ( data , rawOutput . ToArray ( ) ) ;
var bufferWriter = new ArrayBufferWriter < byte > ( ) ;
var bufferWriter = new Test ArrayBufferWriter< byte > ( ) ;
bufferWriter . MaxGrowBy = bufferSize ;
WriteContext . Initialize ( bufferWriter , out WriteContext ctx ) ;
ctx . WriteUInt64 ( value ) ;
@ -174,7 +174,7 @@ namespace Google.Protobuf
output . Flush ( ) ;
Assert . AreEqual ( data , rawOutput . ToArray ( ) ) ;
var bufferWriter = new ArrayBufferWriter < byte > ( ) ;
var bufferWriter = new Test ArrayBufferWriter< byte > ( ) ;
WriteContext . Initialize ( bufferWriter , out WriteContext ctx ) ;
ctx . WriteFixed32 ( value ) ;
ctx . Flush ( ) ;
@ -190,7 +190,7 @@ namespace Google.Protobuf
output . Flush ( ) ;
Assert . AreEqual ( data , rawOutput . ToArray ( ) ) ;
var bufferWriter = new ArrayBufferWriter < byte > ( ) ;
var bufferWriter = new Test ArrayBufferWriter< byte > ( ) ;
bufferWriter . MaxGrowBy = bufferSize ;
WriteContext . Initialize ( bufferWriter , out WriteContext ctx ) ;
ctx . WriteFixed32 ( value ) ;
@ -212,7 +212,7 @@ namespace Google.Protobuf
output . Flush ( ) ;
Assert . AreEqual ( data , rawOutput . ToArray ( ) ) ;
var bufferWriter = new ArrayBufferWriter < byte > ( ) ;
var bufferWriter = new Test ArrayBufferWriter< byte > ( ) ;
WriteContext . Initialize ( bufferWriter , out WriteContext ctx ) ;
ctx . WriteFixed64 ( value ) ;
ctx . Flush ( ) ;
@ -228,7 +228,7 @@ namespace Google.Protobuf
output . Flush ( ) ;
Assert . AreEqual ( data , rawOutput . ToArray ( ) ) ;
var bufferWriter = new ArrayBufferWriter < byte > ( ) ;
var bufferWriter = new Test ArrayBufferWriter< byte > ( ) ;
bufferWriter . MaxGrowBy = blockSize ;
WriteContext . Initialize ( bufferWriter , out WriteContext ctx ) ;
ctx . WriteFixed64 ( value ) ;
@ -270,7 +270,7 @@ namespace Google.Protobuf
output . Flush ( ) ;
Assert . AreEqual ( rawBytes , rawOutput . ToArray ( ) ) ;
var bufferWriter = new ArrayBufferWriter < byte > ( ) ;
var bufferWriter = new Test ArrayBufferWriter< byte > ( ) ;
bufferWriter . MaxGrowBy = blockSize ;
message . WriteTo ( bufferWriter ) ;
Assert . AreEqual ( rawBytes , bufferWriter . WrittenSpan . ToArray ( ) ) ;
@ -292,7 +292,7 @@ namespace Google.Protobuf
output . Flush ( ) ;
byte [ ] expectedBytes2 = expectedOutput . ToArray ( ) ;
var bufferWriter = new ArrayBufferWriter < byte > ( ) ;
var bufferWriter = new Test ArrayBufferWriter< byte > ( ) ;
WriteContext . Initialize ( bufferWriter , out WriteContext ctx ) ;
ctx . WriteMessage ( message ) ;
ctx . Flush ( ) ;
@ -519,7 +519,21 @@ namespace Google.Protobuf
}
[Test]
public void WriteStringsOfDifferentSizes ( )
public void WriteString_AsciiSmall_MaxUtf8SizeExceedsBuffer ( )
{
var buffer = new byte [ 5 ] ;
var output = new CodedOutputStream ( buffer ) ;
output . WriteString ( "ABC" ) ;
output . Flush ( ) ;
// Verify written content
var input = new CodedInputStream ( buffer ) ;
Assert . AreEqual ( "ABC" , input . ReadString ( ) ) ;
}
[Test]
public void WriteStringsOfDifferentSizes_Ascii ( )
{
for ( int i = 1 ; i < = 1 0 2 4 ; i + + )
{
@ -540,5 +554,30 @@ namespace Google.Protobuf
Assert . AreEqual ( s , input . ReadString ( ) ) ;
}
}
[Test]
public void WriteStringsOfDifferentSizes_Unicode ( )
{
for ( int i = 1 ; i < = 1 0 2 4 ; i + + )
{
var buffer = new byte [ 4 0 9 6 ] ;
var output = new CodedOutputStream ( buffer ) ;
var sb = new StringBuilder ( ) ;
for ( int j = 0 ; j < i ; j + + )
{
char c = ( char ) ( ( j % 1 0 ) + 1 0 1 1 2 ) ;
sb . Append ( c . ToString ( ) ) ; // incrementing unicode numbers, repeating
}
var s = sb . ToString ( ) ;
output . WriteString ( s ) ;
output . Flush ( ) ;
// Verify written content
var input = new CodedInputStream ( buffer ) ;
Assert . AreEqual ( s , input . ReadString ( ) ) ;
}
}
}
}