Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ironfede/openmcdf
Browse files Browse the repository at this point in the history
  • Loading branch information
ironfede committed Oct 2, 2024
2 parents b4214ee + 37c6ca2 commit 828c2cf
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 334 deletions.
4 changes: 2 additions & 2 deletions sources/OpenMcdf/CFStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public byte[] GetData()
///
/// byte[] buffer = new byte[2048];
/// item.Read(buffer, 0, 2048);
/// Assert.IsTrue(Helpers.CompareBuffer(b, buffer));
/// CollectionAssert.AreEqual(b, buffer));
/// </code>
/// </example>
/// <exception cref="T:OpenMcdf.CFDisposedException">
Expand Down Expand Up @@ -189,7 +189,7 @@ public int Read(byte[] buffer, long position, int count)
///
/// byte[] buffer = new byte[2048];
/// item.Read(buffer, 0, 2048);
/// Assert.IsTrue(Helpers.CompareBuffer(b, buffer));
/// CollectionAssert.AreEqual(b, buffer);
/// </code>
/// </example>
/// <exception cref="T:OpenMcdf.CFDisposedException">
Expand Down
10 changes: 5 additions & 5 deletions sources/Test/OpenMcdf.Extensions.Test/CFSStreamExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Test_AS_IOSTREAM_READ()
Stream s = cf.RootStorage.GetStorage("MyStorage").GetStream("MyStream").AsIOStream();
BinaryReader br = new BinaryReader(s);
byte[] result = br.ReadBytes(32);
Assert.IsTrue(Helpers.CompareBuffer(Helpers.GetBuffer(32, 1), result));
CollectionAssert.AreEqual(Helpers.GetBuffer(32, 1), result);
}

[TestMethod]
Expand All @@ -69,7 +69,7 @@ public void Test_AS_IOSTREAM_WRITE()
cf = new CompoundFile("$ACFFile.cfs");
BinaryReader br = new BinaryReader(cf.RootStorage.GetStream("ANewStream").AsIOStream());
string st = br.ReadString();
Assert.IsTrue(st == cmp);
Assert.AreEqual(cmp, st);
cf.Close();
}

Expand Down Expand Up @@ -102,8 +102,8 @@ public void Test_AS_IOSTREAM_MULTISECTOR_WRITE()
{
byte[] readData = new byte[data.Length];
int readCount = br.Read(readData, 0, readData.Length);
Assert.IsTrue(readCount == readData.Length);
Assert.IsTrue(data.SequenceEqual(readData));
Assert.AreEqual(readData.Length, readCount);
CollectionAssert.AreEqual(data, readData);
cf.Close();
}
}
Expand All @@ -120,7 +120,7 @@ public void Test_AS_IOSTREAM_MULTISECTOR_WRITE()
readData = ms.ToArray();
}

