예제 #1
0
 public static void ViewFile(String filename)
 {
     using (Stream stream = new FileStream(filename, FileMode.Open))
     {
         POIFSFileSystem fs = new POIFSFileSystem(stream);
         DisplayDirectory(fs.Root, "");
     }
 }
예제 #2
0
        public void TestCopyRecursively()
        {
            POIFSFileSystem fsD = new POIFSFileSystem();
            POIFSFileSystem fs = new POIFSFileSystem();
            DirectoryEntry dirA = fs.CreateDirectory("DirA");
            DirectoryEntry dirB = fs.CreateDirectory("DirB");

            DocumentEntry entryR = fs.CreateDocument(new ByteArrayInputStream(dataSmallA), "EntryRoot");
            DocumentEntry entryA1 = dirA.CreateDocument("EntryA1", new ByteArrayInputStream(dataSmallA));
            DocumentEntry entryA2 = dirA.CreateDocument("EntryA2", new ByteArrayInputStream(dataSmallB));

            // Copy docs
            Assert.AreEqual(0, fsD.Root.EntryCount);
            EntryUtils.CopyNodeRecursively(entryR, fsD.Root);

            Assert.AreEqual(1, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("EntryRoot"));

            EntryUtils.CopyNodeRecursively(entryA1, fsD.Root);
            Assert.AreEqual(2, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("EntryRoot"));
            Assert.IsNotNull(fsD.Root.GetEntry("EntryA1"));

            EntryUtils.CopyNodeRecursively(entryA2, fsD.Root);
            Assert.AreEqual(3, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("EntryRoot"));
            Assert.IsNotNull(fsD.Root.GetEntry("EntryA1"));
            Assert.IsNotNull(fsD.Root.GetEntry("EntryA2"));

            // Copy directories
            fsD = new POIFSFileSystem();
            Assert.AreEqual(0, fsD.Root.EntryCount);

            EntryUtils.CopyNodeRecursively(dirB, fsD.Root);
            Assert.AreEqual(1, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("DirB"));
            Assert.AreEqual(0, ((DirectoryEntry)fsD.Root.GetEntry("DirB")).EntryCount);

            EntryUtils.CopyNodeRecursively(dirA, fsD.Root);
            Assert.AreEqual(2, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("DirB"));
            Assert.AreEqual(0, ((DirectoryEntry)fsD.Root.GetEntry("DirB")).EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("DirA"));
            Assert.AreEqual(2, ((DirectoryEntry)fsD.Root.GetEntry("DirA")).EntryCount);

            // Copy the whole lot
            fsD = new POIFSFileSystem();
            Assert.AreEqual(0, fsD.Root.EntryCount);

            EntryUtils.CopyNodes(fs, fsD, new List<String>());
            Assert.AreEqual(3, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry(dirA.Name));
            Assert.IsNotNull(fsD.Root.GetEntry(dirB.Name));
            Assert.IsNotNull(fsD.Root.GetEntry(entryR.Name));
            Assert.AreEqual(0, ((DirectoryEntry)fsD.Root.GetEntry("DirB")).EntryCount);
            Assert.AreEqual(2, ((DirectoryEntry)fsD.Root.GetEntry("DirA")).EntryCount);
        }
예제 #3
0
        public void TestOleNative()
        {
            POIFSFileSystem fs = new POIFSFileSystem(dataSamples.OpenResourceAsStream("oleObject1.bin"));

            Ole10Native ole = Ole10Native.CreateFromEmbeddedOleObject(fs);

            Assert.AreEqual("File1.svg", ole.Label);
            Assert.AreEqual("D:\\Documents and Settings\\rsc\\My Documents\\file1.svg", ole.Command);
        }
 protected void setUp()
 {
     fs = new POIFSFileSystem();
     dirA = fs.CreateDirectory("DirA");
     dirB = fs.CreateDirectory("DirB");
     dirAA = dirA.CreateDirectory("DirAA");
     eRoot = fs.Root.CreateDocument("Root", new ByteArrayInputStream(new byte[] { }));
     eA = dirA.CreateDocument("NA", new ByteArrayInputStream(new byte[] { }));
     eAA = dirAA.CreateDocument("NAA", new ByteArrayInputStream(new byte[] { }));
 }
