Skip to content

Commit bbef171

Browse files
committed
Fix expected exception type because underlying unpacker no longer throws InvalidMessageStreamException for EoF.
The methods' contracts do not state throwing InvalidMessageStreamException in the first place.
1 parent c907108 commit bbef171

File tree

5 files changed

+155
-155
lines changed

5 files changed

+155
-155
lines changed

test/MsgPack.UnitTest/UnpackingTest.Ext.cs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ public void TestUnpackMessagePackExtendedTypeObject_FixExt1_AndBinaryLengthIs1To
7979
)
8080
)
8181
{
82-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
82+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
8383
}
8484
}
8585

8686
[Test]
8787
public void TestUnpackMessagePackExtendedTypeObject_FixExt1_AndBinaryLengthIs1TooShort_Fail_ByteArray()
8888
{
8989
var buffer = new byte[] { 0xD4, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 0 ) ).ToArray();
90-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
90+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
9191
}
9292

9393
[Test]
@@ -158,15 +158,15 @@ public void TestUnpackMessagePackExtendedTypeObject_FixExt2_AndBinaryLengthIs2To
158158
)
159159
)
160160
{
161-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
161+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
162162
}
163163
}
164164

165165
[Test]
166166
public void TestUnpackMessagePackExtendedTypeObject_FixExt2_AndBinaryLengthIs2TooShort_Fail_ByteArray()
167167
{
168168
var buffer = new byte[] { 0xD5, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 1 ) ).ToArray();
169-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
169+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
170170
}
171171

172172
[Test]
@@ -237,15 +237,15 @@ public void TestUnpackMessagePackExtendedTypeObject_FixExt4_AndBinaryLengthIs4To
237237
)
238238
)
239239
{
240-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
240+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
241241
}
242242
}
243243

244244
[Test]
245245
public void TestUnpackMessagePackExtendedTypeObject_FixExt4_AndBinaryLengthIs4TooShort_Fail_ByteArray()
246246
{
247247
var buffer = new byte[] { 0xD6, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 3 ) ).ToArray();
248-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
248+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
249249
}
250250

251251
[Test]
@@ -316,15 +316,15 @@ public void TestUnpackMessagePackExtendedTypeObject_FixExt8_AndBinaryLengthIs8To
316316
)
317317
)
318318
{
319-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
319+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
320320
}
321321
}
322322

323323
[Test]
324324
public void TestUnpackMessagePackExtendedTypeObject_FixExt8_AndBinaryLengthIs8TooShort_Fail_ByteArray()
325325
{
326326
var buffer = new byte[] { 0xD7, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 7 ) ).ToArray();
327-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
327+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
328328
}
329329

330330
[Test]
@@ -395,15 +395,15 @@ public void TestUnpackMessagePackExtendedTypeObject_FixExt16_AndBinaryLengthIs16
395395
)
396396
)
397397
{
398-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
398+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
399399
}
400400
}
401401

402402
[Test]
403403
public void TestUnpackMessagePackExtendedTypeObject_FixExt16_AndBinaryLengthIs16TooShort_Fail_ByteArray()
404404
{
405405
var buffer = new byte[] { 0xD8, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 15 ) ).ToArray();
406-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
406+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
407407
}
408408

409409
[Test]
@@ -532,15 +532,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext8_AndBinaryLengthIs1TooSh
532532
)
533533
)
534534
{
535-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
535+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
536536
}
537537
}
538538

539539
[Test]
540540
public void TestUnpackMessagePackExtendedTypeObject_Ext8_AndBinaryLengthIs1TooShort_Fail_ByteArray()
541541
{
542542
var buffer = new byte[] { 0xC7, 1, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 0 ) ).ToArray();
543-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
543+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
544544
}
545545

546546
[Test]
@@ -611,15 +611,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext8_AndBinaryLengthIs17TooS
611611
)
612612
)
613613
{
614-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
614+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
615615
}
616616
}
617617

