From: Ugo Cei Date: Tue, 22 Jan 2008 11:26:27 +0000 (+0000) Subject: Tests for XSSFSheet, contributed by Paolo Mottadelli . X-Git-Tag: REL_3_5_BETA2~237 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d0ccd710d971158d89c8e273b19debec40e5f2b4;p=poi.git Tests for XSSFSheet, contributed by Paolo Mottadelli . git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@614178 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java new file mode 100644 index 0000000000..aaa30b3611 --- /dev/null +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java @@ -0,0 +1,93 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.xssf.usermodel; + +import java.util.Iterator; + +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; + +import junit.framework.TestCase; + + +public class TestXSSFSheet extends TestCase { + + public void testRowIterator() throws Exception { + XSSFWorkbook workbook = new XSSFWorkbook(); + Sheet sheet = workbook.createSheet("Sheet 1"); + Row row1 = sheet.createRow(0); + Row row2 = sheet.createRow(1); + Iterator it = sheet.rowIterator(); + assertNotNull(it); + assertTrue(it.hasNext()); + assertEquals(row1, it.next()); + assertTrue(it.hasNext()); + assertEquals(row2, it.next()); + assertFalse(it.hasNext()); + } + + public void testGetRow() throws Exception { + XSSFWorkbook workbook = new XSSFWorkbook(); + Sheet sheet = workbook.createSheet("Sheet 1"); + Row row1 = sheet.createRow(0); + Cell cell = row1.createCell((short) 0); + cell.setCellType(Cell.CELL_TYPE_NUMERIC); + cell.setCellValue((double) 1000); + + // Test getting a row and check its cell's value + Row row_got = sheet.getRow(0); + Cell cell_got = row_got.getCell((short) 0); + assertEquals((double) 1000, cell_got.getNumericCellValue()); + } + + public void testCreateRow() throws Exception { + XSSFWorkbook workbook = new XSSFWorkbook(); + Sheet sheet = workbook.createSheet("Sheet 1"); + + // Test row creation with consecutive indexes + Row row1 = sheet.createRow(0); + Row row2 = sheet.createRow(1); + assertEquals(0, row1.getRowNum()); + Iterator it = sheet.rowIterator(); + assertTrue(it.hasNext()); + assertEquals(row1, it.next()); + assertTrue(it.hasNext()); + assertEquals(row2, it.next()); + + // Test row creation with non consecutive index + Row row101 = sheet.createRow(100); + assertNotNull(row101); + + // Test overwriting an existing row + Row row2_ovrewritten = sheet.createRow(1); + Cell cell = row2_ovrewritten.createCell((short) 0); + cell.setCellType(Cell.CELL_TYPE_NUMERIC); + cell.setCellValue((double) 100); + Iterator it2 = sheet.rowIterator(); + assertTrue(it2.hasNext()); + assertEquals(row1, it2.next()); + assertTrue(it2.hasNext()); + Row row2_overwritten_copy = it2.next(); + assertEquals(row2_ovrewritten, row2_overwritten_copy); + assertEquals(row2_overwritten_copy.getCell((short) 0).getNumericCellValue(), (double) 100); + + + + } +}