01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: 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: package org.apache.poi.hssf.usermodel;
19:
20: import junit.framework.TestCase;
21: import org.apache.poi.hssf.model.Sheet;
22: import org.apache.poi.hssf.record.BOFRecord;
23: import org.apache.poi.hssf.record.EOFRecord;
24: import org.apache.poi.poifs.filesystem.POIFSFileSystem;
25:
26: import java.io.FileInputStream;
27: import java.util.GregorianCalendar;
28: import java.util.List;
29:
30: /**
31: * @author Glen Stampoultzis (glens at apache.org)
32: */
33:
34: public class TestReadWriteChart extends TestCase {
35: public TestReadWriteChart(String s) {
36: super (s);
37: }
38:
39: /**
40: * In the presence of a chart we need to make sure BOF/EOF records still exist.
41: */
42:
43: public void testBOFandEOFRecords() throws Exception {
44: //System.out.println("made it in testBOFandEOF");
45: String path = System.getProperty("HSSF.testdata.path");
46: String filename = path + "/SimpleChart.xls";
47: //System.out.println("path is "+path);
48: POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(
49: filename));
50: //System.out.println("opened file");
51: HSSFWorkbook workbook = new HSSFWorkbook(fs);
52: HSSFSheet sheet = workbook.getSheetAt(0);
53: HSSFRow firstRow = sheet.getRow(0);
54: HSSFCell firstCell = firstRow.getCell((short) 0);
55:
56: //System.out.println("first assertion for date");
57: assertEquals(new GregorianCalendar(2000, 0, 1, 10, 51, 2)
58: .getTime(), HSSFDateUtil.getJavaDate(firstCell
59: .getNumericCellValue(), false));
60: HSSFRow row = sheet.createRow((short) 15);
61: HSSFCell cell = row.createCell((short) 1);
62:
63: cell.setCellValue(22);
64: Sheet newSheet = workbook.getSheetAt(0).getSheet();
65: List records = newSheet.getRecords();
66:
67: //System.out.println("BOF Assertion");
68: assertTrue(records.get(0) instanceof BOFRecord);
69: //System.out.println("EOF Assertion");
70: assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
71: }
72:
73: public static void main(String[] args) {
74: String filename = System.getProperty("HSSF.testdata.path");
75:
76: // assume andy is running this in the debugger
77: if (filename == null) {
78: if (args != null && args[0].length() == 1) {
79: System.setProperty("HSSF.testdata.path", args[0]);
80: } else {
81: System.err
82: .println("Geesh, no HSSF.testdata.path system "
83: + "property, no command line arg with the path "
84: + "what do you expect me to do, guess where teh data "
85: + "files are? Sorry, I give up!");
86:
87: }
88:
89: }
90: System.out
91: .println("Testing org.apache.poi.hssf.usermodel.TestReadWriteChart");
92: junit.textui.TestRunner.run(TestReadWriteChart.class);
93: }
94:
95: }
|