예제 #5
0
        public void TestEmptyConstructor()
        {
            POIFSFileSystem fs = new POIFSFileSystem();
            DirectoryProperty property1 = new DirectoryProperty("parent");
            DirectoryProperty property2 = new DirectoryProperty("child");
            DirectoryNode parent = new DirectoryNode(property1, fs, null);
            DirectoryNode node = new DirectoryNode(property2, fs, parent);

            Assert.AreEqual(0, parent.Path.Length);
            Assert.AreEqual(1, node.Path.Length);
            Assert.AreEqual("child", node.Path.GetComponent(0));

            // Verify that GetEntries behaves correctly
            int count = 0;
            IEnumerator iter = node.Entries;

            while (iter.MoveNext())
            {
                count++;
            }
            Assert.AreEqual(0, count);

            // Verify behavior of IsEmpty
            Assert.IsTrue(node.IsEmpty);

            // Verify behavior of EntryCount
            Assert.AreEqual(0, node.EntryCount);

            // Verify behavior of Entry
            try
            {
                node.GetEntry("foo");
                Assert.Fail("Should have caught FileNotFoundException");
            }
            catch (FileNotFoundException )
            {

                // as expected
            }

            // Verify behavior of isDirectoryEntry
            Assert.IsTrue(node.IsDirectoryEntry);

            // Verify behavior of GetName
            Assert.AreEqual(property2.Name, node.Name);

            // Verify behavior of isDocumentEntry
            Assert.IsTrue(!node.IsDocumentEntry);

            // Verify behavior of GetParent
            Assert.AreEqual(parent, node.Parent);
        }
