001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.usermodel;
019:
020: import junit.framework.TestCase;
021: import org.apache.poi.hssf.usermodel.HSSFHeader;
022: import org.apache.poi.hssf.usermodel.HSSFFooter;
023: import org.apache.poi.hssf.usermodel.HSSFSheet;
024: import org.apache.poi.hssf.usermodel.HSSFWorkbook;
025:
026: import java.io.ByteArrayInputStream;
027: import java.io.ByteArrayOutputStream;
028: import java.io.File;
029: import java.io.FileInputStream;
030: import java.io.FileOutputStream;
031:
032: /**
033: * Tests row shifting capabilities.
034: *
035: *
036: * @author Shawn Laubach (slaubach at apache dot com)
037: */
038:
039: public class TestHSSFHeaderFooter extends TestCase {
040:
041: /**
042: * Constructor for TestHeaderFooter.
043: * @param arg0
044: */
045: public TestHSSFHeaderFooter(String arg0) {
046: super (arg0);
047: }
048:
049: /**
050: * Tests that get header retreives the proper values.
051: *
052: * @author Shawn Laubach (slaubach at apache dot org)
053: */
054: public void testRetrieveCorrectHeader() throws Exception {
055: // Read initial file in
056: String filename = System.getProperty("HSSF.testdata.path");
057: filename = filename + "/EmbeddedChartHeaderTest.xls";
058: FileInputStream fin = new FileInputStream(filename);
059: HSSFWorkbook wb = new HSSFWorkbook(fin);
060: fin.close();
061: HSSFSheet s = wb.getSheetAt(0);
062: HSSFHeader head = s.getHeader();
063:
064: assertEquals("Top Left", head.getLeft());
065: assertEquals("Top Center", head.getCenter());
066: assertEquals("Top Right", head.getRight());
067: }
068:
069: /**
070: * Tests that get header retreives the proper values.
071: *
072: * @author Shawn Laubach (slaubach at apache dot org)
073: */
074: public void testRetrieveCorrectFooter() throws Exception {
075: // Read initial file in
076: String filename = System.getProperty("HSSF.testdata.path");
077: filename = filename + "/EmbeddedChartHeaderTest.xls";
078: FileInputStream fin = new FileInputStream(filename);
079: HSSFWorkbook wb = new HSSFWorkbook(fin);
080: fin.close();
081: HSSFSheet s = wb.getSheetAt(0);
082: HSSFFooter foot = s.getFooter();
083:
084: assertEquals("Bottom Left", foot.getLeft());
085: assertEquals("Bottom Center", foot.getCenter());
086: assertEquals("Bottom Right", foot.getRight());
087: }
088:
089: /**
090: * Testcase for Bug 17039 HSSFHeader doesnot support DBCS
091: */
092: public void testHeaderHas16bitCharacter() throws Exception {
093: HSSFWorkbook b = new HSSFWorkbook();
094: HSSFSheet s = b.createSheet("Test");
095: HSSFHeader h = s.getHeader();
096: h.setLeft("\u0391");
097: h.setCenter("\u0392");
098: h.setRight("\u0393");
099:
100: ByteArrayOutputStream out = new ByteArrayOutputStream();
101: b.write(out);
102:
103: HSSFWorkbook b2 = new HSSFWorkbook(new ByteArrayInputStream(out
104: .toByteArray()));
105: HSSFHeader h2 = b2.getSheet("Test").getHeader();
106:
107: assertEquals(h2.getLeft(), "\u0391");
108: assertEquals(h2.getCenter(), "\u0392");
109: assertEquals(h2.getRight(), "\u0393");
110: }
111:
112: /**
113: * Testcase for Bug 17039 HSSFFooter doesnot support DBCS
114: */
115: public void testFooterHas16bitCharacter() throws Exception {
116: HSSFWorkbook b = new HSSFWorkbook();
117: HSSFSheet s = b.createSheet("Test");
118: HSSFFooter f = s.getFooter();
119: f.setLeft("\u0391");
120: f.setCenter("\u0392");
121: f.setRight("\u0393");
122:
123: ByteArrayOutputStream out = new ByteArrayOutputStream();
124: b.write(out);
125:
126: HSSFWorkbook b2 = new HSSFWorkbook(new ByteArrayInputStream(out
127: .toByteArray()));
128: HSSFFooter f2 = b2.getSheet("Test").getFooter();
129:
130: assertEquals(f2.getLeft(), "\u0391");
131: assertEquals(f2.getCenter(), "\u0392");
132: assertEquals(f2.getRight(), "\u0393");
133: }
134:
135: public void testReadDBCSHeaderFooter() throws Exception {
136: String readFilename = System.getProperty("HSSF.testdata.path");
137: FileInputStream in = new FileInputStream(readFilename
138: + File.separator + "DBCSHeader.xls");
139: HSSFWorkbook wb = new HSSFWorkbook(in);
140: HSSFSheet s = wb.getSheetAt(0);
141: HSSFHeader h = s.getHeader();
142: assertEquals("Header Left ", h.getLeft(), "\u090f\u0915");
143: assertEquals("Header Center ", h.getCenter(),
144: "\u0939\u094b\u0917\u093e");
145: assertEquals("Header Right ", h.getRight(), "\u091c\u093e");
146:
147: HSSFFooter f = s.getFooter();
148: assertEquals("Footer Left ", f.getLeft(), "\u091c\u093e");
149: assertEquals("Footer Center ", f.getCenter(), "\u091c\u093e");
150: assertEquals("Footer Right ", f.getRight(), "\u091c\u093e");
151: }
152: }
|