1 2 17 18 package org.apache.poi.hpsf.basic; 19 20 import java.io.ByteArrayInputStream ; 21 import java.io.File ; 22 import java.io.FileNotFoundException ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.io.UnsupportedEncodingException ; 26 27 import junit.framework.Assert; 28 import junit.framework.TestCase; 29 30 import org.apache.poi.hpsf.HPSFException; 31 import org.apache.poi.hpsf.MarkUnsupportedException; 32 import org.apache.poi.hpsf.NoPropertySetStreamException; 33 import org.apache.poi.hpsf.PropertySet; 34 import org.apache.poi.hpsf.PropertySetFactory; 35 import org.apache.poi.hpsf.SummaryInformation; 36 37 46 public class TestEmptyProperties extends TestCase 47 { 48 49 53 static final String POI_FS = "TestCorel.shw"; 54 55 static final String [] POI_FILES = new String [] 56 { 57 "PerfectOffice_MAIN", 58 "\005SummaryInformation", 59 "Main" 60 }; 61 62 POIFile[] poiFiles; 63 64 65 66 71 public TestEmptyProperties(final String name) 72 { 73 super(name); 74 } 75 76 77 78 85 public void setUp() throws FileNotFoundException , IOException 86 { 87 final File dataDir = 88 new File (System.getProperty("HPSF.testdata.path")); 89 final File data = new File (dataDir, POI_FS); 90 91 poiFiles = Util.readPOIFiles(data); 92 } 93 94 95 96 102 public void testReadFiles() throws IOException 103 { 104 String [] expected = POI_FILES; 105 for (int i = 0; i < expected.length; i++) 106 Assert.assertEquals(poiFiles[i].getName(), expected[i]); 107 } 108 109 110 111 125 public void testCreatePropertySets() 126 throws UnsupportedEncodingException , IOException 127 { 128 Class [] expected = new Class [] 129 { 130 NoPropertySetStreamException.class, 131 SummaryInformation.class, 132 NoPropertySetStreamException.class 133 }; 134 for (int i = 0; i < expected.length; i++) 135 { 136 InputStream in = new ByteArrayInputStream (poiFiles[i].getBytes()); 137 Object o; 138 try 139 { 140 o = PropertySetFactory.create(in); 141 } 142 catch (NoPropertySetStreamException ex) 143 { 144 o = ex; 145 } 146 catch (MarkUnsupportedException ex) 147 { 148 o = ex; 149 } 150 in.close(); 151 Assert.assertEquals(o.getClass(), expected[i]); 152 } 153 } 154 155 156 157 165 public void testPropertySetMethods() throws IOException , HPSFException 166 { 167 byte[] b = poiFiles[1].getBytes(); 168 PropertySet ps = 169 PropertySetFactory.create(new ByteArrayInputStream (b)); 170 SummaryInformation s = (SummaryInformation) ps; 171 assertNull(s.getTitle()); 172 assertNull(s.getSubject()); 173 assertNotNull(s.getAuthor()); 174 assertNull(s.getKeywords()); 175 assertNull(s.getComments()); 176 assertNotNull(s.getTemplate()); 177 assertNotNull(s.getLastAuthor()); 178 assertNotNull(s.getRevNumber()); 179 assertEquals(s.getEditTime(), 0); 180 assertNull(s.getLastPrinted()); 181 assertNull(s.getCreateDateTime()); 182 assertNull(s.getLastSaveDateTime()); 183 assertEquals(s.getPageCount(), 0); 184 assertEquals(s.getWordCount(), 0); 185 assertEquals(s.getCharCount(), 0); 186 assertNull(s.getThumbnail()); 187 assertNull(s.getApplicationName()); 188 } 189 190 191 192 199 public static void main(final String [] args) throws Throwable 200 { 201 System.setProperty("HPSF.testdata.path", 202 "./src/testcases/org/apache/poi/hpsf/data"); 203 junit.textui.TestRunner.run(TestBasic.class); 204 } 205 206 } 207 | Popular Tags |