예제 #6
0
        protected DirectoryNode[] openSamples(Stream[] inps, bool oldFails)
        {
            NPOIFSFileSystem nfs = new NPOIFSFileSystem(inps[0]);
            if (openedFSs == null) openedFSs = new List<NPOIFSFileSystem>();
            openedFSs.Add(nfs);

            POIFSFileSystem ofs = null;
            try
            {
                ofs = new POIFSFileSystem(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 };
        }
예제 #7
0
        /**
         * @return array of properties Read from ROOT._VBA_PROJECT_CUR.VBA node
         */
        protected Property[] GetVBAProperties(POIFSFileSystem fs)
        {
            String _VBA_PROJECT_CUR = "_VBA_PROJECT_CUR";
            String VBA = "VBA";

            DirectoryEntry root = fs.Root;
            DirectoryEntry vba_project = (DirectoryEntry)root.GetEntry(_VBA_PROJECT_CUR);

            DirectoryNode vba = (DirectoryNode)vba_project.GetEntry(VBA);
            DirectoryProperty p = (DirectoryProperty)vba.Property;

            ArrayList lst = new ArrayList();
            for (IEnumerator it = p.Children; it.MoveNext(); )
            {
                Property ch = (Property)it.Current;
                lst.Add(ch);
            }
            return (Property[])lst.ToArray(typeof(Property));
        }
예제 #8
0
        public void TestShortLastBlock()
        {
            String[] files = new String[] { "ShortLastBlock.qwp", "ShortLastBlock.wps" };

            for (int i = 0; i < files.Length; i++)
            {
                // Open the file up
                POIFSFileSystem fs = new POIFSFileSystem(
                        _samples.OpenResourceAsStream(files[i])
                );

                // Write it into a temp output array
                MemoryStream baos = new MemoryStream();
                fs.WriteFileSystem(baos);

                // Check sizes
            }
        }
예제 #9
0
 /**
  * Copies all nodes from one POIFS to the other
  *
  * @param source
  *            is the source POIFS to copy from
  * @param target
  *            is the target POIFS to copy to
  */
 public static void CopyNodes(POIFSFileSystem source,
                              POIFSFileSystem target)
 {
     CopyNodes(source.Root, target.Root);
 }
예제 #10
0
        public void TestSerialization()
        {
            POIFSFileSystem fs = OpenSampleFS();

            MemoryStream out1 = new MemoryStream();
            fs.WriteFileSystem(out1);
            out1.Close();
            Stream is1 = new MemoryStream(out1.ToArray());
            fs = new POIFSFileSystem(is1);
            is1.Close();
            Property[] props = GetVBAProperties(fs);
            Array.Sort(props, new DirectoryProperty.PropertyComparator());

            Assert.AreEqual(_entries.Length, props.Length);
            for (int i = 0; i < props.Length; i++)
            {
                Assert.AreEqual(_entries[i], props[i].Name);
            }
        }
예제 #11
0
 /**
  * Copies nodes from one POIFS to the other, minus the excepts.
  * This delegates the filtering work to {@link FilteringDirectoryNode},
  *  so excepts can be of the form "NodeToExclude" or
  *  "FilteringDirectory/ExcludedChildNode"
  * 
  * @param source is the source POIFS to copy from
  * @param target is the target POIFS to copy to
  * @param excepts is a list of Entry Names to be excluded from the copy
  */
 public static void CopyNodes(POIFSFileSystem source,
         POIFSFileSystem target, List<String> excepts)
 {
     CopyNodes(
           new FilteringDirectoryNode(source.Root, excepts),
           new FilteringDirectoryNode(target.Root, excepts)
     );
 }
예제 #12
0
 public DirectoryNode(DirectoryProperty property,
                      POIFSFileSystem fileSystem,
                      DirectoryNode parent)
     : this(property, parent, fileSystem, (NPOIFSFileSystem)null)
 {
 }
예제 #13
0
 public ReaderWriter(POIFSFileSystem fileSystem)
 {
     this.filesystem = fileSystem;
     root = this.filesystem.Root;
     dataMap = new Hashtable();
 }
예제 #14
0
        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
                POIFSFileSystem fs = new POIFSFileSystem(
                      _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 POIFSFileSystem(
                     _samples.OpenResourceAsStream("BlockSize512.zvi")
               );
                Assert.IsTrue(fs.Root.EntryCount > 3);
                CheckAllDirectoryContents(fs.Root);
            }
            finally
            {
                inp.Close();
            }
        }
예제 #15
0
        public void TestSingleEmptyDocument()
        {
            POIFSFileSystem fs = new POIFSFileSystem();
            DirectoryEntry dir = fs.Root;
            dir.CreateDocument("Foo", new MemoryStream(new byte[] { }));

            MemoryStream output = new MemoryStream();
            fs.WriteFileSystem(output);
            byte[] temp = output.ToArray();
            Assert.IsNotNull(new POIFSFileSystem(new MemoryStream(temp)));
        }
예제 #16
0
        public void NPOIFSReadCopyWritePOIFSRead()
        {
            FileStream testFile = POIDataSamples.GetSpreadSheetInstance().GetFile("Simple.xls");
            NPOIFSFileSystem src = new NPOIFSFileSystem(testFile);
            byte[] wbDataExp = IOUtils.ToByteArray(src.CreateDocumentInputStream("Workbook"));

            NPOIFSFileSystem nfs = new NPOIFSFileSystem();
            EntryUtils.CopyNodes(src.Root, nfs.Root);
            src.Close();

            MemoryStream bos = new MemoryStream();
            nfs.WriteFileSystem(bos);
            nfs.Close();

            POIFSFileSystem pfs = new POIFSFileSystem(new MemoryStream(bos.ToArray()));
            byte[] wbDataAct = IOUtils.ToByteArray(pfs.CreateDocumentInputStream("Workbook"));

            Assert.That(wbDataExp, new EqualConstraint(wbDataAct));
        }
