KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > usermodel > TestReadWriteChart


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.hssf.usermodel;
20
21 import junit.framework.TestCase;
22 import org.apache.poi.hssf.model.Sheet;
23 import org.apache.poi.hssf.record.BOFRecord;
24 import org.apache.poi.hssf.record.EOFRecord;
25 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
26
27 import java.io.FileInputStream JavaDoc;
28 import java.util.GregorianCalendar JavaDoc;
29 import java.util.List JavaDoc;
30
31 /**
32  * @author Glen Stampoultzis (glens at apache.org)
33  */

34
35 public class TestReadWriteChart
36     extends TestCase
37 {
38     public TestReadWriteChart(String JavaDoc s)
39     {
40         super(s);
41     }
42
43     /**
44      * In the presence of a chart we need to make sure BOF/EOF records still exist.
45      */

46
47     public void testBOFandEOFRecords()
48         throws Exception JavaDoc
49     {
50         //System.out.println("made it in testBOFandEOF");
51
String JavaDoc path = System.getProperty("HSSF.testdata.path");
52         String JavaDoc filename = path + "/SimpleChart.xls";
53         //System.out.println("path is "+path);
54
POIFSFileSystem fs =
55             new POIFSFileSystem(new FileInputStream JavaDoc(filename));
56         //System.out.println("opened file");
57
HSSFWorkbook workbook = new HSSFWorkbook(fs);
58         HSSFSheet sheet = workbook.getSheetAt(0);
59         HSSFRow firstRow = sheet.getRow(0);
60         HSSFCell firstCell = firstRow.getCell(( short ) 0);
61
62         //System.out.println("first assertion for date");
63
assertEquals(new GregorianCalendar JavaDoc(2000, 0, 1, 10, 51, 2).getTime(),
64                      HSSFDateUtil
65                          .getJavaDate(firstCell.getNumericCellValue()));
66         HSSFRow row = sheet.createRow(( short ) 15);
67         HSSFCell cell = row.createCell(( short ) 1);
68
69         cell.setCellValue(22);
70         Sheet newSheet = workbook.getSheetAt(0).getSheet();
71         List JavaDoc records = newSheet.getRecords();
72
73         //System.out.println("BOF Assertion");
74
assertTrue(records.get(0) instanceof BOFRecord);
75         //System.out.println("EOF Assertion");
76
assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
77     }
78     
79     public static void main(String JavaDoc [] args)
80     {
81         String JavaDoc filename = System.getProperty("HSSF.testdata.path");
82
83         // assume andy is running this in the debugger
84
if (filename == null)
85         {
86             if (args != null && args[0].length() == 1) {
87             System.setProperty(
88                 "HSSF.testdata.path",
89                 args[0]);
90             } else {
91                 System.err.println("Geesh, no HSSF.testdata.path system " +
92                           "property, no command line arg with the path "+
93                           "what do you expect me to do, guess where teh data " +
94                           "files are? Sorry, I give up!");
95                                    
96             }
97             
98         }
99         System.out
100             .println("Testing org.apache.poi.hssf.usermodel.TestReadWriteChart");
101         junit.textui.TestRunner.run(TestReadWriteChart.class);
102     }
103     
104 }
105
Popular Tags