Source Code Cross Referenced for TestTextRunReWrite.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hslf » model » 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.model 
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.model;
019:
020:        import junit.framework.TestCase;
021:        import java.io.*;
022:
023:        import org.apache.poi.hslf.HSLFSlideShow;
024:        import org.apache.poi.hslf.usermodel.RichTextRun;
025:        import org.apache.poi.hslf.usermodel.SlideShow;
026:        import org.apache.poi.poifs.filesystem.*;
027:
028:        /**
029:         * Tests that if we load something up, get a TextRun, set the text
030:         *  to be the same as it was before, and write it all back out again,
031:         *  that we don't break anything in the process. 
032:         *
033:         * @author Nick Burch (nick at torchbox dot com)
034:         */
035:        public class TestTextRunReWrite extends TestCase {
036:            // HSLFSlideShow primed on the test data
037:            private HSLFSlideShow hss;
038:            // HSLFSlideShow primed on the test data
039:            private SlideShow ss;
040:            // POIFS primed on the test data
041:            private POIFSFileSystem pfs;
042:
043:            /**
044:             * Load up a test PPT file with rich data
045:             */
046:            public void setUp() throws Exception {
047:                String dirname = System.getProperty("HSLF.testdata.path");
048:                String filename = dirname
049:                        + "/Single_Coloured_Page_With_Fonts_and_Alignments.ppt";
050:                FileInputStream fis = new FileInputStream(filename);
051:                pfs = new POIFSFileSystem(fis);
052:                hss = new HSLFSlideShow(pfs);
053:                ss = new SlideShow(hss);
054:            }
055:
056:            public void testWritesOutTheSameNonRich() throws Exception {
057:                // Grab the first text run on the first sheet
058:                TextRun tr1 = ss.getSlides()[0].getTextRuns()[0];
059:                TextRun tr2 = ss.getSlides()[0].getTextRuns()[1];
060:
061:                // Ensure the text lengths are as we'd expect to start with
062:                assertEquals(1, ss.getSlides().length);
063:                assertEquals(2, ss.getSlides()[0].getTextRuns().length);
064:                assertEquals(30, tr1.getText().length());
065:                assertEquals(179, tr2.getText().length());
066:
067:                assertEquals(1, tr1.getRichTextRuns().length);
068:                assertEquals(30, tr1.getRichTextRuns()[0].getLength());
069:                assertEquals(30, tr1.getRichTextRuns()[0].getText().length());
070:                assertEquals(31, tr1.getRichTextRuns()[0]
071:                        ._getRawCharacterStyle().getCharactersCovered());
072:                assertEquals(31, tr1.getRichTextRuns()[0]
073:                        ._getRawParagraphStyle().getCharactersCovered());
074:
075:                // Set the text to be as it is now
076:                tr1.setText(tr1.getText());
077:
078:                // Check the text lengths are still right
079:                assertEquals(30, tr1.getText().length());
080:                assertEquals(179, tr2.getText().length());
081:
082:                assertEquals(1, tr1.getRichTextRuns().length);
083:                assertEquals(30, tr1.getRichTextRuns()[0].getLength());
084:                assertEquals(30, tr1.getRichTextRuns()[0].getText().length());
085:                assertEquals(31, tr1.getRichTextRuns()[0]
086:                        ._getRawCharacterStyle().getCharactersCovered());
087:                assertEquals(31, tr1.getRichTextRuns()[0]
088:                        ._getRawParagraphStyle().getCharactersCovered());
089:
090:                // Write the slideshow out to a byte array
091:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
092:                ss.write(baos);
093:
094:                // Build an input stream of it
095:                ByteArrayInputStream bais = new ByteArrayInputStream(baos
096:                        .toByteArray());
097:
098:                // Use POIFS to query that lot
099:                POIFSFileSystem npfs = new POIFSFileSystem(bais);
100:
101:                // Check that the "PowerPoint Document" sections have the same size
102:                DocumentEntry oProps = (DocumentEntry) pfs.getRoot().getEntry(
103:                        "PowerPoint Document");
104:                DocumentEntry nProps = (DocumentEntry) npfs.getRoot().getEntry(
105:                        "PowerPoint Document");
106:                assertEquals(oProps.getSize(), nProps.getSize());
107:
108:                // Check that they contain the same data
109:                byte[] _oData = new byte[oProps.getSize()];
110:                byte[] _nData = new byte[nProps.getSize()];
111:                pfs.createDocumentInputStream("PowerPoint Document").read(
112:                        _oData);
113:                npfs.createDocumentInputStream("PowerPoint Document").read(
114:                        _nData);
115:                for (int i = 0; i < _oData.length; i++) {
116:                    System.out.println(i + "\t" + Integer.toHexString(i));
117:                    assertEquals(_oData[i], _nData[i]);
118:                }
119:            }
120:
121:            public void testWritesOutTheSameRich() throws Exception {
122:                // Grab the first text run on the first sheet
123:                TextRun tr1 = ss.getSlides()[0].getTextRuns()[0];
124:
125:                // Get the first rich text run
126:                RichTextRun rtr1 = tr1.getRichTextRuns()[0];
127:
128:                // Check that the text sizes are as expected
129:                assertEquals(1, tr1.getRichTextRuns().length);
130:                assertEquals(30, tr1.getText().length());
131:                assertEquals(30, tr1.getRichTextRuns()[0].getText().length());
132:                assertEquals(30, rtr1.getLength());
133:                assertEquals(30, rtr1.getText().length());
134:                assertEquals(31, rtr1._getRawCharacterStyle()
135:                        .getCharactersCovered());
136:                assertEquals(31, rtr1._getRawParagraphStyle()
137:                        .getCharactersCovered());
138:
139:                // Set the text to be as it is now
140:                rtr1.setText(rtr1.getText());
141:                rtr1 = tr1.getRichTextRuns()[0];
142:
143:                // Check that the text sizes are still as expected
144:                assertEquals(1, tr1.getRichTextRuns().length);
145:                assertEquals(30, tr1.getText().length());
146:                assertEquals(30, tr1.getRichTextRuns()[0].getText().length());
147:                assertEquals(30, rtr1.getLength());
148:                assertEquals(30, rtr1.getText().length());
149:                assertEquals(31, rtr1._getRawCharacterStyle()
150:                        .getCharactersCovered());
151:                assertEquals(31, rtr1._getRawParagraphStyle()
152:                        .getCharactersCovered());
153:
154:                // Write the slideshow out to a byte array
155:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
156:                ss.write(baos);
157:
158:                // Build an input stream of it
159:                ByteArrayInputStream bais = new ByteArrayInputStream(baos
160:                        .toByteArray());
161:
162:                // Use POIFS to query that lot
163:                POIFSFileSystem npfs = new POIFSFileSystem(bais);
164:
165:                // Check that the "PowerPoint Document" sections have the same size
166:                DocumentEntry oProps = (DocumentEntry) pfs.getRoot().getEntry(
167:                        "PowerPoint Document");
168:                DocumentEntry nProps = (DocumentEntry) npfs.getRoot().getEntry(
169:                        "PowerPoint Document");
170:                assertEquals(oProps.getSize(), nProps.getSize());
171:
172:                // Check that they contain the same data
173:                byte[] _oData = new byte[oProps.getSize()];
174:                byte[] _nData = new byte[nProps.getSize()];
175:                pfs.createDocumentInputStream("PowerPoint Document").read(
176:                        _oData);
177:                npfs.createDocumentInputStream("PowerPoint Document").read(
178:                        _nData);
179:                for (int i = 0; i < _oData.length; i++) {
180:                    System.out.println(i + "\t" + Integer.toHexString(i) + "\t"
181:                            + _oData[i]);
182:                    assertEquals(_oData[i], _nData[i]);
183:                }
184:            }
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.