예제 #17
0
        public void TestEmptyDocumentBug11744()
        {
            byte[] TestData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            POIFSFileSystem fs = new POIFSFileSystem();
            fs.CreateDocument(new MemoryStream(new byte[0]), "Empty");
            fs.CreateDocument(new MemoryStream(TestData), "NotEmpty");
            MemoryStream output = new MemoryStream();
            fs.WriteFileSystem(output);

            // This line caused the error.
            fs = new POIFSFileSystem(new MemoryStream(output.ToArray()));

            DocumentEntry entry = (DocumentEntry)fs.Root.GetEntry("Empty");
            Assert.AreEqual(0, entry.Size, "Expected zero size");
            byte[] actualReadbackData;
            actualReadbackData = NStorage.Utility.IOUtils.ToByteArray(new DocumentInputStream(entry));
            Assert.AreEqual(0, actualReadbackData.Length, "Expected zero read from stream");

            entry = (DocumentEntry)fs.Root.GetEntry("NotEmpty");
            actualReadbackData = NStorage.Utility.IOUtils.ToByteArray(new DocumentInputStream(entry));
            Assert.AreEqual(TestData.Length, entry.Size, "Expected size was wrong");
            Assert.IsTrue(
                    Arrays.Equals(TestData,actualReadbackData), "Expected different data Read from stream");
        }
예제 #18
0
        public void TestEmptyDocumentEventWithFriend()
        {
            POIFSFileSystem fs = new POIFSFileSystem();
            DirectoryEntry dir = fs.Root;
            dir.CreateDocument("Bar", 1, new AnonymousClass1());
            dir.CreateDocument("Foo", 0, new EmptyClass());

            MemoryStream output = new MemoryStream();
            fs.WriteFileSystem(output);
            Assert.IsNotNull(new POIFSFileSystem(new MemoryStream(output.ToArray())));

        }
예제 #19
0
        public void TestEmptyDocumentWithFriend()
        {
            POIFSFileSystem fs = new POIFSFileSystem();
            DirectoryEntry dir = fs.Root;
            dir.CreateDocument("Bar", new MemoryStream(new byte[]{0}));
            dir.CreateDocument("Foo", new MemoryStream(new byte[]{}));

            MemoryStream output = new MemoryStream();
            fs.WriteFileSystem(output);
            Assert.IsNotNull(new POIFSFileSystem(new MemoryStream(output.ToArray())));
        }
