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