Exemple #1
0
        public void TestDictionary()
        {
            FileStream copy = File.Create(testContextInstance.TestDir + @"\Test-HPSF.ole2");
            //copy.deleteOnExit();

            /* Write: */
            FileStream         out1  = copy;
            POIFSFileSystem    poiFs = new POIFSFileSystem();
            MutablePropertySet ps1   = new MutablePropertySet();
            MutableSection     s     = (MutableSection)ps1.Sections[0];
            Hashtable          m     = new Hashtable(3, 1.0f);

            m[1]         = "String 1";
            m[2]         = "String 2";
            m[3]         = "String 3";
            s.Dictionary = (m);
            s.SetFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID1);
            int codepage = (int)Constants.CP_UNICODE;

            s.SetProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2,
                          codepage);
            poiFs.CreateDocument(ps1.GetStream(), "Test");
            poiFs.WriteFileSystem(out1);

            /* Read back: */
            POIFile[] psf = Util.ReadPropertySets(copy);
            Assert.AreEqual(1, psf.Length);
            byte[]      bytes = psf[0].GetBytes();
            Stream      in1   = new MemoryStream(bytes);
            PropertySet ps2   = PropertySetFactory.Create(in1);

            /* Check if the result is a DocumentSummaryInformation stream, as
             * specified. */
            Assert.IsTrue(ps2.IsDocumentSummaryInformation);

            /* Compare the property Set stream with the corresponding one
             * from the origin file and check whether they are equal. */
            Assert.IsTrue(ps1.Equals(ps2));

            out1.Close();
            copy.Close();
            File.Delete(testContextInstance.TestDir + @"\Test-HPSF.ole2");
        }
Exemple #2
0
        public void TestDictionary()
        {
            using (FileStream copy = File.Create(@".\Test-HPSF.ole2"))
            {
                /* Write: */
                POIFSFileSystem             poiFs = new POIFSFileSystem();
                MutablePropertySet          ps1   = new MutablePropertySet();
                MutableSection              s     = (MutableSection)ps1.Sections[0];
                Dictionary <object, object> m     = new Dictionary <object, object>(3);
                m[1]         = "String 1";
                m[2]         = "String 2";
                m[3]         = "String 3";
                s.Dictionary = (m);
                s.SetFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID1);
                int codepage = CodePageUtil.CP_UNICODE;
                s.SetProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, codepage);
                poiFs.CreateDocument(ps1.ToInputStream(), "Test");
                poiFs.WriteFileSystem(copy);

                /* Read back: */
                POIFile[] psf = Util.ReadPropertySets(copy);
                Assert.AreEqual(1, psf.Length);
                byte[]      bytes = psf[0].GetBytes();
                Stream      in1   = new ByteArrayInputStream(bytes);
                PropertySet ps2   = PropertySetFactory.Create(in1);

                /* Check if the result is a DocumentSummaryInformation stream, as
                 * specified. */
                Assert.IsTrue(ps2.IsDocumentSummaryInformation);

                /* Compare the property Set stream with the corresponding one
                 * from the origin file and check whether they are equal. */
                Assert.IsTrue(ps1.Equals(ps2));
            }

            if (File.Exists(@".\Test-HPSF.ole2"))
            {
                File.Delete(@".\Test-HPSF.ole2");
            }
        }