Source Code Cross Referenced for TestReWrite.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hslf » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Collaboration » poi 3.0.2 beta2 » org.apache.poi.hslf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:         Licensed to the Apache Software Foundation (ASF) under one or more
003:         contributor license agreements.  See the NOTICE file distributed with
004:         this work for additional information regarding copyright ownership.
005:         The ASF licenses this file to You under the Apache License, Version 2.0
006:         (the "License"); you may not use this file except in compliance with
007:         the License.  You may obtain a copy of the License at
008:
009:         http://www.apache.org/licenses/LICENSE-2.0
010:
011:         Unless required by applicable law or agreed to in writing, software
012:         distributed under the License is distributed on an "AS IS" BASIS,
013:         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         See the License for the specific language governing permissions and
015:         limitations under the License.
016:         ==================================================================== */
017:
018:        package org.apache.poi.hslf;
019:
020:        import junit.framework.TestCase;
021:        import java.io.*;
022:
023:        import org.apache.poi.hslf.usermodel.SlideShow;
024:        import org.apache.poi.poifs.filesystem.*;
025:
026:        /**
027:         * Tests that HSLFSlideShow writes the powerpoint bit of data back out
028:         *  correctly. Currently, that means being the same as what it read in
029:         *
030:         * @author Nick Burch (nick at torchbox dot com)
031:         */
032:        public class TestReWrite extends TestCase {
033:            // HSLFSlideShow primed on the test data
034:            private HSLFSlideShow hssA;
035:            private HSLFSlideShow hssB;
036:            private HSLFSlideShow hssC;
037:            // POIFS primed on the test data
038:            private POIFSFileSystem pfsA;
039:            private POIFSFileSystem pfsB;
040:            private POIFSFileSystem pfsC;
041:
042:            public void setUp() throws Exception {
043:                String dirname = System.getProperty("HSLF.testdata.path");
044:
045:                String filenameA = dirname + "/basic_test_ppt_file.ppt";
046:                FileInputStream fisA = new FileInputStream(filenameA);
047:                pfsA = new POIFSFileSystem(fisA);
048:                hssA = new HSLFSlideShow(pfsA);
049:
050:                String filenameB = dirname
051:                        + "/ParagraphStylesShorterThanCharStyles.ppt";
052:                FileInputStream fisB = new FileInputStream(filenameB);
053:                pfsB = new POIFSFileSystem(fisB);
054:                hssB = new HSLFSlideShow(pfsB);
055:
056:                String filenameC = dirname + "/WithMacros.ppt";
057:                FileInputStream fisC = new FileInputStream(filenameC);
058:                pfsC = new POIFSFileSystem(fisC);
059:                hssC = new HSLFSlideShow(pfsC);
060:            }
061:
062:            public void testWritesOutTheSame() throws Exception {
063:                assertWritesOutTheSame(hssA, pfsA);
064:                assertWritesOutTheSame(hssB, pfsB);
065:            }
066:
067:            public void assertWritesOutTheSame(HSLFSlideShow hss,
068:                    POIFSFileSystem pfs) throws Exception {
069:                // Write out to a byte array
070:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
071:                hss.write(baos);
072:
073:                // Build an input stream of it
074:                ByteArrayInputStream bais = new ByteArrayInputStream(baos
075:                        .toByteArray());
076:
077:                // Use POIFS to query that lot
078:                POIFSFileSystem npfs = new POIFSFileSystem(bais);
079:
080:                // Check that the "PowerPoint Document" sections have the same size
081:                DocumentEntry oProps = (DocumentEntry) pfs.getRoot().getEntry(
082:                        "PowerPoint Document");
083:                DocumentEntry nProps = (DocumentEntry) npfs.getRoot().getEntry(
084:                        "PowerPoint Document");
085:                assertEquals(oProps.getSize(), nProps.getSize());
086:
087:                // Check that they contain the same data
088:                byte[] _oData = new byte[oProps.getSize()];
089:                byte[] _nData = new byte[nProps.getSize()];
090:                pfs.createDocumentInputStream("PowerPoint Document").read(
091:                        _oData);
092:                npfs.createDocumentInputStream("PowerPoint Document").read(
093:                        _nData);
094:                for (int i = 0; i < _oData.length; i++) {
095:                    //System.out.println(i + "\t" + Integer.toHexString(i));
096:                    assertEquals(_oData[i], _nData[i]);
097:                }
098:            }
099:
100:            public void testWithMacroStreams() throws Exception {
101:                // Check that they're apparently the same
102:                assertSlideShowWritesOutTheSame(hssC, pfsC);
103:
104:                // Currently has a Macros stream
105:                assertNotNull(pfsC.getRoot().getEntry("Macros"));
106:
107:                // Write out normally, will loose the macro stream
108:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
109:                hssC.write(baos);
110:                POIFSFileSystem pfsNew = new POIFSFileSystem(
111:                        new ByteArrayInputStream(baos.toByteArray()));
112:
113:                try {
114:                    pfsNew.getRoot().getEntry("Macros");
115:                    fail();
116:                } catch (FileNotFoundException e) {
117:                    // Good, as expected
118:                }
119:
120:                // But if we write out with nodes preserved, will be there
121:                baos = new ByteArrayOutputStream();
122:                hssC.write(baos, true);
123:                pfsNew = new POIFSFileSystem(new ByteArrayInputStream(baos
124:                        .toByteArray()));
125:                assertNotNull(pfsNew.getRoot().getEntry("Macros"));
126:            }
127:
128:            /**
129:             * Ensure that simply opening a slideshow (usermodel) view of it
130:             *  doesn't change things 
131:             */
132:            public void testSlideShowWritesOutTheSame() throws Exception {
133:                assertSlideShowWritesOutTheSame(hssA, pfsA);
134:
135:                // Some bug in StyleTextPropAtom rewriting means this will fail
136:                // We need to identify and fix that first
137:                //assertSlideShowWritesOutTheSame(hssB, pfsB);
138:            }
139:
140:            public void assertSlideShowWritesOutTheSame(HSLFSlideShow hss,
141:                    POIFSFileSystem pfs) throws Exception {
142:                // Create a slideshow covering it
143:                SlideShow ss = new SlideShow(hss);
144:                ss.getSlides();
145:                ss.getNotes();
146:
147:                // Now write out to a byte array
148:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
149:                hss.write(baos);
150:
151:                // Build an input stream of it
152:                ByteArrayInputStream bais = new ByteArrayInputStream(baos
153:                        .toByteArray());
154:
155:                // Use POIFS to query that lot
156:                POIFSFileSystem npfs = new POIFSFileSystem(bais);
157:
158:                // Check that the "PowerPoint Document" sections have the same size
159:                DocumentEntry oProps = (DocumentEntry) pfs.getRoot().getEntry(
160:                        "PowerPoint Document");
161:                DocumentEntry nProps = (DocumentEntry) npfs.getRoot().getEntry(
162:                        "PowerPoint Document");
163:                assertEquals(oProps.getSize(), nProps.getSize());
164:
165:                // Check that they contain the same data
166:                byte[] _oData = new byte[oProps.getSize()];
167:                byte[] _nData = new byte[nProps.getSize()];
168:                pfs.createDocumentInputStream("PowerPoint Document").read(
169:                        _oData);
170:                npfs.createDocumentInputStream("PowerPoint Document").read(
171:                        _nData);
172:                for (int i = 0; i < _oData.length; i++) {
173:                    if (_oData[i] != _nData[i])
174:                        System.out.println(i + "\t" + Integer.toHexString(i));
175:                    assertEquals(_oData[i], _nData[i]);
176:                }
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.