You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by kl...@apache.org on 2006/03/03 17:58:00 UTC

svn commit: r382887 [3/3] - in /jakarta/poi/trunk/src: contrib/src/org/apache/poi/contrib/poibrowser/ documentation/content/xdocs/hpsf/ examples/src/org/apache/poi/hpsf/examples/ java/org/apache/poi/hpsf/ java/org/apache/poi/hpsf/wellknown/ java/org/ap...

Added: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java?rev=382887&view=auto
==============================================================================
--- jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java (added)
+++ jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java Fri Mar  3 08:57:55 2006
@@ -0,0 +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();
+      }
+   	}
+      
+
+   
+}
\ No newline at end of file

Modified: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java (original)
+++ jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java Fri Mar  3 08:57:55 2006
@@ -1,6 +1,5 @@
-
 /* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
+   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.
@@ -27,10 +26,12 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hpsf.Constants;
+import org.apache.poi.hpsf.DocumentSummaryInformation;
 import org.apache.poi.hpsf.HPSFException;
 import org.apache.poi.hpsf.PropertySet;
 import org.apache.poi.hpsf.PropertySetFactory;
 import org.apache.poi.hpsf.Section;
+import org.apache.poi.hpsf.SummaryInformation;
 
 
 
@@ -102,7 +103,7 @@
         Assert.assertEquals(s.getProperty(1),
                             new Integer(Constants.CP_UTF16));
         Assert.assertEquals(s.getProperty(2),
-                            new Long(4198897018L));
+                            new Integer(-96070278));
         Assert.assertEquals(s.getProperty(3),
                             "MCon_Info zu Office bei Schreiner");
         Assert.assertEquals(s.getProperty(4),

Modified: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java (original)
+++ jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java Fri Mar  3 08:57:55 2006
@@ -1,5 +1,5 @@
 /* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
+   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.
@@ -13,7 +13,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hpsf.basic;
 
@@ -124,11 +123,8 @@
      * in.</p>
      * 
      * @exception IOException if an I/O exception occurs
-     * @exception UnsupportedVariantTypeException if HPSF does not yet support
-     * a variant type to be written
      */
-    public void testNoFormatID()
-        throws IOException, UnsupportedVariantTypeException
+    public void testNoFormatID() throws IOException
     {
         final String dataDirName = System.getProperty("HPSF.testdata.path");
         final File dataDir = new File(dataDirName);
@@ -409,10 +405,19 @@
             check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5}, codepage);
             check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6}, codepage);
             check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, codepage);
-            check(Variant.VT_I2, new Integer(27), codepage);
-            check(Variant.VT_I4, new Long(28), codepage);
+            check(Variant.VT_I4, new Integer(27), codepage);
+            check(Variant.VT_I8, new Long(28), codepage);
             check(Variant.VT_R8, new Double(29.0), codepage);
+            check(Variant.VT_I4, new Integer(-27), codepage);
+            check(Variant.VT_I8, new Long(-28), codepage);
+            check(Variant.VT_R8, new Double(-29.0), codepage);
             check(Variant.VT_FILETIME, new Date(), codepage);
+            check(Variant.VT_I4, new Integer(Integer.MAX_VALUE), codepage);
+            check(Variant.VT_I4, new Integer(Integer.MIN_VALUE), codepage);
+            check(Variant.VT_I8, new Long(Long.MAX_VALUE), codepage);
+            check(Variant.VT_I8, new Long(Long.MIN_VALUE), codepage);
+            check(Variant.VT_R8, new Double(Double.MAX_VALUE), codepage);
+            check(Variant.VT_R8, new Double(Double.MIN_VALUE), codepage);
 
             check(Variant.VT_LPSTR,
                   "", codepage);
@@ -602,8 +607,11 @@
      *
      * @param variantType The property's variant type.
      * @param value The property's value.
+     * @param codepage The codepage to use for writing and reading.
      * @throws UnsupportedVariantTypeException if the variant is not supported.
      * @throws IOException if an I/O exception occurs.
+     * @throws ReadingNotSupportedException 
+     * @throws UnsupportedEncodingException 
      */
     private void check(final long variantType, final Object value, 
                        final int codepage)
@@ -779,7 +787,7 @@
             m.put(new Long(2), "String 2");
             m.put(new Long(3), "String 3");
             s.setDictionary(m);
-            s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID);
+            s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]);
             int codepage = Constants.CP_UNICODE;
             s.setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2,
                           new Integer(codepage));
@@ -831,7 +839,7 @@
             m.put(new Long(2), "String 2");
             m.put(new Long(3), "String 3");
             s.setDictionary(m);
