public void Flush_Disposed () { string path = TempFolder + Path.DirectorySeparatorChar + "temp"; DeleteFile (path); StdioFileStream stream = new StdioFileStream (path, FileMode.OpenOrCreate, FileAccess.Write); stream.Close (); stream.Flush (); }
public void TestClose () { #if FALSE string path = TempFolder + Path.DirectorySeparatorChar + "TestClose"; DeleteFile (path); StdioFileStream stream = new StdioFileStream (path, FileMode.CreateNew, FileAccess.ReadWrite); stream.Write (new byte [] {1, 2, 3, 4}, 0, 4); stream.ReadByte (); stream.Close (); try { stream.ReadByte (); Assert.Fail (); } catch (Exception e) { Assert.AreEqual (typeof (ObjectDisposedException), e.GetType (), "test#01"); } try { stream.WriteByte (64); Assert.Fail (); } catch (Exception e) { Assert.AreEqual (typeof (ObjectDisposedException), e.GetType (), "test#02"); } try { stream.Flush (); Assert.Fail (); } catch (Exception e) { Assert.AreEqual (typeof (ObjectDisposedException), e.GetType (), "test#03"); } try { long l = stream.Length; Assert.Fail (); } catch (Exception e) { Assert.AreEqual (typeof (ObjectDisposedException), e.GetType (), "test#04"); } try { long l = stream.Position; Assert.Fail (); } catch (Exception e) { Assert.AreEqual (typeof (ObjectDisposedException), e.GetType (), "test#05"); } try { FilePosition fp = stream.FilePosition; fp.Dispose (); Assert.Fail (); } catch (Exception e) { Assert.AreEqual (typeof (ObjectDisposedException), e.GetType (), "test#05"); } Assert.AreEqual (false, stream.CanRead, "test#06"); Assert.AreEqual (false, stream.CanSeek, "test#07"); Assert.AreEqual (false, stream.CanWrite, "test#08"); DeleteFile (path); #endif }
public void Flush () { #if XXX // This test depends too much on the internal implementation of stdio's FILE string path = TempFolder + DSC + "StdioFileStreamTest.Flush"; StdioFileStream stream = null; StdioFileStream stream2 = null; DeleteFile (path); try { stream = new StdioFileStream (path, FileMode.CreateNew, FileAccess.ReadWrite); stream2 = new StdioFileStream (path, FileMode.Open, FileAccess.ReadWrite); stream.Write (new byte [] {1, 2, 3, 4, 5}, 0, 5); byte [] bytes = new byte [5]; stream2.Read (bytes, 0, 5); Assert.AreEqual (0, bytes [0], "test#01"); Assert.AreEqual (0, bytes [1], "test#02"); Assert.AreEqual (0, bytes [2], "test#03"); Assert.AreEqual (0, bytes [3], "test#04"); stream.Flush (); stream2.Read (bytes, 0, 5); Assert.AreEqual (1, bytes [0], "test#05"); Assert.AreEqual (2, bytes [1], "test#06"); Assert.AreEqual (3, bytes [2], "test#07"); Assert.AreEqual (4, bytes [3], "test#08"); } finally { if (stream != null) stream.Close (); if (stream2 != null) stream2.Close (); Console.WriteLine ("P: " + path); //DeleteFile (path); } #endif }
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); }
public void Flush () { string path = TempFolder + DSC + "StdioFileStreamTest.Flush"; StdioFileStream stream = null; StdioFileStream stream2 = null; DeleteFile (path); try { stream = new StdioFileStream (path, FileMode.CreateNew, FileAccess.ReadWrite); stream2 = new StdioFileStream (path, FileMode.Open, FileAccess.ReadWrite); stream.Write (new byte [] {1, 2, 3, 4, 5}, 0, 5); byte [] bytes = new byte [5]; stream2.Read (bytes, 0, 5); Assert.AreEqual (0, bytes [0], "test#01"); Assert.AreEqual (0, bytes [1], "test#02"); Assert.AreEqual (0, bytes [2], "test#03"); Assert.AreEqual (0, bytes [3], "test#04"); stream.Flush (); stream2.Read (bytes, 0, 5); Assert.AreEqual (1, bytes [0], "test#05"); Assert.AreEqual (2, bytes [1], "test#06"); Assert.AreEqual (3, bytes [2], "test#07"); Assert.AreEqual (4, bytes [3], "test#08"); } finally { if (stream != null) stream.Close (); if (stream2 != null) stream2.Close (); DeleteFile (path); } }