protected DirectoryNode[] openSamples(Stream[] inps, bool oldFails) { NPOIFSFileSystem nfs = new NPOIFSFileSystem(inps[0]); if (openedFSs == null) { openedFSs = new List <NPOIFSFileSystem>(); } openedFSs.Add(nfs); OPOIFSFileSystem ofs = null; try { ofs = new OPOIFSFileSystem(inps[1]); if (oldFails) { Assert.Fail("POIFSFileSystem should have failed but didn't"); } } catch (Exception e) { if (!oldFails) { throw e; } } if (ofs == null) { return new DirectoryNode[] { nfs.Root } } ; return(new DirectoryNode[] { ofs.Root, nfs.Root }); }
public void TestReadMultipleTreeLevels() { POIDataSamples _samples = POIDataSamples.GetPublisherInstance(); FileStream sample = _samples.GetFile("Sample.pub"); DocumentInputStream stream; NPOIFSFileSystem npoifs = new NPOIFSFileSystem(sample); try { sample = _samples.GetFile("Sample.pub"); OPOIFSFileSystem opoifs = new OPOIFSFileSystem(sample); // Ensure we have what we expect on the root Assert.AreEqual(npoifs, npoifs.Root.NFileSystem); Assert.AreEqual(npoifs, npoifs.Root.FileSystem); Assert.AreEqual(null, npoifs.Root.OFileSystem); Assert.AreEqual(null, opoifs.Root.FileSystem); Assert.AreEqual(opoifs, opoifs.Root.OFileSystem); Assert.AreEqual(null, opoifs.Root.NFileSystem); // Check inside foreach (DirectoryNode root in new DirectoryNode[] { opoifs.Root, npoifs.Root }) { // Top Level Entry top = root.GetEntry("Contents"); Assert.AreEqual(true, top.IsDocumentEntry); stream = root.CreateDocumentInputStream(top); stream.Read(); // One Level Down DirectoryNode escher = (DirectoryNode)root.GetEntry("Escher"); Entry one = escher.GetEntry("EscherStm"); Assert.AreEqual(true, one.IsDocumentEntry); stream = escher.CreateDocumentInputStream(one); stream.Read(); // Two Levels Down DirectoryNode quill = (DirectoryNode)root.GetEntry("Quill"); DirectoryNode quillSub = (DirectoryNode)quill.GetEntry("QuillSub"); Entry two = quillSub.GetEntry("CONTENTS"); Assert.AreEqual(true, two.IsDocumentEntry); stream = quillSub.CreateDocumentInputStream(two); stream.Read(); } } finally { npoifs.Close(); } }
public void testFileCorruptionOPOIFS() { // create test InputStream byte[] testData = { (byte)1, (byte)2, (byte)3 }; InputStream testInput = new ByteArrayInputStream(testData); // detect header InputStream in1 = new PushbackInputStream(testInput, 10); Assert.IsFalse(OPOIFSFileSystem.HasPOIFSHeader(in1)); // check if InputStream is still intact byte[] test = new byte[3]; in1.Read(test); Assert.IsTrue(Arrays.Equals(testData, test)); Assert.AreEqual(-1, in1.Read()); }
public void TestShortLastBlock() { String[] files = new String[] { "ShortLastBlock.qwp", "ShortLastBlock.wps" }; for (int i = 0; i < files.Length; i++) { // Open the file up OPOIFSFileSystem fs = new OPOIFSFileSystem( _samples.OpenResourceAsStream(files[i]) ); // Write it into a temp output array MemoryStream baos = new MemoryStream(); fs.WriteFileSystem(baos); // Check sizes } }
public void Test4KBlocks() { Stream inp = _samples.OpenResourceAsStream("BlockSize4096.zvi"); try { // First up, check that we can process the header properly HeaderBlock header_block = new HeaderBlock(inp); POIFSBigBlockSize bigBlockSize = header_block.BigBlockSize; Assert.AreEqual(4096, bigBlockSize.GetBigBlockSize()); // Check the fat info looks sane Assert.AreEqual(1, header_block.BATArray.Length); Assert.AreEqual(1, header_block.BATCount); Assert.AreEqual(0, header_block.XBATCount); // Now check we can get the basic fat RawDataBlockList data_blocks = new RawDataBlockList(inp, bigBlockSize); Assert.AreEqual(15, data_blocks.BlockCount()); // Now try and open properly OPOIFSFileSystem fs = new OPOIFSFileSystem( _samples.OpenResourceAsStream("BlockSize4096.zvi") ); Assert.IsTrue(fs.Root.EntryCount > 3); // Check we can get at all the contents CheckAllDirectoryContents(fs.Root); // Finally, check we can do a similar 512byte one too fs = new OPOIFSFileSystem( _samples.OpenResourceAsStream("BlockSize512.zvi") ); Assert.IsTrue(fs.Root.EntryCount > 3); CheckAllDirectoryContents(fs.Root); } finally { inp.Close(); } }
public void TestFATandDIFATsectors() { // Open the file up try { Stream stream = _samples.OpenResourceAsStream("ReferencesInvalidSectors.mpp"); try { OPOIFSFileSystem fs = new OPOIFSFileSystem(stream); Assert.Fail("File is corrupt and shouldn't have been opened"); } finally { stream.Close(); } } catch (IOException e) { String msg = e.Message; Assert.IsTrue(msg.StartsWith("Your file contains 695 sectors")); } }
public void TestWriteReadProperties() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Write them out NPOIFSFileSystem outFS = new NPOIFSFileSystem(); doc.ReadProperties(); doc.WriteProperties(outFS); outFS.WriteFileSystem(baos); // Create a new version ByteArrayInputStream bais = new ByteArrayInputStream(baos.ToByteArray()); OPOIFSFileSystem inFS = new OPOIFSFileSystem(bais); // Check they're still there doc.SetDirectoryNode(inFS.Root); doc.ReadProperties(); // Delegate test TestReadProperties(); }
/** * Opens for decryption */ public EncryptionInfo(OPOIFSFileSystem fs) : this(fs.Root) { }
public HPSFPropertiesOnlyDocument(OPOIFSFileSystem fs) : base(fs) { }
public void TestBATandXBAT() { byte[] hugeStream = new byte[8 * 1024 * 1024]; OPOIFSFileSystem fs = new OPOIFSFileSystem(); fs.Root.CreateDocument("BIG", new MemoryStream(hugeStream)); MemoryStream baos = new MemoryStream(); fs.WriteFileSystem(baos); byte[] fsData = baos.ToArray(); // Check the header was written properly Stream inp = new MemoryStream(fsData); HeaderBlock header = new HeaderBlock(inp); Assert.AreEqual(109 + 21, header.BATCount); Assert.AreEqual(1, header.XBATCount); ByteBuffer xbatData = ByteBuffer.CreateBuffer(512); xbatData.Write(fsData, (1 + header.XBATIndex) * 512, 512); xbatData.Position = 0; BATBlock xbat = BATBlock.CreateBATBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, xbatData); for (int i = 0; i < 21; i++) { Assert.IsTrue(xbat.GetValueAt(i) != POIFSConstants.UNUSED_BLOCK); } for (int i = 21; i < 127; i++) { Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, xbat.GetValueAt(i)); } Assert.AreEqual(POIFSConstants.END_OF_CHAIN, xbat.GetValueAt(127)); RawDataBlockList blockList = new RawDataBlockList(inp, POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS); Assert.AreEqual(fsData.Length / 512, blockList.BlockCount() + 1); new BlockAllocationTableReader(header.BigBlockSize, header.BATCount, header.BATArray, header.XBATCount, header.XBATIndex, blockList); Assert.AreEqual(fsData.Length / 512, blockList.BlockCount() + 1); fs = null; fs = new OPOIFSFileSystem(new MemoryStream(fsData)); DirectoryNode root = fs.Root; Assert.AreEqual(1, root.EntryCount); DocumentNode big = (DocumentNode)root.GetEntry("BIG"); Assert.AreEqual(hugeStream.Length, big.Size); }
public OutputStream GetDataStream(OPOIFSFileSystem fs) { return(GetDataStream(fs.Root)); }
/** * Constructs from an old-style OPOIFS */ protected POIDocument(OPOIFSFileSystem fs) : this(fs.Root) { }