using System;
using System.Text;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NPOI.POIFS.FileSystem;
using NPOI.HWPF.Model;
namespace TestCases.HWPF.Model{
/// <summary>
/// Summary description for FIBBase
/// </summary>
[TestClass]
public class TestFIB
{
public TestFIB()
{
//
// TODO: Add constructor logic here
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
string path = @"..\..\..\TestCases\HWPF\data\test2007.doc";
public MemoryStream ReadFileToMemory()
{
using (var stream = File.OpenRead(path))
{
POIFSFileSystem _currentFileSystem = new POIFSFileSystem(stream);
var entryWordDocument = _currentFileSystem.Root.GetEntry("WordDocument");
Assert.IsNotNull(entryWordDocument, "WordDocument substream doesn't exist");
POIFSDocument document = ((DocumentNode)entryWordDocument).Document;
var dst = new byte[document.Size];
document.Read(dst, 0);
return new MemoryStream(dst);
}
}
[TestMethod]
public void TestFIBBaseRead()
{
MemoryStream ms =ReadFileToMemory();
FIBBase fibbase = new FIBBase();
fibbase.Deserialize(new HWPFStream(ms));
Assert.AreEqual(fibbase.wIdent, unchecked((short)0xA5EC), "word document flag");
Assert.IsFalse(fibbase.HasPicture, "there should be no picture in this document");
Assert.AreEqual(fibbase.WhichTableStream, (short)1,"use 1Table substream");
Assert.IsFalse(fibbase.IsComplex,"none complex file");
//Assert.IsFalse(fibbase.IsFarEast,"edit using none-fareast UI");
Assert.IsFalse(fibbase.IsEncrypted);
Assert.AreEqual(fibbase.fExtChar, 1);
}
[TestMethod]
public void TestFIBRead()
{
MemoryStream ms = ReadFileToMemory();
FIB fib = new FIB();
fib.Deserialize(new HWPFStream(ms));
Assert.AreEqual(fib.csw, 0x000E);
Assert.AreEqual(fib.cslw, 0x0016);
switch (fib.fibRgFcLcb.cbRgFcLcb)
{
case 0x005D:
Assert.AreEqual(0, fib.cswNew);
break;
case 0x006C:
case 0x0088:
case 0x00A4:
Assert.AreEqual(0x0002, fib.cswNew);
break;
case 0x00B7:
Assert.AreEqual(0x0005, fib.cswNew);
break;
default:
Assert.Fail("incorrect nFib exist");
break;
}
}
}
}
|