StreamHelperTest.cs 2.2 KB

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