Assert.IsTrue(data.SequenceEqual(readData));
CollectionAssert.AreEqual(data, readData);
cf.Close();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
namespace OpenMcdf.Test
{
/// <summary>
/// Summary description for CFTorageTest
/// Summary description for CFStorageTest
/// </summary>
[TestClass]
public class CFSTorageTest
public class CFStorageTest
{
//const String OUTPUT_DIR = "C:\\TestOutputFiles\\";

public CFSTorageTest()
public CFStorageTest()
{
}

Expand Down Expand Up @@ -162,44 +162,23 @@ public void Test_TRY_GET_STREAM_STORAGE_NEW()
[TestMethod]
public void Test_VISIT_ENTRIES_CORRUPTED_FILE_VALIDATION_ON()
{
CompoundFile f = null;
CompoundFile f;

try
{
f = new CompoundFile("CorruptedDoc_bug3547815.doc", CFSUpdateMode.ReadOnly, CFSConfiguration.NoValidationException);
f = new CompoundFile("CorruptedDoc_bug3547815.doc", CFSUpdateMode.ReadOnly, CFSConfiguration.Default);
}
catch
{
Assert.Fail("No exception has to be fired on creation due to lazy loading");
return;
}

FileStream output = null;

try
{
output = new FileStream("LogEntriesCorrupted_1.txt", FileMode.Create);

using (StreamWriter tw = new StreamWriter(output))
{
Action<CFItem> va = delegate (CFItem item)
{
tw.WriteLine(item.Name);
};

f.RootStorage.VisitEntries(va, true);
tw.Flush();
}
}
catch (Exception ex)
Assert.ThrowsException<CFCorruptedFileException>(() =>
{
Assert.IsTrue(ex is CFCorruptedFileException);
Assert.IsTrue(f != null && f.IsClosed);
}
finally
{
if (output != null)
output.Close();
}
using StreamWriter tw = new StreamWriter("LogEntriesCorrupted_1.txt");
f.RootStorage.VisitEntries(item => tw.WriteLine(item.Name), true);
});
}

[TestMethod]
Expand All @@ -209,40 +188,24 @@ public void Test_VISIT_ENTRIES_CORRUPTED_FILE_VALIDATION_OFF_BUT_CAN_LOAD()

try
{
//Corrupted file has invalid children item sid reference
// Corrupted file has invalid children item sid reference
f = new CompoundFile("CorruptedDoc_bug3547815_B.doc", CFSUpdateMode.ReadOnly, CFSConfiguration.NoValidationException);
}
catch
{
Assert.Fail("No exception has to be fired on creation due to lazy loading");
}

FileStream output = null;

try
{
output = new FileStream("LogEntriesCorrupted_2.txt", FileMode.Create);

using (StreamWriter tw = new StreamWriter(output))
{
Action<CFItem> va = delegate (CFItem item)
{
tw.WriteLine(item.Name);
};

f.RootStorage.VisitEntries(va, true);
tw.Flush();
}
using StreamWriter tw = new StreamWriter("LogEntriesCorrupted_2.txt");
f.RootStorage.VisitEntries(item => tw.WriteLine(item.Name), true);
tw.Flush();
}
catch
{
Assert.Fail("Fail is corrupted but it has to be loaded anyway by test design");
}
finally
{
if (output != null)
output.Close();
}
}

[TestMethod]
Expand Down Expand Up @@ -357,15 +320,7 @@ public void Test_CHECK_DISPOSED_()
CFStorage st = cf.RootStorage.GetStorage("MyStorage");
cf.Close();

try
{
byte[] temp = st.GetStream("MyStream").GetData();
Assert.Fail("Stream without media");
}
catch (Exception ex)
{
Assert.IsTrue(ex is CFDisposedException);
}
Assert.ThrowsException<CFDisposedException>(() => st.GetStream("MyStream").GetData());
}

[TestMethod]
Expand All @@ -385,7 +340,7 @@ public void Test_LAZY_LOAD_CHILDREN_()
IList<CFItem> i = cf.GetAllNamedEntries("Level2Stream");
Assert.IsNotNull(i[0]);
Assert.IsTrue(i[0] is CFStream);
Assert.IsTrue((i[0] as CFStream).GetData().Length == 100);
Assert.AreEqual(100, (i[0] as CFStream).GetData().Length);
cf.SaveAs("$Hel2");
cf.Close();

Expand Down Expand Up @@ -414,14 +369,11 @@ public void Test_FIX_BUG_31()
cf.Close();

CompoundFile cf1 = new CompoundFile("$Hel3");
try

Assert.ThrowsException<CFDuplicatedItemException>(() =>
{
CFStream cs = cf1.RootStorage.GetStorage("Level_1").AddStream("Level2Stream");
}
catch (Exception ex)
{
Assert.IsTrue(ex.GetType() == typeof(CFDuplicatedItemException));
}
});
}

[TestMethod]
Expand Down
Loading

0 comments on commit 828c2cf

Please sign in to comment.