예제 #20
0
 public void TestFATandDIFATsectors()
 {
     // Open the file up
     try
     {
         Stream stream = _samples.OpenResourceAsStream("ReferencesInvalidSectors.mpp");
         try
         {
             POIFSFileSystem fs = new POIFSFileSystem(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"));
     }
 }
예제 #21
0
 /// <summary>
 /// Creates an instance of this class from an embedded OLE Object. The OLE Object is expected
 /// to include a stream &quot;{01}Ole10Native&quot; which Contains the actual
 /// data relevant for this class.
 /// </summary>
 /// <param name="poifs">poifs POI Filesystem object</param>
 /// <returns>Returns an instance of this class</returns>
 public static Ole10Native CreateFromEmbeddedOleObject(POIFSFileSystem poifs)
 {
     return CreateFromEmbeddedOleObject(poifs.Root);
 }
예제 #22
0
        public void TestBATandXBAT()
        {
            byte[] hugeStream = new byte[8 * 1024 * 1024];
            POIFSFileSystem fs = new POIFSFileSystem();
            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 POIFSFileSystem(new MemoryStream(fsData));


            //DirectoryNode root = fs.Root;
            //Assert.AreEqual(1, root.EntryCount);
            //DocumentNode big = (DocumentNode)root.GetEntry("BIG");
            //Assert.AreEqual(hugeStream.Length, big.Size);

        }
예제 #23
0
        public void TestRename()
        {
            POIFSFileSystem fs = new POIFSFileSystem();
            DirectoryEntry root = fs.Root;

            // Verify cannot Rename the root directory
            Assert.IsTrue(!root.RenameTo("foo"));
            DirectoryEntry dir = fs.CreateDirectory("myDir");

            Assert.IsTrue(dir.RenameTo("foo"));
            Assert.AreEqual("foo", dir.Name);
            DirectoryEntry dir2 = fs.CreateDirectory("myDir");

            Assert.IsTrue(!dir2.RenameTo("foo"));
            Assert.AreEqual("myDir", dir2.Name);
            Assert.IsTrue(dir.RenameTo("FirstDir"));
            Assert.IsTrue(dir2.RenameTo("foo"));
            Assert.AreEqual("foo", dir2.Name);
        }
예제 #24
0
        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");
                POIFSFileSystem opoifs = new POIFSFileSystem(sample);

                // Ensure we have what we expect on the root
                Assert.AreEqual(npoifs, npoifs.Root.NFileSystem);
                Assert.AreEqual(null, npoifs.Root.FileSystem);
                Assert.AreEqual(opoifs, opoifs.Root.FileSystem);
                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();
            }
        }
예제 #25
0
 /**
  * Copies all nodes from one POIFS to the other
  * 
  * @param source
  *            is the source POIFS to copy from
  * @param target
  *            is the target POIFS to copy to
  */
 public static void CopyNodes(POIFSFileSystem source,
         POIFSFileSystem target)
 {
     CopyNodes(source.Root, target.Root);
 }
예제 #26
0
        public void TestAreDirectoriesIdentical()
        {
            POIFSFileSystem fs = new POIFSFileSystem();
            DirectoryEntry dirA = fs.CreateDirectory("DirA");
            DirectoryEntry dirB = fs.CreateDirectory("DirB");

            // Names must match
            Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(dirA, dirB));

            // Empty dirs are fine
            DirectoryEntry dirA1 = dirA.CreateDirectory("TheDir");
            DirectoryEntry dirB1 = dirB.CreateDirectory("TheDir");
            Assert.AreEqual(0, dirA1.EntryCount);
            Assert.AreEqual(0, dirB1.EntryCount);
            Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1));

            // Otherwise children must match
            dirA1.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA));
            Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1));

            dirB1.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA));
            Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1));

            dirA1.CreateDirectory("DD");
            Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1));
            dirB1.CreateDirectory("DD");
            Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1));


            // Excludes support
            List<String> excl = new List<string>(new String[] { "Ignore1", "IgnDir/Ign2" });
            FilteringDirectoryNode fdA = new FilteringDirectoryNode(dirA1, excl);
            FilteringDirectoryNode fdB = new FilteringDirectoryNode(dirB1, excl);

            Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB));

            // Add an ignored doc, no notice is taken
            fdA.CreateDocument("Ignore1", new ByteArrayInputStream(dataSmallA));
            Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB));

            // Add a directory with filtered contents, not the same
            DirectoryEntry dirAI = dirA1.CreateDirectory("IgnDir");
            Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(fdA, fdB));

            DirectoryEntry dirBI = dirB1.CreateDirectory("IgnDir");
            Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB));

            // Add something to the filtered subdir that gets ignored
            dirAI.CreateDocument("Ign2", new ByteArrayInputStream(dataSmallA));
            Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB));

            // And something that doesn't
            dirAI.CreateDocument("IgnZZ", new ByteArrayInputStream(dataSmallA));
            Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(fdA, fdB));

            dirBI.CreateDocument("IgnZZ", new ByteArrayInputStream(dataSmallA));
            Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB));
        }
