@@ -349,6 +349,7 @@ public static void BinaryWriter_PrimitiveTypes()
349
349
double d = 1.0 / 3.0 ;
350
350
Guid guid = Guid . NewGuid ( ) ;
351
351
352
+ // Remarks: Of these types only timespan handles BigEndian/LittleEndian so for other types compare against bare bytes
352
353
AssertBytesWritten ( x => x . WriteValue ( decimal . MaxValue ) , XmlBinaryNodeType . DecimalText , MemoryMarshal . AsBytes ( new ReadOnlySpan < decimal > ( in decMax ) ) ) ;
353
354
AssertBytesWritten ( x => x . WriteValue ( f ) , XmlBinaryNodeType . FloatText , MemoryMarshal . AsBytes ( new ReadOnlySpan < float > ( in f ) ) ) ;
354
355
AssertBytesWritten ( x => x . WriteValue ( guid ) , XmlBinaryNodeType . GuidText , guid . ToByteArray ( ) ) ;
@@ -381,7 +382,7 @@ void AssertBytesWritten(Action<XmlDictionaryWriter> action, XmlBinaryNodeType no
381
382
382
383
383
384
[ Fact ]
384
- public static void BinaryWriter_Array ( )
385
+ public static void BinaryWriter_Arrays ( )
385
386
{
386
387
using var ms = new MemoryStream ( ) ;
387
388
using var writer = XmlDictionaryWriter . CreateBinaryWriter ( ms ) ;
@@ -393,6 +394,10 @@ public static void BinaryWriter_Array()
393
394
394
395
AssertBytesWritten ( x => x . WriteArray ( null , "a" , null , ints , offset , count ) , XmlBinaryNodeType . Int32TextWithEndElement , count , new byte [ ] { 4 , 3 , 2 , 1 , 0x44 , 0x33 , 0x22 , 0x11 } ) ;
395
396
397
+ // Write more than 512 bytes in a single call to trigger different writing logic in XmlStreamNodeWriter.WriteBytes
398
+ long [ ] longs = Enumerable . Range ( 0x01020304 , 127 ) . Select ( i => ( long ) i | ( long ) ( ~ i << 32 ) ) . ToArray ( ) ;
399
+ AssertBytesWritten ( x => x . WriteArray ( null , "a" , null , longs , 0 , longs . Length ) , XmlBinaryNodeType . Int64TextWithEndElement , longs . Length , MemoryMarshal . AsBytes ( longs . AsSpan ( ) ) ) ;
400
+
396
401
void AssertBytesWritten ( Action < XmlDictionaryWriter > action , XmlBinaryNodeType nodeType , int count , ReadOnlySpan < byte > expected )
397
402
{
398
403
// Reset stream so we only compare the actual value written (including end element)
@@ -407,11 +412,9 @@ void AssertBytesWritten(Action<XmlDictionaryWriter> action, XmlBinaryNodeType no
407
412
408
413
var actual = segement . AsSpan ( ) ;
409
414
Assert . Equal ( XmlBinaryNodeType . Array , ( XmlBinaryNodeType ) actual [ 0 ] ) ;
410
-
411
- //// start element: ShortDictionaryElement + lenght of str + str
412
415
Assert . Equal ( XmlBinaryNodeType . ShortElement , ( XmlBinaryNodeType ) actual [ 1 ] ) ;
413
416
int elementLenght = actual [ 2 ] ;
414
- Assert . InRange ( actual [ 2 ] , 0 , 0x8f ) ;
417
+ Assert . InRange ( elementLenght , 0 , 0x8f ) ; // verify count is single byte
415
418
Assert . Equal ( XmlBinaryNodeType . EndElement , ( XmlBinaryNodeType ) actual [ 3 + elementLenght ] ) ;
416
419
417
420
actual = actual . Slice ( 4 + elementLenght ) ;
@@ -420,7 +423,6 @@ void AssertBytesWritten(Action<XmlDictionaryWriter> action, XmlBinaryNodeType no
420
423
Assert . Equal ( checked ( ( sbyte ) count ) , ( sbyte ) actual [ 1 ] ) ;
421
424
422
425
AssertExtensions . SequenceEqual ( expected , actual . Slice ( 2 ) ) ;
423
- writer . WriteEndElement ( ) ;
424
426
}
425
427
}
426
428
0 commit comments