コード例 #1
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");
                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();
            }
        }
コード例 #2
0
ファイル: TestUnicode.cs プロジェクト: zuiwanting/npoi
        public void TestPropertySetMethods()
        {
            POIDataSamples samples = POIDataSamples.GetHPSFInstance();

            using (FileStream data = samples.GetFile(POI_FS))
            {
                POIFile     poiFile = Util.ReadPOIFiles(data, POI_FILES)[0];
                byte[]      b       = poiFile.GetBytes();
                PropertySet ps      =
                    PropertySetFactory.Create(new ByteArrayInputStream(b));
                Assert.IsTrue(ps.IsDocumentSummaryInformation, "IsDocumentSummaryInformation");
                Assert.AreEqual(ps.SectionCount, 2);
                Section s = (Section)ps.Sections[1];
                Assert.AreEqual(s.GetProperty(1),
                                (int)Constants.CP_UTF16);
                Assert.AreEqual(s.GetProperty(2),
                                -96070278);
                Assert.AreEqual(s.GetProperty(3),
                                "MCon_Info zu Office bei Schreiner");
                Assert.AreEqual(s.GetProperty(4),
                                "*****@*****.**");
                Assert.AreEqual(s.GetProperty(5),
                                "Petrovitsch, Wilhelm");
            }
        }
コード例 #3
0
        public void TestFile()
        {
            FileStream f = data.GetFile("Notes.ole2");

            FileBackedDataSource ds = new FileBackedDataSource(f, false);

            try
            {
                CheckDataSource(ds, false);
            }
            finally
            {
                ds.Close();
            }

            // try a second time
            ds = new FileBackedDataSource(f, false);
            try
            {
                CheckDataSource(ds, false);
            }
            finally
            {
                ds.Close();
            }
        }
コード例 #4
0
ファイル: TestNPOIFSStream.cs プロジェクト: shnug/OLE2Storage
        public void TestReadTinyStream()
        {
            NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.GetFile("BlockSize512.zvi"));

            // 98 is actually the last block in a two block stream...
            NPOIFSStream             stream = new NPOIFSStream(fs, 98);
            IEnumerator <ByteBuffer> i      = stream.GetBlockIterator();

            Assert.AreEqual(true, i.MoveNext());
            ByteBuffer b = i.Current;

            Assert.AreEqual(false, i.MoveNext());

            // Check the contents
            Assert.AreEqual((byte)0x81, b[0]);
            Assert.AreEqual((byte)0x00, b[1]);
            Assert.AreEqual((byte)0x00, b[2]);
            Assert.AreEqual((byte)0x00, b[3]);
            Assert.AreEqual((byte)0x82, b[4]);
            Assert.AreEqual((byte)0x00, b[5]);
            Assert.AreEqual((byte)0x00, b[6]);
            Assert.AreEqual((byte)0x00, b[7]);

            fs.Close();
        }
コード例 #5
0
        /**
         * Performs the check described in {@link #TestReCreate()} for a single
         * POI filesystem.
         *
         * @param f the POI filesystem to check
         */
        private void TestRecreate(FileInfo f)
        {
            Console.WriteLine("Recreating file \"" + f.Name + "\"");

            /* Read the POI filesystem's property Set streams: */
            POIFile[] psf1 = Util.ReadPropertySets(_samples.GetFile(f.Name));

            /* Create a new POI filesystem containing the origin file's
             * property Set streams: */
            FileInfo   fi   = new FileInfo(f.Name);
            FileStream copy = File.Create(fi.Name);
            //copy.deleteOnExit();
            FileStream      out1  = copy;
            POIFSFileSystem poiFs = new POIFSFileSystem();

            for (int i = 0; i < psf1.Length; i++)
            {
                Stream in1 =
                    new ByteArrayInputStream(psf1[i].GetBytes());
                PropertySet        psIn     = PropertySetFactory.Create(in1);
                MutablePropertySet psOut    = new MutablePropertySet(psIn);
                MemoryStream       psStream =
                    new MemoryStream();
                psOut.Write(psStream);
                psStream.Close();
                byte[] streamData = psStream.ToArray();
                poiFs.CreateDocument(new ByteArrayInputStream(streamData),
                                     psf1[i].GetName());
                poiFs.WriteFileSystem(out1);
            }

            /* Read the property Set streams from the POI filesystem just
             * Created. */
            POIFile[] psf2 = Util.ReadPropertySets(copy);
            for (int i = 0; i < psf2.Length; i++)
            {
                byte[]      bytes1 = psf1[i].GetBytes();
                byte[]      bytes2 = psf2[i].GetBytes();
                Stream      in1    = new ByteArrayInputStream(bytes1);
                Stream      in2    = new ByteArrayInputStream(bytes2);
                PropertySet ps1    = PropertySetFactory.Create(in1);
                PropertySet ps2    = PropertySetFactory.Create(in2);

                /* Compare the property Set stream with the corresponding one
                 * from the origin file and check whether they are equal. */

                Assert.AreEqual(ps1, ps2, "Equality for file " + f.Name);
            }
            out1.Close();
        }
