aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases
diff options
context:
space:
mode:
authorHenri Yandell <bayard@apache.org>2006-12-22 20:56:04 +0000
committerHenri Yandell <bayard@apache.org>2006-12-22 20:56:04 +0000
commite4d9311a5aced3ca99a3a27010b9f0321c1ae3b4 (patch)
tree41b6fb4ddac92cb4722d02c63fa0ba3b16aaea3e /src/testcases
parentb8f7a14477a11fa9a68cee66baba0e4a32be0fe6 (diff)
downloadpoi-e4d9311a5aced3ca99a3a27010b9f0321c1ae3b4.tar.gz
poi-e4d9311a5aced3ca99a3a27010b9f0321c1ae3b4.zip
Applying dos2unix on some of the Java files. The copy2license script isn't picking up the dos line endings. Hopefully not a problem for anyone
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@489760 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java1652
-rw-r--r--src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java122
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java262
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java304
4 files changed, 1170 insertions, 1170 deletions
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java b/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
index 00fcd2e501..2079d57e64 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
@@ -1,827 +1,827 @@
-/* ====================================================================
- Copyright 2002-2006 Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hpsf.basic;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-import java.util.Random;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.hpsf.CustomProperties;
-import org.apache.poi.hpsf.DocumentSummaryInformation;
-import org.apache.poi.hpsf.MarkUnsupportedException;
-import org.apache.poi.hpsf.NoPropertySetStreamException;
-import org.apache.poi.hpsf.PropertySet;
-import org.apache.poi.hpsf.PropertySetFactory;
-import org.apache.poi.hpsf.SummaryInformation;
-import org.apache.poi.hpsf.UnexpectedPropertySetTypeException;
-import org.apache.poi.hpsf.WritingNotSupportedException;
-import org.apache.poi.poifs.filesystem.DirectoryEntry;
-import org.apache.poi.poifs.filesystem.DocumentEntry;
-import org.apache.poi.poifs.filesystem.DocumentInputStream;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-/**
- * Basing on: src/examples/src/org/apache/poi/hpsf/examples/ModifyDocumentSummaryInformation.java
- * This class tests reading and writing of meta data. No actual document is created. All information
- * is stored in a virtal document in a ByteArrayOutputStream
- * @author Matthias Günter
- * @since 2006-03-03
- * @version $Id: TestEmptyProperties.java 353563 2004-06-22 16:16:33Z klute $
- */
-public class TestMetaDataIPI extends TestCase{
-
- private ByteArrayOutputStream bout= null; //our store
- private POIFSFileSystem poifs=null;
- DirectoryEntry dir = null;
- DocumentSummaryInformation dsi=null;
- SummaryInformation si=null;
-
- /**
- * Standard constructor
- * @param s
- */
- public TestMetaDataIPI(String s ){
- super(s);
- }
-
- /**
- * Setup is used to get the document ready. Gets the DocumentSummaryInformation and the
- * SummaryInformation to reasonable values
- */
- public void setUp(){
- bout=new ByteArrayOutputStream();
- poifs= new POIFSFileSystem();
- dir = poifs.getRoot();
- dsi=null;
- try
- {
- DocumentEntry dsiEntry = (DocumentEntry)
- dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
- DocumentInputStream dis = new DocumentInputStream(dsiEntry);
- PropertySet ps = new PropertySet(dis);
- dis.close();
- dsi = new DocumentSummaryInformation(ps);
-
-
- }
- catch (FileNotFoundException ex)
- {
- /* There is no document summary information yet. We have to create a
- * new one. */
- dsi = PropertySetFactory.newDocumentSummaryInformation();
- assertNotNull(dsi);
- } catch (IOException e) {
- e.printStackTrace();
- fail();
- } catch (NoPropertySetStreamException e) {
- e.printStackTrace();
- fail();
- } catch (MarkUnsupportedException e) {
- e.printStackTrace();
- fail();
- } catch (UnexpectedPropertySetTypeException e) {
- e.printStackTrace();
- fail();
- }
- assertNotNull(dsi);
- try
- {
- DocumentEntry dsiEntry = (DocumentEntry)
- dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
- DocumentInputStream dis = new DocumentInputStream(dsiEntry);
- PropertySet ps = new PropertySet(dis);
- dis.close();
- si = new SummaryInformation(ps);
-
-
- }
- catch (FileNotFoundException ex)
- {
- /* There is no document summary information yet. We have to create a
- * new one. */
- si = PropertySetFactory.newSummaryInformation();
- assertNotNull(si);
- } catch (IOException e) {
- e.printStackTrace();
- fail();
- } catch (NoPropertySetStreamException e) {
- e.printStackTrace();
- fail();
- } catch (MarkUnsupportedException e) {
- e.printStackTrace();
- fail();
- } catch (UnexpectedPropertySetTypeException e) {
- e.printStackTrace();
- fail();
- }
- assertNotNull(dsi);
-
-
- }
-
- /**
- * Setting a lot of things to null.
- */
- public void tearDown(){
- bout=null;
- poifs=null;
- dir=null;
- dsi=null;
-
- }
-
-
- /**
- * Closes the ByteArrayOutputStream and reads it into a ByteArrayInputStream.
- * When finished writing information this method is used in the tests to
- * start reading from the created document and then the see if the results match.
- *
- */
- public void closeAndReOpen(){
-
- try {
- dsi.write(dir, DocumentSummaryInformation.DEFAULT_STREAM_NAME);
- si.write(dir,SummaryInformation.DEFAULT_STREAM_NAME);
- } catch (WritingNotSupportedException e) {
- e.printStackTrace();
- fail();
- } catch (IOException e) {
- e.printStackTrace();
- fail();
- }
-
- si=null;
- dsi=null;
- try {
-
- poifs.writeFilesystem(bout);
- bout.flush();
-
- } catch (IOException e) {
-
- e.printStackTrace();
- fail();
- }
-
- InputStream is=new ByteArrayInputStream(bout.toByteArray());
- assertNotNull(is);
- POIFSFileSystem poifs=null;
- try {
- poifs = new POIFSFileSystem(is);
- } catch (IOException e) {
-
- e.printStackTrace();
- fail();
- }
- try {
- is.close();
- } catch (IOException e) {
- e.printStackTrace();
- fail();
- }
- assertNotNull(poifs);
- /* Read the document summary information. */
- DirectoryEntry dir = poifs.getRoot();
-
- try
- {
- DocumentEntry dsiEntry = (DocumentEntry)
- dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
- DocumentInputStream dis = new DocumentInputStream(dsiEntry);
- PropertySet ps = new PropertySet(dis);
- dis.close();
- dsi = new DocumentSummaryInformation(ps);
- }
- catch (FileNotFoundException ex)
- {
- fail();
- } catch (IOException e) {
- e.printStackTrace();
- fail();
- } catch (NoPropertySetStreamException e) {
- e.printStackTrace();
- fail();
- } catch (MarkUnsupportedException e) {
- e.printStackTrace();
- fail();
- } catch (UnexpectedPropertySetTypeException e) {
- e.printStackTrace();
- fail();
- }
- try
- {
- DocumentEntry dsiEntry = (DocumentEntry)
- dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
- DocumentInputStream dis = new DocumentInputStream(dsiEntry);
- PropertySet ps = new PropertySet(dis);
- dis.close();
- si = new SummaryInformation(ps);
-
-
- }
- catch (FileNotFoundException ex)
- {
- /* There is no document summary information yet. We have to create a
- * new one. */
- si = PropertySetFactory.newSummaryInformation();
- assertNotNull(si);
- } catch (IOException e) {
- e.printStackTrace();
- fail();
- } catch (NoPropertySetStreamException e) {
- e.printStackTrace();
- fail();
- } catch (MarkUnsupportedException e) {
- e.printStackTrace();
- fail();
- } catch (UnexpectedPropertySetTypeException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- /**
- * Sets the most important information in DocumentSummaryInformation and Summary Information and rereads it
- *
- */
- public void testOne(){
-
- //DocumentSummaryInformation
- dsi.setCompany("xxxCompanyxxx");
- dsi.setManager("xxxManagerxxx");
- dsi.setCategory("xxxCategoryxxx");
-
- //SummaryInformation
- si.setTitle("xxxTitlexxx");
- si.setAuthor("xxxAuthorxxx");
- si.setComments("xxxCommentsxxx");
- si.setKeywords("xxxKeyWordsxxx");
- si.setSubject("xxxSubjectxxx");
-
- //Custom Properties (in DocumentSummaryInformation
- CustomProperties customProperties = dsi.getCustomProperties();
- if (customProperties == null){
- customProperties = new CustomProperties();
- }
-
- /* Insert some custom properties into the container. */
- customProperties.put("Key1", "Value1");
- customProperties.put("Schlüssel2", "Wert2");
- customProperties.put("Sample Integer", new Integer(12345));
- customProperties.put("Sample Boolean", new Boolean(true));
- Date date=new Date();
- customProperties.put("Sample Date", date);
- customProperties.put("Sample Double", new Double(-1.0001));
- customProperties.put("Sample Negative Integer", new Integer(-100000));
-
- dsi.setCustomProperties(customProperties);
-
- //start reading
- closeAndReOpen();
-
- //testing
- assertNotNull(dsi);
- assertNotNull(si);
-
- assertEquals("Category","xxxCategoryxxx",dsi.getCategory());
- assertEquals("Company","xxxCompanyxxx",dsi.getCompany());
- assertEquals("Manager","xxxManagerxxx",dsi.getManager());
-
- assertEquals("","xxxAuthorxxx",si.getAuthor());
- assertEquals("","xxxTitlexxx",si.getTitle());
- assertEquals("","xxxCommentsxxx",si.getComments());
- assertEquals("","xxxKeyWordsxxx",si.getKeywords());
- assertEquals("","xxxSubjectxxx",si.getSubject());
-
-
- /* Read the custom properties. If there are no custom properties yet,
- * the application has to create a new CustomProperties object. It will
- * serve as a container for custom properties. */
- customProperties = dsi.getCustomProperties();
- if (customProperties == null){
- fail();
- }
-
- /* Insert some custom properties into the container. */
- String a1=(String) customProperties.get("Key1");
- assertEquals("Key1","Value1",a1);
- String a2=(String) customProperties.get("Schlüssel2");
- assertEquals("Schlüssel2","Wert2",a2);
- Integer a3=(Integer) customProperties.get("Sample Integer");
- assertEquals("Sample Number",new Integer(12345),a3);
- Boolean a4=(Boolean) customProperties.get("Sample Boolean");
- assertEquals("Sample Boolean",new Boolean(true),a4);
- Date a5=(Date) customProperties.get("Sample Date");
- assertEquals("Custom Date:",date,a5);
-
- Double a6=(Double) customProperties.get("Sample Double");
- assertEquals("Custom Float",new Double(-1.0001),a6);
-
- Integer a7=(Integer) customProperties.get("Sample Negative Integer");
- assertEquals("Neg", new Integer(-100000),a7);
- }
-
-
- /**
- * multiplies a string
- * @param s Input String
- * @return the multiplied String
- */
- public String elongate(String s){
- StringBuffer sb=new StringBuffer();
- for (int i=0;i<10000;i++){
- sb.append(s);
- sb.append(" ");
- }
- return sb.toString();
- }
-
-
-
- /**
- * Test very long input in each of the fields (approx 30-60KB each)
- *
- */
-public void testTwo(){
-
- String company=elongate("company");
- String manager=elongate("manager");
- String category=elongate("category");
- String title=elongate("title");
- String author=elongate("author");
- String comments=elongate("comments");
- String keywords=elongate("keywords");
- String subject=elongate("subject");
- String p1=elongate("p1");
- String p2=elongate("p2");
- String k1=elongate("k1");
- String k2=elongate("k2");
-
- dsi.setCompany(company);
- dsi.setManager(manager);
- dsi.setCategory(category);
-
- si.setTitle(title);
- si.setAuthor(author);
- si.setComments(comments);
- si.setKeywords(keywords);
- si.setSubject(subject);
- CustomProperties customProperties = dsi.getCustomProperties();
- if (customProperties == null){
- customProperties = new CustomProperties();
- }
-
- /* Insert some custom properties into the container. */
- customProperties.put(k1, p1);
- customProperties.put(k2, p2);
- customProperties.put("Sample Number", new Integer(12345));
- customProperties.put("Sample Boolean", new Boolean(true));
- Date date=new Date();
- customProperties.put("Sample Date", date);
-
- dsi.setCustomProperties(customProperties);
-
-
- closeAndReOpen();
-
- assertNotNull(dsi);
- assertNotNull(si);
- /* Change the category to "POI example". Any former category value will
- * be lost. If there has been no category yet, it will be created. */
- assertEquals("Category",category,dsi.getCategory());
- assertEquals("Company",company,dsi.getCompany());
- assertEquals("Manager",manager,dsi.getManager());
-
- assertEquals("",author,si.getAuthor());
- assertEquals("",title,si.getTitle());
- assertEquals("",comments,si.getComments());
- assertEquals("",keywords,si.getKeywords());
- assertEquals("",subject,si.getSubject());
-
-
- /* Read the custom properties. If there are no custom properties
- * yet, the application has to create a new CustomProperties object.
- * It will serve as a container for custom properties. */
- customProperties = dsi.getCustomProperties();
- if (customProperties == null){
- fail();
- }
-
- /* Insert some custom properties into the container. */
- String a1=(String) customProperties.get(k1);
- assertEquals("Key1",p1,a1);
- String a2=(String) customProperties.get(k2);
- assertEquals("Schlüssel2",p2,a2);
- Integer a3=(Integer) customProperties.get("Sample Number");
- assertEquals("Sample Number",new Integer(12345),a3);
- Boolean a4=(Boolean) customProperties.get("Sample Boolean");
- assertEquals("Sample Boolean",new Boolean(true),a4);
- Date a5=(Date) customProperties.get("Sample Date");
- assertEquals("Custom Date:",date,a5);
-
-
- }
-
-
-/**
- * adds strange characters to the string
- * @param s Input String
- * @return the multiplied String
- */
-public String strangize(String s){
- StringBuffer sb=new StringBuffer();
- String[] umlaute= {"ä","ü","ö","Ü","$","Ö","Ü","É","Ö","@","ç","&"};
- char j=0;
- Random rand=new Random();
- for (int i=0;i<5;i++){
- sb.append(s);
- sb.append(" ");
- j=(char) rand.nextInt(220);
- j+=33;
- // System.out.println(j);
- sb.append(">");
- sb.append(new Character(j));
- sb.append("=");
- sb.append(umlaute[rand.nextInt(umlaute.length)]);
- sb.append("<");
- }
-
- return sb.toString();
-}
-
-
-/**
- * Tests with strange characters in keys and data (Umlaute etc.)
- *
- */
-public void testThree(){
-
- String company=strangize("company");
- String manager=strangize("manager");
- String category=strangize("category");
- String title=strangize("title");
- String author=strangize("author");
- String comments=strangize("comments");
- String keywords=strangize("keywords");
- String subject=strangize("subject");
- String p1=strangize("p1");
- String p2=strangize("p2");
- String k1=strangize("k1");
- String k2=strangize("k2");
-
- dsi.setCompany(company);
- dsi.setManager(manager);
- dsi.setCategory(category);
-
- si.setTitle(title);
- si.setAuthor(author);
- si.setComments(comments);
- si.setKeywords(keywords);
- si.setSubject(subject);
- CustomProperties customProperties = dsi.getCustomProperties();
- if (customProperties == null){
- customProperties = new CustomProperties();
- }
-
- /* Insert some custom properties into the container. */
- customProperties.put(k1, p1);
- customProperties.put(k2, p2);
- customProperties.put("Sample Number", new Integer(12345));
- customProperties.put("Sample Boolean", new Boolean(false));
- Date date=new Date(0);
- customProperties.put("Sample Date", date);
-
- dsi.setCustomProperties(customProperties);
-
-
- closeAndReOpen();
-
- assertNotNull(dsi);
- assertNotNull(si);
- /* Change the category to "POI example". Any former category value will
- * be lost. If there has been no category yet, it will be created. */
- assertEquals("Category",category,dsi.getCategory());
- assertEquals("Company",company,dsi.getCompany());
- assertEquals("Manager",manager,dsi.getManager());
-
- assertEquals("",author,si.getAuthor());
- assertEquals("",title,si.getTitle());
- assertEquals("",comments,si.getComments());
- assertEquals("",keywords,si.getKeywords());
- assertEquals("",subject,si.getSubject());
-
-
- /* Read the custom properties. If there are no custom properties yet,
- * the application has to create a new CustomProperties object. It will
- * serve as a container for custom properties. */
- customProperties = dsi.getCustomProperties();
- if (customProperties == null){
- fail();
- }
-
- /* Insert some custom properties into the container. */
- // System.out.println(k1);
- String a1=(String) customProperties.get(k1);
- assertEquals("Key1",p1,a1);
- String a2=(String) customProperties.get(k2);
- assertEquals("Schlüssel2",p2,a2);
- Integer a3=(Integer) customProperties.get("Sample Number");
- assertEquals("Sample Number",new Integer(12345),a3);
- Boolean a4=(Boolean) customProperties.get("Sample Boolean");
- assertEquals("Sample Boolean",new Boolean(false),a4);
- Date a5=(Date) customProperties.get("Sample Date");
- assertEquals("Custom Date:",date,a5);
-
-
- }
-
- /**
- * Iterative testing: writing, reading etc.
- *
- */
- public void testFour(){
- for (int i=1;i<100;i++){
- setUp();
- testThree();
- tearDown();
- }
- }
-
-
-
- /**
- * adds strange characters to the string with the adding of unicode characters
- * @param s Input String
- * @return the multiplied String
- */
- public String strangizeU(String s){
-
- StringBuffer sb=new StringBuffer();
- String[] umlaute= {"ä","ü","ö","Ü","$","Ö","Ü","É","Ö","@","ç","&"};
- char j=0;
- Random rand=new Random();
- for (int i=0;i<5;i++){
- sb.append(s);
- sb.append(" ");
- j=(char) rand.nextInt(220);
- j+=33;
- // System.out.println(j);
- sb.append(">");
- sb.append(new Character(j));
- sb.append("=");
- sb.append(umlaute[rand.nextInt(umlaute.length)]);
- sb.append("<");
- }
- sb.append("äöü\uD840\uDC00");
- return sb.toString();
- }
- /**
- * Unicode test
- *
- */
- public void testUnicode(){
- String company=strangizeU("company");
- String manager=strangizeU("manager");
- String category=strangizeU("category");
- String title=strangizeU("title");
- String author=strangizeU("author");
- String comments=strangizeU("comments");
- String keywords=strangizeU("keywords");
- String subject=strangizeU("subject");
- String p1=strangizeU("p1");
- String p2=strangizeU("p2");
- String k1=strangizeU("k1");
- String k2=strangizeU("k2");
-
- dsi.setCompany(company);
- dsi.setManager(manager);
- dsi.setCategory(category);
-
- si.setTitle(title);
- si.setAuthor(author);
- si.setComments(comments);
- si.setKeywords(keywords);
- si.setSubject(subject);
- CustomProperties customProperties = dsi.getCustomProperties();
- if (customProperties == null){
- customProperties = new CustomProperties();
- }
-
- /* Insert some custom properties into the container. */
- customProperties.put(k1, p1);
- customProperties.put(k2, p2);
- customProperties.put("Sample Number", new Integer(12345));
- customProperties.put("Sample Boolean", new Boolean(true));
- Date date=new Date();
- customProperties.put("Sample Date", date);
-
- dsi.setCustomProperties(customProperties);
-
-
- closeAndReOpen();
-
- assertNotNull(dsi);
- assertNotNull(si);
- /* Change the category to "POI example". Any former category value will
- * be lost. If there has been no category yet, it will be created. */
- assertEquals("Category",category,dsi.getCategory());
- assertEquals("Company",company,dsi.getCompany());
- assertEquals("Manager",manager,dsi.getManager());
-
- assertEquals("",author,si.getAuthor());
- assertEquals("",title,si.getTitle());
- assertEquals("",comments,si.getComments());
- assertEquals("",keywords,si.getKeywords());
- assertEquals("",subject,si.getSubject());
-
-
- /* Read the custom properties. If there are no custom properties yet,
- * the application has to create a new CustomProperties object. It will
- * serve as a container for custom properties. */
- customProperties = dsi.getCustomProperties();
- if (customProperties == null){
- fail();
- }
-
- /* Insert some custom properties into the container. */
- // System.out.println(k1);
- String a1=(String) customProperties.get(k1);
- assertEquals("Key1",p1,a1);
- String a2=(String) customProperties.get(k2);
- assertEquals("Schlüssel2",p2,a2);
- Integer a3=(Integer) customProperties.get("Sample Number");
- assertEquals("Sample Number",new Integer(12345),a3);
- Boolean a4=(Boolean) customProperties.get("Sample Boolean");
- assertEquals("Sample Boolean",new Boolean(true),a4);
- Date a5=(Date) customProperties.get("Sample Date");
- assertEquals("Custom Date:",date,a5);
-
-
-
- }
-
-
- /**
- * Iterative testing of the unicode test
- *
- */
- public void testSix(){
- for (int i=1;i<100;i++){
- setUp();
- testUnicode();
- tearDown();
- }
- }
-
-
- /**
- * Tests conversion in custom fields and errors
- *
- */
- public void testConvAndExistance(){
-
-
- CustomProperties customProperties = dsi.getCustomProperties();
- if (customProperties == null){
- customProperties = new CustomProperties();
- }
-
- /* Insert some custom properties into the container. */
- customProperties.put("int", new Integer(12345));
- customProperties.put("negint", new Integer(-12345));
- customProperties.put("long", new Long(12345));
- customProperties.put("neglong", new Long(-12345));
- customProperties.put("boolean", new Boolean(true));
- customProperties.put("string", "a String");
- //customProperties.put("float", new Float(12345.0)); is not valid
- //customProperties.put("negfloat", new Float(-12345.1)); is not valid
- customProperties.put("double", new Double(12345.2));
- customProperties.put("negdouble", new Double(-12345.3));
- //customProperties.put("char", new Character('a')); is not valid
-
- Date date=new Date();
- customProperties.put("date", date);
-
- dsi.setCustomProperties(customProperties);
-
-
- closeAndReOpen();
-
- assertNotNull(dsi);
- assertNotNull(si);
- /* Change the category to "POI example". Any former category value will
- * be lost. If there has been no category yet, it will be created. */
- assertNull(dsi.getCategory());
- assertNull(dsi.getCompany());
- assertNull(dsi.getManager());
-
- assertNull(si.getAuthor());
- assertNull(si.getTitle());
- assertNull(si.getComments());
- assertNull(si.getKeywords());
- assertNull(si.getSubject());
-
-
- /* Read the custom properties. If there are no custom properties
- * yet, the application has to create a new CustomProperties object.
- * It will serve as a container for custom properties. */
- customProperties = dsi.getCustomProperties();
- if (customProperties == null){
- fail();
- }
-
- /* Insert some custom properties into the container. */
-
- Integer a3=(Integer) customProperties.get("int");
- assertEquals("int",new Integer(12345),a3);
-
- a3=(Integer) customProperties.get("negint");
- assertEquals("negint",new Integer(-12345),a3);
-
- Long al=(Long) customProperties.get("neglong");
- assertEquals("neglong",new Long(-12345),al);
-
- al=(Long) customProperties.get("long");
- assertEquals("long",new Long(12345),al);
-
- Boolean a4=(Boolean) customProperties.get("boolean");
- assertEquals("boolean",new Boolean(true),a4);
-
- Date a5=(Date) customProperties.get("date");
- assertEquals("Custom Date:",date,a5);
-
- Double d=(Double) customProperties.get("double");
- assertEquals("int",new Double(12345.2),d);
-
- d=(Double) customProperties.get("negdouble");
- assertEquals("string",new Double(-12345.3),d);
-
- String s=(String) customProperties.get("string");
- assertEquals("sring","a String",s);
-
- Object o=null;
-
- o=customProperties.get("string");
- if (!(o instanceof String)){
- fail();
- }
- o=customProperties.get("boolean");
- if (!(o instanceof Boolean)){
- fail();
- }
-
- o=customProperties.get("int");
- if (!(o instanceof Integer)){
- fail();
- }
- o=customProperties.get("negint");
- if (!(o instanceof Integer)){
- fail();
- }
-
- o=customProperties.get("long");
- if (!(o instanceof Long)){
- fail();
- }
- o=customProperties.get("neglong");
- if (!(o instanceof Long)){
- fail();
- }
-
- o=customProperties.get("double");
- if (!(o instanceof Double)){
- fail();
- }
- o=customProperties.get("negdouble");
- if (!(o instanceof Double)){
- fail();
- }
-
- o=customProperties.get("date");
- if (!(o instanceof Date)){
- fail();
- }
- }
-
-
-
+/* ====================================================================
+ Copyright 2002-2006 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hpsf.basic;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hpsf.CustomProperties;
+import org.apache.poi.hpsf.DocumentSummaryInformation;
+import org.apache.poi.hpsf.MarkUnsupportedException;
+import org.apache.poi.hpsf.NoPropertySetStreamException;
+import org.apache.poi.hpsf.PropertySet;
+import org.apache.poi.hpsf.PropertySetFactory;
+import org.apache.poi.hpsf.SummaryInformation;
+import org.apache.poi.hpsf.UnexpectedPropertySetTypeException;
+import org.apache.poi.hpsf.WritingNotSupportedException;
+import org.apache.poi.poifs.filesystem.DirectoryEntry;
+import org.apache.poi.poifs.filesystem.DocumentEntry;
+import org.apache.poi.poifs.filesystem.DocumentInputStream;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+/**
+ * Basing on: src/examples/src/org/apache/poi/hpsf/examples/ModifyDocumentSummaryInformation.java
+ * This class tests reading and writing of meta data. No actual document is created. All information
+ * is stored in a virtal document in a ByteArrayOutputStream
+ * @author Matthias Günter
+ * @since 2006-03-03
+ * @version $Id: TestEmptyProperties.java 353563 2004-06-22 16:16:33Z klute $
+ */
+public class TestMetaDataIPI extends TestCase{
+
+ private ByteArrayOutputStream bout= null; //our store
+ private POIFSFileSystem poifs=null;
+ DirectoryEntry dir = null;
+ DocumentSummaryInformation dsi=null;
+ SummaryInformation si=null;
+
+ /**
+ * Standard constructor
+ * @param s
+ */
+ public TestMetaDataIPI(String s ){
+ super(s);
+ }
+
+ /**
+ * Setup is used to get the document ready. Gets the DocumentSummaryInformation and the
+ * SummaryInformation to reasonable values
+ */
+ public void setUp(){
+ bout=new ByteArrayOutputStream();
+ poifs= new POIFSFileSystem();
+ dir = poifs.getRoot();
+ dsi=null;
+ try
+ {
+ DocumentEntry dsiEntry = (DocumentEntry)
+ dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+ DocumentInputStream dis = new DocumentInputStream(dsiEntry);
+ PropertySet ps = new PropertySet(dis);
+ dis.close();
+ dsi = new DocumentSummaryInformation(ps);
+
+
+ }
+ catch (FileNotFoundException ex)
+ {
+ /* There is no document summary information yet. We have to create a
+ * new one. */
+ dsi = PropertySetFactory.newDocumentSummaryInformation();
+ assertNotNull(dsi);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail();
+ } catch (NoPropertySetStreamException e) {
+ e.printStackTrace();
+ fail();
+ } catch (MarkUnsupportedException e) {
+ e.printStackTrace();
+ fail();
+ } catch (UnexpectedPropertySetTypeException e) {
+ e.printStackTrace();
+ fail();
+ }
+ assertNotNull(dsi);
+ try
+ {
+ DocumentEntry dsiEntry = (DocumentEntry)
+ dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
+ DocumentInputStream dis = new DocumentInputStream(dsiEntry);
+ PropertySet ps = new PropertySet(dis);
+ dis.close();
+ si = new SummaryInformation(ps);
+
+
+ }
+ catch (FileNotFoundException ex)
+ {
+ /* There is no document summary information yet. We have to create a
+ * new one. */
+ si = PropertySetFactory.newSummaryInformation();
+ assertNotNull(si);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail();
+ } catch (NoPropertySetStreamException e) {
+ e.printStackTrace();
+ fail();
+ } catch (MarkUnsupportedException e) {
+ e.printStackTrace();
+ fail();
+ } catch (UnexpectedPropertySetTypeException e) {
+ e.printStackTrace();
+ fail();
+ }
+ assertNotNull(dsi);
+
+
+ }
+
+ /**
+ * Setting a lot of things to null.
+ */
+ public void tearDown(){
+ bout=null;
+ poifs=null;
+ dir=null;
+ dsi=null;
+
+ }
+
+
+ /**
+ * Closes the ByteArrayOutputStream and reads it into a ByteArrayInputStream.
+ * When finished writing information this method is used in the tests to
+ * start reading from the created document and then the see if the results match.
+ *
+ */
+ public void closeAndReOpen(){
+
+ try {
+ dsi.write(dir, DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+ si.write(dir,SummaryInformation.DEFAULT_STREAM_NAME);
+ } catch (WritingNotSupportedException e) {
+ e.printStackTrace();
+ fail();
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail();
+ }
+
+ si=null;
+ dsi=null;
+ try {
+
+ poifs.writeFilesystem(bout);
+ bout.flush();
+
+ } catch (IOException e) {
+
+ e.printStackTrace();
+ fail();
+ }
+
+ InputStream is=new ByteArrayInputStream(bout.toByteArray());
+ assertNotNull(is);
+ POIFSFileSystem poifs=null;
+ try {
+ poifs = new POIFSFileSystem(is);
+ } catch (IOException e) {
+
+ e.printStackTrace();
+ fail();
+ }
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail();
+ }
+ assertNotNull(poifs);
+ /* Read the document summary information. */
+ DirectoryEntry dir = poifs.getRoot();
+
+ try
+ {
+ DocumentEntry dsiEntry = (DocumentEntry)
+ dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+ DocumentInputStream dis = new DocumentInputStream(dsiEntry);
+ PropertySet ps = new PropertySet(dis);
+ dis.close();
+ dsi = new DocumentSummaryInformation(ps);
+ }
+ catch (FileNotFoundException ex)
+ {
+ fail();
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail();
+ } catch (NoPropertySetStreamException e) {
+ e.printStackTrace();
+ fail();
+ } catch (MarkUnsupportedException e) {
+ e.printStackTrace();
+ fail();
+ } catch (UnexpectedPropertySetTypeException e) {
+ e.printStackTrace();
+ fail();
+ }
+ try
+ {
+ DocumentEntry dsiEntry = (DocumentEntry)
+ dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
+ DocumentInputStream dis = new DocumentInputStream(dsiEntry);
+ PropertySet ps = new PropertySet(dis);
+ dis.close();
+ si = new SummaryInformation(ps);
+
+
+ }
+ catch (FileNotFoundException ex)
+ {
+ /* There is no document summary information yet. We have to create a
+ * new one. */
+ si = PropertySetFactory.newSummaryInformation();
+ assertNotNull(si);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail();
+ } catch (NoPropertySetStreamException e) {
+ e.printStackTrace();
+ fail();
+ } catch (MarkUnsupportedException e) {
+ e.printStackTrace();
+ fail();
+ } catch (UnexpectedPropertySetTypeException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Sets the most important information in DocumentSummaryInformation and Summary Information and rereads it
+ *
+ */
+ public void testOne(){
+
+ //DocumentSummaryInformation
+ dsi.setCompany("xxxCompanyxxx");
+ dsi.setManager("xxxManagerxxx");
+ dsi.setCategory("xxxCategoryxxx");
+
+ //SummaryInformation
+ si.setTitle("xxxTitlexxx");
+ si.setAuthor("xxxAuthorxxx");
+ si.setComments("xxxCommentsxxx");
+ si.setKeywords("xxxKeyWordsxxx");
+ si.setSubject("xxxSubjectxxx");
+
+ //Custom Properties (in DocumentSummaryInformation
+ CustomProperties customProperties = dsi.getCustomProperties();
+ if (customProperties == null){
+ customProperties = new CustomProperties();
+ }
+
+ /* Insert some custom properties into the container. */
+ customProperties.put("Key1", "Value1");
+ customProperties.put("Schlüssel2", "Wert2");
+ customProperties.put("Sample Integer", new Integer(12345));
+ customProperties.put("Sample Boolean", new Boolean(true));
+ Date date=new Date();
+ customProperties.put("Sample Date", date);
+ customProperties.put("Sample Double", new Double(-1.0001));
+ customProperties.put("Sample Negative Integer", new Integer(-100000));
+
+ dsi.setCustomProperties(customProperties);
+
+ //start reading
+ closeAndReOpen();
+
+ //testing
+ assertNotNull(dsi);
+ assertNotNull(si);
+
+ assertEquals("Category","xxxCategoryxxx",dsi.getCategory());
+ assertEquals("Company","xxxCompanyxxx",dsi.getCompany());
+ assertEquals("Manager","xxxManagerxxx",dsi.getManager());
+
+ assertEquals("","xxxAuthorxxx",si.getAuthor());
+ assertEquals("","xxxTitlexxx",si.getTitle());
+ assertEquals("","xxxCommentsxxx",si.getComments());
+ assertEquals("","xxxKeyWordsxxx",si.getKeywords());
+ assertEquals("","xxxSubjectxxx",si.getSubject());
+
+
+ /* Read the custom properties. If there are no custom properties yet,
+ * the application has to create a new CustomProperties object. It will
+ * serve as a container for custom properties. */
+ customProperties = dsi.getCustomProperties();
+ if (customProperties == null){
+ fail();
+ }
+
+ /* Insert some custom properties into the container. */
+ String a1=(String) customProperties.get("Key1");
+ assertEquals("Key1","Value1",a1);
+ String a2=(String) customProperties.get("Schlüssel2");
+ assertEquals("Schlüssel2","Wert2",a2);
+ Integer a3=(Integer) customProperties.get("Sample Integer");
+ assertEquals("Sample Number",new Integer(12345),a3);
+ Boolean a4=(Boolean) customProperties.get("Sample Boolean");
+ assertEquals("Sample Boolean",new Boolean(true),a4);
+ Date a5=(Date) customProperties.get("Sample Date");
+ assertEquals("Custom Date:",date,a5);
+
+ Double a6=(Double) customProperties.get("Sample Double");
+ assertEquals("Custom Float",new Double(-1.0001),a6);
+
+ Integer a7=(Integer) customProperties.get("Sample Negative Integer");
+ assertEquals("Neg", new Integer(-100000),a7);
+ }
+
+
+ /**
+ * multiplies a string
+ * @param s Input String
+ * @return the multiplied String
+ */
+ public String elongate(String s){
+ StringBuffer sb=new StringBuffer();
+ for (int i=0;i<10000;i++){
+ sb.append(s);
+ sb.append(" ");
+ }
+ return sb.toString();
+ }
+
+
+
+ /**
+ * Test very long input in each of the fields (approx 30-60KB each)
+ *
+ */
+public void testTwo(){
+
+ String company=elongate("company");
+ String manager=elongate("manager");
+ String category=elongate("category");
+ String title=elongate("title");
+ String author=elongate("author");
+ String comments=elongate("comments");
+ String keywords=elongate("keywords");
+ String subject=elongate("subject");
+ String p1=elongate("p1");
+ String p2=elongate("p2");
+ String k1=elongate("k1");
+ String k2=elongate("k2");
+
+ dsi.setCompany(company);
+ dsi.setManager(manager);
+ dsi.setCategory(category);
+
+ si.setTitle(title);
+ si.setAuthor(author);
+ si.setComments(comments);
+ si.setKeywords(keywords);
+ si.setSubject(subject);
+ CustomProperties customProperties = dsi.getCustomProperties();
+ if (customProperties == null){
+ customProperties = new CustomProperties();
+ }
+
+ /* Insert some custom properties into the container. */
+ customProperties.put(k1, p1);
+ customProperties.put(k2, p2);
+ customProperties.put("Sample Number", new Integer(12345));
+ customProperties.put("Sample Boolean", new Boolean(true));
+ Date date=new Date();
+ customProperties.put("Sample Date", date);
+
+ dsi.setCustomProperties(customProperties);
+
+
+ closeAndReOpen();
+
+ assertNotNull(dsi);
+ assertNotNull(si);
+ /* Change the category to "POI example". Any former category value will
+ * be lost. If there has been no category yet, it will be created. */
+ assertEquals("Category",category,dsi.getCategory());
+ assertEquals("Company",company,dsi.getCompany());
+ assertEquals("Manager",manager,dsi.getManager());
+
+ assertEquals("",author,si.getAuthor());
+ assertEquals("",title,si.getTitle());
+ assertEquals("",comments,si.getComments());
+ assertEquals("",keywords,si.getKeywords());
+ assertEquals("",subject,si.getSubject());
+
+
+ /* Read the custom properties. If there are no custom properties
+ * yet, the application has to create a new CustomProperties object.
+ * It will serve as a container for custom properties. */
+ customProperties = dsi.getCustomProperties();
+ if (customProperties == null){
+ fail();
+ }
+
+ /* Insert some custom properties into the container. */
+ String a1=(String) customProperties.get(k1);
+ assertEquals("Key1",p1,a1);
+ String a2=(String) customProperties.get(k2);
+ assertEquals("Schlüssel2",p2,a2);
+ Integer a3=(Integer) customProperties.get("Sample Number");
+ assertEquals("Sample Number",new Integer(12345),a3);
+ Boolean a4=(Boolean) customProperties.get("Sample Boolean");
+ assertEquals("Sample Boolean",new Boolean(true),a4);
+ Date a5=(Date) customProperties.get("Sample Date");
+ assertEquals("Custom Date:",date,a5);
+
+
+ }
+
+
+/**
+ * adds strange characters to the string
+ * @param s Input String
+ * @return the multiplied String
+ */
+public String strangize(String s){
+ StringBuffer sb=new StringBuffer();
+ String[] umlaute= {"ä","ü","ö","Ü","$","Ö","Ü","É","Ö","@","ç","&"};
+ char j=0;
+ Random rand=new Random();
+ for (int i=0;i<5;i++){
+ sb.append(s);
+ sb.append(" ");
+ j=(char) rand.nextInt(220);
+ j+=33;
+ // System.out.println(j);
+ sb.append(">");
+ sb.append(new Character(j));
+ sb.append("=");
+ sb.append(umlaute[rand.nextInt(umlaute.length)]);
+ sb.append("<");
+ }
+
+ return sb.toString();
+}
+
+
+/**
+ * Tests with strange characters in keys and data (Umlaute etc.)
+ *
+ */
+public void testThree(){
+
+ String company=strangize("company");
+ String manager=strangize("manager");
+ String category=strangize("category");
+ String title=strangize("title");
+ String author=strangize("author");
+ String comments=strangize("comments");
+ String keywords=strangize("keywords");
+ String subject=strangize("subject");
+ String p1=strangize("p1");
+ String p2=strangize("p2");
+ String k1=strangize("k1");
+ String k2=strangize("k2");
+
+ dsi.setCompany(company);
+ dsi.setManager(manager);
+ dsi.setCategory(category);
+
+ si.setTitle(title);
+ si.setAuthor(author);
+ si.setComments(comments);
+ si.setKeywords(keywords);
+ si.setSubject(subject);
+ CustomProperties customProperties = dsi.getCustomProperties();
+ if (customProperties == null){
+ customProperties = new CustomProperties();
+ }
+
+ /* Insert some custom properties into the container. */
+ customProperties.put(k1, p1);
+ customProperties.put(k2, p2);
+ customProperties.put("Sample Number", new Integer(12345));
+ customProperties.put("Sample Boolean", new Boolean(false));
+ Date date=new Date(0);
+ customProperties.put("Sample Date", date);
+
+ dsi.setCustomProperties(customProperties);
+
+
+ closeAndReOpen();
+
+ assertNotNull(dsi);
+ assertNotNull(si);
+ /* Change the category to "POI example". Any former category value will
+ * be lost. If there has been no category yet, it will be created. */
+ assertEquals("Category",category,dsi.getCategory());
+ assertEquals("Company",company,dsi.getCompany());
+ assertEquals("Manager",manager,dsi.getManager());
+
+ assertEquals("",author,si.getAuthor());
+ assertEquals("",title,si.getTitle());
+ assertEquals("",comments,si.getComments());
+ assertEquals("",keywords,si.getKeywords());
+ assertEquals("",subject,si.getSubject());
+
+
+ /* Read the custom properties. If there are no custom properties yet,
+ * the application has to create a new CustomProperties object. It will
+ * serve as a container for custom properties. */
+ customProperties = dsi.getCustomProperties();
+ if (customProperties == null){
+ fail();
+ }
+
+ /* Insert some custom properties into the container. */
+ // System.out.println(k1);
+ String a1=(String) customProperties.get(k1);
+ assertEquals("Key1",p1,a1);
+ String a2=(String) customProperties.get(k2);
+ assertEquals("Schlüssel2",p2,a2);
+ Integer a3=(Integer) customProperties.get("Sample Number");
+ assertEquals("Sample Number",new Integer(12345),a3);
+ Boolean a4=(Boolean) customProperties.get("Sample Boolean");
+ assertEquals("Sample Boolean",new Boolean(false),a4);
+ Date a5=(Date) customProperties.get("Sample Date");
+ assertEquals("Custom Date:",date,a5);
+
+
+ }
+
+ /**
+ * Iterative testing: writing, reading etc.
+ *
+ */
+ public void testFour(){
+ for (int i=1;i<100;i++){
+ setUp();
+ testThree();
+ tearDown();
+ }
+ }
+
+
+
+ /**
+ * adds strange characters to the string with the adding of unicode characters
+ * @param s Input String
+ * @return the multiplied String
+ */
+ public String strangizeU(String s){
+
+ StringBuffer sb=new StringBuffer();
+ String[] umlaute= {"ä","ü","ö","Ü","$","Ö","Ü","É","Ö","@","ç","&"};
+ char j=0;
+ Random rand=new Random();
+ for (int i=0;i<5;i++){
+ sb.append(s);
+ sb.append(" ");
+ j=(char) rand.nextInt(220);
+ j+=33;
+ // System.out.println(j);
+ sb.append(">");
+ sb.append(new Character(j));
+ sb.append("=");
+ sb.append(umlaute[rand.nextInt(umlaute.length)]);
+ sb.append("<");
+ }
+ sb.append("äöü\uD840\uDC00");
+ return sb.toString();
+ }
+ /**
+ * Unicode test
+ *
+ */
+ public void testUnicode(){
+ String company=strangizeU("company");
+ String manager=strangizeU("manager");
+ String category=strangizeU("category");
+ String title=strangizeU("title");
+ String author=strangizeU("author");
+ String comments=strangizeU("comments");
+ String keywords=strangizeU("keywords");
+ String subject=strangizeU("subject");
+ String p1=strangizeU("p1");
+ String p2=strangizeU("p2");
+ String k1=strangizeU("k1");
+ String k2=strangizeU("k2");
+
+ dsi.setCompany(company);
+ dsi.setManager(manager);
+ dsi.setCategory(category);
+
+ si.setTitle(title);
+ si.setAuthor(author);
+ si.setComments(comments);
+ si.setKeywords(keywords);
+ si.setSubject(subject);
+ CustomProperties customProperties = dsi.getCustomProperties();
+ if (customProperties == null){
+ customProperties = new CustomProperties();
+ }
+
+ /* Insert some custom properties into the container. */
+ customProperties.put(k1, p1);
+ customProperties.put(k2, p2);
+ customProperties.put("Sample Number", new Integer(12345));
+ customProperties.put("Sample Boolean", new Boolean(true));
+ Date date=new Date();
+ customProperties.put("Sample Date", date);
+
+ dsi.setCustomProperties(customProperties);
+
+
+ closeAndReOpen();
+
+ assertNotNull(dsi);
+ assertNotNull(si);
+ /* Change the category to "POI example". Any former category value will
+ * be lost. If there has been no category yet, it will be created. */
+ assertEquals("Category",category,dsi.getCategory());
+ assertEquals("Company",company,dsi.getCompany());
+ assertEquals("Manager",manager,dsi.getManager());
+
+ assertEquals("",author,si.getAuthor());
+ assertEquals("",title,si.getTitle());
+ assertEquals("",comments,si.getComments());
+ assertEquals("",keywords,si.getKeywords());
+ assertEquals("",subject,si.getSubject());
+
+
+ /* Read the custom properties. If there are no custom properties yet,
+ * the application has to create a new CustomProperties object. It will
+ * serve as a container for custom properties. */
+ customProperties = dsi.getCustomProperties();
+ if (customProperties == null){
+ fail();
+ }
+
+ /* Insert some custom properties into the container. */
+ // System.out.println(k1);
+ String a1=(String) customProperties.get(k1);
+ assertEquals("Key1",p1,a1);
+ String a2=(String) customProperties.get(k2);
+ assertEquals("Schlüssel2",p2,a2);
+ Integer a3=(Integer) customProperties.get("Sample Number");
+ assertEquals("Sample Number",new Integer(12345),a3);
+ Boolean a4=(Boolean) customProperties.get("Sample Boolean");
+ assertEquals("Sample Boolean",new Boolean(true),a4);
+ Date a5=(Date) customProperties.get("Sample Date");
+ assertEquals("Custom Date:",date,a5);
+
+
+
+ }
+
+
+ /**
+ * Iterative testing of the unicode test
+ *
+ */
+ public void testSix(){
+ for (int i=1;i<100;i++){
+ setUp();
+ testUnicode();
+ tearDown();
+ }
+ }
+
+
+ /**
+ * Tests conversion in custom fields and errors
+ *
+ */
+ public void testConvAndExistance(){
+
+
+ CustomProperties customProperties = dsi.getCustomProperties();
+ if (customProperties == null){
+ customProperties = new CustomProperties();
+ }
+
+ /* Insert some custom properties into the container. */
+ customProperties.put("int", new Integer(12345));
+ customProperties.put("negint", new Integer(-12345));
+ customProperties.put("long", new Long(12345));
+ customProperties.put("neglong", new Long(-12345));
+ customProperties.put("boolean", new Boolean(true));
+ customProperties.put("string", "a String");
+ //customProperties.put("float", new Float(12345.0)); is not valid
+ //customProperties.put("negfloat", new Float(-12345.1)); is not valid
+ customProperties.put("double", new Double(12345.2));
+ customProperties.put("negdouble", new Double(-12345.3));
+ //customProperties.put("char", new Character('a')); is not valid
+
+ Date date=new Date();
+ customProperties.put("date", date);
+
+ dsi.setCustomProperties(customProperties);
+
+
+ closeAndReOpen();
+
+ assertNotNull(dsi);
+ assertNotNull(si);
+ /* Change the category to "POI example". Any former category value will
+ * be lost. If there has been no category yet, it will be created. */
+ assertNull(dsi.getCategory());
+ assertNull(dsi.getCompany());
+ assertNull(dsi.getManager());
+
+ assertNull(si.getAuthor());
+ assertNull(si.getTitle());
+ assertNull(si.getComments());
+ assertNull(si.getKeywords());
+ assertNull(si.getSubject());
+
+
+ /* Read the custom properties. If there are no custom properties
+ * yet, the application has to create a new CustomProperties object.
+ * It will serve as a container for custom properties. */
+ customProperties = dsi.getCustomProperties();
+ if (customProperties == null){
+ fail();
+ }
+
+ /* Insert some custom properties into the container. */
+
+ Integer a3=(Integer) customProperties.get("int");
+ assertEquals("int",new Integer(12345),a3);
+
+ a3=(Integer) customProperties.get("negint");
+ assertEquals("negint",new Integer(-12345),a3);
+
+ Long al=(Long) customProperties.get("neglong");
+ assertEquals("neglong",new Long(-12345),al);
+
+ al=(Long) customProperties.get("long");
+ assertEquals("long",new Long(12345),al);
+
+ Boolean a4=(Boolean) customProperties.get("boolean");
+ assertEquals("boolean",new Boolean(true),a4);
+
+ Date a5=(Date) customProperties.get("date");
+ assertEquals("Custom Date:",date,a5);
+
+ Double d=(Double) customProperties.get("double");
+ assertEquals("int",new Double(12345.2),d);
+
+ d=(Double) customProperties.get("negdouble");
+ assertEquals("string",new Double(-12345.3),d);
+
+ String s=(String) customProperties.get("string");
+ assertEquals("sring","a String",s);
+
+ Object o=null;
+
+ o=customProperties.get("string");
+ if (!(o instanceof String)){
+ fail();
+ }
+ o=customProperties.get("boolean");
+ if (!(o instanceof Boolean)){
+ fail();
+ }
+
+ o=customProperties.get("int");
+ if (!(o instanceof Integer)){
+ fail();
+ }
+ o=customProperties.get("negint");
+ if (!(o instanceof Integer)){
+ fail();
+ }
+
+ o=customProperties.get("long");
+ if (!(o instanceof Long)){
+ fail();
+ }
+ o=customProperties.get("neglong");
+ if (!(o instanceof Long)){
+ fail();
+ }
+
+ o=customProperties.get("double");
+ if (!(o instanceof Double)){
+ fail();
+ }
+ o=customProperties.get("negdouble");
+ if (!(o instanceof Double)){
+ fail();
+ }
+
+ o=customProperties.get("date");
+ if (!(o instanceof Date)){
+ fail();
+ }
+ }
+
+
+
} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java b/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java
index 71d85c8657..6203f775ca 100644
--- a/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java
@@ -1,61 +1,61 @@
-
-/* ====================================================================
- Copyright 2003-2004 Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hssf.record.formula;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-
-/**
- * Convenient abstract class to reduce the amount of boilerplate code needed
- * in ptg-related unit tests.
- *
- * @author Daniel Noll (daniel at nuix dot com dot au)
- */
-public class AbstractPtgTestCase extends TestCase
-{
- /** Directory containing the test data. */
- private static String dataDir = System.getProperty("HSSF.testdata.path");
-
- /**
- * Loads a workbook from the given filename in the test data dir.
- *
- * @param filename the filename.
- * @return the loaded workbook.
- * @throws IOException if an error occurs loading the workbook.
- */
- protected static HSSFWorkbook loadWorkbook(String filename)
- throws IOException {
- File file = new File(dataDir, filename);
- InputStream stream = new BufferedInputStream(new FileInputStream(file));
- try
- {
- return new HSSFWorkbook(stream);
- }
- finally
- {
- stream.close();
- }
- }
-}
+
+/* ====================================================================
+ Copyright 2003-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+
+/**
+ * Convenient abstract class to reduce the amount of boilerplate code needed
+ * in ptg-related unit tests.
+ *
+ * @author Daniel Noll (daniel at nuix dot com dot au)
+ */
+public class AbstractPtgTestCase extends TestCase
+{
+ /** Directory containing the test data. */
+ private static String dataDir = System.getProperty("HSSF.testdata.path");
+
+ /**
+ * Loads a workbook from the given filename in the test data dir.
+ *
+ * @param filename the filename.
+ * @return the loaded workbook.
+ * @throws IOException if an error occurs loading the workbook.
+ */
+ protected static HSSFWorkbook loadWorkbook(String filename)
+ throws IOException {
+ File file = new File(dataDir, filename);
+ InputStream stream = new BufferedInputStream(new FileInputStream(file));
+ try
+ {
+ return new HSSFWorkbook(stream);
+ }
+ finally
+ {
+ stream.close();
+ }
+ }
+}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java
index eabf78961f..44917c4dd1 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java
@@ -1,131 +1,131 @@
-package org.apache.poi.hssf.usermodel;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileInputStream;
-
-import org.apache.poi.util.TempFile;
-
-import junit.framework.TestCase;
-
-public class TestUnicodeWorkbook extends TestCase {
-
- public TestUnicodeWorkbook(String s) {
- super(s);
- }
-
- /** Tests that all of the unicode capable string fields can be set, written and then read back
- *
- *
- */
- public void testUnicodeInAll() throws Exception {
- HSSFWorkbook wb = new HSSFWorkbook();
- //Create a unicode dataformat (contains euro symbol)
- HSSFDataFormat df = wb.createDataFormat();
- final String formatStr = "_([$\u20ac-2]\\\\\\ * #,##0.00_);_([$\u20ac-2]\\\\\\ * \\\\\\(#,##0.00\\\\\\);_([$\u20ac-2]\\\\\\ *\\\"\\-\\\\\"??_);_(@_)";
- short fmt = df.getFormat(formatStr);
-
- //Create a unicode sheet name (euro symbol)
- HSSFSheet s = wb.createSheet("\u20ac");
-
- //Set a unicode header (you guessed it the euro symbol)
- HSSFHeader h = s.getHeader();
- h.setCenter("\u20ac");
- h.setLeft("\u20ac");
- h.setRight("\u20ac");
-
- //Set a unicode footer
- HSSFFooter f = s.getFooter();
- f.setCenter("\u20ac");
- f.setLeft("\u20ac");
- f.setRight("\u20ac");
-
- HSSFRow r = s.createRow(0);
- HSSFCell c = r.createCell((short)1);
- c.setCellValue(12.34);
- c.getCellStyle().setDataFormat(fmt);
-
- HSSFCell c2 = r.createCell((short)2);
- c.setCellValue(new HSSFRichTextString("\u20ac"));
-
- HSSFCell c3 = r.createCell((short)3);
- String formulaString = "TEXT(12.34,\"\u20ac###,##\")";
- c3.setCellFormula(formulaString);
-
-
- File tempFile = TempFile.createTempFile("unicode", "test.xls");
- FileOutputStream stream = new FileOutputStream(tempFile);
- wb.write(stream);
-
- wb = null;
- FileInputStream in = new FileInputStream(tempFile);
- wb = new HSSFWorkbook(in);
-
- //Test the sheetname
- s = wb.getSheet("\u20ac");
- assertNotNull(s);
-
- //Test the header
- h = s.getHeader();
- assertEquals(h.getCenter(), "\u20ac");
- assertEquals(h.getLeft(), "\u20ac");
- assertEquals(h.getRight(), "\u20ac");
-
- //Test the footer
- f = s.getFooter();
- assertEquals(f.getCenter(), "\u20ac");
- assertEquals(f.getLeft(), "\u20ac");
- assertEquals(f.getRight(), "\u20ac");
-
- //Test the dataformat
- r = s.getRow(0);
- c = r.getCell((short)1);
- df = wb.createDataFormat();
- assertEquals(formatStr, df.getFormat(c.getCellStyle().getDataFormat()));
-
- //Test the cell string value
- c2 = r.getCell((short)2);
- assertEquals(c.getRichStringCellValue().getString(), "\u20ac");
-
- //Test the cell formula
- c3 = r.getCell((short)3);
- assertEquals(c3.getCellFormula(), formulaString);
- }
-
- /** Tests Bug38230
- * That a Umlat is written and then read back.
- * It should have been written as a compressed unicode.
- *
- *
- *
- */
- public void testUmlatReadWrite() throws Exception {
- HSSFWorkbook wb = new HSSFWorkbook();
-
- //Create a unicode sheet name (euro symbol)
- HSSFSheet s = wb.createSheet("test");
-
- HSSFRow r = s.createRow(0);
- HSSFCell c = r.createCell((short)1);
- c.setCellValue(new HSSFRichTextString("\u00e4"));
-
- //Confirm that the sring will be compressed
- assertEquals(c.getRichStringCellValue().getUnicodeString().getOptionFlags(), 0);
-
- File tempFile = TempFile.createTempFile("umlat", "test.xls");
- FileOutputStream stream = new FileOutputStream(tempFile);
- wb.write(stream);
-
- wb = null;
- FileInputStream in = new FileInputStream(tempFile);
- wb = new HSSFWorkbook(in);
-
- //Test the sheetname
- s = wb.getSheet("test");
- assertNotNull(s);
-
- c = r.getCell((short)1);
- assertEquals(c.getRichStringCellValue().getString(), "\u00e4");
- }
-
-}
+package org.apache.poi.hssf.usermodel;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+
+import org.apache.poi.util.TempFile;
+
+import junit.framework.TestCase;
+
+public class TestUnicodeWorkbook extends TestCase {
+
+ public TestUnicodeWorkbook(String s) {
+ super(s);
+ }
+
+ /** Tests that all of the unicode capable string fields can be set, written and then read back
+ *
+ *
+ */
+ public void testUnicodeInAll() throws Exception {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ //Create a unicode dataformat (contains euro symbol)
+ HSSFDataFormat df = wb.createDataFormat();
+ final String formatStr = "_([$\u20ac-2]\\\\\\ * #,##0.00_);_([$\u20ac-2]\\\\\\ * \\\\\\(#,##0.00\\\\\\);_([$\u20ac-2]\\\\\\ *\\\"\\-\\\\\"??_);_(@_)";
+ short fmt = df.getFormat(formatStr);
+
+ //Create a unicode sheet name (euro symbol)
+ HSSFSheet s = wb.createSheet("\u20ac");
+
+ //Set a unicode header (you guessed it the euro symbol)
+ HSSFHeader h = s.getHeader();
+ h.setCenter("\u20ac");
+ h.setLeft("\u20ac");
+ h.setRight("\u20ac");
+
+ //Set a unicode footer
+ HSSFFooter f = s.getFooter();
+ f.setCenter("\u20ac");
+ f.setLeft("\u20ac");
+ f.setRight("\u20ac");
+
+ HSSFRow r = s.createRow(0);
+ HSSFCell c = r.createCell((short)1);
+ c.setCellValue(12.34);
+ c.getCellStyle().setDataFormat(fmt);
+
+ HSSFCell c2 = r.createCell((short)2);
+ c.setCellValue(new HSSFRichTextString("\u20ac"));
+
+ HSSFCell c3 = r.createCell((short)3);
+ String formulaString = "TEXT(12.34,\"\u20ac###,##\")";
+ c3.setCellFormula(formulaString);
+
+
+ File tempFile = TempFile.createTempFile("unicode", "test.xls");
+ FileOutputStream stream = new FileOutputStream(tempFile);
+ wb.write(stream);
+
+ wb = null;
+ FileInputStream in = new FileInputStream(tempFile);
+ wb = new HSSFWorkbook(in);
+
+ //Test the sheetname
+ s = wb.getSheet("\u20ac");
+ assertNotNull(s);
+
+ //Test the header
+ h = s.getHeader();
+ assertEquals(h.getCenter(), "\u20ac");
+ assertEquals(h.getLeft(), "\u20ac");
+ assertEquals(h.getRight(), "\u20ac");
+
+ //Test the footer
+ f = s.getFooter();
+ assertEquals(f.getCenter(), "\u20ac");
+ assertEquals(f.getLeft(), "\u20ac");
+ assertEquals(f.getRight(), "\u20ac");
+
+ //Test the dataformat
+ r = s.getRow(0);
+ c = r.getCell((short)1);
+ df = wb.createDataFormat();
+ assertEquals(formatStr, df.getFormat(c.getCellStyle().getDataFormat()));
+
+ //Test the cell string value
+ c2 = r.getCell((short)2);
+ assertEquals(c.getRichStringCellValue().getString(), "\u20ac");
+
+ //Test the cell formula
+ c3 = r.getCell((short)3);
+ assertEquals(c3.getCellFormula(), formulaString);
+ }
+
+ /** Tests Bug38230
+ * That a Umlat is written and then read back.
+ * It should have been written as a compressed unicode.
+ *
+ *
+ *
+ */
+ public void testUmlatReadWrite() throws Exception {
+ HSSFWorkbook wb = new HSSFWorkbook();
+
+ //Create a unicode sheet name (euro symbol)
+ HSSFSheet s = wb.createSheet("test");
+
+ HSSFRow r = s.createRow(0);
+ HSSFCell c = r.createCell((short)1);
+ c.setCellValue(new HSSFRichTextString("\u00e4"));
+
+ //Confirm that the sring will be compressed
+ assertEquals(c.getRichStringCellValue().getUnicodeString().getOptionFlags(), 0);
+
+ File tempFile = TempFile.createTempFile("umlat", "test.xls");
+ FileOutputStream stream = new FileOutputStream(tempFile);
+ wb.write(stream);
+
+ wb = null;
+ FileInputStream in = new FileInputStream(tempFile);
+ wb = new HSSFWorkbook(in);
+
+ //Test the sheetname
+ s = wb.getSheet("test");
+ assertNotNull(s);
+
+ c = r.getCell((short)1);
+ assertEquals(c.getRichStringCellValue().getString(), "\u00e4");
+ }
+
+}
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java b/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java
index 7ddd2cca9d..2c5bc954b4 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java
@@ -1,152 +1,152 @@
-
-/* ====================================================================
- Copyright 2002-2004 Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.poifs.filesystem;
-
-import junit.framework.TestCase;
-import junit.framework.ComparisonFailure;
-
-import java.io.*;
-import java.util.*;
-
-import org.apache.poi.poifs.property.DirectoryProperty;
-import org.apache.poi.poifs.property.Property;
-
-/**
- * Verify the order of entries <code>DirectoryProperty</code> .
- * <p>
- * In particular it is important to serialize ROOT._VBA_PROJECT_CUR.VBA node.
- * See bug 39234 in bugzilla. Thanks to Bill Seddon for providing the solution.
- * </p>
- *
- * @author Yegor Kozlov
- */
-public class TestPropertySorter extends TestCase {
-
- //the correct order of entries in the test file
- protected static final String[] _entries = {
- "dir", "JML", "UTIL", "Loader", "Sheet1", "Sheet2", "Sheet3",
- "__SRP_0", "__SRP_1", "__SRP_2", "__SRP_3", "__SRP_4", "__SRP_5",
- "ThisWorkbook", "_VBA_PROJECT",
- };
-
- protected File testFile;
-
- public void setUp(){
- String home = System.getProperty("HSSF.testdata.path");
- testFile = new File(home + "/39234.xls");
- }
-
- /**
- * Test sorting of properties in <code>DirectoryProperty</code>
- */
- public void testSortProperties() throws IOException {
- InputStream is = new FileInputStream(testFile);
- POIFSFileSystem fs = new POIFSFileSystem(is);
- is.close();
- Property[] props = getVBAProperties(fs);
-
- assertEquals(_entries.length, props.length);
-
- // (1). See that there is a problem with the old case-sensitive property comparartor
- Arrays.sort(props, new CaseSensitivePropertyComparator());
- try {
- for (int i = 0; i < props.length; i++) {
- assertEquals(_entries[i], props[i].getName());
- }
- fail("case-sensitive property comparator returns properties in wrong order");
- } catch (ComparisonFailure e){
- ; // as expected
- }
-
- // (2) Verify that the fixed proeprty comparator works right
- Arrays.sort(props, new DirectoryProperty.PropertyComparator());
- for (int i = 0; i < props.length; i++) {
- assertEquals(_entries[i], props[i].getName());
- }
- }
-
- /**
- * Serialize file system and verify that the order of properties is the same as in the original file.
- */
- public void testSerialization() throws IOException {
- InputStream is = new FileInputStream(testFile);
- POIFSFileSystem fs = new POIFSFileSystem(is);
- is.close();
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- fs.writeFilesystem(out);
- out.close();
- is = new ByteArrayInputStream(out.toByteArray());
- fs = new POIFSFileSystem(is);
- is.close();
- Property[] props = getVBAProperties(fs);
- Arrays.sort(props, new DirectoryProperty.PropertyComparator());
-
- assertEquals(_entries.length, props.length);
- for (int i = 0; i < props.length; i++) {
- assertEquals(_entries[i], props[i].getName());
- }
- }
-
- /**
- * @return array of properties read from ROOT._VBA_PROJECT_CUR.VBA node
- */
- protected Property[] getVBAProperties(POIFSFileSystem fs) throws IOException {
- String _VBA_PROJECT_CUR = "_VBA_PROJECT_CUR";
- String VBA = "VBA";
-
- DirectoryEntry root = fs.getRoot();
- DirectoryEntry vba_project = (DirectoryEntry)root.getEntry(_VBA_PROJECT_CUR);
-
- DirectoryNode vba = (DirectoryNode)vba_project.getEntry(VBA);
- DirectoryProperty p = (DirectoryProperty)vba.getProperty();
-
- ArrayList lst = new ArrayList();
- for (Iterator it = p.getChildren(); it.hasNext();){
- Property ch = (Property)it.next();
- lst.add(ch);
- }
- return (Property [])lst.toArray(new Property[ 0 ]);
- }
-
- /**
- * Old version of case-sensitive PropertyComparator to demonstrate the problem
- */
- private class CaseSensitivePropertyComparator implements Comparator
- {
-
- public boolean equals(Object o)
- {
- return this == o;
- }
-
- public int compare(Object o1, Object o2)
- {
- String name1 = (( Property ) o1).getName();
- String name2 = (( Property ) o2).getName();
- int result = name1.length() - name2.length();
-
- if (result == 0)
- {
- result = name1.compareTo(name2);
- }
- return result;
- }
- }
-
-}
+
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.poifs.filesystem;
+
+import junit.framework.TestCase;
+import junit.framework.ComparisonFailure;
+
+import java.io.*;
+import java.util.*;
+
+import org.apache.poi.poifs.property.DirectoryProperty;
+import org.apache.poi.poifs.property.Property;
+
+/**
+ * Verify the order of entries <code>DirectoryProperty</code> .
+ * <p>
+ * In particular it is important to serialize ROOT._VBA_PROJECT_CUR.VBA node.
+ * See bug 39234 in bugzilla. Thanks to Bill Seddon for providing the solution.
+ * </p>
+ *
+ * @author Yegor Kozlov
+ */
+public class TestPropertySorter extends TestCase {
+
+ //the correct order of entries in the test file
+ protected static final String[] _entries = {
+ "dir", "JML", "UTIL", "Loader", "Sheet1", "Sheet2", "Sheet3",
+ "__SRP_0", "__SRP_1", "__SRP_2", "__SRP_3", "__SRP_4", "__SRP_5",
+ "ThisWorkbook", "_VBA_PROJECT",
+ };
+
+ protected File testFile;
+
+ public void setUp(){
+ String home = System.getProperty("HSSF.testdata.path");
+ testFile = new File(home + "/39234.xls");
+ }
+
+ /**
+ * Test sorting of properties in <code>DirectoryProperty</code>
+ */
+ public void testSortProperties() throws IOException {
+ InputStream is = new FileInputStream(testFile);
+ POIFSFileSystem fs = new POIFSFileSystem(is);
+ is.close();
+ Property[] props = getVBAProperties(fs);
+
+ assertEquals(_entries.length, props.length);
+
+ // (1). See that there is a problem with the old case-sensitive property comparartor
+ Arrays.sort(props, new CaseSensitivePropertyComparator());
+ try {
+ for (int i = 0; i < props.length; i++) {
+ assertEquals(_entries[i], props[i].getName());
+ }
+ fail("case-sensitive property comparator returns properties in wrong order");
+ } catch (ComparisonFailure e){
+ ; // as expected
+ }
+
+ // (2) Verify that the fixed proeprty comparator works right
+ Arrays.sort(props, new DirectoryProperty.PropertyComparator());
+ for (int i = 0; i < props.length; i++) {
+ assertEquals(_entries[i], props[i].getName());
+ }
+ }
+
+ /**
+ * Serialize file system and verify that the order of properties is the same as in the original file.
+ */
+ public void testSerialization() throws IOException {
+ InputStream is = new FileInputStream(testFile);
+ POIFSFileSystem fs = new POIFSFileSystem(is);
+ is.close();
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ fs.writeFilesystem(out);
+ out.close();
+ is = new ByteArrayInputStream(out.toByteArray());
+ fs = new POIFSFileSystem(is);
+ is.close();
+ Property[] props = getVBAProperties(fs);
+ Arrays.sort(props, new DirectoryProperty.PropertyComparator());
+
+ assertEquals(_entries.length, props.length);
+ for (int i = 0; i < props.length; i++) {
+ assertEquals(_entries[i], props[i].getName());
+ }
+ }
+
+ /**
+ * @return array of properties read from ROOT._VBA_PROJECT_CUR.VBA node
+ */
+ protected Property[] getVBAProperties(POIFSFileSystem fs) throws IOException {
+ String _VBA_PROJECT_CUR = "_VBA_PROJECT_CUR";
+ String VBA = "VBA";
+
+ DirectoryEntry root = fs.getRoot();
+ DirectoryEntry vba_project = (DirectoryEntry)root.getEntry(_VBA_PROJECT_CUR);
+
+ DirectoryNode vba = (DirectoryNode)vba_project.getEntry(VBA);
+ DirectoryProperty p = (DirectoryProperty)vba.getProperty();
+
+ ArrayList lst = new ArrayList();
+ for (Iterator it = p.getChildren(); it.hasNext();){
+ Property ch = (Property)it.next();
+ lst.add(ch);
+ }
+ return (Property [])lst.toArray(new Property[ 0 ]);
+ }
+
+ /**
+ * Old version of case-sensitive PropertyComparator to demonstrate the problem
+ */
+ private class CaseSensitivePropertyComparator implements Comparator
+ {
+
+ public boolean equals(Object o)
+ {
+ return this == o;
+ }
+
+ public int compare(Object o1, Object o2)
+ {
+ String name1 = (( Property ) o1).getName();
+ String name2 = (( Property ) o2).getName();
+ int result = name1.length() - name2.length();
+
+ if (result == 0)
+ {
+ result = name1.compareTo(name2);
+ }
+ return result;
+ }
+ }
+
+}