예제 #27
0
 /// <summary>
 /// Creates an instance of this class from an embedded OLE Object. The OLE Object is expected
 /// to include a stream &quot;{01}Ole10Native&quot; which Contains the actual
 /// data relevant for this class.
 /// </summary>
 /// <param name="poifs">poifs POI Filesystem object</param>
 /// <returns>Returns an instance of this class</returns>
 public static Ole10Native CreateFromEmbeddedOleObject(POIFSFileSystem poifs)
 {
     return(CreateFromEmbeddedOleObject(poifs.Root));
 }
예제 #28
0
        public void TestAreDocumentsIdentical()
        {
            POIFSFileSystem fs = new POIFSFileSystem();
            DirectoryEntry dirA = fs.CreateDirectory("DirA");
            DirectoryEntry dirB = fs.CreateDirectory("DirB");

            DocumentEntry entryA1 = dirA.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA));
            DocumentEntry entryA1b = dirA.CreateDocument("Entry1b", new ByteArrayInputStream(dataSmallA));
            DocumentEntry entryA2 = dirA.CreateDocument("Entry2", new ByteArrayInputStream(dataSmallB));
            DocumentEntry entryB1 = dirB.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA));


            // Names must match
            Assert.AreEqual(false, entryA1.Name.Equals(entryA1b.Name));
            Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(entryA1, entryA1b));

            // Contents must match
            Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(entryA1, entryA2));

            // Parents don't matter if contents + names are the same
            Assert.AreEqual(false, entryA1.Parent.Equals(entryB1.Parent));
            Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(entryA1, entryB1));


            // Can work with NPOIFS + POIFS
            //ByteArrayOutputStream tmpO = new ByteArrayOutputStream();
            MemoryStream tmpO = new MemoryStream();
            fs.WriteFileSystem(tmpO);
            ByteArrayInputStream tmpI = new ByteArrayInputStream(tmpO.ToArray());
            NPOIFSFileSystem nfs = new NPOIFSFileSystem(tmpI);

            DirectoryEntry dN1 = (DirectoryEntry)nfs.Root.GetEntry("DirA");
            DirectoryEntry dN2 = (DirectoryEntry)nfs.Root.GetEntry("DirB");
            DocumentEntry eNA1 = (DocumentEntry)dN1.GetEntry(entryA1.Name);
            DocumentEntry eNA2 = (DocumentEntry)dN1.GetEntry(entryA2.Name);
            DocumentEntry eNB1 = (DocumentEntry)dN2.GetEntry(entryB1.Name);

            Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(eNA1, eNA2));
            Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(eNA1, eNB1));

            Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(eNA1, entryA1b));
            Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(eNA1, entryA2));

            Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(eNA1, entryA1));
            Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(eNA1, entryB1));
        }
예제 #29
0
        public void TestDeletion()
        {
            POIFSFileSystem fs = new POIFSFileSystem();
            DirectoryEntry root = fs.Root;

            Assert.IsFalse(root.Delete());
            Assert.IsTrue(root.IsEmpty);

            DirectoryEntry dir = fs.CreateDirectory("myDir");

            Assert.IsFalse(root.IsEmpty);
            Assert.IsTrue(dir.IsEmpty);

            Assert.IsFalse(root.Delete());
            // Verify can Delete empty directory
            Assert.IsTrue(dir.Delete());
            dir = fs.CreateDirectory("NextDir");
            DocumentEntry doc = dir.CreateDocument("foo", new MemoryStream(new byte[1]));

            Assert.IsFalse(root.IsEmpty);
            Assert.IsFalse(dir.IsEmpty);

            Assert.IsFalse(dir.Delete());

            // Verify cannot Delete empty directory
            Assert.IsTrue(!dir.Delete());
            Assert.IsTrue(doc.Delete());
            Assert.IsTrue(dir.IsEmpty);
            // Verify now we can Delete it
            Assert.IsTrue(dir.Delete());
            Assert.IsTrue(root.IsEmpty);
        }