TestFIB.cs :  » GUI » NPOI » TestCases » HWPF » Model » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » NPOI 
NPOI » TestCases » HWPF » Model » TestFIB.cs
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;
            }            
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.