コード例 #6
0
        public void TestFile()
        {
            FileStream f = data.GetFile("Notes.ole2");

            FileBackedDataSource ds = new FileBackedDataSource(f, true);

            try
            {
                Assert.AreEqual(8192, ds.Size);

                ByteBuffer bs;
                bs = ds.Read(4, 0);
                Assert.AreEqual(4, bs.Length);
                //Assert.AreEqual(0, bs
                Assert.AreEqual(unchecked ((byte)0xd0 - (byte)256), bs[0]);
                Assert.AreEqual(unchecked ((byte)0xcf - (byte)256), bs[1]);
                Assert.AreEqual(unchecked ((byte)0x11 - 0), bs[2]);
                Assert.AreEqual(unchecked ((byte)0xe0 - (byte)256), bs[3]);

                bs = ds.Read(8, 0x400);
                Assert.AreEqual(8, bs.Length);
                //Assert.AreEqual(0, bs.position());
                Assert.AreEqual((byte)'R', bs[0]);
                Assert.AreEqual(0, bs[1]);
                Assert.AreEqual((byte)'o', bs[2]);
                Assert.AreEqual(0, bs[3]);
                Assert.AreEqual((byte)'o', bs[4]);
                Assert.AreEqual(0, bs[5]);
                Assert.AreEqual((byte)'t', bs[6]);
                Assert.AreEqual(0, bs[7]);

                // Can go to the end, but not past it
                bs = ds.Read(8, 8190);
                Assert.AreEqual(0, bs.Position);// TODO How best to warn of a short read?

                // Can't go off the end
                try
                {
                    bs = ds.Read(4, 8192);
                    Assert.Fail("Shouldn't be able to read off the end of the file");
                }
                catch (System.ArgumentException)
                {
                }
            }
            finally
            {
                ds.Close();
            }
        }
コード例 #7
0
ファイル: TestWrite.cs プロジェクト: thinhmascot/NPOI
        public void TestNoFormatID()
        {
            FileStream file = _samples.GetFile(POI_FS);
            //FileStream filename = File.OpenRead(dataDir + POI_FS);
            //filename.deleteOnExit();

            /* Create a mutable property Set with a section that does not have the
             * formatID Set: */
            FileStream         out1  = file;
            POIFSFileSystem    poiFs = new POIFSFileSystem();
            MutablePropertySet ps    = new MutablePropertySet();

            ps.ClearSections();
            ps.AddSection(new MutableSection());

            /* Write it to a POIFS and the latter to disk: */
            try
            {
                MemoryStream psStream = new MemoryStream();
                ps.Write(psStream);
                psStream.Close();
                byte[] streamData = psStream.ToArray();
                poiFs.CreateDocument(new MemoryStream(streamData),
                                     SummaryInformation.DEFAULT_STREAM_NAME);
                poiFs.WriteFileSystem(out1);
                out1.Close();
                Assert.Fail("Should have thrown a NoFormatIDException.");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is NoFormatIDException);
            }
            finally
            {
                out1.Close();
            }
        }
コード例 #8
0
ファイル: TestDataSource.cs プロジェクト: zuiwanting/npoi
        public void TestFile()
        {
            FileStream f = data.GetFile("Notes.ole2");

            FileBackedDataSource ds = new FileBackedDataSource(f);

            Assert.AreEqual(8192, ds.Size);

            ByteBuffer bs;

            bs = ds.Read(4, 0);
            Assert.AreEqual(4, bs.Length);
            //Assert.AreEqual(0, bs
            Assert.AreEqual(unchecked ((byte)0xd0 - (byte)256), bs[0]);
            Assert.AreEqual(unchecked ((byte)0xcf - (byte)256), bs[1]);
            Assert.AreEqual(unchecked ((byte)0x11 - 0), bs[2]);
            Assert.AreEqual(unchecked ((byte)0xe0 - (byte)256), bs[3]);

            bs = ds.Read(8, 0x400);
            Assert.AreEqual(8, bs.Length);
            //Assert.AreEqual(0, bs.position());
            Assert.AreEqual((byte)'R', bs[0]);
            Assert.AreEqual(0, bs[1]);
            Assert.AreEqual((byte)'o', bs[2]);
            Assert.AreEqual(0, bs[3]);
            Assert.AreEqual((byte)'o', bs[4]);
            Assert.AreEqual(0, bs[5]);
            Assert.AreEqual((byte)'t', bs[6]);
            Assert.AreEqual(0, bs[7]);

            bs = ds.Read(8, 8190);
            //Assert.AreEqual(0,

            try
            {
                bs = ds.Read(4, 8192);
                Assert.Fail("Shouldn't be able to read off the end of the file");
            }
            catch (System.ArgumentException)
            {
            }
        }
