@@ -366,4 +366,72 @@ public void SetFileDropList_InvalidFileInPaths_ThrowsArgumentException(string fi
366
366
Action action = ( ) => ClipboardCore . SetFileDropList ( filePaths ) ;
367
367
action . Should ( ) . Throw < ArgumentException > ( ) ;
368
368
}
369
+
370
+ [ Fact ]
371
+ public void SetText_InvokeString_GetReturnsExpected ( )
372
+ {
373
+ ClipboardCore . SetData ( new DataObject ( DataFormatNames . UnicodeText , "text" ) , copy : false , retryTimes : 1 , retryDelay : 0 ) ;
374
+ ClipboardCore . GetDataObject < DataObject , ITestDataObject > ( out var outData , retryTimes : 1 , retryDelay : 0 ) ;
375
+ outData . Should ( ) . NotBeNull ( ) ;
376
+ outData . GetDataPresent ( DataFormatNames . UnicodeText ) . Should ( ) . BeTrue ( ) ;
377
+ outData . GetData ( DataFormatNames . UnicodeText ) . Should ( ) . Be ( "text" ) ;
378
+ }
379
+
380
+ [ Theory ]
381
+ [ InlineData ( null ) ]
382
+ [ InlineData ( "" ) ]
383
+ [ InlineData ( "\t " ) ]
384
+ public void GetData_NullOrEmptyFormat_Returns_Null ( string ? format )
385
+ {
386
+ ClipboardCore . SetData ( new DataObject ( SomeDataObject . Format , null ! ) , copy : false , retryTimes : 1 , retryDelay : 0 ) ;
387
+ ClipboardCore . GetDataObject < DataObject , ITestDataObject > ( out var outData , retryTimes : 1 , retryDelay : 0 ) ;
388
+ outData . Should ( ) . NotBeNull ( ) ;
389
+ outData . GetDataPresent ( format ! ) . Should ( ) . BeFalse ( ) ;
390
+ }
391
+
392
+ [ Theory ]
393
+ [ EnumData < TextDataFormat > ]
394
+ public void GetData_InvalidFormat_Returns_Null ( string format )
395
+ {
396
+ ClipboardCore . SetData ( new DataObject ( SomeDataObject . Format , null ! ) , copy : false , retryTimes : 1 , retryDelay : 0 ) ;
397
+ ClipboardCore . GetDataObject < DataObject , ITestDataObject > ( out var outData , retryTimes : 1 , retryDelay : 0 ) ;
398
+ outData . Should ( ) . NotBeNull ( ) ;
399
+ outData . GetData ( format ) . Should ( ) . BeNull ( ) ;
400
+ }
401
+
402
+ [ Theory ]
403
+ [ InlineData ( new byte [ ] { 1 , 2 , 3 } ) ]
404
+ [ InlineData ( new byte [ ] { } ) ]
405
+ [ InlineData ( null ) ]
406
+ public void SetAudio_InvokeByteArray_GetReturnsExpected ( byte [ ] ? audioBytes )
407
+ {
408
+ DataObject dataObject = new ( DataFormatNames . WaveAudio , audioBytes ! ) ;
409
+ HRESULT result = ClipboardCore . SetData ( dataObject , copy : false , retryTimes : 1 , retryDelay : 0 ) ;
410
+ result . Should ( ) . Be ( HRESULT . S_OK ) ;
411
+
412
+ ClipboardCore . GetDataObject < DataObject , ITestDataObject > ( out var outData , retryTimes : 1 , retryDelay : 0 ) ;
413
+ outData . Should ( ) . NotBeNull ( ) ;
414
+ outData . GetDataPresent ( DataFormatNames . WaveAudio ) . Should ( ) . BeTrue ( ) ;
415
+ outData . GetData ( DataFormatNames . WaveAudio ) . Should ( ) . Be ( audioBytes ) ;
416
+ }
417
+
418
+ public static IEnumerable < object [ ] > GetEmptyStreamData ( )
419
+ {
420
+ yield return new object [ ] { new MemoryStream ( [ 1 , 2 , 3 ] ) , new byte [ ] { 1 , 2 , 3 } } ;
421
+ yield return new object [ ] { new MemoryStream ( [ ] ) , Array . Empty < byte > ( ) } ;
422
+ }
423
+
424
+ [ Theory ]
425
+ [ MemberData ( nameof ( GetEmptyStreamData ) ) ]
426
+ public void SetAudio_InvokeStream_GetReturnsExpected ( Stream audioStream , byte [ ] audioBytes )
427
+ {
428
+ DataObject dataObject = new ( DataFormatNames . WaveAudio , audioStream ) ;
429
+ HRESULT result = ClipboardCore . SetData ( dataObject , copy : false , retryTimes : 1 , retryDelay : 0 ) ;
430
+ result . Should ( ) . Be ( HRESULT . S_OK ) ;
431
+
432
+ ClipboardCore . GetDataObject < DataObject , ITestDataObject > ( out var outData , retryTimes : 1 , retryDelay : 0 ) ;
433
+ outData . Should ( ) . NotBeNull ( ) ;
434
+ outData . GetDataPresent ( DataFormatNames . WaveAudio ) . Should ( ) . BeTrue ( ) ;
435
+ outData . GetData ( DataFormatNames . WaveAudio ) . Should ( ) . BeOfType < MemoryStream > ( ) . Which . ToArray ( ) . Should ( ) . Equal ( audioBytes ) ;
436
+ }
369
437
}
0 commit comments