1 // BinaryReaderTest.cs - NUnit Test Cases for the SystemIO.BinaryReader class
3 // Eduardo Garcia Cebollero (kiwnix@yahoo.es)
5 // (C) Eduardo Garcia Cebollero.
6 // (C) Ximian, Inc. http://www.ximian.com
13 namespace MonoTests.System.IO
15 public class BinaryReaderTest : TestCase
17 string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");
18 private string _codeFileName;
20 public BinaryReaderTest()
22 if (Directory.Exists (TempFolder))
23 Directory.Delete (TempFolder, true);
24 Directory.CreateDirectory (TempFolder);
25 _codeFileName = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
30 if (Directory.Exists (TempFolder))
31 Directory.Delete (TempFolder, true);
34 override protected void SetUp() {
36 if (!Directory.Exists (TempFolder))
37 Directory.CreateDirectory (TempFolder);
38 if (!File.Exists (_codeFileName))
39 File.Create (_codeFileName).Close ();
42 public void TestCtor1()
45 bool errorThrown = false;
47 BinaryReader r = new BinaryReader ((Stream) null);
48 } catch (ArgumentNullException) {
51 Assert ("#01 null string error not thrown", errorThrown);
54 bool errorThrown = false;
55 FileStream f = new FileStream (_codeFileName, FileMode.Open, FileAccess.Write);
57 BinaryReader r = new BinaryReader (f);
59 } catch (ArgumentException) {
63 Assert ("#02 no read error not thrown", errorThrown);
66 FileStream f = new FileStream (_codeFileName,
69 BinaryReader r = new BinaryReader (f);
70 AssertNotNull ("#03 no binary reader created", r);
77 public void TestCtor2 ()
80 bool errorThrown = false;
82 BinaryReader r = new BinaryReader ((Stream) null, Encoding.ASCII);
83 } catch (ArgumentNullException) {
85 } catch (Exception e) {
86 Fail ("#04 Incorrect exception thrown: " + e.ToString ());
88 Assert ("#05 null stream error not thrown", errorThrown);
91 bool errorThrown = false;
93 BinaryReader r = new BinaryReader ((Stream) null, Encoding.Unicode);
94 } catch (ArgumentNullException) {
96 } catch (Exception e) {
97 Fail ("#06 Incorrect exception thrown: " + e.ToString ());
99 Assert("#07 null stream error not thrown", errorThrown);
102 bool errorThrown = false;
104 BinaryReader r = new BinaryReader ((Stream) null, Encoding.UTF7);
105 } catch (ArgumentNullException) {
107 } catch (Exception e) {
108 Fail ("#08 Incorrect exception thrown: " + e.ToString ());
110 Assert ("#09 null stream error not thrown", errorThrown);
113 bool errorThrown = false;
115 BinaryReader r = new BinaryReader ((Stream) null, Encoding.UTF8);
116 } catch (ArgumentNullException) {
118 } catch (Exception e) {
119 Fail ("#0A Incorrect exception thrown: " + e.ToString ());
121 Assert ("#0B null stream error not thrown", errorThrown);
125 public void TestCtor3 ()
127 bool errorThrown = false;
128 byte [] b = new byte [30];
129 MemoryStream m = new MemoryStream (b);
131 BinaryReader r = new BinaryReader (m, (Encoding) null);
132 } catch (ArgumentNullException) {
134 } catch(Exception e) {
135 Fail ("#0C Incorrect Exception thrown: " + e.ToString ());
137 Assert ("#0D No exception trown: ", errorThrown);
140 //TODO: (TestCtor*) Verify the Use of a wrong Stream
141 //TODO: (TestClose*) Verify the Close Method
142 public void TestClose1 ()
145 byte [] b = new byte [30];
146 MemoryStream m = new MemoryStream (b);
148 BinaryReader r = new BinaryReader (m);
150 } catch (Exception e) {
151 Fail ("#0E Unhandled Exception: "+ e.ToString ());
156 //TODO: (TestRead*) Verify Read Method
157 public void TestReadBoolean ()
159 bool [] a = {true, true, false};
160 byte [] arr_a = new byte [3];
162 foreach (bool a1 in a) {
163 arr_a [i] = Convert.ToByte (a1);
168 MemoryStream m = new MemoryStream (arr_a);
170 BinaryReader r = new BinaryReader (m);
171 b = r.ReadBoolean ();
172 AssertEquals ("#11 No well readed boolean: ", a [0], b);
173 } catch (Exception e) {
174 Fail ("#12 Unexpected exception thrown: " + e.ToString ());
178 public void TestReadByte ()
180 byte [] a = {0, 2, 3, 1, 5, 2};
182 MemoryStream m = new MemoryStream (a);
184 BinaryReader r = new BinaryReader (m);
186 AssertEquals ("#13 No well readed byte: ", a [0], b);
187 } catch (Exception e) {
188 Fail ("#14 Unexpected Exception thrown: " + e.ToString ());
192 public void TestReadChar()
194 char [] a = {'a','b','c','d','e'};
195 byte [] arr_a = new byte [5];
199 foreach (char a1 in a) {
200 arr_a [i] = Convert.ToByte (a1);
204 MemoryStream m = new MemoryStream (arr_a);
205 BinaryReader r = new BinaryReader (m);
208 AssertEquals ("#15 No well readed Char", a [0], c);
209 } catch (Exception e) {
210 Fail ("#16 Unexpeted Exception: " + e.ToString ());
214 public void TestReadInt32 () //Uses BinaryWriter!!
216 int [] arr_int = {1,10,200,3000,40000,500000,6000000};
217 byte [] arr_byte = new byte [28]; //Sizeof arr_int * 4
218 int [] arr_int2 = new int [7];
221 MemoryStream mem_stream = new MemoryStream (arr_byte);
222 BinaryWriter bin_writer = new BinaryWriter (mem_stream);
224 foreach (int elem in arr_int) {
225 bin_writer.Write(elem);
228 mem_stream.Seek(0,SeekOrigin.Begin);
229 BinaryReader bin_reader = new BinaryReader (mem_stream);
230 bin_reader.BaseStream.Seek(0,SeekOrigin.Begin);
234 arr_int2 [i] = bin_reader.ReadInt32();
235 AssertEquals("#2E Wrong Readed Int32 in iteration "+ i,arr_int [i],arr_int2 [i]);
236 } catch (IOException e) {
237 Fail("#2F Unexpected IO Exception" + e.ToString());
243 //-TODO: (TestRead[Type]*) Verify the ReadBoolean, ReadByte ....
244 // ReadBoolean, ReadByte, ReadChar, ReadInt32 Done
246 //TODO: (TestFillBuffer*) Verify the FillBuffer Method
247 public void TestPeekChar ()
250 char [] b = {'A', 'B', 'C'};
251 byte [] arr_b = new byte [3];
254 foreach (char b1 in b) {
255 arr_b [i] = Convert.ToByte (b1);
259 MemoryStream m = new MemoryStream (arr_b);
260 BinaryReader r = new BinaryReader (m);
262 char1 = (char) r.PeekChar ();
263 char2 = (char) r.PeekChar ();
264 AssertEquals ("#20 the stream pointer have been altered in peek", char1, char2);
265 } catch (Exception e) {
266 Fail ("#21 Unexpected exception thrown: " + e.ToString ());
270 public void TestBaseSeek1 ()
273 char [] b = {'A','B','C','D','E','F'};
274 byte [] arr_b = new byte[6];
276 foreach (char b1 in b) {
277 arr_b [i] = Convert.ToByte (b1);
281 MemoryStream m = new MemoryStream (arr_b);
282 BinaryReader r = new BinaryReader (m);
284 char1 = (char) r.PeekChar ();
285 r.BaseStream.Seek (0,SeekOrigin.Current);
286 char2 = (char) r.PeekChar ();
287 AssertEquals ("#22 the stream Has been altered in Seek", char1, char2);
288 } catch (Exception e) {
289 Fail ("#23 Unexpected exception thrown: " + e.ToString ());
293 public void TestBaseSeek2 ()
296 char [] b = {'A','B','C','D','E','F'};
297 byte [] arr_b = new byte[6];
299 foreach (char b1 in b) {
300 arr_b [i] = Convert.ToByte (b1);
304 MemoryStream m = new MemoryStream (arr_b);
305 BinaryReader r = new BinaryReader (m);
307 char1 = (char) r.PeekChar ();
308 r.BaseStream.Seek (3,SeekOrigin.Current);
309 r.BaseStream.Seek (-3,SeekOrigin.Current);
310 char2 = (char) r.PeekChar ();
311 AssertEquals ("#24 the stream Has been altered in Seek", char1, char2);
312 } catch (Exception e) {
313 Fail ("#25 Unexpected exception thrown: " + e.ToString ());
316 public void TestInterleavedSeek1 ()
319 byte [] arr_byte = {0,1,2,3,4,5,6,7,8,9};
321 MemoryStream m = new MemoryStream (arr_byte);
322 BinaryReader r = new BinaryReader (m);
327 AssertEquals("#26 Not well readed Byte", int1, arr_byte[0]);
328 } catch (Exception e) {
329 Fail ("#27 Unexpected exception thrown: " + e.ToString ());
334 r.BaseStream.Seek(-1,SeekOrigin.End);
336 AssertEquals("#28 Not well readed Byte",int1,arr_byte[9]);
337 } catch (Exception e) {
338 Fail ("#29 Unexpected exception thrown: " + e.ToString ());
343 r.BaseStream.Seek(3,SeekOrigin.Begin);
345 AssertEquals("#2A Not well readed Byte",int1,arr_byte[3]);
346 } catch (Exception e) {
347 Fail ("#2B Unexpected exception thrown: " + e.ToString ());
352 r.BaseStream.Seek(2,SeekOrigin.Current);
354 AssertEquals("#2C Not well readed Int32",int1,arr_byte [6]);
355 } catch (Exception e) {
356 Fail ("#2D Unexpected exception thrown: " + e.ToString ());
363 /// Throws an exception if stream is null
366 [ExpectedException(typeof(ArgumentNullException))]
367 public void CtorNullExceptionStream ()
369 BinaryReader reader = new BinaryReader (null);
374 /// Throws an exception if encoding is null
377 [ExpectedException(typeof(ArgumentNullException))]
378 public void CtorNullExceptionEncoding ()
380 MemoryStream stream = new MemoryStream (64);
381 BinaryReader reader = new BinaryReader (stream, null);
386 /// Throws an exception if stream does not support writing
389 [ExpectedException(typeof(ArgumentException))]
390 public void CtorArgumentExceptionCannotWrite ()
392 string path = TempFolder + "/BinaryReaderTestFile.1";
395 FileStream file = new FileStream (path, FileMode.CreateNew, FileAccess.Read);
396 BinaryReader breader = new BinaryReader (file);
398 if (File.Exists (path))
403 /// Throws an exception if stream is already closed
406 [ExpectedException(typeof(ArgumentException))]
407 public void CtorArgumentExceptionClosedStream ()
409 string path = TempFolder + "/BinaryReaderTestFile.2";
412 FileStream file = new FileStream (path, FileMode.CreateNew, FileAccess.Write);
414 BinaryReader breader = new BinaryReader (file);
416 if (File.Exists (path))
421 /// Throws an exception if stream is closed
424 [ExpectedException(typeof(ArgumentException))]
425 public void CtorArgumentExceptionEncoding ()
427 MemoryStream stream = new MemoryStream (64);
430 BinaryReader reader = new BinaryReader (stream, new ASCIIEncoding ());
435 /// Tests read () method
440 byte [] bytes = new byte [] {0, 1, 2, 3};
441 MemoryStream stream = new MemoryStream (bytes);
442 BinaryReader reader = new BinaryReader (stream);
444 Assertion.AssertEquals ("test#01", 0, reader.Read ());
445 Assertion.AssertEquals ("test#02", 1, reader.Read ());
446 Assertion.AssertEquals ("test#03", 2, reader.Read ());
447 Assertion.AssertEquals ("test#04", 3, reader.Read ());
448 Assertion.AssertEquals ("test#05", -1, reader.Read ());
452 public void PeakChar ()
454 byte [] bytes = new byte [] {0, 1, 2, 3};
455 MemoryStream stream = new MemoryStream (bytes);
456 BinaryReader reader = new BinaryReader (stream);
458 Assertion.AssertEquals ("test#01", 0, reader.PeekChar ());
459 Assertion.AssertEquals ("test#02", 0, reader.PeekChar ());
460 Assertion.AssertEquals ("test#03", 0, reader.Read ());
461 Assertion.AssertEquals ("test#03", 1, reader.Read ());
462 Assertion.AssertEquals ("test#03", 2, reader.PeekChar ());
466 [ExpectedException(typeof(ObjectDisposedException))]
467 public void CloseRead ()
469 byte [] bytes = new byte [] {0, 1, 2, 3};
470 MemoryStream stream = new MemoryStream (bytes);
471 BinaryReader reader = new BinaryReader (stream);
477 [ExpectedException(typeof(ObjectDisposedException))]
478 public void ClosePeakChar ()
480 byte [] bytes = new byte [] {0, 1, 2, 3};
481 MemoryStream stream = new MemoryStream (bytes);
482 BinaryReader reader = new BinaryReader (stream);
488 [ExpectedException(typeof(ObjectDisposedException))]
489 public void CloseReadBytes ()
491 byte [] bytes = new byte [] {0, 1, 2, 3};
492 MemoryStream stream = new MemoryStream (bytes);
493 BinaryReader reader = new BinaryReader (stream);
495 reader.ReadBytes (1);
499 public void BaseStream ()
501 byte [] bytes = new byte [] {0, 1, 2, 3};
502 MemoryStream stream = new MemoryStream (bytes);
503 BinaryReader reader = new BinaryReader (stream);
505 Assertion.AssertEquals ("test#01", 4, reader.BaseStream.Length);
506 Assertion.AssertEquals ("test#02", true, reader.BaseStream.CanRead);
508 Assertion.AssertEquals ("test#03", null, reader.BaseStream);
513 /// Tests read (byte [], int, int) method
516 public void ReadByteArray ()
518 byte [] bytes = new byte [] {0, 1, 2, 3, 4, 5};
519 MemoryStream stream = new MemoryStream (bytes);
520 BinaryReader reader = new BinaryReader (stream);
522 bytes = new byte [3];
523 reader.Read (bytes, 0, 3);
524 Assertion.AssertEquals ("test#01", 0, bytes [0]);
525 Assertion.AssertEquals ("test#02", 1, bytes [1]);
526 Assertion.AssertEquals ("test#03", 2, bytes [2]);
528 bytes = new byte [6];
529 reader.Read (bytes, 3, 3);
530 Assertion.AssertEquals ("test#04", 0, bytes [0]);
531 Assertion.AssertEquals ("test#05", 0, bytes [1]);
532 Assertion.AssertEquals ("test#06", 0, bytes [2]);
533 Assertion.AssertEquals ("test#07", 3, bytes [3]);
534 Assertion.AssertEquals ("test#08", 4, bytes [4]);
535 Assertion.AssertEquals ("test#09", 5, bytes [5]);
537 bytes = new byte [2];
538 reader.Read (bytes, 0, 2);
539 Assertion.AssertEquals ("test#10", 0, bytes [0]);
540 Assertion.AssertEquals ("test#11", 0, bytes [1]);
544 /// Test Read (char [], int, int)
547 public void ReadCharArray ()
550 MemoryStream stream = new MemoryStream (new byte [] {109, 111, 110, 111, 58, 58});
551 BinaryReader reader = new BinaryReader (stream);
553 char [] chars = new char [3];
554 reader.Read (chars, 0, 3);
555 Assertion.AssertEquals ("test#01", 'm', chars [0]);
556 Assertion.AssertEquals ("test#02", 'o', chars [1]);
557 Assertion.AssertEquals ("test#03", 'n', chars [2]);
559 chars = new char [6];
560 reader.Read (chars, 3, 3);
561 Assertion.AssertEquals ("test#04", 0, chars [0]);
562 Assertion.AssertEquals ("test#05", 0, chars [1]);
563 Assertion.AssertEquals ("test#06", 0, chars [2]);
564 Assertion.AssertEquals ("test#07", 'o', chars [3]);
565 Assertion.AssertEquals ("test#08", ':', chars [4]);
566 Assertion.AssertEquals ("test#09", ':', chars [5]);
568 chars = new char [2];
569 reader.Read (chars, 0, 2);
570 Assertion.AssertEquals ("test#08", 0, chars [0]);
571 Assertion.AssertEquals ("test#09", 0, chars [1]);
576 /// Test ReadBoolean () method.
579 public void ReadBoolean ()
581 MemoryStream stream = new MemoryStream (new byte [] {0, 1, 99, 0, 13});
582 BinaryReader reader = new BinaryReader (stream);
584 Assertion.AssertEquals ("test#01", false, reader.ReadBoolean ());
585 Assertion.AssertEquals ("test#02", true, reader.ReadBoolean ());
586 Assertion.AssertEquals ("test#03", true, reader.ReadBoolean ());
587 Assertion.AssertEquals ("test#04", false, reader.ReadBoolean ());
588 Assertion.AssertEquals ("test#05", true, reader.ReadBoolean ());
592 /// Test ReadBoolean () method exceptions.
595 [ExpectedException(typeof(EndOfStreamException))]
596 public void ReadBooleanException ()
598 MemoryStream stream = new MemoryStream (new byte [] {0, 1});
599 BinaryReader reader = new BinaryReader (stream);
601 reader.ReadBoolean ();
602 reader.ReadBoolean ();
603 reader.ReadBoolean ();
608 /// Test ReadByte () method.
611 public void ReadByte ()
613 MemoryStream stream = new MemoryStream (new byte [] {0, 1, 99, 0, 13});
614 BinaryReader reader = new BinaryReader (stream);
616 Assertion.AssertEquals ("test#01", 0, reader.ReadByte ());
617 Assertion.AssertEquals ("test#02", 1, reader.ReadByte ());
618 Assertion.AssertEquals ("test#03", 99, reader.ReadByte ());
619 Assertion.AssertEquals ("test#04", 0, reader.ReadByte ());
620 Assertion.AssertEquals ("test#05", 13, reader.ReadByte ());
624 /// Test ReadByte () method exceptions.
627 [ExpectedException(typeof(EndOfStreamException))]
628 public void ReadByteException ()
630 MemoryStream stream = new MemoryStream (new byte [] {0, 1});
631 BinaryReader reader = new BinaryReader (stream);
639 /// Test ReadBytes (int) method.
642 public void ReadBytes ()
644 MemoryStream stream = new MemoryStream (new byte [] {0, 1, 99, 0, 13});
645 BinaryReader reader = new BinaryReader (stream);
647 byte [] bytes = reader.ReadBytes (2);
648 Assertion.AssertEquals ("test#01", 0, bytes [0]);
649 Assertion.AssertEquals ("test#02", 1, bytes [1]);
651 bytes = reader.ReadBytes (2);
652 Assertion.AssertEquals ("test#03", 99, bytes [0]);
653 Assertion.AssertEquals ("test#04", 0, bytes [1]);
655 bytes = reader.ReadBytes (2);
656 Assertion.AssertEquals ("test#05", 13, bytes [0]);
657 Assertion.AssertEquals ("test#06", 1, bytes.Length);
661 /// Test ReadBytes (int) method exception.
664 [ExpectedException(typeof(ArgumentOutOfRangeException))]
665 public void ReadBytesException ()
667 MemoryStream stream = new MemoryStream (new byte [] {0, 1, 99, 0, 13});
668 BinaryReader reader = new BinaryReader (stream);
669 reader.ReadBytes (-1);
673 /// Test ReadChar () method.
676 public void ReadChar ()
678 MemoryStream stream = new MemoryStream (new byte [] {0, 1, 99, 0, 13});
679 BinaryReader reader = new BinaryReader (stream);
681 Assertion.AssertEquals ("test#01", 0, reader.ReadChar ());
682 Assertion.AssertEquals ("test#02", 1, reader.ReadChar ());
683 Assertion.AssertEquals ("test#03", 99, reader.ReadChar ());
684 Assertion.AssertEquals ("test#04", 0, reader.ReadChar ());
685 Assertion.AssertEquals ("test#05", 13, reader.ReadChar ());
689 /// Test ReadChar () method exception.
692 [ExpectedException(typeof(EndOfStreamException))]
693 public void ReadCharException ()
695 MemoryStream stream = new MemoryStream (new byte [] {0, 1});
696 BinaryReader reader = new BinaryReader (stream);
704 /// Test ReadChars (int) method.
707 public void ReadChars ()
709 MemoryStream stream = new MemoryStream (new byte [] {0, 1, 99, 0, 13});
710 BinaryReader reader = new BinaryReader (stream);
712 char [] chars = reader.ReadChars (2);
713 Assertion.AssertEquals ("test#01", 0, chars [0]);
714 Assertion.AssertEquals ("test#02", 1, chars [1]);
716 chars = reader.ReadChars (2);
717 Assertion.AssertEquals ("test#03", 99, chars [0]);
718 Assertion.AssertEquals ("test#04", 0, chars [1]);
720 chars = reader.ReadChars (2);
721 Assertion.AssertEquals ("test#05", 13, chars [0]);
722 Assertion.AssertEquals ("test#06", 1, chars.Length);
726 /// Test ReadChars (int value) exceptions. If value is negative exception is thrown
729 [ExpectedException(typeof(ArgumentOutOfRangeException))]
730 public void ReadCharsException ()
732 MemoryStream stream = new MemoryStream (new byte [] {0, 1, 99, 0, 13});
733 BinaryReader reader = new BinaryReader (stream);
734 reader.ReadChars (-1);
739 /// Test ReadDecimal () method.
742 public void ReadDecimal ()
744 MemoryStream stream = new MemoryStream (new byte [] {0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0 ,87, 98, 0, 0, 0, 0});
745 BinaryReader reader = new BinaryReader (stream);
746 Assertion.AssertEquals ("test#01", -18295873486192640, reader.ReadDecimal ());
750 [ExpectedException(typeof(EndOfStreamException))]
751 public void ReadDecimalException ()
753 MemoryStream stream = new MemoryStream (new byte [] {0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0 ,87, 98, 0, 0, 0, 0, 0});
754 BinaryReader reader = new BinaryReader (stream);
755 reader.ReadDecimal ();
756 reader.ReadDecimal ();
760 public void ReadDouble ()
762 MemoryStream stream = new MemoryStream (new byte [] {0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0 ,87, 98, 0, 0, 0, 0});
763 BinaryReader reader = new BinaryReader (stream);
765 Assertion.AssertEquals ("test#01", 1.89131277973112E-307, reader.ReadDouble ());
766 Assertion.AssertEquals ("test#02", 1.2024538023802E+111, reader.ReadDouble ());
770 [ExpectedException(typeof(EndOfStreamException))]
771 public void ReadDoubleException ()
773 MemoryStream stream = new MemoryStream (new byte [] {0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0 ,87, 98, 0, 0, 0, 0});
774 BinaryReader reader = new BinaryReader (stream);
776 reader.ReadDouble ();
777 reader.ReadDouble ();
778 reader.ReadDouble ();
782 public void ReadInt16 ()
784 MemoryStream stream = new MemoryStream (new byte [] {65, 1, 32, 43, 5, 3, 54, 0});
785 BinaryReader reader = new BinaryReader (stream);
787 Assertion.AssertEquals ("test#01", 321, reader.ReadInt16 ());
788 Assertion.AssertEquals ("test#02", 11040, reader.ReadInt16 ());
789 Assertion.AssertEquals ("test#03", 773, reader.ReadInt16 ());
790 Assertion.AssertEquals ("test#04", 54, reader.ReadInt16 ());
794 [ExpectedException(typeof(EndOfStreamException))]
795 public void ReadInt16Exception ()
797 MemoryStream stream = new MemoryStream (new byte [] {65, 1});
798 BinaryReader reader = new BinaryReader (stream);
804 public void ReadInt32 ()
806 MemoryStream stream = new MemoryStream (new byte [] {65, 1, 32, 43, 5, 3, 54, 0});
807 BinaryReader reader = new BinaryReader (stream);
809 Assertion.AssertEquals ("test#01", 723517761, reader.ReadInt32 ());
810 Assertion.AssertEquals ("test#02", 3539717, reader.ReadInt32 ());
814 [ExpectedException(typeof(EndOfStreamException))]
815 public void ReadInt32Exception ()
817 MemoryStream stream = new MemoryStream (new byte [] {65, 1, 32, 43});
818 BinaryReader reader = new BinaryReader (stream);
825 public void ReadInt64 ()
827 MemoryStream stream = new MemoryStream (new byte [] {65, 1, 32, 43, 5, 3, 54, 0, 34, 5, 7, 4, 23, 4, 76, 34, 76, 2, 6,45});
828 BinaryReader reader = new BinaryReader (stream);
830 Assertion.AssertEquals ("test#01", 15202969475612993, reader.ReadInt64 ());
831 Assertion.AssertEquals ("test#02", 2471354792417887522, reader.ReadInt64 ());
835 [ExpectedException(typeof(EndOfStreamException))]
836 public void ReadInt64Exception ()
838 MemoryStream stream = new MemoryStream (new byte [] {65, 1, 32, 43, 5, 3, 54, 0, 34, 5, 7, 4, 23, 4, 76, 34, 76, 2, 6,45});
839 BinaryReader reader = new BinaryReader (stream);
847 public void ReadSByte ()
849 MemoryStream stream = new MemoryStream (new byte [] {65, 200, 32});
850 BinaryReader reader = new BinaryReader (stream);
852 Assertion.AssertEquals ("test#01", 65, reader.ReadSByte ());
853 Assertion.AssertEquals ("test#02", -56, reader.ReadSByte ());
854 Assertion.AssertEquals ("test#03", 32, reader.ReadSByte ());
858 [ExpectedException(typeof(EndOfStreamException))]
859 public void ReadSByteException ()
861 MemoryStream stream = new MemoryStream (new byte [] {65, 200});
862 BinaryReader reader = new BinaryReader (stream);
870 public void ReadSingle ()
872 MemoryStream stream = new MemoryStream (new byte [] {65, 200, 0, 0, 0, 1, 2, 3, 4});
873 BinaryReader reader = new BinaryReader (stream);
875 Assertion.AssertEquals ("test#01", 7.183757E-41, reader.ReadSingle ());
876 Assertion.AssertEquals ("test#01", 3.820471E-37, reader.ReadSingle ());
880 [ExpectedException(typeof(EndOfStreamException))]
881 public void ReadSingleException ()
883 MemoryStream stream = new MemoryStream (new byte [] {65, 200, 0, 0, 0, 1, 2, 3, 4});
884 BinaryReader reader = new BinaryReader (stream);
886 reader.ReadSingle ();
887 reader.ReadSingle ();
888 reader.ReadSingle ();
892 public void ReadString ()
894 MemoryStream stream = new MemoryStream (new byte [] {6,109, 111, 110, 111, 58, 58});
895 BinaryReader reader = new BinaryReader (stream);
897 Assertion.AssertEquals ("test#01", "mono::", reader.ReadString ());
899 stream = new MemoryStream (new byte [] {2,109, 111, 3, 111, 58, 58});
900 reader = new BinaryReader (stream);
901 Assertion.AssertEquals ("test#02", "mo", reader.ReadString ());
902 Assertion.AssertEquals ("test#03", "o::", reader.ReadString ());
906 [ExpectedException(typeof(EndOfStreamException))]
907 public void ReadStringException ()
909 MemoryStream stream = new MemoryStream (new byte [] {2,109, 111, 3, 111, 58, 58});
910 BinaryReader reader = new BinaryReader (stream);
911 reader.ReadString ();
912 reader.ReadString ();
913 reader.ReadString ();
917 public void ReadUInt16 ()
919 MemoryStream stream = new MemoryStream (new byte [] {200, 200, 32, 43, 5, 3, 54, 0});
920 BinaryReader reader = new BinaryReader (stream);
922 Assertion.AssertEquals ("test#01", 51400, reader.ReadUInt16 ());
923 Assertion.AssertEquals ("test#02", 11040, reader.ReadUInt16 ());
924 Assertion.AssertEquals ("test#03", 773, reader.ReadUInt16 ());
925 Assertion.AssertEquals ("test#04", 54, reader.ReadUInt16 ());
929 [ExpectedException(typeof(EndOfStreamException))]
930 public void ReadUInt16Exception ()
932 MemoryStream stream = new MemoryStream (new byte [] {65, 1});
933 BinaryReader reader = new BinaryReader (stream);
934 reader.ReadUInt16 ();
935 reader.ReadUInt16 ();
939 public void ReadUInt32 ()
941 MemoryStream stream = new MemoryStream (new byte [] {65, 1, 32, 43, 5, 3, 54, 0});
942 BinaryReader reader = new BinaryReader (stream);
944 Assertion.AssertEquals ("test#01", 723517761, reader.ReadUInt32 ());
945 Assertion.AssertEquals ("test#02", 3539717, reader.ReadUInt32 ());
949 [ExpectedException(typeof(EndOfStreamException))]
950 public void ReadUInt32Exception ()
952 MemoryStream stream = new MemoryStream (new byte [] {65, 1, 32, 43});
953 BinaryReader reader = new BinaryReader (stream);
955 reader.ReadUInt32 ();
956 reader.ReadUInt32 ();
960 public void ReadUInt64 ()
962 MemoryStream stream = new MemoryStream (new byte [] {65, 1, 32, 43, 5, 3, 54, 0, 34, 5, 7, 4, 23, 4, 76, 34, 76, 2, 6,45});
963 BinaryReader reader = new BinaryReader (stream);
965 Assertion.AssertEquals ("test#01", 15202969475612993, reader.ReadUInt64 ());
966 Assertion.AssertEquals ("test#02", 2471354792417887522, reader.ReadUInt64 ());
970 [ExpectedException(typeof(EndOfStreamException))]
971 public void ReadUInt64Exception ()
973 MemoryStream stream = new MemoryStream (new byte [] {65, 1, 32, 43, 5, 3, 54, 0, 34, 5, 7, 4, 23, 4, 76, 34, 76, 2, 6,45});
974 BinaryReader reader = new BinaryReader (stream);
976 reader.ReadUInt64 ();
977 reader.ReadUInt64 ();
978 reader.ReadUInt64 ();
981 private void DeleteFile (string path)
983 if (File.Exists (path))