コード例 #9
0
        public void TestWriteWellKnown1()
        {
            POIDataSamples _samples = POIDataSamples.GetHPSFInstance();

            using (FileStream doc1 = _samples.GetFile(POI_FS))
            {
                /* Read a Test document <em>doc1</em> into a POI filesystem. */
                POIFSFileSystem poifs    = new POIFSFileSystem(doc1);
                DirectoryEntry  dir      = poifs.Root;
                DocumentEntry   siEntry  = (DocumentEntry)dir.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME);
                DocumentEntry   dsiEntry = (DocumentEntry)dir.GetEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);

                /*
                 * Read the summary information stream and the document summary
                 * information stream from the POI filesystem.
                 *
                 * Please note that the result consists of SummaryInformation and
                 * DocumentSummaryInformation instances which are in memory only. To
                 * make them permanent they have to be written to a POI filesystem
                 * explicitly (overwriting the former contents). Then the POI filesystem
                 * should be saved to a file.
                 */
                DocumentInputStream dis = new DocumentInputStream(siEntry);
                PropertySet         ps  = new PropertySet(dis);
                SummaryInformation  si  = new SummaryInformation(ps);
                dis = new DocumentInputStream(dsiEntry);
                ps  = new PropertySet(dis);
                DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps);

                /*
                 * Write all properties supported by HPSF to the summary information
                 * (e.g. author, edit date, application name) and to the document
                 * summary information (e.g. company, manager).
                 */
                Calendar cal = new GregorianCalendar();
                //long time1 = (long)cal.GetMilliseconds(new DateTime(2000, 6, 6, 6, 6, 6));

                //long time2 = (long)cal.GetMilliseconds(new DateTime(2001, 7, 7, 7, 7, 7));
                //long time3 = (long)cal.GetMilliseconds(new DateTime(2002, 8, 8, 8, 8, 8));

                int      nr = 4711;
                String   P_APPLICATION_NAME    = "Microsoft Office Word";
                String   P_AUTHOR              = "Rainer Klute";
                int      P_CHAR_COUNT          = 125;
                String   P_COMMENTS            = ""; //"Comments";
                DateTime P_CREATE_DATE_TIME    = new DateTime(2006, 2, 1, 7, 36, 0);
                long     P_EDIT_TIME           = ++nr * 1000 * 10;
                String   P_KEYWORDS            = "Test HPSF SummaryInformation DocumentSummaryInformation Writing";
                String   P_LAST_AUTHOR         = "LastAuthor";
                DateTime?P_LAST_PRINTED        = new DateTime(2001, 7, 7, 7, 7, 7);
                DateTime P_LAST_SAVE_DATE_TIME = new DateTime(2008, 9, 30, 9, 54, 0);
                int      P_PAGE_COUNT          = 1;
                String   P_REV_NUMBER          = "RevNumber";
                int      P_SECURITY            = 1;
                String   P_SUBJECT             = "Subject";
                String   P_TEMPLATE            = "Normal.dotm";
                // FIXME (byte array properties not yet implemented): byte[] P_THUMBNAIL = new byte[123];
                String P_TITLE      = "This document is used for testing POI HPSF¡¯s writing capabilities for the summary information stream and the document summary information stream";
                int    P_WORD_COUNT = 21;

                int    P_BYTE_COUNT = ++nr;
                String P_CATEGORY   = "Category";
                String P_COMPANY    = "Rainer Klute IT-Consulting GmbH";
                // FIXME (byte array properties not yet implemented): byte[]  P_DOCPARTS = new byte[123];
                // FIXME (byte array properties not yet implemented): byte[]  P_HEADING_PAIR = new byte[123];
                int      P_HIDDEN_COUNT        = ++nr;
                int      P_LINE_COUNT          = ++nr;
                bool     P_LINKS_DIRTY         = true;
                String   P_MANAGER             = "Manager";
                int      P_MM_CLIP_COUNT       = ++nr;
                int      P_NOTE_COUNT          = ++nr;
                int      P_PAR_COUNT           = ++nr;
                String   P_PRESENTATION_FORMAT = "PresentationFormat";
                bool     P_SCALE       = false;
                int      P_SLIDE_COUNT = ++nr;
                DateTime now           = DateTime.Now;

                int    POSITIVE_INTEGER = 2222;
                long   POSITIVE_LONG    = 3333;
                Double POSITIVE_DOUBLE  = 4444;
                int    NEGATIVE_INTEGER = 2222;
                long   NEGATIVE_LONG    = 3333;
                Double NEGATIVE_DOUBLE  = 4444;

                int    MAX_INTEGER = int.MaxValue;
                int    MIN_INTEGER = int.MinValue;
                long   MAX_LONG    = long.MaxValue;
                long   MIN_LONG    = long.MinValue;
                Double MAX_DOUBLE  = Double.MaxValue;
                Double MIN_DOUBLE  = Double.MinValue;

                si.ApplicationName  = P_APPLICATION_NAME;
                si.Author           = P_AUTHOR;
                si.CharCount        = P_CHAR_COUNT;
                si.Comments         = P_COMMENTS;
                si.CreateDateTime   = P_CREATE_DATE_TIME;
                si.EditTime         = P_EDIT_TIME;
                si.Keywords         = P_KEYWORDS;
                si.LastAuthor       = P_LAST_AUTHOR;
                si.LastPrinted      = P_LAST_PRINTED;
                si.LastSaveDateTime = P_LAST_SAVE_DATE_TIME;
                si.PageCount        = P_PAGE_COUNT;
                si.RevNumber        = P_REV_NUMBER;
                si.Security         = P_SECURITY;
                si.Subject          = P_SUBJECT;
                si.Template         = P_TEMPLATE;
                // FIXME (byte array properties not yet implemented): si.Thumbnail=P_THUMBNAIL;
                si.Title     = P_TITLE;
                si.WordCount = P_WORD_COUNT;

                dsi.ByteCount = P_BYTE_COUNT;
                dsi.Category  = P_CATEGORY;
                dsi.Company   = P_COMPANY;
                // FIXME (byte array properties not yet implemented): dsi.Docparts=P_DOCPARTS;
                // FIXME (byte array properties not yet implemented): dsi.HeadingPair=P_HEADING_PAIR;
                dsi.HiddenCount        = P_HIDDEN_COUNT;
                dsi.LineCount          = P_LINE_COUNT;
                dsi.LinksDirty         = P_LINKS_DIRTY;
                dsi.Manager            = P_MANAGER;
                dsi.MMClipCount        = P_MM_CLIP_COUNT;
                dsi.NoteCount          = P_NOTE_COUNT;
                dsi.ParCount           = P_PAR_COUNT;
                dsi.PresentationFormat = P_PRESENTATION_FORMAT;
                dsi.Scale      = P_SCALE;
                dsi.SlideCount = P_SLIDE_COUNT;

                CustomProperties customProperties = dsi.CustomProperties;
                if (customProperties == null)
                {
                    customProperties = new CustomProperties();
                }
                customProperties.Put("Schlüssel 1", "Wert 1");
                customProperties.Put("Schlüssel 2", "Wert 2");
                customProperties.Put("Schlüssel 3", "Wert 3");
                customProperties.Put("Schlüssel 4", "Wert 4");
                customProperties.Put("positive_int", POSITIVE_INTEGER);
                customProperties.Put("positive_long", POSITIVE_LONG);
                customProperties.Put("positive_Double", POSITIVE_DOUBLE);
                customProperties.Put("negative_int", NEGATIVE_INTEGER);
                customProperties.Put("negative_long", NEGATIVE_LONG);
                customProperties.Put("negative_Double", NEGATIVE_DOUBLE);
                customProperties.Put("Boolean", true);
                customProperties.Put("Date", now);
                customProperties.Put("max_int", MAX_INTEGER);
                customProperties.Put("min_int", MIN_INTEGER);
                customProperties.Put("max_long", MAX_LONG);
                customProperties.Put("min_long", MIN_LONG);
                customProperties.Put("max_Double", MAX_DOUBLE);
                customProperties.Put("min_Double", MIN_DOUBLE);
                dsi.CustomProperties = customProperties;

                /* Write the summary information stream and the document summary
                 * information stream to the POI filesystem. */
                si.Write(dir, siEntry.Name);
                dsi.Write(dir, dsiEntry.Name);

                /* Write the POI filesystem to a (temporary) file <em>doc2</em>
                 * and Close the latter. */
                using (FileStream doc2 = File.Create(@".\POI_HPSF_Test2.tmp"))
                {
                    poifs.WriteFileSystem(doc2);
                    //doc2.Flush();

                    /*
                     * Open <em>doc2</em> for Reading and check summary information and
                     * document summary information. All properties written before must be
                     * found in the property streams of <em>doc2</em> and have the correct
                     * values.
                     */
                    doc2.Flush();
                    doc2.Position = 0;
                    POIFSFileSystem poifs2 = new POIFSFileSystem(doc2);
                    dir      = poifs2.Root;
                    siEntry  = (DocumentEntry)dir.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME);
                    dsiEntry = (DocumentEntry)dir.GetEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);

                    dis = new DocumentInputStream(siEntry);
                    ps  = new PropertySet(dis);
                    si  = new SummaryInformation(ps);
                    dis = new DocumentInputStream(dsiEntry);
                    ps  = new PropertySet(dis);
                    dsi = new DocumentSummaryInformation(ps);

                    Assert.AreEqual(P_APPLICATION_NAME, si.ApplicationName);
                    Assert.AreEqual(P_AUTHOR, si.Author);
                    Assert.AreEqual(P_CHAR_COUNT, si.CharCount);
                    Assert.AreEqual(P_COMMENTS, si.Comments);
                    Assert.AreEqual(P_CREATE_DATE_TIME, si.CreateDateTime);
                    Assert.AreEqual(P_EDIT_TIME, si.EditTime);
                    Assert.AreEqual(P_KEYWORDS, si.Keywords);
                    Assert.AreEqual(P_LAST_AUTHOR, si.LastAuthor);
                    Assert.AreEqual(P_LAST_PRINTED, si.LastPrinted);
                    Assert.AreEqual(P_LAST_SAVE_DATE_TIME, si.LastSaveDateTime);
                    Assert.AreEqual(P_PAGE_COUNT, si.PageCount);
                    Assert.AreEqual(P_REV_NUMBER, si.RevNumber);
                    Assert.AreEqual(P_SECURITY, si.Security);
                    Assert.AreEqual(P_SUBJECT, si.Subject);
                    Assert.AreEqual(P_TEMPLATE, si.Template);
                    // FIXME (byte array properties not yet implemented): Assert.AreEqual(P_THUMBNAIL, si.Thumbnail);
                    Assert.AreEqual(P_TITLE, si.Title);
                    Assert.AreEqual(P_WORD_COUNT, si.WordCount);

                    Assert.AreEqual(P_BYTE_COUNT, dsi.ByteCount);
                    Assert.AreEqual(P_CATEGORY, dsi.Category);
                    Assert.AreEqual(P_COMPANY, dsi.Company);
                    // FIXME (byte array properties not yet implemented): Assert.AreEqual(P_, dsi.Docparts);
                    // FIXME (byte array properties not yet implemented): Assert.AreEqual(P_, dsi.HeadingPair);
                    Assert.AreEqual(P_HIDDEN_COUNT, dsi.HiddenCount);
                    Assert.AreEqual(P_LINE_COUNT, dsi.LineCount);
                    Assert.AreEqual(P_LINKS_DIRTY, dsi.LinksDirty);
                    Assert.AreEqual(P_MANAGER, dsi.Manager);
                    Assert.AreEqual(P_MM_CLIP_COUNT, dsi.MMClipCount);
                    Assert.AreEqual(P_NOTE_COUNT, dsi.NoteCount);
                    Assert.AreEqual(P_PAR_COUNT, dsi.ParCount);
                    Assert.AreEqual(P_PRESENTATION_FORMAT, dsi.PresentationFormat);
                    Assert.AreEqual(P_SCALE, dsi.Scale);
                    Assert.AreEqual(P_SLIDE_COUNT, dsi.SlideCount);

                    CustomProperties cps = dsi.CustomProperties;
                    //Assert.AreEqual(customProperties, cps);
                    Assert.IsNull(cps["No value available"]);
                    Assert.AreEqual("Wert 1", cps["Schlüssel 1"]);
                    Assert.AreEqual("Wert 2", cps["Schlüssel 2"]);
                    Assert.AreEqual("Wert 3", cps["Schlüssel 3"]);
                    Assert.AreEqual("Wert 4", cps["Schlüssel 4"]);
                    Assert.AreEqual(POSITIVE_INTEGER, cps["positive_int"]);
                    Assert.AreEqual(POSITIVE_LONG, cps["positive_long"]);
                    Assert.AreEqual(POSITIVE_DOUBLE, cps["positive_Double"]);
                    Assert.AreEqual(NEGATIVE_INTEGER, cps["negative_int"]);
                    Assert.AreEqual(NEGATIVE_LONG, cps["negative_long"]);
                    Assert.AreEqual(NEGATIVE_DOUBLE, cps["negative_Double"]);
                    Assert.AreEqual(true, cps["Boolean"]);
                    Assert.AreEqual(now, cps["Date"]);
                    Assert.AreEqual(MAX_INTEGER, cps["max_int"]);
                    Assert.AreEqual(MIN_INTEGER, cps["min_int"]);
                    Assert.AreEqual(MAX_LONG, cps["max_long"]);
                    Assert.AreEqual(MIN_LONG, cps["min_long"]);
                    Assert.AreEqual(MAX_DOUBLE, cps["max_Double"]);
                    Assert.AreEqual(MIN_DOUBLE, cps["min_Double"]);

                    /* Remove all properties supported by HPSF from the summary
                     * information (e.g. author, edit date, application name) and from the
                     * document summary information (e.g. company, manager). */
                    si.RemoveApplicationName();
                    si.RemoveAuthor();
                    si.RemoveCharCount();
                    si.RemoveComments();
                    si.RemoveCreateDateTime();
                    si.RemoveEditTime();
                    si.RemoveKeywords();
                    si.RemoveLastAuthor();
                    si.RemoveLastPrinted();
                    si.RemoveLastSaveDateTime();
                    si.RemovePageCount();
                    si.RemoveRevNumber();
                    si.RemoveSecurity();
                    si.RemoveSubject();
                    si.RemoveTemplate();
                    si.RemoveThumbnail();
                    si.RemoveTitle();
                    si.RemoveWordCount();

                    dsi.RemoveByteCount();
                    dsi.RemoveCategory();
                    dsi.RemoveCompany();
                    dsi.RemoveCustomProperties();
                    dsi.RemoveDocparts();
                    dsi.RemoveHeadingPair();
                    dsi.RemoveHiddenCount();
                    dsi.RemoveLineCount();
                    dsi.RemoveLinksDirty();
                    dsi.RemoveManager();
                    dsi.RemoveMMClipCount();
                    dsi.RemoveNoteCount();
                    dsi.RemoveParCount();
                    dsi.RemovePresentationFormat();
                    dsi.RemoveScale();
                    dsi.RemoveSlideCount();

                    /*
                     * <li>Write the summary information stream and the document summary
                     * information stream to the POI filesystem. */
                    si.Write(dir, siEntry.Name);
                    dsi.Write(dir, dsiEntry.Name);

                    /*
                     * <li>Write the POI filesystem to a (temporary) file <em>doc3</em>
                     * and Close the latter. */
                    using (FileStream doc3 = File.Create(@".\POI_HPSF_Test3.tmp"))
                    {
                        poifs2.WriteFileSystem(doc3);
                        doc3.Position = 0;

                        /*
                         * Open <em>doc3</em> for Reading and check summary information
                         * and document summary information. All properties Removed before must not
                         * be found in the property streams of <em>doc3</em>.
                         */
                        POIFSFileSystem poifs3 = new POIFSFileSystem(doc3);

                        dir      = poifs3.Root;
                        siEntry  = (DocumentEntry)dir.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME);
                        dsiEntry = (DocumentEntry)dir.GetEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);

                        dis = new DocumentInputStream(siEntry);
                        ps  = new PropertySet(dis);
                        si  = new SummaryInformation(ps);
                        dis = new DocumentInputStream(dsiEntry);
                        ps  = new PropertySet(dis);
                        dsi = new DocumentSummaryInformation(ps);

                        Assert.AreEqual(null, si.ApplicationName);
                        Assert.AreEqual(null, si.Author);
                        Assert.AreEqual(0, si.CharCount);
                        Assert.IsTrue(si.WasNull);
                        Assert.AreEqual(null, si.Comments);
                        Assert.AreEqual(null, si.CreateDateTime);
                        Assert.AreEqual(0, si.EditTime);
                        Assert.IsTrue(si.WasNull);
                        Assert.AreEqual(null, si.Keywords);
                        Assert.AreEqual(null, si.LastAuthor);
                        Assert.AreEqual(null, si.LastPrinted);
                        Assert.AreEqual(null, si.LastSaveDateTime);
                        Assert.AreEqual(0, si.PageCount);
                        Assert.IsTrue(si.WasNull);
                        Assert.AreEqual(null, si.RevNumber);
                        Assert.AreEqual(0, si.Security);
                        Assert.IsTrue(si.WasNull);
                        Assert.AreEqual(null, si.Subject);
                        Assert.AreEqual(null, si.Template);
                        Assert.AreEqual(null, si.Thumbnail);
                        Assert.AreEqual(null, si.Title);
                        Assert.AreEqual(0, si.WordCount);
                        Assert.IsTrue(si.WasNull);

                        Assert.AreEqual(0, dsi.ByteCount);
                        Assert.IsTrue(dsi.WasNull);
                        Assert.AreEqual(null, dsi.Category);
                        Assert.AreEqual(null, dsi.CustomProperties);
                        // FIXME (byte array properties not yet implemented): Assert.AreEqual(null, dsi.Docparts);
                        // FIXME (byte array properties not yet implemented): Assert.AreEqual(null, dsi.HeadingPair);
                        Assert.AreEqual(0, dsi.HiddenCount);
                        Assert.IsTrue(dsi.WasNull);
                        Assert.AreEqual(0, dsi.LineCount);
                        Assert.IsTrue(dsi.WasNull);
                        Assert.AreEqual(false, dsi.LinksDirty);
                        Assert.IsTrue(dsi.WasNull);
                        Assert.AreEqual(null, dsi.Manager);
                        Assert.AreEqual(0, dsi.MMClipCount);
                        Assert.IsTrue(dsi.WasNull);
                        Assert.AreEqual(0, dsi.NoteCount);
                        Assert.IsTrue(dsi.WasNull);
                        Assert.AreEqual(0, dsi.ParCount);
                        Assert.IsTrue(dsi.WasNull);
                        Assert.AreEqual(null, dsi.PresentationFormat);
                        Assert.AreEqual(false, dsi.Scale);
                        Assert.IsTrue(dsi.WasNull);
                        Assert.AreEqual(0, dsi.SlideCount);
                        Assert.IsTrue(dsi.WasNull);
                    }
                }
            }

            if (File.Exists(@".\POI_HPSF_Test3.tmp"))
            {
                File.Delete(@".\POI_HPSF_Test3.tmp");
            }

            if (File.Exists(@".\POI_HPSF_Test2.tmp"))
            {
                File.Delete(@".\POI_HPSF_Test2.tmp");
            }
        }