618618
[Test]
619619
public void TestUnpackMessagePackExtendedTypeObject_Ext8_AndBinaryLengthIs17TooShort_Fail_ByteArray()
620620
{
621621
var buffer = new byte[] { 0xC7, 17, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 16 ) ).ToArray();
622-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
622+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
623623
}
624624

625625
[Test]
@@ -690,15 +690,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext8_AndBinaryLengthIs255Too
690690
)
691691
)
692692
{
693-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
693+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
694694
}
695695
}
696696

697697
[Test]
698698
public void TestUnpackMessagePackExtendedTypeObject_Ext8_AndBinaryLengthIs255TooShort_Fail_ByteArray()
699699
{
700700
var buffer = new byte[] { 0xC7, 0xFF, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 254 ) ).ToArray();
701-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
701+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
702702
}
703703

704704
[Test]
@@ -827,15 +827,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext16_AndBinaryLengthIs1TooS
827827
)
828828
)
829829
{
830-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
830+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
831831
}
832832
}
833833

834834
[Test]
835835
public void TestUnpackMessagePackExtendedTypeObject_Ext16_AndBinaryLengthIs1TooShort_Fail_ByteArray()
836836
{
837837
var buffer = new byte[] { 0xC8, 0, 1, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 0 ) ).ToArray();
838-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
838+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
839839
}
840840

841841
[Test]
@@ -906,15 +906,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext16_AndBinaryLengthIs17Too
906906
)
907907
)
908908
{
909-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
909+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
910910
}
911911
}
912912

913913
[Test]
914914
public void TestUnpackMessagePackExtendedTypeObject_Ext16_AndBinaryLengthIs17TooShort_Fail_ByteArray()
915915
{
916916
var buffer = new byte[] { 0xC8, 0, 17, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 16 ) ).ToArray();
917-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
917+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
918918
}
919919

920920
[Test]
@@ -985,15 +985,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext16_AndBinaryLengthIs255To
985985
)
986986
)
987987
{
988-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
988+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
989989
}
990990
}
991991

992992
[Test]
993993
public void TestUnpackMessagePackExtendedTypeObject_Ext16_AndBinaryLengthIs255TooShort_Fail_ByteArray()
994994
{
995995
var buffer = new byte[] { 0xC8, 0, 0xFF, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 254 ) ).ToArray();
996-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
996+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
997997
}
998998

999999
[Test]
@@ -1064,15 +1064,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext16_AndBinaryLengthIs256To
10641064
)
10651065
)
10661066
{
1067-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1067+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
10681068
}
10691069
}
10701070

10711071
[Test]
10721072
public void TestUnpackMessagePackExtendedTypeObject_Ext16_AndBinaryLengthIs256TooShort_Fail_ByteArray()
10731073
{
10741074
var buffer = new byte[] { 0xC8, 1, 0, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 255 ) ).ToArray();
1075-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1075+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
10761076
}
10771077

10781078
[Test]
@@ -1143,15 +1143,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext16_AndBinaryLengthIs65535
11431143
)
11441144
)
11451145
{
1146-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1146+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
11471147
}
11481148
}
11491149

11501150
[Test]
11511151
public void TestUnpackMessagePackExtendedTypeObject_Ext16_AndBinaryLengthIs65535TooShort_Fail_ByteArray()
11521152
{
11531153
var buffer = new byte[] { 0xC8, 0xFF, 0xFF, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 65534 ) ).ToArray();
1154-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1154+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
11551155
}
11561156

11571157
[Test]
@@ -1280,15 +1280,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext32_AndBinaryLengthIs1TooS
12801280
)
12811281
)
12821282
{
1283-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1283+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
12841284
}
12851285
}
12861286