-            s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID);
+            s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]);
             int codepage = 12345;
             s.setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2,
                           new Integer(codepage));
@@ -902,8 +910,11 @@
 
     /**
      * <p>In order to execute tests with characters beyond US-ASCII, this
-     * method checks whether the application has is runing in an environment
+     * method checks whether the application is runing in an environment
      * where the default character set is 16-bit-capable.</p>
+     *
+     * @return <code>true</code> if the default character set is 16-bit-capable,
+     * else <code>false</code>.
      */
     private boolean hasProperDefaultCharset()
     {
@@ -916,6 +927,9 @@
 
     /**
      * <p>Runs the test cases stand-alone.</p>
+     * 
+     * @param args The command-line parameters.
+     * @throws Throwable if anything goes wrong.
      */
     public static void main(final String[] args) throws Throwable
     {

Added: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java?rev=382887&view=auto
==============================================================================
--- jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java (added)
+++ jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java Fri Mar  3 08:57:55 2006
@@ -0,0 +1,763 @@
+/* ====================================================================
+   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.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hpsf.CustomProperties;
+import org.apache.poi.hpsf.CustomProperty;
+import org.apache.poi.hpsf.DocumentSummaryInformation;
+import org.apache.poi.hpsf.MarkUnsupportedException;
+import org.apache.poi.hpsf.MutableProperty;
+import org.apache.poi.hpsf.MutableSection;
+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.Variant;
+import org.apache.poi.hpsf.VariantSupport;
+import org.apache.poi.hpsf.WritingNotSupportedException;
+import org.apache.poi.hpsf.wellknown.SectionIDMap;
+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;
+
+
+
+/**
+ * <p>Tests HPSF's high-level writing functionality for the well-known property
+ * set "SummaryInformation" and "DocumentSummaryInformation".</p>
+ * 
+ * @author Rainer Klute
+ *     <a href="mailto:klute@rainer-klute.de">klute@rainer-klute.de</a>
+ * @since 2006-02-01
+ * @version $Id$
+ */
+public class TestWriteWellKnown extends TestCase
+{
+
+    private static final String POI_FS = "TestWriteWellKnown.doc";
+
+    /**
+     * <p>Constructor</p>
+     * 
+     * @param name the test case's name
+     */
+    public TestWriteWellKnown(final String name)
+    {
+        super(name);
+    }
+
+
+
+    /**
+     * @see TestCase#setUp()
+     */
+    public void setUp()
+    {
+        VariantSupport.setLogUnsupportedTypes(false);
+    }
+
+
+
+    /**
+     * <p>This test method checks whether DocumentSummary information streams
+     * can be read. This is done by opening all "Test*" files in the directrory
+     * pointed to by the "HPSF.testdata.path" system property, trying to extract
+     * the document summary information stream in the root directory and calling
+     * its get... methods.</p>
+     * @throws IOException 
+     * @throws FileNotFoundException 
+     * @throws MarkUnsupportedException 
+     * @throws NoPropertySetStreamException 
+     * @throws UnexpectedPropertySetTypeException 
+     */
+    public void testReadDocumentSummaryInformation()
+            throws FileNotFoundException, IOException,
+            NoPropertySetStreamException, MarkUnsupportedException,
+            UnexpectedPropertySetTypeException
+    {
+        final String dataDirName = System.getProperty("HPSF.testdata.path");
+        final File dataDir = new File(dataDirName);
+        final File[] docs = dataDir.listFiles(new FileFilter()
+        {
+            public boolean accept(final File file)
+            {
+                return file.isFile() && file.getName().startsWith("Test");
+            }});
+        for (int i = 0; i < docs.length; i++)
+        {
+            final File doc = docs[i];
+            System.out.println("Reading file " + doc);
+
+            /* Read a test document <em>doc</em> into a POI filesystem. */
+            final POIFSFileSystem poifs = new POIFSFileSystem(new FileInputStream(doc));
+            final DirectoryEntry dir = poifs.getRoot();
+            DocumentEntry dsiEntry = null;
+            try
+            {
+                dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+            }
+            catch (FileNotFoundException ex)
+            {
+                /*
+                 * A missing document summary information stream is not an error
+                 * and therefore silently ignored here.
+                 */
+            }
+
+            /*
+             * If there is a document summry information stream, read it from
+             * the POI filesystem.
+             */
+            if (dsiEntry != null)
+            {
+                final DocumentInputStream dis = new DocumentInputStream(dsiEntry);
+                final PropertySet ps = new PropertySet(dis);
+                final DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps);
+                
+                /* Execute the get... methods. */
+                dsi.getByteCount();
+                dsi.getByteOrder();
+                dsi.getCategory();
+                dsi.getCompany();
+                dsi.getCustomProperties();
+                // FIXME dsi.getDocparts();
+                // FIXME dsi.getHeadingPair();
+                dsi.getHiddenCount();
+                dsi.getLineCount();
+                dsi.getLinksDirty();
+                dsi.getManager();
+                dsi.getMMClipCount();
+                dsi.getNoteCount();
+                dsi.getParCount();
+                dsi.getPresentationFormat();
+                dsi.getScale();
+                dsi.getSlideCount();
+            }
+        }
+    }
+
+
+    /**
+     * <p>This test method test the writing of properties in the well-known
+     * property set streams "SummaryInformation" and
+     * "DocumentSummaryInformation" by performing the following steps:</p>
+     * 
+     * <ol>
+     * 
+     * <li><p>Read a test document <em>doc1</em> into a POI filesystem.</p></li>
+     * 
+     * <li><p>Read the summary information stream and the document summary
+     * information stream from the POI filesystem.</p></li>
+     * 
+     * <li><p>Write all properties supported by HPSF to the summary
+     * information (e.g. author, edit date, application name) and to the
+     * document summary information (e.g. company, manager).</p></li>
+     * 
+     * <li><p>Write the summary information stream and the document summary
+     * information stream to the POI filesystem.</p></li>
+     * 
+     * <li><p>Write the POI filesystem to a (temporary) file <em>doc2</em>
+     * and close the latter.</p></li>
+     * 
+     * <li><p>Open <em>doc2</em> for reading and check summary information
+     * and document summary information. All properties written before must be
+     * found in the property streams of <em>doc2</em> and have the correct
+     * values.</p></li>
+     * 
+     * <li><p>Remove all properties supported by HPSF from the summary
+     * information (e.g. author, edit date, application name) and from the
+     * document summary information (e.g. company, manager).</p></li>
+     * 
+     * <li><p>Write the summary information stream and the document summary
+     * information stream to the POI filesystem.</p></li>
+     * 
+     * <li><p>Write the POI filesystem to a (temporary) file <em>doc3</em>
+     * and close the latter.</p></li>
+     * 
+     * <li><p>Open <em>doc3</em> for reading and check summary information
+     * and document summary information. All properties removed before must not
+     * be found in the property streams of <em>doc3</em>.</p></li> </ol>
+     * 
+     * @throws IOException if some I/O error occurred.
+     * @throws MarkUnsupportedException
+     * @throws NoPropertySetStreamException
+     * @throws UnexpectedPropertySetTypeException
+     * @throws WritingNotSupportedException
+     */
+    public void testWriteWellKnown() throws IOException,
+            NoPropertySetStreamException, MarkUnsupportedException,
+            UnexpectedPropertySetTypeException, WritingNotSupportedException
+    {
+        final String dataDirName = System.getProperty("HPSF.testdata.path");
+        final File dataDir = new File(dataDirName);
+        final File doc1 = new File(dataDir, POI_FS);
+    
+        /* Read a test document <em>doc1</em> into a POI filesystem. */
+        POIFSFileSystem poifs = new POIFSFileSystem(new FileInputStream(doc1));
+        DirectoryEntry dir = poifs.getRoot();
+        DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
+        DocumentEntry dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+    
+        /*
+         * Read the summary information stream and the document summary
+         * information stream from the POI filesystem.
+         * 
+         * Please note that the result consists of SummaryInformation and
+         * DocumentSummaryInformation instances which are in memory only. To
+         * make them permanent they have to be written to a POI filesystem
+         * explicitly (overwriting the former contents). Then the POI filesystem
+         * should be saved to a file.
+         */
+        DocumentInputStream dis = new DocumentInputStream(siEntry);
+        PropertySet ps = new PropertySet(dis);
+        SummaryInformation si = new SummaryInformation(ps);
+        dis = new DocumentInputStream(dsiEntry);
+        ps = new PropertySet(dis);
+        DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps);
+    
+        /*
+         * Write all properties supported by HPSF to the summary information
+         * (e.g. author, edit date, application name) and to the document
+         * summary information (e.g. company, manager).
+         */
+        Calendar cal = new GregorianCalendar();
+        cal.set(2000, 6, 6, 6, 6, 6);
+        final long time1 = cal.getTimeInMillis();
+        cal.set(2001, 7, 7, 7, 7, 7);
+        final long time2 = cal.getTimeInMillis();
+        cal.set(2002, 8, 8, 8, 8, 8);
+        final long time3 = cal.getTimeInMillis();
+    
+        int nr = 4711;
+        final String P_APPLICATION_NAME = "ApplicationName";
+        final String P_AUTHOR = "Author";
+        final int    P_CHAR_COUNT = ++nr;
+        final String P_COMMENTS = "Comments";
+        final Date   P_CREATE_DATE_TIME = new Date(time1);
+        final long   P_EDIT_TIME = ++nr * 1000 * 10;
+        final String P_KEYWORDS = "Keywords";
+        final String P_LAST_AUTHOR = "LastAuthor";
+        final Date   P_LAST_PRINTED = new Date(time2);
+        final Date   P_LAST_SAVE_DATE_TIME = new Date(time3);
+        final int    P_PAGE_COUNT = ++nr;
+        final String P_REV_NUMBER = "RevNumber";
+        final int    P_SECURITY = 1;
+        final String P_SUBJECT = "Subject";
+        final String P_TEMPLATE = "Template";
+        // FIXME (byte array properties not yet implemented): final byte[] P_THUMBNAIL = new byte[123];
+        final String P_TITLE = "Title";
+        final int    P_WORD_COUNT = ++nr;
+    
+        final int     P_BYTE_COUNT = ++nr;
+        final String  P_CATEGORY = "Category";
+        final String  P_COMPANY = "Company";
+        // FIXME (byte array properties not yet implemented): final byte[]  P_DOCPARTS = new byte[123];
+        // FIXME (byte array properties not yet implemented): final byte[]  P_HEADING_PAIR = new byte[123];
+        final int     P_HIDDEN_COUNT = ++nr;
+        final int     P_LINE_COUNT = ++nr;
+        final boolean P_LINKS_DIRTY = true;
+        final String  P_MANAGER = "Manager";
+        final int     P_MM_CLIP_COUNT = ++nr;
+        final int     P_NOTE_COUNT = ++nr;
+        final int     P_PAR_COUNT = ++nr;
+        final String  P_PRESENTATION_FORMAT = "PresentationFormat";
+        final boolean P_SCALE = false;
+        final int     P_SLIDE_COUNT = ++nr;
+        final Date    now = new Date();
+
+        final Integer POSITIVE_INTEGER = new Integer(2222);
+        final Long POSITIVE_LONG = new  Long(3333);
+        final Double POSITIVE_DOUBLE = new  Double(4444);
+        final Integer NEGATIVE_INTEGER = new Integer(2222);
+        final Long NEGATIVE_LONG = new  Long(3333);
+        final Double NEGATIVE_DOUBLE = new  Double(4444);
+
+        final Integer MAX_INTEGER = new Integer(Integer.MAX_VALUE);
+        final Integer MIN_INTEGER = new Integer(Integer.MIN_VALUE);
+        final Long MAX_LONG = new Long(Long.MAX_VALUE);
+        final Long MIN_LONG = new Long(Long.MIN_VALUE);
+        final Double MAX_DOUBLE = new Double(Double.MAX_VALUE);
+        final Double MIN_DOUBLE = new Double(Double.MIN_VALUE);
+        
+        si.setApplicationName(P_APPLICATION_NAME);
+        si.setAuthor(P_AUTHOR);
+        si.setCharCount(P_CHAR_COUNT);
+        si.setComments(P_COMMENTS);
+        si.setCreateDateTime(P_CREATE_DATE_TIME);
+        si.setEditTime(P_EDIT_TIME);
+        si.setKeywords(P_KEYWORDS);
+        si.setLastAuthor(P_LAST_AUTHOR);
+        si.setLastPrinted(P_LAST_PRINTED);
+        si.setLastSaveDateTime(P_LAST_SAVE_DATE_TIME);
+        si.setPageCount(P_PAGE_COUNT);
+        si.setRevNumber(P_REV_NUMBER);
+        si.setSecurity(P_SECURITY);
+        si.setSubject(P_SUBJECT);
+        si.setTemplate(P_TEMPLATE);
+        // FIXME (byte array properties not yet implemented): si.setThumbnail(P_THUMBNAIL);
+        si.setTitle(P_TITLE);
+        si.setWordCount(P_WORD_COUNT);
+    
+        dsi.setByteCount(P_BYTE_COUNT);
+        dsi.setCategory(P_CATEGORY);
+        dsi.setCompany(P_COMPANY);
+        // FIXME (byte array properties not yet implemented): dsi.setDocparts(P_DOCPARTS);
+        // FIXME (byte array properties not yet implemented): dsi.setHeadingPair(P_HEADING_PAIR);
+        dsi.setHiddenCount(P_HIDDEN_COUNT);
+        dsi.setLineCount(P_LINE_COUNT);
+        dsi.setLinksDirty(P_LINKS_DIRTY);
+        dsi.setManager(P_MANAGER);
+        dsi.setMMClipCount(P_MM_CLIP_COUNT);
+        dsi.setNoteCount(P_NOTE_COUNT);
+        dsi.setParCount(P_PAR_COUNT);
+        dsi.setPresentationFormat(P_PRESENTATION_FORMAT);
+        dsi.setScale(P_SCALE);
+        dsi.setSlideCount(P_SLIDE_COUNT);
+
+        CustomProperties customProperties = dsi.getCustomProperties();
+        if (customProperties == null)
+            customProperties = new CustomProperties();
+        customProperties.put("Schlüssel ä",    "Wert ä");
+        customProperties.put("Schlüssel äö",   "Wert äö");
+        customProperties.put("Schlüssel äöü",  "Wert äöü");
+        customProperties.put("Schlüssel äöüß", "Wert äöüß");
+        customProperties.put("positive_Integer", POSITIVE_INTEGER);
+        customProperties.put("positive_Long", POSITIVE_LONG);
+        customProperties.put("positive_Double", POSITIVE_DOUBLE);
+        customProperties.put("negative_Integer", NEGATIVE_INTEGER);
+        customProperties.put("negative_Long", NEGATIVE_LONG);
+        customProperties.put("negative_Double", NEGATIVE_DOUBLE);
+        customProperties.put("Boolean", new Boolean(true));
+        customProperties.put("Date", now);
+        customProperties.put("max_Integer", MAX_INTEGER);
+        customProperties.put("min_Integer", MIN_INTEGER);
+        customProperties.put("max_Long", MAX_LONG);
+        customProperties.put("min_Long", MIN_LONG);
+        customProperties.put("max_Double", MAX_DOUBLE);
+        customProperties.put("min_Double", MIN_DOUBLE);
+        dsi.setCustomProperties(customProperties);
+
+        /* Write the summary information stream and the document summary
+         * information stream to the POI filesystem. */
+        si.write(dir, siEntry.getName());
+        dsi.write(dir, dsiEntry.getName());
+
+        /* Write the POI filesystem to a (temporary) file <em>doc2</em>
+         * and close the latter. */
+        final File doc2 = File.createTempFile("POI_HPSF_Test.", ".tmp");
+        doc2.deleteOnExit();
+        OutputStream out = new FileOutputStream(doc2);
+        poifs.writeFilesystem(out);
+        out.close();
+
+        /*
+         * Open <em>doc2</em> for reading and check summary information and
+         * document summary information. All properties written before must be
+         * found in the property streams of <em>doc2</em> and have the correct
+         * values.
+         */
+        poifs = new POIFSFileSystem(new FileInputStream(doc2));
+        dir = poifs.getRoot();
+        siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
+        dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+    
+        dis = new DocumentInputStream(siEntry);
+        ps = new PropertySet(dis);
+        si = new SummaryInformation(ps);
+        dis = new DocumentInputStream(dsiEntry);
+        ps = new PropertySet(dis);
+        dsi = new DocumentSummaryInformation(ps);
+    
+        assertEquals(P_APPLICATION_NAME, si.getApplicationName());
+        assertEquals(P_AUTHOR, si.getAuthor());
+        assertEquals(P_CHAR_COUNT, si.getCharCount());
+        assertEquals(P_COMMENTS, si.getComments());
+        assertEquals(P_CREATE_DATE_TIME, si.getCreateDateTime());
+        assertEquals(P_EDIT_TIME, si.getEditTime());
+        assertEquals(P_KEYWORDS, si.getKeywords());
+        assertEquals(P_LAST_AUTHOR, si.getLastAuthor());
+        assertEquals(P_LAST_PRINTED, si.getLastPrinted());
+        assertEquals(P_LAST_SAVE_DATE_TIME, si.getLastSaveDateTime());
+        assertEquals(P_PAGE_COUNT, si.getPageCount());
+        assertEquals(P_REV_NUMBER, si.getRevNumber());
+        assertEquals(P_SECURITY, si.getSecurity());
+        assertEquals(P_SUBJECT, si.getSubject());
+        assertEquals(P_TEMPLATE, si.getTemplate());
+        // FIXME (byte array properties not yet implemented): assertEquals(P_THUMBNAIL, si.getThumbnail());
+        assertEquals(P_TITLE, si.getTitle());
+        assertEquals(P_WORD_COUNT, si.getWordCount());
+    
+        assertEquals(P_BYTE_COUNT, dsi.getByteCount());
+        assertEquals(P_CATEGORY, dsi.getCategory());
+        assertEquals(P_COMPANY, dsi.getCompany());
+        // FIXME (byte array properties not yet implemented): assertEquals(P_, dsi.getDocparts());
+        // FIXME (byte array properties not yet implemented): assertEquals(P_, dsi.getHeadingPair());
+        assertEquals(P_HIDDEN_COUNT, dsi.getHiddenCount());
+        assertEquals(P_LINE_COUNT, dsi.getLineCount());
+        assertEquals(P_LINKS_DIRTY, dsi.getLinksDirty());
+        assertEquals(P_MANAGER, dsi.getManager());
+        assertEquals(P_MM_CLIP_COUNT, dsi.getMMClipCount());
+        assertEquals(P_NOTE_COUNT, dsi.getNoteCount());
+        assertEquals(P_PAR_COUNT, dsi.getParCount());
+        assertEquals(P_PRESENTATION_FORMAT, dsi.getPresentationFormat());
+        assertEquals(P_SCALE, dsi.getScale());
+        assertEquals(P_SLIDE_COUNT, dsi.getSlideCount());
+
+        final CustomProperties cps = dsi.getCustomProperties();
+        assertEquals(customProperties, cps);
+        assertNull(cps.get("No value available"));
+        assertEquals("Wert ä", cps.get("Schlüssel ä"));
+        assertEquals("Wert äö", cps.get("Schlüssel äö"));
+        assertEquals("Wert äöü", cps.get("Schlüssel äöü"));
+        assertEquals("Wert äöüß", cps.get("Schlüssel äöüß"));
+        assertEquals(POSITIVE_INTEGER, cps.get("positive_Integer"));
+        assertEquals(POSITIVE_LONG, cps.get("positive_Long"));
+        assertEquals(POSITIVE_DOUBLE, cps.get("positive_Double"));
+        assertEquals(NEGATIVE_INTEGER, cps.get("negative_Integer"));
+        assertEquals(NEGATIVE_LONG, cps.get("negative_Long"));
+        assertEquals(NEGATIVE_DOUBLE, cps.get("negative_Double"));
+        assertEquals(new Boolean(true), cps.get("Boolean"));
+        assertEquals(now, cps.get("Date"));
+        assertEquals(MAX_INTEGER, cps.get("max_Integer"));
+        assertEquals(MIN_INTEGER, cps.get("min_Integer"));
+        assertEquals(MAX_LONG, cps.get("max_Long"));
+        assertEquals(MIN_LONG, cps.get("min_Long"));
+        assertEquals(MAX_DOUBLE, cps.get("max_Double"));
+        assertEquals(MIN_DOUBLE, cps.get("min_Double"));
+
+        /* Remove all properties supported by HPSF from the summary
+         * information (e.g. author, edit date, application name) and from the
+         * document summary information (e.g. company, manager). */
+        si.removeApplicationName();
+        si.removeAuthor();
+        si.removeCharCount();
+        si.removeComments();
+        si.removeCreateDateTime();
+        si.removeEditTime();
+        si.removeKeywords();
+        si.removeLastAuthor();
+        si.removeLastPrinted();
+        si.removeLastSaveDateTime();
+        si.removePageCount();
+        si.removeRevNumber();
+        si.removeSecurity();
+        si.removeSubject();
+        si.removeTemplate();
+        si.removeThumbnail();
+        si.removeTitle();
+        si.removeWordCount();
+    
+        dsi.removeByteCount();
+        dsi.removeCategory();
+        dsi.removeCompany();
+        dsi.removeCustomProperties();
+        dsi.removeDocparts();
+        dsi.removeHeadingPair();
+        dsi.removeHiddenCount();
+        dsi.removeLineCount();
+        dsi.removeLinksDirty();
+        dsi.removeManager();
+        dsi.removeMMClipCount();
+        dsi.removeNoteCount();
+        dsi.removeParCount();
+        dsi.removePresentationFormat();
+        dsi.removeScale();
+        dsi.removeSlideCount();
+    
+        /* 
+         * <li><p>Write the summary information stream and the document summary
+         * information stream to the POI filesystem. */
+        si.write(dir, siEntry.getName());
+        dsi.write(dir, dsiEntry.getName());
+    
+        /* 
+         * <li><p>Write the POI filesystem to a (temporary) file <em>doc3</em>
+         * and close the latter. */
+        final File doc3 = File.createTempFile("POI_HPSF_Test.", ".tmp");
+        doc3.deleteOnExit();
+        out = new FileOutputStream(doc3);
+        poifs.writeFilesystem(out);
+        out.close();
+    
+        /* 
+         * Open <em>doc3</em> for reading and check summary information
+         * and document summary information. All properties removed before must not
+         * be found in the property streams of <em>doc3</em>.
+         */
+        poifs = new POIFSFileSystem(new FileInputStream(doc3));
+        dir = poifs.getRoot();
+        siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
+        dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+    
+        dis = new DocumentInputStream(siEntry);
+        ps = new PropertySet(dis);
+        si = new SummaryInformation(ps);
+        dis = new DocumentInputStream(dsiEntry);
+        ps = new PropertySet(dis);
+        dsi = new DocumentSummaryInformation(ps);
+    
+        assertEquals(null, si.getApplicationName());
+        assertEquals(null, si.getAuthor());
+        assertEquals(0, si.getCharCount());
+        assertTrue(si.wasNull());
+        assertEquals(null, si.getComments());
+        assertEquals(null, si.getCreateDateTime());
+        assertEquals(0, si.getEditTime());
+        assertTrue(si.wasNull());
+        assertEquals(null, si.getKeywords());
+        assertEquals(null, si.getLastAuthor());
+        assertEquals(null, si.getLastPrinted());
+        assertEquals(null, si.getLastSaveDateTime());
+        assertEquals(0, si.getPageCount());
+        assertTrue(si.wasNull());
+        assertEquals(null, si.getRevNumber());
+        assertEquals(0, si.getSecurity());
+        assertTrue(si.wasNull());
+        assertEquals(null, si.getSubject());
+        assertEquals(null, si.getTemplate());
+        assertEquals(null, si.getThumbnail());
+        assertEquals(null, si.getTitle());
+        assertEquals(0, si.getWordCount());
+        assertTrue(si.wasNull());
+    
+        assertEquals(0, dsi.getByteCount());
+        assertTrue(dsi.wasNull());
+        assertEquals(null, dsi.getCategory());
+        assertEquals(null, dsi.getCustomProperties());
+        // FIXME (byte array properties not yet implemented): assertEquals(null, dsi.getDocparts());
+        // FIXME (byte array properties not yet implemented): assertEquals(null, dsi.getHeadingPair());
+        assertEquals(0, dsi.getHiddenCount());
+        assertTrue(dsi.wasNull());
+        assertEquals(0, dsi.getLineCount());
+        assertTrue(dsi.wasNull());
+        assertEquals(false, dsi.getLinksDirty());
+        assertTrue(dsi.wasNull());
+        assertEquals(null, dsi.getManager());
+        assertEquals(0, dsi.getMMClipCount());
+        assertTrue(dsi.wasNull());
+        assertEquals(0, dsi.getNoteCount());
+        assertTrue(dsi.wasNull());
+        assertEquals(0, dsi.getParCount());
+        assertTrue(dsi.wasNull());
+        assertEquals(null, dsi.getPresentationFormat());
+        assertEquals(false, dsi.getScale());
+        assertTrue(dsi.wasNull());
+        assertEquals(0, dsi.getSlideCount());
+        assertTrue(dsi.wasNull());
+    }
+
+
+
+    /**
+     * <p>Tests the simplified custom properties by reading them from the
+     * available test files.</p>
+     *
+     * @throws Throwable if anything goes wrong.
+     */
+    public void testReadCustomPropertiesFromFiles() throws Throwable
+    {
+        final AllDataFilesTester.TestTask task = new AllDataFilesTester.TestTask()
+        {
+            public void runTest(final File file) throws FileNotFoundException,
+                    IOException, NoPropertySetStreamException,
+                    MarkUnsupportedException,
+                    UnexpectedPropertySetTypeException
+            {
+                /* Read a test document <em>doc</em> into a POI filesystem. */
+                final POIFSFileSystem poifs = new POIFSFileSystem(new FileInputStream(file));
+                final DirectoryEntry dir = poifs.getRoot();
+                DocumentEntry dsiEntry = null;
+                try
+                {
+                    dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+                }
+                catch (FileNotFoundException ex)
+                {
+                    /*
+                     * A missing document summary information stream is not an error
+                     * and therefore silently ignored here.
+                     */
+                }
+
+                /*
+                 * If there is a document summry information stream, read it from
+                 * the POI filesystem, else create a new one.
+                 */
+                DocumentSummaryInformation dsi;
+                if (dsiEntry != null)
+                {
+                    final DocumentInputStream dis = new DocumentInputStream(dsiEntry);
+                    final PropertySet ps = new PropertySet(dis);
+                    dsi = new DocumentSummaryInformation(ps);
+                }
+                else
+                    dsi = PropertySetFactory.newDocumentSummaryInformation();
+                final CustomProperties cps = dsi.getCustomProperties();
+                
+                if (cps == null)
+                    /* The document does not have custom properties. */
+                    return;
+
+                for (final Iterator i = cps.entrySet().iterator(); i.hasNext();)
+                {
+                    final Map.Entry e = (Entry) i.next();
+                    final CustomProperty cp = (CustomProperty) e.getValue();
+                    cp.getName();
+                    cp.getValue();
+                }
+            }
+        };
+
+        final String dataDirName = System.getProperty("HPSF.testdata.path");
+        final File dataDir = new File(dataDirName);
+        final File[] docs = dataDir.listFiles(new FileFilter()
+        {
+            public boolean accept(final File file)
+            {
+                return file.isFile() && file.getName().startsWith("Test");
+            }
+        });
+
+        for (int i = 0; i < docs.length; i++)
+        {
+            task.runTest(docs[i]);
+        }
+    }
+
+
+
+    /**
+     * <p>Tests basic custom property features.</p>
+     */
+    public void testCustomerProperties()
+    {
+        final String KEY = "Schlüssel ä";
+        final String VALUE_1 = "Wert 1";
+        final String VALUE_2 = "Wert 2";
+
+        CustomProperty cp;
+        CustomProperties cps = new CustomProperties();
+        assertEquals(0, cps.size());
+
+        /* After adding a custom property the size must be 1 and it must be
+         * possible to extract the custom property from the map. */
+        cps.put(KEY, VALUE_1);
+        assertEquals(1, cps.size());
+        Object v1 = cps.get(KEY);
+        assertEquals(VALUE_1, v1);
+        
+        /* After adding a custom property with the same name the size must still
+         * be one. */
+        cps.put(KEY, VALUE_2);
+        assertEquals(1, cps.size());
+        Object v2 = cps.get(KEY);
+        assertEquals(VALUE_2, v2);
+        
+        /* Removing the custom property must return the remove property and
+         * reduce the size to 0. */
+        cp = (CustomProperty) cps.remove(KEY);
+        assertEquals(KEY, cp.getName());
+        assertEquals(VALUE_2, cp.getValue());
+        assertEquals(0, cps.size());
+    }
+
+
+
+    /**
+     * <p>Tests reading custom properties from a section including reading
+     * custom properties which are not pure.</p>
+     */
+    public void testGetCustomerProperties()
+    {
+        final int ID_1 = 2;
+        final int ID_2 = 3;
+        final String NAME_1 = "Schlüssel ä";
+        final String VALUE_1 = "Wert 1";
+        final Map dictionary = new HashMap();
+
+        DocumentSummaryInformation dsi = PropertySetFactory.newDocumentSummaryInformation();
+        CustomProperties cps;
+        MutableSection s;
+
+        /* A document summary information set stream by default does have custom properties. */
+        cps = dsi.getCustomProperties();
+        assertEquals(null, cps);
+
+        /* Test an empty custom properties set. */
+        s = new MutableSection();
+        s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[1]);
+        // s.setCodepage(Constants.CP_UNICODE);
+        dsi.addSection(s);
+        cps = dsi.getCustomProperties();
+        assertEquals(0, cps.size());
+
+        /* Add a custom property. */
+        MutableProperty p = new MutableProperty();
+        p.setID(ID_1);
+        p.setType(Variant.VT_LPWSTR);
+        p.setValue(VALUE_1);
+        s.setProperty(p);
+        dictionary.put(new Long(ID_1), NAME_1);
+        s.setDictionary(dictionary);
+        cps = dsi.getCustomProperties();
+        assertEquals(1, cps.size());
+        assertTrue(cps.isPure());
+
+        /* Add another custom property. */
+        s.setProperty(ID_2, Variant.VT_LPWSTR, VALUE_1);
+        dictionary.put(new Long(ID_2), NAME_1);
+        s.setDictionary(dictionary);
+        cps = dsi.getCustomProperties();
+        assertEquals(1, cps.size());
+        assertFalse(cps.isPure());
+    }
+
+
+
+    /**
+     * <p>Runs the test cases stand-alone.</p>
+     * 
+     * @param args The command-line parameters.
+     * @throws Throwable if anything goes wrong.
+     */
+    public static void main(final String[] args) throws Throwable
+    {
+        System.setProperty("HPSF.testdata.path",
+                           "./src/testcases/org/apache/poi/hpsf/data");
+        junit.textui.TestRunner.run(TestWriteWellKnown.class);
+    }
+
+}

Propchange: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/data/TestCorel.shw
            ('svn:executable' removed)

Propchange: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/data/TestGermanWord90.doc
            ('svn:executable' removed)

Propchange: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/data/TestRobert_Flaherty.doc
            ('svn:executable' removed)

Added: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/data/TestWriteWellKnown.doc
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/data/TestWriteWellKnown.doc?rev=382887&view=auto
==============================================================================
Binary file - no diff available.

Propchange: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/data/TestWriteWellKnown.doc
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/