From 9a5d56022a889ef51eef6b32dc5cff061d1b5289 Mon Sep 17 00:00:00 2001 From: Jeremy Powell Date: Sun, 17 Nov 2024 22:23:18 +1300 Subject: [PATCH] Add read/write span tests --- OpenMcdf.Tests/StreamTests.cs | 44 ++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/OpenMcdf.Tests/StreamTests.cs b/OpenMcdf.Tests/StreamTests.cs index 8d95404..f4487f6 100644 --- a/OpenMcdf.Tests/StreamTests.cs +++ b/OpenMcdf.Tests/StreamTests.cs @@ -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); @@ -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);