Add test
[mono.git] / mcs / class / corlib / Test / System.IO / StreamHelperTest.cs
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 //
9
10 using System;
11 using System.IO;
12
13 namespace MonoTests.System.IO {
14
15         public class TestHelperStream : Stream {
16
17                 private bool _read;
18                 private bool _write;
19                 private bool _seek;
20                 private long _pos;
21                 private long _length;
22
23                 public TestHelperStream (bool read, bool write, bool seek) 
24                 {
25                         _read = read;
26                         _write = write;
27                         _seek = seek;
28                 }
29
30                 public override bool CanRead {
31                         get { return _read; }
32                 }
33
34                 public override bool CanSeek {
35                         get { return _seek; }
36                 }
37
38                 public override bool CanWrite {
39                         get { return _write; }
40                 }
41
42                 public override long Length {
43                         get { return _length; }
44                 }
45
46                 public override long Position
47                 {
48                         get {
49                                 if (!_seek)
50                                         throw new NotSupportedException ("Not seekable");
51                                 return _pos;
52                         }
53                         set {
54                                 if (!_seek)
55                                         throw new NotSupportedException ("Not seekable");
56                                 _pos = value;
57                         }
58                 }
59
60                 public override void Flush ()
61                 {
62                 }
63
64                 public override int Read (byte[] buffer, int offset, int count)
65                 {
66                         if (!_read)
67                                 throw new NotSupportedException ("Not readable");
68                         return count;
69                 }
70
71                 public override int ReadByte ()
72                 {
73                         return -1;
74                 }
75
76                 public override long Seek (long offset, SeekOrigin origin)
77                 {
78                         if (!_seek)
79                                 throw new NotSupportedException ("Not seekable");
80                         return offset;
81                 }
82
83                 public override void SetLength (long value)
84                 {
85                         if (!_write)
86                                 throw new NotSupportedException ("Not writeable");
87                         _length = value;
88                 }
89
90                 public override void Write (byte[] buffer, int offset, int count)
91                 {
92                         if (!_write)
93                                 throw new NotSupportedException ("Not writeable");
94                 }
95
96                 public override void WriteByte (byte value)
97                 {
98                         if (!_write)
99                                 throw new NotSupportedException ("Not writeable");
100                 }
101         }
102
103         public class ReadOnlyStream : TestHelperStream {
104
105                 public ReadOnlyStream () : base (true, false, true)
106                 {
107                 }
108         }
109
110         public class WriteOnlyStream : TestHelperStream {
111
112                 public WriteOnlyStream () : base (false, true, true)
113                 {
114                 }
115         }
116
117         public class NonSeekableStream : TestHelperStream {
118
119                 public NonSeekableStream () : base (true, true, false)
120                 {
121                 }
122         }
123 }