コード例 #10
0
ファイル: TestPackage.cs プロジェクト: zzy092/npoi
        public void NonOOXMLFileTypes()
        {
            // Spreadsheet has a good mix of alternate file types
            POIDataSamples files = POIDataSamples.GetSpreadSheetInstance();

            // OLE2 - Stream
            try
            {
                Stream stream = files.OpenResourceAsStream("SampleSS.xls");
                try
                {
                    OPCPackage.Open(stream);
                }
                finally
                {
                    stream.Dispose();//.Close();
                }
                Assert.Fail("Shouldn't be able to open OLE2");
            }
            catch (OLE2NotOfficeXmlFileException e)
            {
                Assert.IsTrue(e.Message.Contains("The supplied data appears to be in the OLE2 Format"));
                Assert.IsTrue(e.Message.Contains("You are calling the part of POI that deals with OOXML"));
            }
            // OLE2 - File
            try
            {
                OPCPackage.Open(files.GetFile("SampleSS.xls"));
                Assert.Fail("Shouldn't be able to open OLE2");
            }
            catch (OLE2NotOfficeXmlFileException e)
            {
                Assert.IsTrue(e.Message.Contains("The supplied data appears to be in the OLE2 Format"));
                Assert.IsTrue(e.Message.Contains("You are calling the part of POI that deals with OOXML"));
            }

            // Raw XML - Stream
            try
            {
                Stream stream = files.OpenResourceAsStream("SampleSS.xml");
                try
                {
                    OPCPackage.Open(stream);
                }
                finally
                {
                    stream.Dispose();//.Close();
                }
                Assert.Fail("Shouldn't be able to open XML");
            }
            catch (NotOfficeXmlFileException e)
            {
                Assert.IsTrue(e.Message.Contains("The supplied data appears to be a raw XML file"));
                Assert.IsTrue(e.Message.Contains("Formats such as Office 2003 XML"));
            }
            // Raw XML - File
            try
            {
                OPCPackage.Open(files.GetFile("SampleSS.xml"));
                Assert.Fail("Shouldn't be able to open XML");
            }
            catch (NotOfficeXmlFileException e)
            {
                Assert.IsTrue(e.Message.Contains("The supplied data appears to be a raw XML file"));
                Assert.IsTrue(e.Message.Contains("Formats such as Office 2003 XML"));
            }

            // ODF / ODS - Stream
            try
            {
                Stream stream = files.OpenResourceAsStream("SampleSS.ods");
                try
                {
                    OPCPackage.Open(stream);
                }
                finally
                {
                    stream.Dispose();//.Close();
                }
                Assert.Fail("Shouldn't be able to open ODS");
            }
            catch (ODFNotOfficeXmlFileException e)
            {
                Assert.IsTrue(e.ToString().Contains("The supplied data appears to be in ODF"));
                Assert.IsTrue(e.ToString().Contains("Formats like these (eg ODS"));
            }
            // ODF / ODS - File
            try
            {
                OPCPackage.Open(files.GetFile("SampleSS.ods"));
                Assert.Fail("Shouldn't be able to open ODS");
            }
            catch (ODFNotOfficeXmlFileException e)
            {
                Assert.IsTrue(e.ToString().Contains("The supplied data appears to be in ODF"));
                Assert.IsTrue(e.ToString().Contains("Formats like these (eg ODS"));
            }

            // Plain Text - Stream
            try
            {
                Stream stream = files.OpenResourceAsStream("SampleSS.txt");
                try
                {
                    OPCPackage.Open(stream);
                }
                finally
                {
                    stream.Dispose();//.Close();
                }
                Assert.Fail("Shouldn't be able to open Plain Text");
            }
            catch (NotOfficeXmlFileException e)
            {
                Assert.IsTrue(e.Message.Contains("No valid entries or contents found"));
                Assert.IsTrue(e.Message.Contains("not a valid OOXML"));
            }
            // Plain Text - File
            try
            {
                OPCPackage.Open(files.GetFile("SampleSS.txt"));
                Assert.Fail("Shouldn't be able to open Plain Text");
            }
            catch (UnsupportedFileFormatException)
            {
                // Unhelpful low-level error, sorry
            }
        }
