Skip to content

Commit 909a888

Browse files
Add Seek test
1 parent 525cde8 commit 909a888

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

OpenMcdf.Tests/StreamTests.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace OpenMcdf.Tests;
1+
using System;
2+
3+
namespace OpenMcdf.Tests;
24

35
[TestClass]
46
public sealed class StreamTests
@@ -104,6 +106,22 @@ public void ReadSingleByte(Version version, int length)
104106
StreamAssert.AreEqual(expectedStream, actualStream);
105107
}
106108

109+
[TestMethod]
110+
[DataRow(Version.V3, 64)] // Mini-stream
111+
[DataRow(Version.V4, 4096)] // Regular stream
112+
public void Seek(Version version, int length)
113+
{
114+
string fileName = $"TestStream_v{(int)version}_{length}.cfs";
115+
using var rootStorage = RootStorage.OpenRead(fileName);
116+
using Stream stream = rootStorage.OpenStream("TestStream");
117+
118+
stream.Seek(0, SeekOrigin.Begin);
119+
Assert.ThrowsException<IOException>(() => stream.Seek(-1, SeekOrigin.Begin));
120+
Assert.ThrowsException<IOException>(() => stream.Seek(-1, SeekOrigin.Current));
121+
Assert.ThrowsException<IOException>(() => stream.Seek(length + 1, SeekOrigin.End));
122+
Assert.ThrowsException<ArgumentException>(() => stream.Seek(length, (SeekOrigin)3));
123+
}
124+
107125
[TestMethod]
108126
[DataRow(Version.V3, 0)]
109127
[DataRow(Version.V3, 63)]

OpenMcdf/ThrowHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void ThrowIfNotWritable(this Stream stream)
3737
throw new NotSupportedException("Stream does not support writing.");
3838
}
3939

40-
public static void ThrowSeekBeforeOrigin() => throw new IOException("Seek before origin.");
40+
public static void ThrowSeekBeforeOrigin() => throw new IOException("An attempt was made to move the position before the beginning of the stream.");
4141

4242
public static void ThrowIfNameIsInvalid(string value)
4343
{

0 commit comments

Comments
 (0)