コード例 #1
0
		public void ReadBytePastEndOfStream () 
		{
			string path = TempFolder + Path.DirectorySeparatorChar + "temp";
			DeleteFile (path);
			using (StdioFileStream stream = new StdioFileStream (path, FileMode.OpenOrCreate, FileAccess.Read)) {
				stream.Seek (0, SeekOrigin.End);
				Assert.AreEqual (-1, stream.ReadByte (), "ReadByte");
				stream.Close ();
			}
		}
コード例 #2
0
		public void Seek_Disposed () 
		{
			string path = TempFolder + Path.DirectorySeparatorChar + "temp";
			DeleteFile (path);
			StdioFileStream stream = new StdioFileStream (path, FileMode.OpenOrCreate, FileAccess.Write);
			stream.Close ();
			stream.Seek (0, SeekOrigin.Begin);
		}
コード例 #3
0
		public void Seek_InvalidSeekOrigin () 
		{
			string path = TempFolder + Path.DirectorySeparatorChar + "temp";
			DeleteFile (path);

			using (StdioFileStream stream = new StdioFileStream (path, FileMode.OpenOrCreate, FileAccess.Read)) {
				stream.Seek (0, (SeekOrigin) (-1));
			}
		}
コード例 #4
0
		public void TestSeek ()
		{
			string path = TempFolder + Path.DirectorySeparatorChar + "TestSeek";
			DeleteFile (path);

			StdioFileStream stream = new StdioFileStream (path, FileMode.CreateNew, FileAccess.ReadWrite);
			stream.Write (new byte[] {1, 2, 3, 4, 5, 6, 7, 8 , 9, 10}, 0, 10);

			stream.Seek (5, SeekOrigin.End);
			Assert.AreEqual (-1, stream.ReadByte (), "test#01");

			stream.Seek (-5, SeekOrigin.End);
			Assert.AreEqual (6, stream.ReadByte (), "test#02");

			try {
				stream.Seek (-11, SeekOrigin.End);
				Assert.Fail ();
			} catch (Exception e) {
				Assert.AreEqual (typeof (IOException), e.GetType (), "test#03");
			}

			stream.Seek (19, SeekOrigin.Begin);
			Assert.AreEqual (-1, stream.ReadByte (), "test#04");

			stream.Seek (1, SeekOrigin.Begin);
			Assert.AreEqual (2, stream.ReadByte (), "test#05");

			stream.Seek (3, SeekOrigin.Current);
			Assert.AreEqual (6, stream.ReadByte (), "test#06");

			stream.Seek (-2, SeekOrigin.Current);
			Assert.AreEqual (5, stream.ReadByte (), "test#07");

			stream.Flush ();

			// Test that seeks work correctly when seeking inside the buffer
			stream.Seek (0, SeekOrigin.Begin);
			stream.WriteByte (0);
			stream.WriteByte (1);
			stream.Seek (0, SeekOrigin.Begin);
			byte[] buf = new byte [1];
			buf [0] = 2;
			stream.Write (buf, 0, 1);
			stream.Write (buf, 0, 1);
			stream.Flush ();
			stream.Seek (0, SeekOrigin.Begin);
			Assert.AreEqual (2, stream.ReadByte (), "test#08");
			Assert.AreEqual (2, stream.ReadByte (), "test#09");

			stream.Close ();

			DeleteFile (path);
		}
コード例 #5
0
		public void Seek ()
		{
			string path = TempFolder + DSC + "FST.Seek.Test";
			DeleteFile (path);			

			StdioFileStream stream = new StdioFileStream (path, FileMode.CreateNew, FileAccess.ReadWrite);
			StdioFileStream stream2 = new StdioFileStream (path, FileMode.Open, FileAccess.ReadWrite);

			stream.Write (new byte [] {1, 2, 3, 4, 5, 6, 7, 8, 10}, 0, 9);
			Assert.AreEqual (5, stream2.Seek (5, SeekOrigin.Begin), "test#01");
			Assert.AreEqual (-1, stream2.ReadByte (), "test#02");

			Assert.AreEqual (2, stream2.Seek (-3, SeekOrigin.Current), "test#03");
			Assert.AreEqual (-1, stream2.ReadByte (), "test#04");

			Assert.AreEqual (12, stream.Seek (3, SeekOrigin.Current), "test#05");
			Assert.AreEqual (-1, stream.ReadByte (), "test#06");

			Assert.AreEqual (5, stream.Seek (-7, SeekOrigin.Current), "test#07");
			Assert.AreEqual (6, stream.ReadByte (), "test#08");

			Assert.AreEqual (5, stream2.Seek (5, SeekOrigin.Begin), "test#09");
			Assert.AreEqual (6, stream2.ReadByte (), "test#10");

			stream.Close ();
			stream2.Close ();

			DeleteFile (path);
		}
コード例 #6
0
		public void Write ()
		{
			string path = TempFolder + DSC + "StdioFileStreamTest.Write";

			DeleteFile (path);

			StdioFileStream stream = new StdioFileStream (path, FileMode.CreateNew, FileAccess.ReadWrite);

			byte[] outbytes = new byte [] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
			byte[] bytes = new byte [15];

			// Check that the data is flushed when we overflow the buffer
			// with a large amount of data
			stream.Write (outbytes, 0, 5);
			stream.Write (outbytes, 5, 10);
			stream.Seek (0, SeekOrigin.Begin);

			stream.Read (bytes, 0, 15);
			for (int i = 0; i < 15; ++i)
				Assert.AreEqual (i + 1, bytes [i]);

			// Check that the data is flushed when we overflow the buffer
			// with a small amount of data
			stream.Write (outbytes, 0, 7);
			stream.Write (outbytes, 7, 7);
			stream.Write (outbytes, 14, 1);

			stream.Seek (15, SeekOrigin.Begin);
			Array.Clear (bytes, 0, bytes.Length);
			stream.Read (bytes, 0, 15);
			for (int i = 0; i < 15; ++i)
				Assert.AreEqual (i + 1, bytes [i]);
			stream.Close ();
		}