コード例 #11
0
        public void TestNextBlock()
        {
            // It's the same on 512 byte and 4096 byte block files!
            NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.GetFile("BlockSize512.zvi"));
            NPOIFSFileSystem fsB = new NPOIFSFileSystem(_inst.OpenResourceAsStream("BlockSize512.zvi"));
            NPOIFSFileSystem fsC = new NPOIFSFileSystem(_inst.GetFile("BlockSize4096.zvi"));
            NPOIFSFileSystem fsD = new NPOIFSFileSystem(_inst.OpenResourceAsStream("BlockSize4096.zvi"));

            foreach (NPOIFSFileSystem fs in new NPOIFSFileSystem[] { fsA, fsB, fsC, fsD })
            {
                NPOIFSMiniStore ministore = fs.GetMiniStore();

                // 0 -> 51 is one stream
                for (int i = 0; i < 50; i++)
                {
                    Assert.AreEqual(i + 1, ministore.GetNextBlock(i));
                }
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(50));

                // 51 -> 103 is the next
                for (int i = 51; i < 103; i++)
                {
                    Assert.AreEqual(i + 1, ministore.GetNextBlock(i));
                }
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(103));

                // Then there are 3 one block ones
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(104));
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(105));
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(106));

                // 107 -> 154 is the next
                for (int i = 107; i < 154; i++)
                {
                    Assert.AreEqual(i + 1, ministore.GetNextBlock(i));
                }
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(154));

                // 155 -> 160 is the next
                for (int i = 155; i < 160; i++)
                {
                    Assert.AreEqual(i + 1, ministore.GetNextBlock(i));
                }
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(160));

                // 161 -> 166 is the next
                for (int i = 161; i < 166; i++)
                {
                    Assert.AreEqual(i + 1, ministore.GetNextBlock(i));
                }
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(166));

                // 167 -> 172 is the next
                for (int i = 167; i < 172; i++)
                {
                    Assert.AreEqual(i + 1, ministore.GetNextBlock(i));
                }
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(172));

                // Now some short ones
                Assert.AreEqual(174, ministore.GetNextBlock(173));
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(174));

                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(175));

                Assert.AreEqual(177, ministore.GetNextBlock(176));
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(177));

                Assert.AreEqual(179, ministore.GetNextBlock(178));
                Assert.AreEqual(180, ministore.GetNextBlock(179));
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(180));

                // 181 onwards is free
                for (int i = 181; i < fs.GetBigBlockSizeDetails().GetBATEntriesPerBlock(); i++)
                {
                    Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, ministore.GetNextBlock(i));
                }
                fs.Close();
            }

            fsD.Close();
            fsC.Close();
            fsB.Close();
            fsA.Close();
        }
