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: package org.apache.poi.hssf.usermodel;
018:
019: import java.io.ByteArrayInputStream;
020: import java.io.ByteArrayOutputStream;
021: import java.io.FileInputStream;
022: import java.io.FileNotFoundException;
023:
024: import org.apache.poi.poifs.filesystem.POIFSFileSystem;
025:
026: import junit.framework.TestCase;
027:
028: /**
029: * Tests for how HSSFWorkbook behaves with XLS files
030: * with a WORKBOOK directory entry (instead of the more
031: * usual, Workbook)
032: */
033: public class TestSheetHiding extends TestCase {
034: private String dirPath;
035: private String xlsHidden = "TwoSheetsOneHidden.xls";
036: private String xlsShown = "TwoSheetsNoneHidden.xls";
037:
038: protected void setUp() throws Exception {
039: super .setUp();
040:
041: dirPath = System.getProperty("HSSF.testdata.path");
042: }
043:
044: /**
045: * Test that we get the right number of sheets,
046: * with the right text on them, no matter what
047: * the hidden flags are
048: */
049: public void testTextSheets() throws Exception {
050: FileInputStream isH = new FileInputStream(dirPath + "/"
051: + xlsHidden);
052: POIFSFileSystem fsH = new POIFSFileSystem(isH);
053:
054: FileInputStream isU = new FileInputStream(dirPath + "/"
055: + xlsShown);
056: POIFSFileSystem fsU = new POIFSFileSystem(isU);
057:
058: HSSFWorkbook wbH = new HSSFWorkbook(fsH);
059: HSSFWorkbook wbU = new HSSFWorkbook(fsU);
060:
061: // Both should have two sheets
062: assertEquals(2, wbH.sheets.size());
063: assertEquals(2, wbU.sheets.size());
064:
065: // All sheets should have one row
066: assertEquals(0, wbH.getSheetAt(0).getLastRowNum());
067: assertEquals(0, wbH.getSheetAt(1).getLastRowNum());
068: assertEquals(0, wbU.getSheetAt(0).getLastRowNum());
069: assertEquals(0, wbU.getSheetAt(1).getLastRowNum());
070:
071: // All rows should have one column
072: assertEquals(1, wbH.getSheetAt(0).getRow(0).getLastCellNum());
073: assertEquals(1, wbH.getSheetAt(1).getRow(0).getLastCellNum());
074: assertEquals(1, wbU.getSheetAt(0).getRow(0).getLastCellNum());
075: assertEquals(1, wbU.getSheetAt(1).getRow(0).getLastCellNum());
076:
077: // Text should be sheet based
078: assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell(
079: (short) 0).getStringCellValue());
080: assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell(
081: (short) 0).getStringCellValue());
082: assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell(
083: (short) 0).getStringCellValue());
084: assertEquals("Sheet2A1", wbU.getSheetAt(1).getRow(0).getCell(
085: (short) 0).getStringCellValue());
086: }
087:
088: /**
089: * Check that we can get and set the hidden flags
090: * as expected
091: */
092: public void testHideUnHideFlags() throws Exception {
093: // TODO
094: }
095:
096: /**
097: * Turn the sheet with none hidden into the one with
098: * one hidden
099: */
100: public void testHide() throws Exception {
101: // TODO
102: }
103:
104: /**
105: * Turn the sheet with one hidden into the one with
106: * none hidden
107: */
108: public void testUnHide() throws Exception {
109: // TODO
110: }
111: }
|