**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / Test / System.IO / StreamHelperTest.cs
blob9e97f08cbbd6e89f2d730bdfe13d976af34470f9
1 //
2 // Stream Test Helper Classes
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // Copyright (C) 2004 Novell (http://www.novell.com)
8 //
10 using System;
11 using System.IO;
13 namespace MonoTests.System.IO {
15 public class TestHelperStream : Stream {
17 private bool _read;
18 private bool _write;
19 private bool _seek;
20 private long _pos;
21 private long _length;
23 public TestHelperStream (bool read, bool write, bool seek)
25 _read = read;
26 _write = write;
27 _seek = seek;
30 public override bool CanRead {
31 get { return _read; }
34 public override bool CanSeek {
35 get { return _seek; }
38 public override bool CanWrite {
39 get { return _write; }
42 public override long Length {
43 get { return _length; }
46 public override long Position
48 get {
49 if (!_seek)
50 throw new NotSupportedException ("Not seekable");
51 return _pos;
53 set {
54 if (!_seek)
55 throw new NotSupportedException ("Not seekable");
56 _pos = value;
60 public override void Flush ()
64 public override int Read (byte[] buffer, int offset, int count)
66 if (!_read)
67 throw new NotSupportedException ("Not readable");
68 return count;
71 public override int ReadByte ()
73 return -1;
76 public override long Seek (long offset, SeekOrigin origin)
78 if (!_seek)
79 throw new NotSupportedException ("Not seekable");
80 return offset;
83 public override void SetLength (long value)
85 if (!_write)
86 throw new NotSupportedException ("Not writeable");
87 _length = value;
90 public override void Write (byte[] buffer, int offset, int count)
92 if (!_write)
93 throw new NotSupportedException ("Not writeable");
96 public override void WriteByte (byte value)
98 if (!_write)
99 throw new NotSupportedException ("Not writeable");
103 public class ReadOnlyStream : TestHelperStream {
105 public ReadOnlyStream () : base (true, false, true)
110 public class WriteOnlyStream : TestHelperStream {
112 public WriteOnlyStream () : base (false, true, true)
117 public class NonSeekableStream : TestHelperStream {
119 public NonSeekableStream () : base (true, true, false)