コード例 #12
0
        /**
         * Returns test files with 512 byte and 4k block sizes, loaded
         *  both from InputStreams and Files
         */
        protected NPOIFSFileSystem[] get512and4kFileAndInput()
        {
            NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.GetFile("BlockSize512.zvi"));
            NPOIFSFileSystem fsB = new NPOIFSFileSystem(_inst.OpenResourceAsStream("BlockSize512.zvi"));
            NPOIFSFileSystem fsC = new NPOIFSFileSystem(_inst.GetFile("BlockSize4096.zvi"));
            NPOIFSFileSystem fsD = new NPOIFSFileSystem(_inst.OpenResourceAsStream("BlockSize4096.zvi"));

            return(new NPOIFSFileSystem[] { fsA, fsB, fsC, fsD });
        }
コード例 #13
0
        public void TestBasicOpen()
        {
            NPOIFSFileSystem fsA, fsB;

            fsA = new NPOIFSFileSystem(_inst.GetFile("BlockSize512.zvi"));
            fsB = new NPOIFSFileSystem(_inst.OpenResourceAsStream("BlockSize512.zvi"));

            foreach (NPOIFSFileSystem fs in new NPOIFSFileSystem[] { fsA, fsB })
            {
                Assert.AreEqual(512, fs.GetBigBlockSize());
            }

            fsA = new NPOIFSFileSystem(_inst.GetFile("BlockSize4096.zvi"));
            fsB = new NPOIFSFileSystem(_inst.OpenResourceAsStream("BlockSize4096.zvi"));

            foreach (NPOIFSFileSystem fs in new NPOIFSFileSystem[] { fsA, fsB })
            {
                Assert.AreEqual(4096, fs.GetBigBlockSize());
            }
        }
コード例 #14
0
ファイル: TestUnicode.cs プロジェクト: thinhmascot/NPOI
        public void Setup()
        {
            POIDataSamples samples = POIDataSamples.GetHPSFInstance();

            data = samples.GetFile(POI_FS);
        }