12871287
[Test]
12881288
public void TestUnpackMessagePackExtendedTypeObject_Ext32_AndBinaryLengthIs1TooShort_Fail_ByteArray()
12891289
{
12901290
var buffer = new byte[] { 0xC9, 0, 0, 0, 1, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 0 ) ).ToArray();
1291-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1291+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
12921292
}
12931293

12941294
[Test]
@@ -1359,15 +1359,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext32_AndBinaryLengthIs17Too
13591359
)
13601360
)
13611361
{
1362-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1362+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
13631363
}
13641364
}
13651365

13661366
[Test]
13671367
public void TestUnpackMessagePackExtendedTypeObject_Ext32_AndBinaryLengthIs17TooShort_Fail_ByteArray()
13681368
{
13691369
var buffer = new byte[] { 0xC9, 0, 0, 0, 17, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 16 ) ).ToArray();
1370-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1370+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
13711371
}
13721372

13731373
[Test]
@@ -1438,15 +1438,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext32_AndBinaryLengthIs255To
14381438
)
14391439
)
14401440
{
1441-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1441+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
14421442
}
14431443
}
14441444

14451445
[Test]
14461446
public void TestUnpackMessagePackExtendedTypeObject_Ext32_AndBinaryLengthIs255TooShort_Fail_ByteArray()
14471447
{
14481448
var buffer = new byte[] { 0xC9, 0, 0, 0, 0xFF, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 254 ) ).ToArray();
1449-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1449+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
14501450
}
14511451

14521452
[Test]
@@ -1517,15 +1517,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext32_AndBinaryLengthIs256To
15171517
)
15181518
)
15191519
{
1520-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1520+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
15211521
}
15221522
}
15231523

15241524
[Test]
15251525
public void TestUnpackMessagePackExtendedTypeObject_Ext32_AndBinaryLengthIs256TooShort_Fail_ByteArray()
15261526
{
15271527
var buffer = new byte[] { 0xC9, 0, 0, 1, 0, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 255 ) ).ToArray();
1528-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1528+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
15291529
}
15301530

15311531
[Test]
@@ -1596,15 +1596,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext32_AndBinaryLengthIs65535
15961596
)
15971597
)
15981598
{
1599-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1599+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
16001600
}
16011601
}
16021602

16031603
[Test]
16041604
public void TestUnpackMessagePackExtendedTypeObject_Ext32_AndBinaryLengthIs65535TooShort_Fail_ByteArray()
16051605
{
16061606
var buffer = new byte[] { 0xC9, 0, 0, 0xFF, 0xFF, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 65534 ) ).ToArray();
1607-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1607+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
16081608
}
16091609

16101610
[Test]
@@ -1675,15 +1675,15 @@ public void TestUnpackMessagePackExtendedTypeObject_Ext32_AndBinaryLengthIs65536
16751675
)
16761676
)
16771677
{
1678-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1678+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
16791679
}
16801680
}
16811681

16821682
[Test]
16831683
public void TestUnpackMessagePackExtendedTypeObject_Ext32_AndBinaryLengthIs65536TooShort_Fail_ByteArray()
16841684
{
16851685
var buffer = new byte[] { 0xC9, 0, 1, 0, 0, 1 }.Concat( Enumerable.Repeat( ( byte )0xFF, 65535 ) ).ToArray();
1686-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
1686+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
16871687
}
16881688

16891689
[Test]

test/MsgPack.UnitTest/UnpackingTest.Ext.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private void PutTestMethod( string methodName, string headerFormat, int? lengthO
164164
else
165165
{
166166
#>
167-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
167+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
168168
<#+
169169
}
170170
#>
@@ -189,7 +189,7 @@ private void PutTestMethod( string methodName, string headerFormat, int? lengthO
189189
else
190190
{
191191
#>
192-
Assert.Throws<InvalidMessagePackStreamException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
192+
Assert.Throws<UnpackException>( () => Unpacking.UnpackExtendedTypeObject( buffer ) );
193193
<#+
194194
}
195195
#>

0 commit comments

Comments
 (0)