Skip to content

Commit

Permalink
Add test for StreamDecorator.CopyTo
Browse files Browse the repository at this point in the history
Test for buffer lengths at various sector boundaries, for v3 and v4
  • Loading branch information
jeremy-visionaid committed Oct 10, 2024
1 parent b761843 commit 0fa4d41
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions sources/Test/OpenMcdf.Extensions.Test/CFSStreamExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public void Test_AS_IOSTREAM_MULTISECTOR_WRITE()
cf.SaveAs("$ACFFile2.cfs");
}

// Works
using (CompoundFile cf = new("$ACFFile2.cfs"))
{
using Stream s = cf.RootStorage.GetStream("ANewStream").AsIOStream();
Expand All @@ -102,15 +101,42 @@ public void Test_AS_IOSTREAM_MULTISECTOR_WRITE()
Assert.AreEqual(readData.Length, readCount);
CollectionAssert.AreEqual(data, readData);
}
}

// Won't work until #88 is fixed.
using (CompoundFile cf = new("$ACFFile2.cfs"))
{
using Stream readStream = cf.RootStorage.GetStream("ANewStream").AsIOStream();
using MemoryStream ms = new();
readStream.CopyTo(ms);
CollectionAssert.AreEqual(data, ms.ToArray());
}
[TestMethod]
[DataRow(CFSVersion.Ver_3, 0)]
[DataRow(CFSVersion.Ver_3, 63)]
[DataRow(CFSVersion.Ver_3, 64)]
[DataRow(CFSVersion.Ver_3, 65)]
[DataRow(CFSVersion.Ver_3, 511)]
[DataRow(CFSVersion.Ver_3, 512)]
[DataRow(CFSVersion.Ver_3, 513)]
[DataRow(CFSVersion.Ver_3, 4095)]
[DataRow(CFSVersion.Ver_3, 4096)]
[DataRow(CFSVersion.Ver_3, 409)]
[DataRow(CFSVersion.Ver_4, 0)]
[DataRow(CFSVersion.Ver_4, 63)]
[DataRow(CFSVersion.Ver_4, 64)]
[DataRow(CFSVersion.Ver_4, 65)]
[DataRow(CFSVersion.Ver_4, 511)]
[DataRow(CFSVersion.Ver_4, 512)]
[DataRow(CFSVersion.Ver_4, 513)]
[DataRow(CFSVersion.Ver_4, 4095)]
[DataRow(CFSVersion.Ver_4, 4096)]
[DataRow(CFSVersion.Ver_4, 4097)]
public void Test_STREAMDECORATOR_COPY(CFSVersion version, int length)
{
using CompoundFile cf = new(version, CFSConfiguration.Default);
CFStream cfStream = cf.RootStorage.AddStream("MyStream");
using StreamDecorator stream = new(cfStream);
var buffer = Helpers.GetBuffer(length);
stream.Write(buffer, 0, buffer.Length);
stream.Position = 0;
Assert.AreEqual(length, cfStream.Size);

using MemoryStream memoryStream = new();
stream.CopyTo(memoryStream);
CollectionAssert.AreEqual(buffer, memoryStream.ToArray());
}
}
}

0 comments on commit 0fa4d41

Please sign in to comment.