Skip to content

Commit

Permalink
Add read/write span tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-visionaid committed Nov 17, 2024
1 parent fa34eca commit 9a5d560
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion OpenMcdf.Tests/StreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,41 @@ public void Seek(Version version, int length)
[DataRow(Version.V4, 1024 * 4096)] // Multiple FAT sectors (1024 * 4096)
[DataRow(Version.V4, 7087616 * 4)] // First DIFAT chain
[DataRow(Version.V4, 2 * 7087616 * 4)] // Long DIFAT chain
public void Write(Version version, int length)
public void Write(Version version, int length) => WriteCore(version, length, false);

#if (!NETSTANDARD2_0 && !NETFRAMEWORK)
[TestMethod]
[DataRow(Version.V3, 0)]
[DataRow(Version.V3, 63)]
[DataRow(Version.V3, 64)] // Mini-stream sector size
[DataRow(Version.V3, 65)]
[DataRow(Version.V3, 511)]
[DataRow(Version.V3, 512)] // Multiple stream sectors
[DataRow(Version.V3, 513)]
[DataRow(Version.V3, 4095)]
[DataRow(Version.V3, 4096)]
[DataRow(Version.V3, 4097)]
[DataRow(Version.V3, 128 * 512)] // Multiple FAT sectors
[DataRow(Version.V3, 1024 * 4096)] // Multiple FAT sectors
[DataRow(Version.V3, 7087616)] // First DIFAT chain
[DataRow(Version.V3, 2 * 7087616)] // Long DIFAT chain
[DataRow(Version.V4, 0)]
[DataRow(Version.V4, 63)]
[DataRow(Version.V4, 64)] // Mini-stream sector size
[DataRow(Version.V4, 65)]
[DataRow(Version.V4, 511)]
[DataRow(Version.V4, 512)]
[DataRow(Version.V4, 513)]
[DataRow(Version.V4, 4095)]
[DataRow(Version.V4, 4096)] // Multiple stream sectors
[DataRow(Version.V4, 4097)]
[DataRow(Version.V4, 1024 * 4096)] // Multiple FAT sectors (1024 * 4096)
[DataRow(Version.V4, 7087616 * 4)] // First DIFAT chain
[DataRow(Version.V4, 2 * 7087616 * 4)] // Long DIFAT chain
public void WriteSpan(Version version, int length) => WriteCore(version, length, true);
#endif

static void WriteCore(Version version, int length, bool preferSpan)
{
using MemoryStream memoryStream = new();
using var rootStorage = RootStorage.Create(memoryStream, version);
Expand All @@ -162,7 +196,15 @@ public void Write(Version version, int length)
for (int i = 0; i < length; i++)
expectedBuffer[i] = (byte)i;

#if (!NETSTANDARD2_0 && !NETFRAMEWORK)
if (preferSpan)
stream.Write(expectedBuffer);
else
stream.Write(expectedBuffer, 0, expectedBuffer.Length);
#else
stream.Write(expectedBuffer, 0, expectedBuffer.Length);
#endif

Assert.AreEqual(length, stream.Length);
Assert.AreEqual(length, stream.Position);

Expand Down

0 comments on commit 9a5d560

Please sign in to comment.