KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hpsf > basic > TestUnicode


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19 package org.apache.poi.hpsf.basic;
20
21 import java.io.ByteArrayInputStream JavaDoc;
22 import java.io.File JavaDoc;
23 import java.io.FileNotFoundException JavaDoc;
24 import java.io.IOException JavaDoc;
25
26 import junit.framework.Assert;
27 import junit.framework.TestCase;
28
29 import org.apache.poi.hpsf.Constants;
30 import org.apache.poi.hpsf.HPSFException;
31 import org.apache.poi.hpsf.PropertySet;
32 import org.apache.poi.hpsf.PropertySetFactory;
33 import org.apache.poi.hpsf.Section;
34
35
36
37 /**
38  * <p>Tests whether Unicode string can be read from a
39  * DocumentSummaryInformation.</p>
40  *
41  * @author Rainer Klute (klute@rainer-klute.de)
42  * @since 2002-12-09
43  * @version $Id: TestUnicode.java,v 1.6 2004/06/22 16:15:10 klute Exp $
44  */

45 public class TestUnicode extends TestCase
46 {
47
48     static final String JavaDoc POI_FS = "TestUnicode.xls";
49     static final String JavaDoc[] POI_FILES = new String JavaDoc[]
50         {
51             "\005DocumentSummaryInformation",
52         };
53     File JavaDoc data;
54     POIFile[] poiFiles;
55
56
57
58     /**
59      * <p>Constructor</p>
60      *
61      * @param name the test case's name
62      */

63     public TestUnicode(final String JavaDoc name)
64     {
65         super(name);
66     }
67
68
69
70     /**
71      * <p>Read a the test file from the "data" directory.</p>
72      *
73      * @exception FileNotFoundException if the file to be read does not exist.
74      * @exception IOException if any other I/O exception occurs
75      */

76     protected void setUp() throws FileNotFoundException JavaDoc, IOException JavaDoc
77     {
78         final File JavaDoc dataDir =
79             new File JavaDoc(System.getProperty("HPSF.testdata.path"));
80         data = new File JavaDoc(dataDir, POI_FS);
81     }
82
83
84
85     /**
86      * <p>Tests the {@link PropertySet} methods. The test file has two
87      * property set: the first one is a {@link SummaryInformation},
88      * the second one is a {@link DocumentSummaryInformation}.</p>
89      *
90      * @exception IOException if an I/O exception occurs
91      * @exception HPSFException if an HPSF exception occurs
92      */

93     public void testPropertySetMethods() throws IOException JavaDoc, HPSFException
94     {
95         POIFile poiFile = Util.readPOIFiles(data, POI_FILES)[0];
96         byte[] b = poiFile.getBytes();
97         PropertySet ps =
98             PropertySetFactory.create(new ByteArrayInputStream JavaDoc(b));
99         Assert.assertTrue(ps.isDocumentSummaryInformation());
100         Assert.assertEquals(ps.getSectionCount(), 2);
101         Section s = (Section) ps.getSections().get(1);
102         Assert.assertEquals(s.getProperty(1),
103                             new Integer JavaDoc(Constants.CP_UTF16));
104         Assert.assertEquals(s.getProperty(2),
105                             new Long JavaDoc(4198897018L));
106         Assert.assertEquals(s.getProperty(3),
107                             "MCon_Info zu Office bei Schreiner");
108         Assert.assertEquals(s.getProperty(4),
109                             "petrovitsch@schreiner-online.de");
110         Assert.assertEquals(s.getProperty(5),
111                             "Petrovitsch, Wilhelm");
112     }
113
114
115
116     /**
117      * <p>Runs the test cases stand-alone.</p>
118      *
119      * @param args Command-line arguments.
120      */

121     public static void main(final String JavaDoc[] args)
122     {
123         System.setProperty("HPSF.testdata.path",
124                            "./src/testcases/org/apache/poi/hpsf/data");
125         junit.textui.TestRunner.run(TestUnicode.class);
126     }
127
128 }
129
Popular Tags