fix eclipse resource leak warnings
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1797043 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4232a72208
commit
efccafd898
@ -18,12 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.ss.util.CellReference;
|
import org.apache.poi.ss.util.CellReference;
|
||||||
@ -31,17 +30,26 @@ import org.apache.poi.xslf.XSLFTestDataSamples;
|
|||||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.*;
|
import org.junit.Test;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumData;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumVal;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieChart;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieSer;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrData;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrVal;
|
||||||
|
|
||||||
/**
|
public class TestXSLFChart {
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
|
||||||
public class TestXSLFChart extends TestCase {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a modified version from POI-examples
|
* a modified version from POI-examples
|
||||||
*/
|
*/
|
||||||
public void testFillChartTemplate() throws Exception {
|
@Test
|
||||||
|
public void testFillChartTemplate() throws IOException {
|
||||||
|
|
||||||
String chartTitle = "Apache POI"; // first line is chart title
|
String chartTitle = "Apache POI"; // first line is chart title
|
||||||
|
|
||||||
@ -126,7 +134,7 @@ public class TestXSLFChart extends TestCase {
|
|||||||
OutputStream xlsOut = xlsPart.getPackagePart().getOutputStream();
|
OutputStream xlsOut = xlsPart.getPackagePart().getOutputStream();
|
||||||
wb.write(xlsOut);
|
wb.write(xlsOut);
|
||||||
xlsOut.close();
|
xlsOut.close();
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -18,32 +18,31 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test common operations on containers of shapes (sheets and groups of shapes)
|
* test common operations on containers of shapes (sheets and groups of shapes)
|
||||||
*
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
*/
|
||||||
public class TestXSLFShapeContainer {
|
public class TestXSLFShapeContainer {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public void verifyContainer(XSLFShapeContainer container) {
|
public void verifyContainer(XSLFShapeContainer container) {
|
||||||
container.clear();
|
container.clear();
|
||||||
assertEquals(0, container.getShapes().size());
|
assertEquals(0, container.getShapes().size());
|
||||||
|
|
||||||
XSLFGroupShape shape1 = container.createGroup();
|
container.createGroup();
|
||||||
assertEquals(1, container.getShapes().size());
|
assertEquals(1, container.getShapes().size());
|
||||||
|
|
||||||
XSLFTextBox shape2 = container.createTextBox();
|
container.createTextBox();
|
||||||
assertEquals(2, container.getShapes().size());
|
assertEquals(2, container.getShapes().size());
|
||||||
|
|
||||||
XSLFAutoShape shape3 = container.createAutoShape();
|
container.createAutoShape();
|
||||||
assertEquals(3, container.getShapes().size());
|
assertEquals(3, container.getShapes().size());
|
||||||
|
|
||||||
XSLFConnectorShape shape4 = container.createConnector();
|
container.createConnector();
|
||||||
assertEquals(4, container.getShapes().size());
|
assertEquals(4, container.getShapes().size());
|
||||||
|
|
||||||
container.clear();
|
container.clear();
|
||||||
@ -51,7 +50,7 @@ public class TestXSLFShapeContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSheet() {
|
public void testSheet() throws IOException {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSheet sheet = ppt.createSlide();
|
XSLFSheet sheet = ppt.createSlide();
|
||||||
verifyContainer(sheet);
|
verifyContainer(sheet);
|
||||||
@ -60,5 +59,6 @@ public class TestXSLFShapeContainer {
|
|||||||
XSLFGroupShape group = sheet.createGroup();
|
XSLFGroupShape group = sheet.createGroup();
|
||||||
verifyContainer(group);
|
verifyContainer(group);
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,46 +17,60 @@
|
|||||||
|
|
||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
|
||||||
|
|
||||||
|
|
||||||
public class TestXSSFDialogSheet extends TestCase {
|
public class TestXSSFDialogSheet {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreateDialogSheet() {
|
public void testCreateDialogSheet() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
Sheet dialogsheet = workbook.createDialogsheet("Dialogsheet 1", CTDialogsheet.Factory.newInstance());
|
Sheet dialogsheet = workbook.createDialogsheet("Dialogsheet 1", CTDialogsheet.Factory.newInstance());
|
||||||
assertNotNull(dialogsheet);
|
assertNotNull(dialogsheet);
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetDialog() {
|
@Test
|
||||||
|
public void testGetDialog() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet dialogsheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet dialogsheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertTrue(dialogsheet.getDialog());
|
assertTrue(dialogsheet.getDialog());
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddRow() {
|
@Test
|
||||||
|
public void testAddRow() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
Sheet dialogsheet = workbook.createDialogsheet("Dialogsheet 1", CTDialogsheet.Factory.newInstance());
|
Sheet dialogsheet = workbook.createDialogsheet("Dialogsheet 1", CTDialogsheet.Factory.newInstance());
|
||||||
assertNotNull(dialogsheet);
|
assertNotNull(dialogsheet);
|
||||||
Row row = dialogsheet.createRow(0);
|
Row row = dialogsheet.createRow(0);
|
||||||
assertNull(row);
|
assertNull(row);
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetSetAutoBreaks() {
|
@Test
|
||||||
|
public void testGetSetAutoBreaks() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertTrue(sheet.getAutobreaks());
|
assertTrue(sheet.getAutobreaks());
|
||||||
sheet.setAutobreaks(false);
|
sheet.setAutobreaks(false);
|
||||||
assertFalse(sheet.getAutobreaks());
|
assertFalse(sheet.getAutobreaks());
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIsSetFitToPage() {
|
@Test
|
||||||
|
public void testIsSetFitToPage() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertFalse(sheet.getFitToPage());
|
assertFalse(sheet.getFitToPage());
|
||||||
@ -64,18 +78,22 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
assertTrue(sheet.getFitToPage());
|
assertTrue(sheet.getFitToPage());
|
||||||
sheet.setFitToPage(false);
|
sheet.setFitToPage(false);
|
||||||
assertFalse(sheet.getFitToPage());
|
assertFalse(sheet.getFitToPage());
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testGetFooter() {
|
@Test
|
||||||
|
public void testGetFooter() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertNotNull(sheet.getFooter());
|
assertNotNull(sheet.getFooter());
|
||||||
sheet.getFooter().setCenter("test center footer");
|
sheet.getFooter().setCenter("test center footer");
|
||||||
assertEquals("test center footer", sheet.getFooter().getCenter());
|
assertEquals("test center footer", sheet.getFooter().getCenter());
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetAllHeadersFooters() {
|
@Test
|
||||||
|
public void testGetAllHeadersFooters() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertNotNull(sheet);
|
assertNotNull(sheet);
|
||||||
@ -109,10 +127,11 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
assertEquals("", sheet.getOddHeader().getCenter());
|
assertEquals("", sheet.getOddHeader().getCenter());
|
||||||
sheet.getOddHeader().setCenter("odd header center");
|
sheet.getOddHeader().setCenter("odd header center");
|
||||||
assertEquals("odd header center", sheet.getOddHeader().getCenter());
|
assertEquals("odd header center", sheet.getOddHeader().getCenter());
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetSetHorizontallyCentered() {
|
@Test
|
||||||
|
public void testGetSetHorizontallyCentered() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertFalse(sheet.getHorizontallyCenter());
|
assertFalse(sheet.getHorizontallyCenter());
|
||||||
@ -120,9 +139,11 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
assertTrue(sheet.getHorizontallyCenter());
|
assertTrue(sheet.getHorizontallyCenter());
|
||||||
sheet.setHorizontallyCenter(false);
|
sheet.setHorizontallyCenter(false);
|
||||||
assertFalse(sheet.getHorizontallyCenter());
|
assertFalse(sheet.getHorizontallyCenter());
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetSetVerticallyCentered() {
|
@Test
|
||||||
|
public void testGetSetVerticallyCentered() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertFalse(sheet.getVerticallyCenter());
|
assertFalse(sheet.getVerticallyCenter());
|
||||||
@ -130,44 +151,55 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
assertTrue(sheet.getVerticallyCenter());
|
assertTrue(sheet.getVerticallyCenter());
|
||||||
sheet.setVerticallyCenter(false);
|
sheet.setVerticallyCenter(false);
|
||||||
assertFalse(sheet.getVerticallyCenter());
|
assertFalse(sheet.getVerticallyCenter());
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIsSetPrintGridlines() {
|
@Test
|
||||||
|
public void testIsSetPrintGridlines() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertFalse(sheet.isPrintGridlines());
|
assertFalse(sheet.isPrintGridlines());
|
||||||
sheet.setPrintGridlines(true);
|
sheet.setPrintGridlines(true);
|
||||||
assertTrue(sheet.isPrintGridlines());
|
assertTrue(sheet.isPrintGridlines());
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIsSetDisplayFormulas() {
|
@Test
|
||||||
|
public void testIsSetDisplayFormulas() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertFalse(sheet.isDisplayFormulas());
|
assertFalse(sheet.isDisplayFormulas());
|
||||||
sheet.setDisplayFormulas(true);
|
sheet.setDisplayFormulas(true);
|
||||||
assertTrue(sheet.isDisplayFormulas());
|
assertTrue(sheet.isDisplayFormulas());
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIsSetDisplayGridLines() {
|
@Test
|
||||||
|
public void testIsSetDisplayGridLines() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertTrue(sheet.isDisplayGridlines());
|
assertTrue(sheet.isDisplayGridlines());
|
||||||
sheet.setDisplayGridlines(false);
|
sheet.setDisplayGridlines(false);
|
||||||
assertFalse(sheet.isDisplayGridlines());
|
assertFalse(sheet.isDisplayGridlines());
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIsSetDisplayRowColHeadings() {
|
@Test
|
||||||
|
public void testIsSetDisplayRowColHeadings() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertTrue(sheet.isDisplayRowColHeadings());
|
assertTrue(sheet.isDisplayRowColHeadings());
|
||||||
sheet.setDisplayRowColHeadings(false);
|
sheet.setDisplayRowColHeadings(false);
|
||||||
assertFalse(sheet.isDisplayRowColHeadings());
|
assertFalse(sheet.isDisplayRowColHeadings());
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetScenarioProtect() {
|
@Test
|
||||||
|
public void testGetScenarioProtect() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertFalse(sheet.getScenarioProtect());
|
assertFalse(sheet.getScenarioProtect());
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,13 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.xssf.model.StylesTable;
|
import org.apache.poi.xssf.model.StylesTable;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||||
@ -329,7 +330,7 @@ public final class TestColumnHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetOrCreateColumn() {
|
public void testGetOrCreateColumn() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = workbook.createSheet("Sheet 1");
|
XSSFSheet sheet = workbook.createSheet("Sheet 1");
|
||||||
ColumnHelper columnHelper = sheet.getColumnHelper();
|
ColumnHelper columnHelper = sheet.getColumnHelper();
|
||||||
@ -348,10 +349,12 @@ public final class TestColumnHelper {
|
|||||||
assertNotNull(columnHelper.getColumn(29, false));
|
assertNotNull(columnHelper.getColumn(29, false));
|
||||||
assertNotNull(columnHelper.getColumn1Based(30, false));
|
assertNotNull(columnHelper.getColumn1Based(30, false));
|
||||||
assertNull(columnHelper.getColumn(30, false));
|
assertNull(columnHelper.getColumn(30, false));
|
||||||
|
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetSetColDefaultStyle() {
|
public void testGetSetColDefaultStyle() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = workbook.createSheet();
|
XSSFSheet sheet = workbook.createSheet();
|
||||||
CTWorksheet ctWorksheet = sheet.getCTWorksheet();
|
CTWorksheet ctWorksheet = sheet.getCTWorksheet();
|
||||||
@ -382,6 +385,8 @@ public final class TestColumnHelper {
|
|||||||
columnHelper.setColDefaultStyle(11, cellStyle);
|
columnHelper.setColDefaultStyle(11, cellStyle);
|
||||||
assertEquals(0, col_2.getStyle());
|
assertEquals(0, col_2.getStyle());
|
||||||
assertEquals(1, columnHelper.getColDefaultStyle(10));
|
assertEquals(1, columnHelper.getColDefaultStyle(10));
|
||||||
|
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int countColumns(CTWorksheet worksheet) {
|
private static int countColumns(CTWorksheet worksheet) {
|
||||||
|
@ -28,6 +28,7 @@ import org.apache.poi.POITextExtractor;
|
|||||||
import org.apache.poi.hdgf.extractor.VisioTextExtractor;
|
import org.apache.poi.hdgf.extractor.VisioTextExtractor;
|
||||||
import org.apache.poi.hpbf.extractor.PublisherTextExtractor;
|
import org.apache.poi.hpbf.extractor.PublisherTextExtractor;
|
||||||
import org.apache.poi.hslf.extractor.PowerPointExtractor;
|
import org.apache.poi.hslf.extractor.PowerPointExtractor;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
import org.apache.poi.hsmf.MAPIMessage;
|
import org.apache.poi.hsmf.MAPIMessage;
|
||||||
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
|
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
|
||||||
import org.apache.poi.hsmf.extractor.OutlookTextExtactor;
|
import org.apache.poi.hsmf.extractor.OutlookTextExtactor;
|
||||||
@ -63,7 +64,7 @@ public class OLE2ScratchpadExtractorFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (poifsDir.hasEntry("PowerPoint Document")) {
|
if (poifsDir.hasEntry(HSLFSlideShow.POWERPOINT_DOCUMENT)) {
|
||||||
return new PowerPointExtractor(poifsDir);
|
return new PowerPointExtractor(poifsDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ import java.io.Writer;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
import org.apache.poi.hslf.record.RecordTypes;
|
import org.apache.poi.hslf.record.RecordTypes;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
@ -40,7 +41,6 @@ import org.apache.poi.util.LittleEndian;
|
|||||||
public final class PPTXMLDump {
|
public final class PPTXMLDump {
|
||||||
private static final int HEADER_SIZE = 8; //size of the record header
|
private static final int HEADER_SIZE = 8; //size of the record header
|
||||||
private static final int PICT_HEADER_SIZE = 25; //size of the picture header
|
private static final int PICT_HEADER_SIZE = 25; //size of the picture header
|
||||||
private static final String PPDOC_ENTRY = "PowerPoint Document";
|
|
||||||
private static final String PICTURES_ENTRY = "Pictures";
|
private static final String PICTURES_ENTRY = "Pictures";
|
||||||
private static final String CR = System.getProperty("line.separator");
|
private static final String CR = System.getProperty("line.separator");
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ public final class PPTXMLDump {
|
|||||||
public PPTXMLDump(File ppt) throws IOException {
|
public PPTXMLDump(File ppt) throws IOException {
|
||||||
NPOIFSFileSystem fs = new NPOIFSFileSystem(ppt, true);
|
NPOIFSFileSystem fs = new NPOIFSFileSystem(ppt, true);
|
||||||
try {
|
try {
|
||||||
docstream = readEntry(fs, PPDOC_ENTRY);
|
docstream = readEntry(fs, HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
pictstream = readEntry(fs, PICTURES_ENTRY);
|
pictstream = readEntry(fs, PICTURES_ENTRY);
|
||||||
} finally {
|
} finally {
|
||||||
fs.close();
|
fs.close();
|
||||||
|
@ -29,6 +29,7 @@ import org.apache.poi.ddf.EscherRecord;
|
|||||||
import org.apache.poi.ddf.EscherTextboxRecord;
|
import org.apache.poi.ddf.EscherTextboxRecord;
|
||||||
import org.apache.poi.hslf.record.HSLFEscherRecordFactory;
|
import org.apache.poi.hslf.record.HSLFEscherRecordFactory;
|
||||||
import org.apache.poi.hslf.record.RecordTypes;
|
import org.apache.poi.hslf.record.RecordTypes;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||||
import org.apache.poi.util.HexDump;
|
import org.apache.poi.util.HexDump;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
@ -96,7 +97,7 @@ public final class SlideShowDumper {
|
|||||||
*/
|
*/
|
||||||
public SlideShowDumper(NPOIFSFileSystem filesystem, PrintStream out) throws IOException {
|
public SlideShowDumper(NPOIFSFileSystem filesystem, PrintStream out) throws IOException {
|
||||||
// Grab the document stream
|
// Grab the document stream
|
||||||
InputStream is = filesystem.createDocumentInputStream("PowerPoint Document");
|
InputStream is = filesystem.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
docstream = IOUtils.toByteArray(is);
|
docstream = IOUtils.toByteArray(is);
|
||||||
is.close();
|
is.close();
|
||||||
this.out = out;
|
this.out = out;
|
||||||
|
@ -28,6 +28,7 @@ import org.apache.poi.hslf.record.Record;
|
|||||||
import org.apache.poi.hslf.record.RecordTypes;
|
import org.apache.poi.hslf.record.RecordTypes;
|
||||||
import org.apache.poi.hslf.record.TextBytesAtom;
|
import org.apache.poi.hslf.record.TextBytesAtom;
|
||||||
import org.apache.poi.hslf.record.TextCharsAtom;
|
import org.apache.poi.hslf.record.TextCharsAtom;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
|
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
|
||||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
@ -102,7 +103,7 @@ public final class QuickButCruddyTextExtractor {
|
|||||||
fs = poifs;
|
fs = poifs;
|
||||||
|
|
||||||
// Find the PowerPoint bit, and get out the bytes
|
// Find the PowerPoint bit, and get out the bytes
|
||||||
InputStream pptIs = fs.createDocumentInputStream("PowerPoint Document");
|
InputStream pptIs = fs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
pptContents = IOUtils.toByteArray(pptIs);
|
pptContents = IOUtils.toByteArray(pptIs);
|
||||||
pptIs.close();
|
pptIs.close();
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,9 @@ import org.apache.poi.util.Units;
|
|||||||
* understanding DocSlideList and DocNotesList) - handle Slide creation cleaner
|
* understanding DocSlideList and DocNotesList) - handle Slide creation cleaner
|
||||||
*/
|
*/
|
||||||
public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagraph>, Closeable {
|
public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagraph>, Closeable {
|
||||||
|
/** Powerpoint document entry/stream name */
|
||||||
|
public static final String POWERPOINT_DOCUMENT = "PowerPoint Document";
|
||||||
|
|
||||||
enum LoadSavePhase {
|
enum LoadSavePhase {
|
||||||
INIT, LOADED
|
INIT, LOADED
|
||||||
}
|
}
|
||||||
@ -1078,7 +1081,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
|||||||
|
|
||||||
protected static Map<String,ClassID> getOleMap() {
|
protected static Map<String,ClassID> getOleMap() {
|
||||||
Map<String,ClassID> olemap = new HashMap<String,ClassID>();
|
Map<String,ClassID> olemap = new HashMap<String,ClassID>();
|
||||||
olemap.put("PowerPoint Document", ClassID.PPT_SHOW);
|
olemap.put(POWERPOINT_DOCUMENT, ClassID.PPT_SHOW);
|
||||||
olemap.put("Workbook", ClassID.EXCEL97); // as per BIFF8 spec
|
olemap.put("Workbook", ClassID.EXCEL97); // as per BIFF8 spec
|
||||||
olemap.put("WORKBOOK", ClassID.EXCEL97); // Typically from third party programs
|
olemap.put("WORKBOOK", ClassID.EXCEL97); // Typically from third party programs
|
||||||
olemap.put("BOOK", ClassID.EXCEL97); // Typically odd Crystal Reports exports
|
olemap.put("BOOK", ClassID.EXCEL97); // Typically odd Crystal Reports exports
|
||||||
|
@ -209,11 +209,11 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
|
|||||||
private void readPowerPointStream() throws IOException {
|
private void readPowerPointStream() throws IOException {
|
||||||
// Get the main document stream
|
// Get the main document stream
|
||||||
DocumentEntry docProps =
|
DocumentEntry docProps =
|
||||||
(DocumentEntry) getDirectory().getEntry("PowerPoint Document");
|
(DocumentEntry) getDirectory().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
|
|
||||||
// Grab the document stream
|
// Grab the document stream
|
||||||
int len = docProps.getSize();
|
int len = docProps.getSize();
|
||||||
InputStream is = getDirectory().createDocumentInputStream("PowerPoint Document");
|
InputStream is = getDirectory().createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
try {
|
try {
|
||||||
_docstream = IOUtils.toByteArray(is, len);
|
_docstream = IOUtils.toByteArray(is, len);
|
||||||
} finally {
|
} finally {
|
||||||
@ -701,8 +701,8 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
|
|||||||
|
|
||||||
// Write the PPT stream into the POIFS layer
|
// Write the PPT stream into the POIFS layer
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(_docstream);
|
ByteArrayInputStream bais = new ByteArrayInputStream(_docstream);
|
||||||
outFS.createOrUpdateDocument(bais, "PowerPoint Document");
|
outFS.createOrUpdateDocument(bais, HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
writtenEntries.add("PowerPoint Document");
|
writtenEntries.add(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
|
|
||||||
currentUser.setEncrypted(encryptedSS.getDocumentEncryptionAtom() != null);
|
currentUser.setEncrypted(encryptedSS.getDocumentEncryptionAtom() != null);
|
||||||
currentUser.writeToFS(outFS);
|
currentUser.writeToFS(outFS);
|
||||||
|
@ -101,15 +101,15 @@ public final class TestReWrite {
|
|||||||
// Check all of them in turn
|
// Check all of them in turn
|
||||||
for (POIFSFileSystem npf : new POIFSFileSystem[] { npfS, npfF, npfRF }) {
|
for (POIFSFileSystem npf : new POIFSFileSystem[] { npfS, npfF, npfRF }) {
|
||||||
// Check that the "PowerPoint Document" sections have the same size
|
// Check that the "PowerPoint Document" sections have the same size
|
||||||
DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry("PowerPoint Document");
|
DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
DocumentEntry nProps = (DocumentEntry)npf.getRoot().getEntry("PowerPoint Document");
|
DocumentEntry nProps = (DocumentEntry)npf.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
assertEquals(oProps.getSize(),nProps.getSize());
|
assertEquals(oProps.getSize(),nProps.getSize());
|
||||||
|
|
||||||
// Check that they contain the same data
|
// Check that they contain the same data
|
||||||
byte[] _oData = new byte[oProps.getSize()];
|
byte[] _oData = new byte[oProps.getSize()];
|
||||||
byte[] _nData = new byte[nProps.getSize()];
|
byte[] _nData = new byte[nProps.getSize()];
|
||||||
pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
|
pfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_oData);
|
||||||
npf.createDocumentInputStream("PowerPoint Document").read(_nData);
|
npf.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_nData);
|
||||||
for(int i=0; i<_oData.length; i++) {
|
for(int i=0; i<_oData.length; i++) {
|
||||||
//System.out.println(i + "\t" + Integer.toHexString(i));
|
//System.out.println(i + "\t" + Integer.toHexString(i));
|
||||||
assertEquals(_oData[i], _nData[i]);
|
assertEquals(_oData[i], _nData[i]);
|
||||||
@ -174,15 +174,15 @@ public final class TestReWrite {
|
|||||||
POIFSFileSystem npfs = new POIFSFileSystem(bais);
|
POIFSFileSystem npfs = new POIFSFileSystem(bais);
|
||||||
|
|
||||||
// Check that the "PowerPoint Document" sections have the same size
|
// Check that the "PowerPoint Document" sections have the same size
|
||||||
DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry("PowerPoint Document");
|
DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry("PowerPoint Document");
|
DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
assertEquals(oProps.getSize(),nProps.getSize());
|
assertEquals(oProps.getSize(),nProps.getSize());
|
||||||
|
|
||||||
// Check that they contain the same data
|
// Check that they contain the same data
|
||||||
byte[] _oData = new byte[oProps.getSize()];
|
byte[] _oData = new byte[oProps.getSize()];
|
||||||
byte[] _nData = new byte[nProps.getSize()];
|
byte[] _nData = new byte[nProps.getSize()];
|
||||||
pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
|
pfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_oData);
|
||||||
npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
|
npfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_nData);
|
||||||
for(int i=0; i<_oData.length; i++) {
|
for(int i=0; i<_oData.length; i++) {
|
||||||
if(_oData[i] != _nData[i])
|
if(_oData[i] != _nData[i])
|
||||||
System.out.println(i + "\t" + Integer.toHexString(i));
|
System.out.println(i + "\t" + Integer.toHexString(i));
|
||||||
|
@ -191,7 +191,7 @@ public final class TestExtractor {
|
|||||||
private PowerPointExtractor assertExtractFromEmbedded(DirectoryNode root, String entryName, String expected)
|
private PowerPointExtractor assertExtractFromEmbedded(DirectoryNode root, String entryName, String expected)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
DirectoryNode dir = (DirectoryNode)root.getEntry(entryName);
|
DirectoryNode dir = (DirectoryNode)root.getEntry(entryName);
|
||||||
assertTrue(dir.hasEntry("PowerPoint Document"));
|
assertTrue(dir.hasEntry(HSLFSlideShow.POWERPOINT_DOCUMENT));
|
||||||
|
|
||||||
// Check the first file
|
// Check the first file
|
||||||
HSLFSlideShowImpl ppt = new HSLFSlideShowImpl(dir);
|
HSLFSlideShowImpl ppt = new HSLFSlideShowImpl(dir);
|
||||||
|
@ -18,23 +18,22 @@
|
|||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.model;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFLine;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlide;
|
import org.apache.poi.hslf.usermodel.HSLFSlide;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFLine;
|
|
||||||
import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound;
|
import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound;
|
||||||
import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
|
import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Line shape.
|
* Test Line shape.
|
||||||
*
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
*/
|
||||||
public final class TestLine {
|
public final class TestLine {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateLines() {
|
public void testCreateLines() throws IOException {
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow();
|
HSLFSlideShow ppt = new HSLFSlideShow();
|
||||||
|
|
||||||
HSLFSlide slide = ppt.createSlide();
|
HSLFSlide slide = ppt.createSlide();
|
||||||
@ -127,5 +126,7 @@ public final class TestLine {
|
|||||||
line.setLineCompound(LineCompound.DOUBLE);
|
line.setLineCompound(LineCompound.DOUBLE);
|
||||||
line.setLineWidth(8.0);
|
line.setLineWidth(8.0);
|
||||||
slide.addShape(line);
|
slide.addShape(line);
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,19 +19,19 @@ package org.apache.poi.hslf.model;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test adding fonts to the presenataion resources
|
* Test adding fonts to the presenataion resources
|
||||||
*
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
*/
|
||||||
public final class TestPPFont {
|
public final class TestPPFont {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate() {
|
public void testCreate() throws IOException {
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow();
|
HSLFSlideShow ppt = new HSLFSlideShow();
|
||||||
assertEquals(1, ppt.getNumberOfFonts());
|
assertEquals(1, ppt.getNumberOfFonts());
|
||||||
assertEquals("Arial", ppt.getFont(0).getFontName());
|
assertEquals("Arial", ppt.getFont(0).getFontName());
|
||||||
@ -53,5 +53,7 @@ public final class TestPPFont {
|
|||||||
assertEquals(PPFont.WINGDINGS.getFontName(), font3.getFontName());
|
assertEquals(PPFont.WINGDINGS.getFontName(), font3.getFontName());
|
||||||
assertEquals(PPFont.SYMBOL_CHARSET, font3.getCharSet());
|
assertEquals(PPFont.SYMBOL_CHARSET, font3.getCharSet());
|
||||||
assertEquals(PPFont.VARIABLE_PITCH, font3.getPitchAndFamily());
|
assertEquals(PPFont.VARIABLE_PITCH, font3.getPitchAndFamily());
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,19 +22,25 @@ import static org.junit.Assert.assertTrue;
|
|||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
|
import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
|
||||||
import org.apache.poi.hslf.record.Environment;
|
import org.apache.poi.hslf.record.Environment;
|
||||||
import org.apache.poi.hslf.record.TextHeaderAtom;
|
import org.apache.poi.hslf.record.TextHeaderAtom;
|
||||||
import org.apache.poi.hslf.usermodel.*;
|
import org.apache.poi.hslf.usermodel.HSLFMasterSheet;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlide;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideMaster;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFTextRun;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFTitleMaster;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for SlideMaster
|
* Tests for SlideMaster
|
||||||
*
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
*/
|
||||||
public final class TestSlideMaster {
|
public final class TestSlideMaster {
|
||||||
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
|
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
|
||||||
@ -44,7 +50,7 @@ public final class TestSlideMaster {
|
|||||||
* Check we can read their attributes.
|
* Check we can read their attributes.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSlideMaster() throws Exception {
|
public void testSlideMaster() throws IOException {
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
|
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
|
||||||
|
|
||||||
Environment env = ppt.getDocumentRecord().getEnvironment();
|
Environment env = ppt.getDocumentRecord().getEnvironment();
|
||||||
@ -79,13 +85,15 @@ public final class TestSlideMaster {
|
|||||||
int b2 = master.get(1).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.font", false).getValue();
|
int b2 = master.get(1).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.font", false).getValue();
|
||||||
assertEquals("Arial", env.getFontCollection().getFontWithId(b1));
|
assertEquals("Arial", env.getFontCollection().getFontWithId(b1));
|
||||||
assertEquals("Georgia", env.getFontCollection().getFontWithId(b2));
|
assertEquals("Georgia", env.getFontCollection().getFontWithId(b2));
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test we can read default text attributes for a title master sheet
|
* Test we can read default text attributes for a title master sheet
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testTitleMasterTextAttributes() throws Exception {
|
public void testTitleMasterTextAttributes() throws IOException {
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
|
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
|
||||||
List<HSLFTitleMaster> master = ppt.getTitleMasters();
|
List<HSLFTitleMaster> master = ppt.getTitleMasters();
|
||||||
assertEquals(1, master.size());
|
assertEquals(1, master.size());
|
||||||
@ -101,13 +109,15 @@ public final class TestSlideMaster {
|
|||||||
assertEquals(true, prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
|
assertEquals(true, prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
|
||||||
assertEquals(false, prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
|
assertEquals(false, prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
|
||||||
assertEquals(false, prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
|
assertEquals(false, prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Slide 3 has title layout and follows the TitleMaster. Verify that.
|
* Slide 3 has title layout and follows the TitleMaster. Verify that.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testTitleMaster() throws Exception {
|
public void testTitleMaster() throws IOException {
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
|
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
|
||||||
HSLFSlide slide = ppt.getSlides().get(2);
|
HSLFSlide slide = ppt.getSlides().get(2);
|
||||||
HSLFMasterSheet masterSheet = slide.getMasterSheet();
|
HSLFMasterSheet masterSheet = slide.getMasterSheet();
|
||||||
@ -131,7 +141,9 @@ public final class TestSlideMaster {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a style attribute is not set ensure it is read from the master
|
* If a style attribute is not set ensure it is read from the master
|
||||||
*/
|
*/
|
||||||
@ -178,13 +190,14 @@ public final class TestSlideMaster {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check we can dynamically assign a slide master to a slide.
|
* Check we can dynamically assign a slide master to a slide.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testChangeSlideMaster() throws Exception {
|
public void testChangeSlideMaster() throws IOException {
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
|
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
|
||||||
List<HSLFSlideMaster> master = ppt.getSlideMasters();
|
List<HSLFSlideMaster> master = ppt.getSlideMasters();
|
||||||
List<HSLFSlide> slide = ppt.getSlides();
|
List<HSLFSlide> slide = ppt.getSlides();
|
||||||
@ -212,6 +225,8 @@ public final class TestSlideMaster {
|
|||||||
for (HSLFSlide s : slide) {
|
for (HSLFSlide s : slide) {
|
||||||
assertEquals(sheetNo, s.getMasterSheet()._getSheetNumber());
|
assertEquals(sheetNo, s.getMasterSheet()._getSheetNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -219,7 +234,7 @@ public final class TestSlideMaster {
|
|||||||
* (typical for the "bullted body" placeholder)
|
* (typical for the "bullted body" placeholder)
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testIndentation() throws Exception {
|
public void testIndentation() throws IOException {
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
|
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
|
||||||
HSLFSlide slide = ppt.getSlides().get(0);
|
HSLFSlide slide = ppt.getSlides().get(0);
|
||||||
|
|
||||||
@ -238,7 +253,6 @@ public final class TestSlideMaster {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -17,14 +17,19 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.model;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hslf.usermodel.*;
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFTextRun;
|
||||||
|
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||||
import org.apache.poi.poifs.filesystem.DocumentEntry;
|
import org.apache.poi.poifs.filesystem.DocumentEntry;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -34,16 +39,10 @@ import org.junit.Test;
|
|||||||
* Tests that if we load something up, get a TextRun, set the text
|
* Tests that if we load something up, get a TextRun, set the text
|
||||||
* to be the same as it was before, and write it all back out again,
|
* to be the same as it was before, and write it all back out again,
|
||||||
* that we don't break anything in the process.
|
* that we don't break anything in the process.
|
||||||
*
|
|
||||||
* @author Nick Burch (nick at torchbox dot com)
|
|
||||||
*/
|
*/
|
||||||
public final class TestTextRunReWrite {
|
public final class TestTextRunReWrite {
|
||||||
// HSLFSlideShow primed on the test data
|
|
||||||
private HSLFSlideShowImpl hss;
|
|
||||||
// HSLFSlideShow primed on the test data
|
// HSLFSlideShow primed on the test data
|
||||||
private HSLFSlideShow ss;
|
private HSLFSlideShow ss;
|
||||||
// POIFS primed on the test data
|
|
||||||
private POIFSFileSystem pfs;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load up a test PPT file with rich data
|
* Load up a test PPT file with rich data
|
||||||
@ -52,13 +51,11 @@ public final class TestTextRunReWrite {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||||
String filename = "Single_Coloured_Page_With_Fonts_and_Alignments.ppt";
|
String filename = "Single_Coloured_Page_With_Fonts_and_Alignments.ppt";
|
||||||
pfs = new POIFSFileSystem(slTests.openResourceAsStream(filename));
|
ss = new HSLFSlideShow(slTests.openResourceAsStream(filename));
|
||||||
hss = new HSLFSlideShowImpl(pfs);
|
|
||||||
ss = new HSLFSlideShow(hss);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWritesOutTheSameNonRich() throws Exception {
|
public void testWritesOutTheSameNonRich() throws IOException {
|
||||||
// Ensure the text lengths are as we'd expect to start with
|
// Ensure the text lengths are as we'd expect to start with
|
||||||
assertEquals(1, ss.getSlides().size());
|
assertEquals(1, ss.getSlides().size());
|
||||||
assertEquals(2, ss.getSlides().get(0).getTextParagraphs().size());
|
assertEquals(2, ss.getSlides().get(0).getTextParagraphs().size());
|
||||||
@ -103,23 +100,24 @@ public final class TestTextRunReWrite {
|
|||||||
POIFSFileSystem npfs = new POIFSFileSystem(bais);
|
POIFSFileSystem npfs = new POIFSFileSystem(bais);
|
||||||
|
|
||||||
// Check that the "PowerPoint Document" sections have the same size
|
// Check that the "PowerPoint Document" sections have the same size
|
||||||
DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry("PowerPoint Document");
|
DirectoryNode oDir = ss.getSlideShowImpl().getDirectory();
|
||||||
DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry("PowerPoint Document");
|
|
||||||
|
DocumentEntry oProps = (DocumentEntry)oDir.getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
|
DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
assertEquals(oProps.getSize(),nProps.getSize());
|
assertEquals(oProps.getSize(),nProps.getSize());
|
||||||
|
|
||||||
// Check that they contain the same data
|
// Check that they contain the same data
|
||||||
byte[] _oData = new byte[oProps.getSize()];
|
byte[] _oData = new byte[oProps.getSize()];
|
||||||
byte[] _nData = new byte[nProps.getSize()];
|
byte[] _nData = new byte[nProps.getSize()];
|
||||||
pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
|
oDir.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_oData);
|
||||||
npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
|
npfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_nData);
|
||||||
for(int i=0; i<_oData.length; i++) {
|
assertArrayEquals(_oData, _nData);
|
||||||
// System.out.println(i + "\t" + Integer.toHexString(i));
|
|
||||||
assertEquals(_oData[i], _nData[i]);
|
npfs.close();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWritesOutTheSameRich() throws Exception {
|
public void testWritesOutTheSameRich() throws IOException {
|
||||||
// Grab the first text run on the first sheet
|
// Grab the first text run on the first sheet
|
||||||
List<HSLFTextParagraph> tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
|
List<HSLFTextParagraph> tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
|
||||||
|
|
||||||
@ -160,18 +158,20 @@ public final class TestTextRunReWrite {
|
|||||||
POIFSFileSystem npfs = new POIFSFileSystem(bais);
|
POIFSFileSystem npfs = new POIFSFileSystem(bais);
|
||||||
|
|
||||||
// Check that the "PowerPoint Document" sections have the same size
|
// Check that the "PowerPoint Document" sections have the same size
|
||||||
DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry("PowerPoint Document");
|
DirectoryNode oDir = ss.getSlideShowImpl().getDirectory();
|
||||||
DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry("PowerPoint Document");
|
|
||||||
|
DocumentEntry oProps = (DocumentEntry)oDir.getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
|
DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
assertEquals(oProps.getSize(),nProps.getSize());
|
assertEquals(oProps.getSize(),nProps.getSize());
|
||||||
|
|
||||||
// Check that they contain the same data
|
// Check that they contain the same data
|
||||||
byte[] _oData = new byte[oProps.getSize()];
|
byte[] _oData = new byte[oProps.getSize()];
|
||||||
byte[] _nData = new byte[nProps.getSize()];
|
byte[] _nData = new byte[nProps.getSize()];
|
||||||
pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
|
|
||||||
npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
|
oDir.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_oData);
|
||||||
for(int i=0; i<_oData.length; i++) {
|
npfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_nData);
|
||||||
// System.out.println(i + "\t" + Integer.toHexString(i) + "\t" + _oData[i]);
|
assertArrayEquals(_oData, _nData);
|
||||||
assertEquals(_oData[i], _nData[i]);
|
|
||||||
}
|
npfs.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,86 +18,48 @@
|
|||||||
package org.apache.poi.hslf.record;
|
package org.apache.poi.hslf.record;
|
||||||
|
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import org.apache.poi.POIDataSamples;
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that ExHyperlink works properly.
|
* Tests that ExHyperlink works properly.
|
||||||
*
|
|
||||||
* @author Nick Burch (nick at torchbox dot com)
|
|
||||||
*/
|
*/
|
||||||
public final class TestExHyperlink extends TestCase {
|
public final class TestExHyperlink {
|
||||||
|
@Test
|
||||||
|
public void testReadWrite() throws IOException {
|
||||||
// From a real file
|
// From a real file
|
||||||
private final byte[] data_a = new byte[] {
|
byte[] exHyperlinkBytes = org.apache.poi.poifs.storage.RawDataUtil.decompress(
|
||||||
0x0F, 00, 0xD7-256, 0x0F, 0xA8-256, 00, 00, 00,
|
"H4sIAAAAAAAAAONnuM6/ggEELvOzAElmMHsXvxuQzGAoAcICBisGfSDMYkhkyAbi"+
|
||||||
|
"IqBYIoMeEBcAcTJQVSqQlw8UTweqKgCyMoF0BkMxEKYBWQJUNQ0A/k1x3rAAAAA="
|
||||||
|
);
|
||||||
|
ExHyperlink exHyperlink = new ExHyperlink(exHyperlinkBytes, 0, exHyperlinkBytes.length);
|
||||||
|
|
||||||
00, 00, 0xD3-256, 0x0F, 04, 00, 00, 00,
|
|
||||||
03, 00, 00, 00,
|
|
||||||
|
|
||||||
00, 00, 0xBA-256, 0x0F, 0x46, 00, 00, 00,
|
assertEquals(4055l, exHyperlink.getRecordType());
|
||||||
0x68, 00, 0x74, 00, 0x74, 00, 0x70, 00,
|
assertEquals(3, exHyperlink.getExHyperlinkAtom().getNumber());
|
||||||
0x3A, 00, 0x2F, 00, 0x2F, 00, 0x6A, 00,
|
String expURL = "http://jakarta.apache.org/poi/hssf/";
|
||||||
0x61, 00, 0x6B, 00, 0x61, 00, 0x72, 00,
|
assertEquals(expURL, exHyperlink.getLinkURL());
|
||||||
0x74, 00, 0x61, 00, 0x2E, 00, 0x61, 00,
|
assertEquals(expURL, exHyperlink._getDetailsA());
|
||||||
0x70, 00, 0x61, 00, 0x63, 00, 0x68, 00,
|
assertEquals(expURL, exHyperlink._getDetailsB());
|
||||||
0x65, 00, 0x2E, 00, 0x6F, 00, 0x72, 00,
|
|
||||||
0x67, 00, 0x2F, 00, 0x70, 00, 0x6F, 00,
|
|
||||||
0x69, 00, 0x2F, 00, 0x68, 00, 0x73, 00,
|
|
||||||
0x73, 00, 0x66, 00, 0x2F, 00,
|
|
||||||
|
|
||||||
0x10, 00, 0xBA-256, 0x0F, 0x46, 00, 00, 00,
|
|
||||||
0x68, 00, 0x74, 00, 0x74, 00, 0x70, 00,
|
|
||||||
0x3A, 00, 0x2F, 00, 0x2F, 00, 0x6A, 00,
|
|
||||||
0x61, 00, 0x6B, 00, 0x61, 00, 0x72, 00,
|
|
||||||
0x74, 00, 0x61, 00, 0x2E, 00, 0x61, 00,
|
|
||||||
0x70, 00, 0x61, 00, 0x63, 00, 0x68, 00,
|
|
||||||
0x65, 00, 0x2E, 00, 0x6F, 00, 0x72, 00,
|
|
||||||
0x67, 00, 0x2F, 00, 0x70, 00, 0x6F, 00,
|
|
||||||
0x69, 00, 0x2F, 00, 0x68, 00, 0x73, 00,
|
|
||||||
0x73, 00, 0x66, 00, 0x2F, 00
|
|
||||||
};
|
|
||||||
|
|
||||||
public void testRecordType() {
|
|
||||||
ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
|
|
||||||
assertEquals(4055l, eh.getRecordType());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNumber() {
|
|
||||||
ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
|
|
||||||
assertEquals(3, eh.getExHyperlinkAtom().getNumber());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testLinkURL() {
|
|
||||||
ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
|
|
||||||
assertEquals("http://jakarta.apache.org/poi/hssf/", eh.getLinkURL());
|
|
||||||
}
|
|
||||||
public void testDetails() {
|
|
||||||
ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
|
|
||||||
assertEquals("http://jakarta.apache.org/poi/hssf/", eh._getDetailsA());
|
|
||||||
assertEquals("http://jakarta.apache.org/poi/hssf/", eh._getDetailsB());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testWrite() throws Exception {
|
|
||||||
ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
eh.writeOut(baos);
|
exHyperlink.writeOut(baos);
|
||||||
byte[] b = baos.toByteArray();
|
assertArrayEquals(exHyperlinkBytes, baos.toByteArray());
|
||||||
|
|
||||||
assertEquals(data_a.length, b.length);
|
|
||||||
for(int i=0; i<data_a.length; i++) {
|
|
||||||
assertEquals(data_a[i],b[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRealFile() throws Exception {
|
@Test
|
||||||
|
public void testRealFile() throws IOException {
|
||||||
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||||
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithLinks.ppt"));
|
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithLinks.ppt"));
|
||||||
HSLFSlideShow ss = new HSLFSlideShow(hss);
|
HSLFSlideShow ss = new HSLFSlideShow(hss);
|
||||||
@ -111,9 +73,8 @@ public final class TestExHyperlink extends TestCase {
|
|||||||
exObjList = (ExObjList)rec;
|
exObjList = (ExObjList)rec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (exObjList == null) {
|
|
||||||
throw new AssertionFailedError("exObjList must not be null");
|
assertNotNull(exObjList);
|
||||||
}
|
|
||||||
|
|
||||||
// Within that, grab out the Hyperlink atoms
|
// Within that, grab out the Hyperlink atoms
|
||||||
List<ExHyperlink> linksA = new ArrayList<ExHyperlink>();
|
List<ExHyperlink> linksA = new ArrayList<ExHyperlink>();
|
||||||
@ -145,5 +106,6 @@ public final class TestExHyperlink extends TestCase {
|
|||||||
assertEquals(4, links[3].getExHyperlinkAtom().getNumber());
|
assertEquals(4, links[3].getExHyperlinkAtom().getNumber());
|
||||||
assertEquals("http://jakarta.apache.org/hslf/", links[3].getLinkURL());
|
assertEquals("http://jakarta.apache.org/hslf/", links[3].getLinkURL());
|
||||||
|
|
||||||
|
ss.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,22 +18,21 @@
|
|||||||
package org.apache.poi.hslf.record;
|
package org.apache.poi.hslf.record;
|
||||||
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that ExObjList works properly.
|
* Tests that ExObjList works properly.
|
||||||
*
|
|
||||||
* @author Nick Burch (nick at torchbox dot com)
|
|
||||||
*/
|
*/
|
||||||
public class TestExObjList extends TestCase {
|
public class TestExObjList {
|
||||||
|
@Test
|
||||||
public void testRealFile() throws Exception {
|
public void testRealFile() throws Exception {
|
||||||
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||||
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithLinks.ppt"));
|
HSLFSlideShow ss = new HSLFSlideShow(slTests.openResourceAsStream("WithLinks.ppt"));
|
||||||
HSLFSlideShow ss = new HSLFSlideShow(hss);
|
|
||||||
|
|
||||||
// Get the document
|
// Get the document
|
||||||
Document doc = ss.getDocumentRecord();
|
Document doc = ss.getDocumentRecord();
|
||||||
@ -65,5 +64,6 @@ public class TestExObjList extends TestCase {
|
|||||||
assertEquals(4, links[3].getExHyperlinkAtom().getNumber());
|
assertEquals(4, links[3].getExHyperlinkAtom().getNumber());
|
||||||
assertEquals("http://jakarta.apache.org/hslf/", links[3].getLinkURL());
|
assertEquals("http://jakarta.apache.org/hslf/", links[3].getLinkURL());
|
||||||
|
|
||||||
|
ss.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,20 +18,22 @@
|
|||||||
package org.apache.poi.hslf.record;
|
package org.apache.poi.hslf.record;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import junit.framework.AssertionFailedError;
|
import static org.junit.Assert.assertEquals;
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests Sound-related records: SoundCollection(2020), Sound(2022) and
|
* Tests Sound-related records: SoundCollection(2020), Sound(2022) and
|
||||||
* SoundData(2023)).
|
* SoundData(2023)).
|
||||||
*
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
*/
|
||||||
public final class TestSound extends TestCase {
|
public final class TestSound {
|
||||||
public void testRealFile() throws Exception {
|
@Test
|
||||||
|
public void testRealFile() throws IOException {
|
||||||
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||||
|
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream("sound.ppt"));
|
HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream("sound.ppt"));
|
||||||
@ -46,9 +48,7 @@ public final class TestSound extends TestCase {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (soundCollection == null) {
|
assertNotNull(soundCollection);
|
||||||
throw new AssertionFailedError("soundCollection must not be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
Sound sound = null;
|
Sound sound = null;
|
||||||
Record[] sound_ch = soundCollection.getChildRecords();
|
Record[] sound_ch = soundCollection.getChildRecords();
|
||||||
@ -59,9 +59,8 @@ public final class TestSound extends TestCase {
|
|||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sound == null) {
|
|
||||||
throw new AssertionFailedError("sound must not be null");
|
assertNotNull(sound);
|
||||||
}
|
|
||||||
assertEquals(1, k);
|
assertEquals(1, k);
|
||||||
|
|
||||||
assertEquals("ringin.wav", sound.getSoundName());
|
assertEquals("ringin.wav", sound.getSoundName());
|
||||||
@ -70,5 +69,7 @@ public final class TestSound extends TestCase {
|
|||||||
|
|
||||||
byte[] ref_data = slTests.readFile("ringin.wav");
|
byte[] ref_data = slTests.readFile("ringin.wav");
|
||||||
assertArrayEquals(ref_data, sound.getSoundData());
|
assertArrayEquals(ref_data, sound.getSoundData());
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import static org.junit.Assume.assumeTrue;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
import java.awt.FontFormatException;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
@ -31,6 +32,7 @@ import java.awt.geom.Rectangle2D;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.DataBufferByte;
|
import java.awt.image.DataBufferByte;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -51,7 +53,7 @@ public class TestFontRendering {
|
|||||||
|
|
||||||
// @Ignore2("This fails on some systems because fonts are rendered slightly different")
|
// @Ignore2("This fails on some systems because fonts are rendered slightly different")
|
||||||
@Test
|
@Test
|
||||||
public void bug55902mixedFontWithChineseCharacters() throws Exception {
|
public void bug55902mixedFontWithChineseCharacters() throws IOException, FontFormatException {
|
||||||
// font files need to be downloaded first via
|
// font files need to be downloaded first via
|
||||||
// ant test-scratchpad-download-resources
|
// ant test-scratchpad-download-resources
|
||||||
String fontFiles[][] = {
|
String fontFiles[][] = {
|
||||||
@ -117,5 +119,6 @@ public class TestFontRendering {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assertArrayEquals("Expected to have matching raster-arrays, but found differences", expectedData, actualData);
|
assertArrayEquals("Expected to have matching raster-arrays, but found differences", expectedData, actualData);
|
||||||
|
ss.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,19 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.usermodel;
|
package org.apache.poi.hslf.usermodel;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hslf.model.textproperties.TextPFException9;
|
import org.apache.poi.hslf.model.textproperties.TextPFException9;
|
||||||
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
|
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
|
||||||
import org.apache.poi.hslf.record.*;
|
import org.apache.poi.hslf.record.EscherTextboxWrapper;
|
||||||
|
import org.apache.poi.hslf.record.StyleTextProp9Atom;
|
||||||
|
import org.apache.poi.hslf.record.StyleTextPropAtom;
|
||||||
import org.apache.poi.sl.usermodel.AutoNumberingScheme;
|
import org.apache.poi.sl.usermodel.AutoNumberingScheme;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -36,14 +41,12 @@ import org.junit.Test;
|
|||||||
* if a paragraph has autonumber ()
|
* if a paragraph has autonumber ()
|
||||||
* @see <a href="http://social.msdn.microsoft.com/Forums/mr-IN/os_binaryfile/thread/650888db-fabd-4b95-88dc-f0455f6e2d28">
|
* @see <a href="http://social.msdn.microsoft.com/Forums/mr-IN/os_binaryfile/thread/650888db-fabd-4b95-88dc-f0455f6e2d28">
|
||||||
* PPT: Missing TextAutoNumberScheme structure providing the style of the number bullets</a>
|
* PPT: Missing TextAutoNumberScheme structure providing the style of the number bullets</a>
|
||||||
*
|
|
||||||
* @author Alex Nikiforov [mailto:anikif@gmail.com]
|
|
||||||
*/
|
*/
|
||||||
public final class TestNumberedList2 {
|
public final class TestNumberedList2 {
|
||||||
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
|
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNumberedList() throws Exception {
|
public void testNumberedList() throws IOException {
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers2.ppt"));
|
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers2.ppt"));
|
||||||
assertTrue("No Exceptions while reading file", true);
|
assertTrue("No Exceptions while reading file", true);
|
||||||
|
|
||||||
@ -51,7 +54,10 @@ public final class TestNumberedList2 {
|
|||||||
assertEquals(2, slides.size());
|
assertEquals(2, slides.size());
|
||||||
checkSlide0(slides.get(0));
|
checkSlide0(slides.get(0));
|
||||||
checkSlide1(slides.get(1));
|
checkSlide1(slides.get(1));
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkSlide0(final HSLFSlide s) {
|
private void checkSlide0(final HSLFSlide s) {
|
||||||
final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
|
final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
|
||||||
assertNotNull(numberedListArray);
|
assertNotNull(numberedListArray);
|
||||||
@ -89,6 +95,7 @@ public final class TestNumberedList2 {
|
|||||||
checkSingleRunWrapper(44, styleAtoms[0]);
|
checkSingleRunWrapper(44, styleAtoms[0]);
|
||||||
checkSingleRunWrapper(130, styleAtoms[1]);
|
checkSingleRunWrapper(130, styleAtoms[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkSlide1(final HSLFSlide s) {
|
private void checkSlide1(final HSLFSlide s) {
|
||||||
final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
|
final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
|
||||||
assertNotNull(numberedListArray);
|
assertNotNull(numberedListArray);
|
||||||
@ -119,6 +126,7 @@ public final class TestNumberedList2 {
|
|||||||
checkSingleRunWrapper(67, styleAtoms[1]);
|
checkSingleRunWrapper(67, styleAtoms[1]);
|
||||||
checkSingleRunWrapper(70, styleAtoms[2]);
|
checkSingleRunWrapper(70, styleAtoms[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkSingleRunWrapper(final int exceptedLength, final EscherTextboxWrapper wrapper) {
|
private void checkSingleRunWrapper(final int exceptedLength, final EscherTextboxWrapper wrapper) {
|
||||||
final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
|
final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
|
||||||
final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
|
final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
|
||||||
|
@ -22,15 +22,15 @@ import static org.junit.Assert.assertEquals;
|
|||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
|
import org.apache.poi.hslf.HSLFTestDataSamples;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that SlideShow can re-order slides properly
|
* Tests that SlideShow can re-order slides properly
|
||||||
*
|
|
||||||
* @author Nick Burch (nick at torchbox dot com)
|
|
||||||
*/
|
*/
|
||||||
public final class TestReOrderingSlides {
|
public final class TestReOrderingSlides {
|
||||||
// A SlideShow with one slide
|
// A SlideShow with one slide
|
||||||
@ -66,7 +66,7 @@ public final class TestReOrderingSlides {
|
|||||||
* Test that we can "re-order" a slideshow with only 1 slide on it
|
* Test that we can "re-order" a slideshow with only 1 slide on it
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testReOrder1() throws Exception {
|
public void testReOrder1() throws IOException {
|
||||||
// Has one slide
|
// Has one slide
|
||||||
assertEquals(1, ss_one.getSlides().size());
|
assertEquals(1, ss_one.getSlides().size());
|
||||||
HSLFSlide s1 = ss_one.getSlides().get(0);
|
HSLFSlide s1 = ss_one.getSlides().get(0);
|
||||||
@ -80,12 +80,7 @@ public final class TestReOrderingSlides {
|
|||||||
ss_one.reorderSlide(1, 1);
|
ss_one.reorderSlide(1, 1);
|
||||||
|
|
||||||
// Write out, and read back in
|
// Write out, and read back in
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_one);
|
||||||
hss_one.write(baos);
|
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
|
||||||
|
|
||||||
HSLFSlideShowImpl hss_read = new HSLFSlideShowImpl(bais);
|
|
||||||
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
|
|
||||||
|
|
||||||
// Check it still has 1 slide
|
// Check it still has 1 slide
|
||||||
assertEquals(1, ss_read.getSlides().size());
|
assertEquals(1, ss_read.getSlides().size());
|
||||||
@ -95,6 +90,8 @@ public final class TestReOrderingSlides {
|
|||||||
assertEquals(256, s1._getSheetNumber());
|
assertEquals(256, s1._getSheetNumber());
|
||||||
assertEquals(3, s1._getSheetRefId());
|
assertEquals(3, s1._getSheetRefId());
|
||||||
assertEquals(1, s1.getSlideNumber());
|
assertEquals(1, s1.getSlideNumber());
|
||||||
|
|
||||||
|
ss_read.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,7 +99,7 @@ public final class TestReOrderingSlides {
|
|||||||
* two slides in it
|
* two slides in it
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testReOrder2() throws Exception {
|
public void testReOrder2() throws IOException {
|
||||||
// Has two slides
|
// Has two slides
|
||||||
assertEquals(2, ss_two.getSlides().size());
|
assertEquals(2, ss_two.getSlides().size());
|
||||||
HSLFSlide s1 = ss_two.getSlides().get(0);
|
HSLFSlide s1 = ss_two.getSlides().get(0);
|
||||||
@ -121,12 +118,7 @@ public final class TestReOrderingSlides {
|
|||||||
ss_two.reorderSlide(2, 2);
|
ss_two.reorderSlide(2, 2);
|
||||||
|
|
||||||
// Write out, and read back in
|
// Write out, and read back in
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_two);
|
||||||
hss_two.write(baos);
|
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
|
||||||
|
|
||||||
HSLFSlideShowImpl hss_read = new HSLFSlideShowImpl(bais);
|
|
||||||
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
|
|
||||||
|
|
||||||
// Check it still has 2 slides
|
// Check it still has 2 slides
|
||||||
assertEquals(2, ss_read.getSlides().size());
|
assertEquals(2, ss_read.getSlides().size());
|
||||||
@ -140,13 +132,15 @@ public final class TestReOrderingSlides {
|
|||||||
assertEquals(257, s2._getSheetNumber());
|
assertEquals(257, s2._getSheetNumber());
|
||||||
assertEquals(6, s2._getSheetRefId());
|
assertEquals(6, s2._getSheetRefId());
|
||||||
assertEquals(2, s2.getSlideNumber());
|
assertEquals(2, s2.getSlideNumber());
|
||||||
|
|
||||||
|
ss_read.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test re-ordering slides in a slideshow with 2 slides on it
|
* Test re-ordering slides in a slideshow with 2 slides on it
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testReOrder2swap() throws Exception {
|
public void testReOrder2swap() throws IOException {
|
||||||
// Has two slides
|
// Has two slides
|
||||||
assertEquals(2, ss_two.getSlides().size());
|
assertEquals(2, ss_two.getSlides().size());
|
||||||
HSLFSlide s1 = ss_two.getSlides().get(0);
|
HSLFSlide s1 = ss_two.getSlides().get(0);
|
||||||
@ -165,12 +159,7 @@ public final class TestReOrderingSlides {
|
|||||||
ss_two.reorderSlide(2, 1);
|
ss_two.reorderSlide(2, 1);
|
||||||
|
|
||||||
// Write out, and read back in
|
// Write out, and read back in
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_two);
|
||||||
hss_two.write(baos);
|
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
|
||||||
|
|
||||||
HSLFSlideShowImpl hss_read = new HSLFSlideShowImpl(bais);
|
|
||||||
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
|
|
||||||
|
|
||||||
// Check it still has 2 slides
|
// Check it still has 2 slides
|
||||||
assertEquals(2, ss_read.getSlides().size());
|
assertEquals(2, ss_read.getSlides().size());
|
||||||
@ -184,6 +173,8 @@ public final class TestReOrderingSlides {
|
|||||||
assertEquals(256, s2._getSheetNumber());
|
assertEquals(256, s2._getSheetNumber());
|
||||||
assertEquals(4, s2._getSheetRefId());
|
assertEquals(4, s2._getSheetRefId());
|
||||||
assertEquals(2, s2.getSlideNumber());
|
assertEquals(2, s2.getSlideNumber());
|
||||||
|
|
||||||
|
ss_read.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -191,7 +182,7 @@ public final class TestReOrderingSlides {
|
|||||||
* three slides in it
|
* three slides in it
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testReOrder3() throws Exception {
|
public void testReOrder3() throws IOException {
|
||||||
// Has three slides
|
// Has three slides
|
||||||
assertEquals(3, ss_three.getSlides().size());
|
assertEquals(3, ss_three.getSlides().size());
|
||||||
HSLFSlide s1 = ss_three.getSlides().get(0);
|
HSLFSlide s1 = ss_three.getSlides().get(0);
|
||||||
@ -215,12 +206,7 @@ public final class TestReOrderingSlides {
|
|||||||
ss_three.reorderSlide(2, 2);
|
ss_three.reorderSlide(2, 2);
|
||||||
|
|
||||||
// Write out, and read back in
|
// Write out, and read back in
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_three);
|
||||||
hss_three.write(baos);
|
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
|
||||||
|
|
||||||
HSLFSlideShowImpl hss_read = new HSLFSlideShowImpl(bais);
|
|
||||||
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
|
|
||||||
|
|
||||||
// Check it still has 3 slides
|
// Check it still has 3 slides
|
||||||
assertEquals(3, ss_read.getSlides().size());
|
assertEquals(3, ss_read.getSlides().size());
|
||||||
@ -239,13 +225,15 @@ public final class TestReOrderingSlides {
|
|||||||
assertEquals(257, s3._getSheetNumber());
|
assertEquals(257, s3._getSheetNumber());
|
||||||
assertEquals(4, s3._getSheetRefId());
|
assertEquals(4, s3._getSheetRefId());
|
||||||
assertEquals(3, s3.getSlideNumber());
|
assertEquals(3, s3.getSlideNumber());
|
||||||
|
|
||||||
|
ss_read.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test re-ordering slides in a slideshow with 3 slides on it
|
* Test re-ordering slides in a slideshow with 3 slides on it
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testReOrder3swap() throws Exception {
|
public void testReOrder3swap() throws IOException {
|
||||||
// Has three slides
|
// Has three slides
|
||||||
assertEquals(3, ss_three.getSlides().size());
|
assertEquals(3, ss_three.getSlides().size());
|
||||||
HSLFSlide s1 = ss_three.getSlides().get(0);
|
HSLFSlide s1 = ss_three.getSlides().get(0);
|
||||||
@ -282,12 +270,7 @@ public final class TestReOrderingSlides {
|
|||||||
assertEquals("Slide 1", ((HSLFTextShape)s3.getShapes().get(0)).getText());
|
assertEquals("Slide 1", ((HSLFTextShape)s3.getShapes().get(0)).getText());
|
||||||
|
|
||||||
// Write out, and read back in
|
// Write out, and read back in
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_three);
|
||||||
hss_three.write(baos);
|
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
|
||||||
|
|
||||||
HSLFSlideShowImpl hss_read = new HSLFSlideShowImpl(bais);
|
|
||||||
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
|
|
||||||
|
|
||||||
// Check it still has 3 slides
|
// Check it still has 3 slides
|
||||||
assertEquals(3, ss_read.getSlides().size());
|
assertEquals(3, ss_read.getSlides().size());
|
||||||
@ -311,5 +294,7 @@ public final class TestReOrderingSlides {
|
|||||||
assertEquals(s3._getSheetNumber(), _s3._getSheetNumber());
|
assertEquals(s3._getSheetNumber(), _s3._getSheetNumber());
|
||||||
assertEquals(s3._getSheetRefId(), _s3._getSheetRefId());
|
assertEquals(s3._getSheetRefId(), _s3._getSheetRefId());
|
||||||
assertEquals(3, s3.getSlideNumber());
|
assertEquals(3, s3.getSlideNumber());
|
||||||
|
|
||||||
|
ss_read.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,7 @@ public final class TestRichTextRun {
|
|||||||
private static void assertMatchesFileC(HSLFSlideShow s) throws IOException {
|
private static void assertMatchesFileC(HSLFSlideShow s) throws IOException {
|
||||||
// Grab the bytes of the file
|
// Grab the bytes of the file
|
||||||
NPOIFSFileSystem fs = new NPOIFSFileSystem(HSLFTestDataSamples.openSampleFileStream(filenameC));
|
NPOIFSFileSystem fs = new NPOIFSFileSystem(HSLFTestDataSamples.openSampleFileStream(filenameC));
|
||||||
InputStream is = fs.createDocumentInputStream("PowerPoint Document");
|
InputStream is = fs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
byte[] raw_file = IOUtils.toByteArray(is);
|
byte[] raw_file = IOUtils.toByteArray(is);
|
||||||
is.close();
|
is.close();
|
||||||
fs.close();
|
fs.close();
|
||||||
@ -406,7 +406,7 @@ public final class TestRichTextRun {
|
|||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
s.write(baos);
|
s.write(baos);
|
||||||
fs = new NPOIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
|
fs = new NPOIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
|
||||||
is = fs.createDocumentInputStream("PowerPoint Document");
|
is = fs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT);
|
||||||
byte[] raw_ss = IOUtils.toByteArray(is);
|
byte[] raw_ss = IOUtils.toByteArray(is);
|
||||||
is.close();
|
is.close();
|
||||||
fs.close();
|
fs.close();
|
||||||
|
@ -49,7 +49,7 @@ public final class TestPOIFSChunkParser {
|
|||||||
private final POIDataSamples samples = POIDataSamples.getHSMFInstance();
|
private final POIDataSamples samples = POIDataSamples.getHSMFInstance();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindsCore() throws Exception {
|
public void testFindsCore() throws IOException, ChunkNotFoundException {
|
||||||
NPOIFSFileSystem simple = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
|
NPOIFSFileSystem simple = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
|
||||||
|
|
||||||
// Check a few core things are present
|
// Check a few core things are present
|
||||||
@ -71,9 +71,11 @@ public final class TestPOIFSChunkParser {
|
|||||||
Calendar calAct = msg.getMessageDate();
|
Calendar calAct = msg.getMessageDate();
|
||||||
assertEquals( calExp, calAct );
|
assertEquals( calExp, calAct );
|
||||||
|
|
||||||
|
msg.close();
|
||||||
simple.close();
|
simple.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFindsRecips() throws IOException, ChunkNotFoundException {
|
public void testFindsRecips() throws IOException, ChunkNotFoundException {
|
||||||
NPOIFSFileSystem simple = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
|
NPOIFSFileSystem simple = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
|
||||||
|
|
||||||
@ -109,6 +111,7 @@ public final class TestPOIFSChunkParser {
|
|||||||
assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].recipientSMTPChunk.getValue());
|
assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].recipientSMTPChunk.getValue());
|
||||||
assertEquals("/O=HOSTEDSERVICE2/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=Kevin.roast@ben",
|
assertEquals("/O=HOSTEDSERVICE2/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=Kevin.roast@ben",
|
||||||
msg.getRecipientDetailsChunks()[0].recipientEmailChunk.getValue());
|
msg.getRecipientDetailsChunks()[0].recipientEmailChunk.getValue());
|
||||||
|
msg.close();
|
||||||
simple.close();
|
simple.close();
|
||||||
|
|
||||||
|
|
||||||
@ -124,9 +127,11 @@ public final class TestPOIFSChunkParser {
|
|||||||
assertEquals("travis@overwrittenstack.com", msg.getRecipientDetailsChunks()[0].recipientEmailChunk.getValue());
|
assertEquals("travis@overwrittenstack.com", msg.getRecipientDetailsChunks()[0].recipientEmailChunk.getValue());
|
||||||
assertEquals("travis@overwrittenstack.com", msg.getRecipientEmailAddress());
|
assertEquals("travis@overwrittenstack.com", msg.getRecipientEmailAddress());
|
||||||
|
|
||||||
|
msg.close();
|
||||||
simple.close();
|
simple.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFindsMultipleRecipients() throws IOException, ChunkNotFoundException {
|
public void testFindsMultipleRecipients() throws IOException, ChunkNotFoundException {
|
||||||
NPOIFSFileSystem multiple = new NPOIFSFileSystem(samples.getFile("example_received_unicode.msg"), true);
|
NPOIFSFileSystem multiple = new NPOIFSFileSystem(samples.getFile("example_received_unicode.msg"), true);
|
||||||
|
|
||||||
@ -215,9 +220,11 @@ public final class TestPOIFSChunkParser {
|
|||||||
assertEquals("nick.burch@alfresco.com", msg.getRecipientEmailAddressList()[4]);
|
assertEquals("nick.burch@alfresco.com", msg.getRecipientEmailAddressList()[4]);
|
||||||
assertEquals("roy.wetherall@alfresco.com", msg.getRecipientEmailAddressList()[5]);
|
assertEquals("roy.wetherall@alfresco.com", msg.getRecipientEmailAddressList()[5]);
|
||||||
|
|
||||||
|
msg.close();
|
||||||
multiple.close();
|
multiple.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFindsNameId() throws IOException {
|
public void testFindsNameId() throws IOException {
|
||||||
NPOIFSFileSystem simple = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
|
NPOIFSFileSystem simple = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
|
||||||
|
|
||||||
@ -237,10 +244,12 @@ public final class TestPOIFSChunkParser {
|
|||||||
assertNotNull(msg.getNameIdChunks());
|
assertNotNull(msg.getNameIdChunks());
|
||||||
assertEquals(10, msg.getNameIdChunks().getAll().length);
|
assertEquals(10, msg.getNameIdChunks().getAll().length);
|
||||||
|
|
||||||
|
msg.close();
|
||||||
simple.close();
|
simple.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFindsAttachments() throws Exception {
|
@Test
|
||||||
|
public void testFindsAttachments() throws IOException, ChunkNotFoundException {
|
||||||
NPOIFSFileSystem with = new NPOIFSFileSystem(samples.getFile("attachment_test_msg.msg"), true);
|
NPOIFSFileSystem with = new NPOIFSFileSystem(samples.getFile("attachment_test_msg.msg"), true);
|
||||||
NPOIFSFileSystem without = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
|
NPOIFSFileSystem without = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
|
||||||
AttachmentChunks attachment;
|
AttachmentChunks attachment;
|
||||||
@ -304,6 +313,8 @@ public final class TestPOIFSChunkParser {
|
|||||||
assertEquals("Kevin Roast", msgWithout.getDisplayFrom());
|
assertEquals("Kevin Roast", msgWithout.getDisplayFrom());
|
||||||
assertEquals("Test the content transformer", msgWithout.getSubject());
|
assertEquals("Test the content transformer", msgWithout.getSubject());
|
||||||
|
|
||||||
|
msgWithout.close();
|
||||||
|
msgWith.close();
|
||||||
without.close();
|
without.close();
|
||||||
with.close();
|
with.close();
|
||||||
}
|
}
|
||||||
@ -313,7 +324,8 @@ public final class TestPOIFSChunkParser {
|
|||||||
* dropping files to the disk include a non-standard named streams
|
* dropping files to the disk include a non-standard named streams
|
||||||
* such as "Olk10SideProps_0001"
|
* such as "Olk10SideProps_0001"
|
||||||
*/
|
*/
|
||||||
public void testOlk10SideProps() throws Exception {
|
@Test
|
||||||
|
public void testOlk10SideProps() throws IOException, ChunkNotFoundException {
|
||||||
NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("51873.msg"), true);
|
NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("51873.msg"), true);
|
||||||
MAPIMessage msg = new MAPIMessage(poifs);
|
MAPIMessage msg = new MAPIMessage(poifs);
|
||||||
|
|
||||||
@ -321,6 +333,7 @@ public final class TestPOIFSChunkParser {
|
|||||||
assertEquals("bubba@bubbasmith.com", msg.getDisplayTo());
|
assertEquals("bubba@bubbasmith.com", msg.getDisplayTo());
|
||||||
assertEquals("Test with Olk10SideProps_ Chunk", msg.getSubject());
|
assertEquals("Test with Olk10SideProps_ Chunk", msg.getSubject());
|
||||||
|
|
||||||
|
msg.close();
|
||||||
poifs.close();
|
poifs.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,6 +158,8 @@ public final class TestHWPFOldDocument extends HWPFTestCase {
|
|||||||
assertContains(txt, "APPLICOLOR");
|
assertContains(txt, "APPLICOLOR");
|
||||||
assertContains(txt, "les meilleurs");
|
assertContains(txt, "les meilleurs");
|
||||||
assertContains(txt, "GUY LECOLE");
|
assertContains(txt, "GUY LECOLE");
|
||||||
|
ex.close();
|
||||||
|
doc.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -172,6 +174,8 @@ public final class TestHWPFOldDocument extends HWPFTestCase {
|
|||||||
sb.append(p);
|
sb.append(p);
|
||||||
}
|
}
|
||||||
assertContains(sb.toString(), "\u043F\u0440\u0438\u0432\u0435\u0442");//Greetings!
|
assertContains(sb.toString(), "\u043F\u0440\u0438\u0432\u0435\u0442");//Greetings!
|
||||||
|
ex.close();
|
||||||
|
doc.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -187,6 +191,8 @@ public final class TestHWPFOldDocument extends HWPFTestCase {
|
|||||||
sb.append(p);
|
sb.append(p);
|
||||||
}
|
}
|
||||||
assertContains(sb.toString(), "4 sk\u00f3re a p\u0159ed 7 lety");//Greetings!
|
assertContains(sb.toString(), "4 sk\u00f3re a p\u0159ed 7 lety");//Greetings!
|
||||||
|
ex.close();
|
||||||
|
doc.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -249,6 +255,8 @@ public final class TestHWPFOldDocument extends HWPFTestCase {
|
|||||||
//TODO: figure out why these two aren't passing
|
//TODO: figure out why these two aren't passing
|
||||||
//assertContains(txt, "\u2019\u0078 block2");//make sure smart quote is extracted correctly
|
//assertContains(txt, "\u2019\u0078 block2");//make sure smart quote is extracted correctly
|
||||||
//assertContains(txt, "We are able to");//not sure if we can get this easily?
|
//assertContains(txt, "We are able to");//not sure if we can get this easily?
|
||||||
|
ex.close();
|
||||||
|
doc.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,106 +17,90 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import static org.junit.Assert.assertFalse;
|
||||||
import java.io.ByteArrayOutputStream;
|
import static org.junit.Assert.assertTrue;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for how HSSFWorkbook behaves with XLS files
|
* Tests for how HSSFWorkbook behaves with XLS files
|
||||||
* with a WORKBOOK or BOOK directory entry (instead of
|
* with a WORKBOOK or BOOK directory entry (instead of
|
||||||
* the more usual, Workbook)
|
* the more usual, Workbook)
|
||||||
*/
|
*/
|
||||||
public final class TestNonStandardWorkbookStreamNames extends TestCase {
|
public final class TestNonStandardWorkbookStreamNames {
|
||||||
private final String xlsA = "WORKBOOK_in_capitals.xls";
|
private final String xlsA = "WORKBOOK_in_capitals.xls";
|
||||||
private final String xlsB = "BOOK_in_capitals.xls";
|
private final String xlsB = "BOOK_in_capitals.xls";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that we can open a file with WORKBOOK
|
* Test that we can open a file with WORKBOOK
|
||||||
*/
|
*/
|
||||||
public void testOpenWORKBOOK() throws Exception {
|
@Test
|
||||||
|
public void testOpenWORKBOOK() throws IOException {
|
||||||
|
// Try to open the workbook
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
|
||||||
|
HSSFWorkbook wb = new HSSFWorkbook(is);
|
||||||
|
is.close();
|
||||||
|
DirectoryNode root = wb.getDirectory();
|
||||||
|
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(is);
|
// Ensure that we have a WORKBOOK entry and a summary
|
||||||
|
assertTrue(root.hasEntry("WORKBOOK"));
|
||||||
// Ensure that we have a WORKBOOK entry
|
assertTrue(root.hasEntry("\005SummaryInformation"));
|
||||||
fs.getRoot().getEntry("WORKBOOK");
|
|
||||||
// And a summary
|
|
||||||
fs.getRoot().getEntry("\005SummaryInformation");
|
|
||||||
assertTrue(true);
|
|
||||||
|
|
||||||
// But not a Workbook one
|
// But not a Workbook one
|
||||||
try {
|
assertFalse(root.hasEntry("Workbook"));
|
||||||
fs.getRoot().getEntry("Workbook");
|
|
||||||
fail();
|
|
||||||
} catch(FileNotFoundException e) {}
|
|
||||||
|
|
||||||
// Try to open the workbook
|
wb.close();
|
||||||
HSSFWorkbook wb = new HSSFWorkbook(fs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that we can open a file with BOOK
|
* Test that we can open a file with BOOK
|
||||||
*/
|
*/
|
||||||
public void testOpenBOOK() throws Exception {
|
@Test
|
||||||
|
public void testOpenBOOK() throws IOException {
|
||||||
|
// Try to open the workbook
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsB);
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsB);
|
||||||
|
HSSFWorkbook wb = new HSSFWorkbook(is);
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(is);
|
is.close();
|
||||||
|
DirectoryNode root = wb.getDirectory();
|
||||||
|
|
||||||
// Ensure that we have a BOOK entry
|
// Ensure that we have a BOOK entry
|
||||||
fs.getRoot().getEntry("BOOK");
|
assertTrue(root.hasEntry("BOOK"));
|
||||||
assertTrue(true);
|
|
||||||
|
|
||||||
// But not a Workbook one
|
// But not a Workbook one and not a Summary one
|
||||||
try {
|
assertFalse(root.hasEntry("Workbook"));
|
||||||
fs.getRoot().getEntry("Workbook");
|
assertFalse(root.hasEntry("\\005SummaryInformation"));
|
||||||
fail();
|
|
||||||
} catch(FileNotFoundException e) {}
|
|
||||||
// And not a Summary one
|
|
||||||
try {
|
|
||||||
fs.getRoot().getEntry("\005SummaryInformation");
|
|
||||||
fail();
|
|
||||||
} catch(FileNotFoundException e) {}
|
|
||||||
|
|
||||||
// Try to open the workbook
|
wb.close();
|
||||||
HSSFWorkbook wb = new HSSFWorkbook(fs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that when we write out, we go back to the correct case
|
* Test that when we write out, we go back to the correct case
|
||||||
*/
|
*/
|
||||||
public void testWrite() throws Exception {
|
@Test
|
||||||
|
public void testWrite() throws IOException {
|
||||||
for (String file : new String[] {xlsA, xlsB}) {
|
for (String file : new String[] {xlsA, xlsB}) {
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(file);
|
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(is);
|
|
||||||
|
|
||||||
// Open the workbook, not preserving nodes
|
// Open the workbook, not preserving nodes
|
||||||
HSSFWorkbook wb = new HSSFWorkbook(fs);
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(file);
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
HSSFWorkbook wb = new HSSFWorkbook(is, false);
|
||||||
wb.write(out);
|
is.close();
|
||||||
|
|
||||||
// Check now
|
// Check now it can be opened
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||||
POIFSFileSystem fs2 = new POIFSFileSystem(in);
|
wb.close();
|
||||||
|
|
||||||
|
DirectoryNode root = wb2.getDirectory();
|
||||||
|
|
||||||
// Check that we have the new entries
|
// Check that we have the new entries
|
||||||
fs2.getRoot().getEntry("Workbook");
|
assertTrue(root.hasEntry("Workbook"));
|
||||||
try {
|
assertFalse(root.hasEntry("BOOK"));
|
||||||
fs2.getRoot().getEntry("BOOK");
|
assertFalse(root.hasEntry("WORKBOOK"));
|
||||||
fail();
|
|
||||||
} catch(FileNotFoundException e) {}
|
|
||||||
try {
|
|
||||||
fs2.getRoot().getEntry("WORKBOOK");
|
|
||||||
fail();
|
|
||||||
} catch(FileNotFoundException e) {}
|
|
||||||
|
|
||||||
// And it can be opened
|
wb2.close();
|
||||||
HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,31 +108,26 @@ public final class TestNonStandardWorkbookStreamNames extends TestCase {
|
|||||||
* Test that when we write out preserving nodes, we go back to the
|
* Test that when we write out preserving nodes, we go back to the
|
||||||
* correct case
|
* correct case
|
||||||
*/
|
*/
|
||||||
public void testWritePreserve() throws Exception {
|
@Test
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
|
public void testWritePreserve() throws IOException {
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(is);
|
|
||||||
|
|
||||||
// Open the workbook, not preserving nodes
|
// Open the workbook, not preserving nodes
|
||||||
HSSFWorkbook wb = new HSSFWorkbook(fs,true);
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
|
||||||
|
HSSFWorkbook wb = new HSSFWorkbook(is,true);
|
||||||
|
is.close();
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
// Check now it can be opened
|
||||||
wb.write(out);
|
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||||
|
wb.close();
|
||||||
|
|
||||||
// Check now
|
DirectoryNode root = wb2.getDirectory();
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
|
||||||
POIFSFileSystem fs2 = new POIFSFileSystem(in);
|
|
||||||
|
|
||||||
// Check that we have the new entries
|
// Check that we have the new entries
|
||||||
fs2.getRoot().getEntry("Workbook");
|
assertTrue(root.hasEntry("Workbook"));
|
||||||
try {
|
assertFalse(root.hasEntry("BOOK"));
|
||||||
fs2.getRoot().getEntry("WORKBOOK");
|
assertFalse(root.hasEntry("WORKBOOK"));
|
||||||
fail();
|
|
||||||
} catch(FileNotFoundException e) {}
|
|
||||||
|
|
||||||
// As we preserved, should also have a few other streams
|
// As we preserved, should also have a few other streams
|
||||||
fs2.getRoot().getEntry("\005SummaryInformation");
|
assertTrue(root.hasEntry("\005SummaryInformation"));
|
||||||
|
wb2.close();
|
||||||
// And it can be opened
|
|
||||||
HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,23 +17,25 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.POITestCase;
|
import org.apache.poi.POITestCase;
|
||||||
import org.apache.poi.ddf.EscherContainerRecord;
|
import org.apache.poi.ddf.EscherContainerRecord;
|
||||||
import org.apache.poi.ddf.EscherSpgrRecord;
|
import org.apache.poi.ddf.EscherSpgrRecord;
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.record.EscherAggregate;
|
import org.apache.poi.hssf.record.EscherAggregate;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
public class TestShapeGroup {
|
||||||
|
|
||||||
/**
|
@Test
|
||||||
* @author Evgeniy Berlog
|
public void testSetGetCoordinates() throws IOException {
|
||||||
* @date 29.06.12
|
HSSFWorkbook wb1 = new HSSFWorkbook();
|
||||||
*/
|
HSSFSheet sh = wb1.createSheet();
|
||||||
public class TestShapeGroup extends TestCase{
|
|
||||||
|
|
||||||
public void testSetGetCoordinates(){
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
|
||||||
HSSFSheet sh = wb.createSheet();
|
|
||||||
HSSFPatriarch patriarch = sh.createDrawingPatriarch();
|
HSSFPatriarch patriarch = sh.createDrawingPatriarch();
|
||||||
HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());
|
HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());
|
||||||
assertEquals(group.getX1(), 0);
|
assertEquals(group.getX1(), 0);
|
||||||
@ -48,8 +50,9 @@ public class TestShapeGroup extends TestCase{
|
|||||||
assertEquals(group.getX2(), 3);
|
assertEquals(group.getX2(), 3);
|
||||||
assertEquals(group.getY2(), 4);
|
assertEquals(group.getY2(), 4);
|
||||||
|
|
||||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
|
||||||
sh = wb.getSheetAt(0);
|
wb1.close();
|
||||||
|
sh = wb2.getSheetAt(0);
|
||||||
patriarch = sh.getDrawingPatriarch();
|
patriarch = sh.getDrawingPatriarch();
|
||||||
|
|
||||||
group = (HSSFShapeGroup) patriarch.getChildren().get(0);
|
group = (HSSFShapeGroup) patriarch.getChildren().get(0);
|
||||||
@ -57,11 +60,13 @@ public class TestShapeGroup extends TestCase{
|
|||||||
assertEquals(group.getY1(), 2);
|
assertEquals(group.getY1(), 2);
|
||||||
assertEquals(group.getX2(), 3);
|
assertEquals(group.getX2(), 3);
|
||||||
assertEquals(group.getY2(), 4);
|
assertEquals(group.getY2(), 4);
|
||||||
|
wb2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddToExistingFile(){
|
@Test
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
public void testAddToExistingFile() throws IOException {
|
||||||
HSSFSheet sh = wb.createSheet();
|
HSSFWorkbook wb1 = new HSSFWorkbook();
|
||||||
|
HSSFSheet sh = wb1.createSheet();
|
||||||
HSSFPatriarch patriarch = sh.createDrawingPatriarch();
|
HSSFPatriarch patriarch = sh.createDrawingPatriarch();
|
||||||
HSSFShapeGroup group1 = patriarch.createGroup(new HSSFClientAnchor());
|
HSSFShapeGroup group1 = patriarch.createGroup(new HSSFClientAnchor());
|
||||||
HSSFShapeGroup group2 = patriarch.createGroup(new HSSFClientAnchor());
|
HSSFShapeGroup group2 = patriarch.createGroup(new HSSFClientAnchor());
|
||||||
@ -69,8 +74,9 @@ public class TestShapeGroup extends TestCase{
|
|||||||
group1.setCoordinates(1,2,3,4);
|
group1.setCoordinates(1,2,3,4);
|
||||||
group2.setCoordinates(5,6,7,8);
|
group2.setCoordinates(5,6,7,8);
|
||||||
|
|
||||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
|
||||||
sh = wb.getSheetAt(0);
|
wb1.close();
|
||||||
|
sh = wb2.getSheetAt(0);
|
||||||
patriarch = sh.getDrawingPatriarch();
|
patriarch = sh.getDrawingPatriarch();
|
||||||
|
|
||||||
assertEquals(patriarch.getChildren().size(), 2);
|
assertEquals(patriarch.getChildren().size(), 2);
|
||||||
@ -78,18 +84,21 @@ public class TestShapeGroup extends TestCase{
|
|||||||
HSSFShapeGroup group3 = patriarch.createGroup(new HSSFClientAnchor());
|
HSSFShapeGroup group3 = patriarch.createGroup(new HSSFClientAnchor());
|
||||||
group3.setCoordinates(9,10,11,12);
|
group3.setCoordinates(9,10,11,12);
|
||||||
|
|
||||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
|
||||||
sh = wb.getSheetAt(0);
|
wb2.close();
|
||||||
|
sh = wb3.getSheetAt(0);
|
||||||
patriarch = sh.getDrawingPatriarch();
|
patriarch = sh.getDrawingPatriarch();
|
||||||
|
|
||||||
assertEquals(patriarch.getChildren().size(), 3);
|
assertEquals(patriarch.getChildren().size(), 3);
|
||||||
|
wb3.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testModify() throws Exception {
|
@Test
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
public void testModify() throws IOException {
|
||||||
|
HSSFWorkbook wb1 = new HSSFWorkbook();
|
||||||
|
|
||||||
// create a sheet with a text box
|
// create a sheet with a text box
|
||||||
HSSFSheet sheet = wb.createSheet();
|
HSSFSheet sheet = wb1.createSheet();
|
||||||
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
||||||
|
|
||||||
HSSFShapeGroup group1 = patriarch.createGroup(new
|
HSSFShapeGroup group1 = patriarch.createGroup(new
|
||||||
@ -103,8 +112,9 @@ public class TestShapeGroup extends TestCase{
|
|||||||
textbox1.setString(rt1);
|
textbox1.setString(rt1);
|
||||||
|
|
||||||
// write, read back and check that our text box is there
|
// write, read back and check that our text box is there
|
||||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
|
||||||
sheet = wb.getSheetAt(0);
|
wb1.close();
|
||||||
|
sheet = wb2.getSheetAt(0);
|
||||||
patriarch = sheet.getDrawingPatriarch();
|
patriarch = sheet.getDrawingPatriarch();
|
||||||
assertEquals(1, patriarch.getChildren().size());
|
assertEquals(1, patriarch.getChildren().size());
|
||||||
|
|
||||||
@ -128,8 +138,9 @@ public class TestShapeGroup extends TestCase{
|
|||||||
textbox2.setString(rt2);
|
textbox2.setString(rt2);
|
||||||
assertEquals(2, group1.getChildren().size());
|
assertEquals(2, group1.getChildren().size());
|
||||||
|
|
||||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
|
||||||
sheet = wb.getSheetAt(0);
|
wb2.close();
|
||||||
|
sheet = wb3.getSheetAt(0);
|
||||||
patriarch = sheet.getDrawingPatriarch();
|
patriarch = sheet.getDrawingPatriarch();
|
||||||
assertEquals(1, patriarch.getChildren().size());
|
assertEquals(1, patriarch.getChildren().size());
|
||||||
|
|
||||||
@ -146,8 +157,9 @@ public class TestShapeGroup extends TestCase{
|
|||||||
assertEquals(new HSSFChildAnchor(400, 400, 600, 600),
|
assertEquals(new HSSFChildAnchor(400, 400, 600, 600),
|
||||||
textbox2.getAnchor());
|
textbox2.getAnchor());
|
||||||
|
|
||||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
HSSFWorkbook wb4 = HSSFTestDataSamples.writeOutAndReadBack(wb3);
|
||||||
sheet = wb.getSheetAt(0);
|
wb3.close();
|
||||||
|
sheet = wb4.getSheetAt(0);
|
||||||
patriarch = sheet.getDrawingPatriarch();
|
patriarch = sheet.getDrawingPatriarch();
|
||||||
group1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
|
group1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
|
||||||
textbox1 = (HSSFTextbox)group1.getChildren().get(0);
|
textbox1 = (HSSFTextbox)group1.getChildren().get(0);
|
||||||
@ -156,25 +168,28 @@ public class TestShapeGroup extends TestCase{
|
|||||||
HSSFChildAnchor(400,200, 600, 400));
|
HSSFChildAnchor(400,200, 600, 400));
|
||||||
HSSFRichTextString rt3 = new HSSFRichTextString("Hello, World-3");
|
HSSFRichTextString rt3 = new HSSFRichTextString("Hello, World-3");
|
||||||
textbox3.setString(rt3);
|
textbox3.setString(rt3);
|
||||||
|
wb4.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddShapesToGroup(){
|
@Test
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
public void testAddShapesToGroup() throws IOException {
|
||||||
|
HSSFWorkbook wb1 = new HSSFWorkbook();
|
||||||
|
|
||||||
// create a sheet with a text box
|
// create a sheet with a text box
|
||||||
HSSFSheet sheet = wb.createSheet();
|
HSSFSheet sheet = wb1.createSheet();
|
||||||
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
||||||
|
|
||||||
HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());
|
HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());
|
||||||
int index = wb.addPicture(new byte[]{1,2,3}, HSSFWorkbook.PICTURE_TYPE_JPEG);
|
int index = wb1.addPicture(new byte[]{1,2,3}, HSSFWorkbook.PICTURE_TYPE_JPEG);
|
||||||
group.createPicture(new HSSFChildAnchor(), index);
|
group.createPicture(new HSSFChildAnchor(), index);
|
||||||
HSSFPolygon polygon = group.createPolygon(new HSSFChildAnchor());
|
HSSFPolygon polygon = group.createPolygon(new HSSFChildAnchor());
|
||||||
polygon.setPoints(new int[]{1,100, 1}, new int[]{1, 50, 100});
|
polygon.setPoints(new int[]{1,100, 1}, new int[]{1, 50, 100});
|
||||||
group.createTextbox(new HSSFChildAnchor());
|
group.createTextbox(new HSSFChildAnchor());
|
||||||
group.createShape(new HSSFChildAnchor());
|
group.createShape(new HSSFChildAnchor());
|
||||||
|
|
||||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
|
||||||
sheet = wb.getSheetAt(0);
|
wb1.close();
|
||||||
|
sheet = wb2.getSheetAt(0);
|
||||||
patriarch = sheet.getDrawingPatriarch();
|
patriarch = sheet.getDrawingPatriarch();
|
||||||
assertEquals(1, patriarch.getChildren().size());
|
assertEquals(1, patriarch.getChildren().size());
|
||||||
|
|
||||||
@ -190,7 +205,7 @@ public class TestShapeGroup extends TestCase{
|
|||||||
|
|
||||||
HSSFShapeGroup group2 = patriarch.createGroup(new HSSFClientAnchor());
|
HSSFShapeGroup group2 = patriarch.createGroup(new HSSFClientAnchor());
|
||||||
|
|
||||||
index = wb.addPicture(new byte[]{2,2,2}, HSSFWorkbook.PICTURE_TYPE_JPEG);
|
index = wb2.addPicture(new byte[]{2,2,2}, HSSFWorkbook.PICTURE_TYPE_JPEG);
|
||||||
group2.createPicture(new HSSFChildAnchor(), index);
|
group2.createPicture(new HSSFChildAnchor(), index);
|
||||||
polygon = group2.createPolygon(new HSSFChildAnchor());
|
polygon = group2.createPolygon(new HSSFChildAnchor());
|
||||||
polygon.setPoints(new int[]{1,100, 1}, new int[]{1, 50, 100});
|
polygon.setPoints(new int[]{1,100, 1}, new int[]{1, 50, 100});
|
||||||
@ -198,8 +213,9 @@ public class TestShapeGroup extends TestCase{
|
|||||||
group2.createShape(new HSSFChildAnchor());
|
group2.createShape(new HSSFChildAnchor());
|
||||||
group2.createShape(new HSSFChildAnchor());
|
group2.createShape(new HSSFChildAnchor());
|
||||||
|
|
||||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
|
||||||
sheet = wb.getSheetAt(0);
|
wb2.close();
|
||||||
|
sheet = wb3.getSheetAt(0);
|
||||||
patriarch = sheet.getDrawingPatriarch();
|
patriarch = sheet.getDrawingPatriarch();
|
||||||
assertEquals(2, patriarch.getChildren().size());
|
assertEquals(2, patriarch.getChildren().size());
|
||||||
|
|
||||||
@ -214,9 +230,11 @@ public class TestShapeGroup extends TestCase{
|
|||||||
assertTrue(group.getChildren().get(4) instanceof HSSFSimpleShape);
|
assertTrue(group.getChildren().get(4) instanceof HSSFSimpleShape);
|
||||||
|
|
||||||
group.getShapeId();
|
group.getShapeId();
|
||||||
|
wb3.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSpgrRecord(){
|
@Test
|
||||||
|
public void testSpgrRecord() throws IOException {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
|
|
||||||
// create a sheet with a text box
|
// create a sheet with a text box
|
||||||
@ -225,15 +243,17 @@ public class TestShapeGroup extends TestCase{
|
|||||||
|
|
||||||
HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());
|
HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());
|
||||||
assertSame(((EscherContainerRecord)group.getEscherContainer().getChild(0)).getChildById(EscherSpgrRecord.RECORD_ID), getSpgrRecord(group));
|
assertSame(((EscherContainerRecord)group.getEscherContainer().getChild(0)).getChildById(EscherSpgrRecord.RECORD_ID), getSpgrRecord(group));
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EscherSpgrRecord getSpgrRecord(HSSFShapeGroup group) {
|
private static EscherSpgrRecord getSpgrRecord(HSSFShapeGroup group) {
|
||||||
return POITestCase.getFieldValue(HSSFShapeGroup.class, group, EscherSpgrRecord.class, "_spgrRecord");
|
return POITestCase.getFieldValue(HSSFShapeGroup.class, group, EscherSpgrRecord.class, "_spgrRecord");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClearShapes(){
|
@Test
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
public void testClearShapes() throws IOException {
|
||||||
HSSFSheet sheet = wb.createSheet();
|
HSSFWorkbook wb1 = new HSSFWorkbook();
|
||||||
|
HSSFSheet sheet = wb1.createSheet();
|
||||||
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
||||||
HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());
|
HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());
|
||||||
|
|
||||||
@ -252,8 +272,9 @@ public class TestShapeGroup extends TestCase{
|
|||||||
assertEquals(agg.getTailRecords().size(), 0);
|
assertEquals(agg.getTailRecords().size(), 0);
|
||||||
assertEquals(group.getChildren().size(), 0);
|
assertEquals(group.getChildren().size(), 0);
|
||||||
|
|
||||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
|
||||||
sheet = wb.getSheetAt(0);
|
wb1.close();
|
||||||
|
sheet = wb2.getSheetAt(0);
|
||||||
patriarch = sheet.getDrawingPatriarch();
|
patriarch = sheet.getDrawingPatriarch();
|
||||||
|
|
||||||
group = (HSSFShapeGroup) patriarch.getChildren().get(0);
|
group = (HSSFShapeGroup) patriarch.getChildren().get(0);
|
||||||
@ -261,5 +282,6 @@ public class TestShapeGroup extends TestCase{
|
|||||||
assertEquals(agg.getShapeToObjMapping().size(), 1);
|
assertEquals(agg.getShapeToObjMapping().size(), 1);
|
||||||
assertEquals(agg.getTailRecords().size(), 0);
|
assertEquals(agg.getTailRecords().size(), 0);
|
||||||
assertEquals(group.getChildren().size(), 0);
|
assertEquals(group.getChildren().size(), 0);
|
||||||
|
wb2.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,21 +17,32 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.ss.formula.FormulaParseException;
|
import org.apache.poi.ss.formula.FormulaParseException;
|
||||||
import org.apache.poi.ss.formula.eval.*;
|
import org.apache.poi.ss.formula.eval.AreaEval;
|
||||||
|
import org.apache.poi.ss.formula.eval.ErrorEval;
|
||||||
import junit.framework.TestCase;
|
import org.apache.poi.ss.formula.eval.NotImplementedException;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.formula.eval.NumberEval;
|
||||||
|
import org.apache.poi.ss.formula.eval.ValueEval;
|
||||||
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.CellValue;
|
||||||
|
import org.apache.poi.ss.usermodel.FormulaError;
|
||||||
|
import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link Subtotal}
|
* Tests for {@link Subtotal}
|
||||||
*
|
|
||||||
* @author Paul Tomlin
|
|
||||||
*/
|
*/
|
||||||
public final class TestSubtotal extends TestCase {
|
public final class TestSubtotal {
|
||||||
private static final int FUNCTION_AVERAGE = 1;
|
private static final int FUNCTION_AVERAGE = 1;
|
||||||
private static final int FUNCTION_COUNT = 2;
|
private static final int FUNCTION_COUNT = 2;
|
||||||
private static final int FUNCTION_MAX = 4;
|
private static final int FUNCTION_MAX = 4;
|
||||||
@ -63,6 +74,7 @@ public final class TestSubtotal extends TestCase {
|
|||||||
assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0);
|
assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBasics() {
|
public void testBasics() {
|
||||||
confirmSubtotal(FUNCTION_SUM, 55.0);
|
confirmSubtotal(FUNCTION_SUM, 55.0);
|
||||||
confirmSubtotal(FUNCTION_AVERAGE, 5.5);
|
confirmSubtotal(FUNCTION_AVERAGE, 5.5);
|
||||||
@ -73,7 +85,8 @@ public final class TestSubtotal extends TestCase {
|
|||||||
confirmSubtotal(FUNCTION_STDEV, 3.0276503540974917);
|
confirmSubtotal(FUNCTION_STDEV, 3.0276503540974917);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAvg(){
|
@Test
|
||||||
|
public void testAvg() throws IOException {
|
||||||
Workbook wb = new HSSFWorkbook();
|
Workbook wb = new HSSFWorkbook();
|
||||||
|
|
||||||
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
|
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
|
||||||
@ -98,13 +111,16 @@ public final class TestSubtotal extends TestCase {
|
|||||||
|
|
||||||
fe.evaluateAll();
|
fe.evaluateAll();
|
||||||
|
|
||||||
assertEquals(2.0, a3.getNumericCellValue());
|
assertEquals(2.0, a3.getNumericCellValue(), 0);
|
||||||
assertEquals(8.0, a6.getNumericCellValue());
|
assertEquals(8.0, a6.getNumericCellValue(), 0);
|
||||||
assertEquals(3.0, a7.getNumericCellValue());
|
assertEquals(3.0, a7.getNumericCellValue(), 0);
|
||||||
assertEquals(3.0, a8.getNumericCellValue());
|
assertEquals(3.0, a8.getNumericCellValue(), 0);
|
||||||
|
wb.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSum(){
|
@Test
|
||||||
|
public void testSum() throws IOException {
|
||||||
Workbook wb = new HSSFWorkbook();
|
Workbook wb = new HSSFWorkbook();
|
||||||
|
|
||||||
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
|
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
|
||||||
@ -129,13 +145,15 @@ public final class TestSubtotal extends TestCase {
|
|||||||
|
|
||||||
fe.evaluateAll();
|
fe.evaluateAll();
|
||||||
|
|
||||||
assertEquals(4.0, a3.getNumericCellValue());
|
assertEquals(4.0, a3.getNumericCellValue(), 0);
|
||||||
assertEquals(26.0, a6.getNumericCellValue());
|
assertEquals(26.0, a6.getNumericCellValue(), 0);
|
||||||
assertEquals(12.0, a7.getNumericCellValue());
|
assertEquals(12.0, a7.getNumericCellValue(), 0);
|
||||||
assertEquals(12.0, a8.getNumericCellValue());
|
assertEquals(12.0, a8.getNumericCellValue(), 0);
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCount(){
|
@Test
|
||||||
|
public void testCount() throws IOException {
|
||||||
|
|
||||||
Workbook wb = new HSSFWorkbook();
|
Workbook wb = new HSSFWorkbook();
|
||||||
|
|
||||||
@ -161,13 +179,15 @@ public final class TestSubtotal extends TestCase {
|
|||||||
|
|
||||||
fe.evaluateAll();
|
fe.evaluateAll();
|
||||||
|
|
||||||
assertEquals(2.0, a3.getNumericCellValue());
|
assertEquals(2.0, a3.getNumericCellValue(), 0);
|
||||||
assertEquals(6.0, a6.getNumericCellValue());
|
assertEquals(6.0, a6.getNumericCellValue(), 0);
|
||||||
assertEquals(2.0, a7.getNumericCellValue());
|
assertEquals(2.0, a7.getNumericCellValue(), 0);
|
||||||
assertEquals(2.0, a8.getNumericCellValue());
|
assertEquals(2.0, a8.getNumericCellValue(), 0);
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCounta(){
|
@Test
|
||||||
|
public void testCounta() throws IOException {
|
||||||
|
|
||||||
Workbook wb = new HSSFWorkbook();
|
Workbook wb = new HSSFWorkbook();
|
||||||
|
|
||||||
@ -193,13 +213,15 @@ public final class TestSubtotal extends TestCase {
|
|||||||
|
|
||||||
fe.evaluateAll();
|
fe.evaluateAll();
|
||||||
|
|
||||||
assertEquals(2.0, a3.getNumericCellValue());
|
assertEquals(2.0, a3.getNumericCellValue(), 0);
|
||||||
assertEquals(8.0, a6.getNumericCellValue());
|
assertEquals(8.0, a6.getNumericCellValue(), 0);
|
||||||
assertEquals(3.0, a7.getNumericCellValue());
|
assertEquals(3.0, a7.getNumericCellValue(), 0);
|
||||||
assertEquals(3.0, a8.getNumericCellValue());
|
assertEquals(3.0, a8.getNumericCellValue(), 0);
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMax(){
|
@Test
|
||||||
|
public void testMax() throws IOException {
|
||||||
|
|
||||||
Workbook wb = new HSSFWorkbook();
|
Workbook wb = new HSSFWorkbook();
|
||||||
|
|
||||||
@ -225,13 +247,15 @@ public final class TestSubtotal extends TestCase {
|
|||||||
|
|
||||||
fe.evaluateAll();
|
fe.evaluateAll();
|
||||||
|
|
||||||
assertEquals(3.0, a3.getNumericCellValue());
|
assertEquals(3.0, a3.getNumericCellValue(), 0);
|
||||||
assertEquals(16.0, a6.getNumericCellValue());
|
assertEquals(16.0, a6.getNumericCellValue(), 0);
|
||||||
assertEquals(7.0, a7.getNumericCellValue());
|
assertEquals(7.0, a7.getNumericCellValue(), 0);
|
||||||
assertEquals(7.0, a8.getNumericCellValue());
|
assertEquals(7.0, a8.getNumericCellValue(), 0);
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMin(){
|
@Test
|
||||||
|
public void testMin() throws IOException {
|
||||||
|
|
||||||
Workbook wb = new HSSFWorkbook();
|
Workbook wb = new HSSFWorkbook();
|
||||||
|
|
||||||
@ -257,13 +281,15 @@ public final class TestSubtotal extends TestCase {
|
|||||||
|
|
||||||
fe.evaluateAll();
|
fe.evaluateAll();
|
||||||
|
|
||||||
assertEquals(1.0, a3.getNumericCellValue());
|
assertEquals(1.0, a3.getNumericCellValue(), 0);
|
||||||
assertEquals(4.0, a6.getNumericCellValue());
|
assertEquals(4.0, a6.getNumericCellValue(), 0);
|
||||||
assertEquals(1.0, a7.getNumericCellValue());
|
assertEquals(1.0, a7.getNumericCellValue(), 0);
|
||||||
assertEquals(1.0, a8.getNumericCellValue());
|
assertEquals(1.0, a8.getNumericCellValue(), 0);
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStdev(){
|
@Test
|
||||||
|
public void testStdev() throws IOException {
|
||||||
|
|
||||||
Workbook wb = new HSSFWorkbook();
|
Workbook wb = new HSSFWorkbook();
|
||||||
|
|
||||||
@ -293,9 +319,11 @@ public final class TestSubtotal extends TestCase {
|
|||||||
assertEquals(7.65685, a6.getNumericCellValue(), 0.0001);
|
assertEquals(7.65685, a6.getNumericCellValue(), 0.0001);
|
||||||
assertEquals(2.82842, a7.getNumericCellValue(), 0.0001);
|
assertEquals(2.82842, a7.getNumericCellValue(), 0.0001);
|
||||||
assertEquals(2.82842, a8.getNumericCellValue(), 0.0001);
|
assertEquals(2.82842, a8.getNumericCellValue(), 0.0001);
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test50209(){
|
@Test
|
||||||
|
public void test50209() throws IOException {
|
||||||
Workbook wb = new HSSFWorkbook();
|
Workbook wb = new HSSFWorkbook();
|
||||||
Sheet sh = wb.createSheet();
|
Sheet sh = wb.createSheet();
|
||||||
Cell a1 = sh.createRow(1).createCell(1);
|
Cell a1 = sh.createRow(1).createCell(1);
|
||||||
@ -307,8 +335,9 @@ public final class TestSubtotal extends TestCase {
|
|||||||
|
|
||||||
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
|
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
|
||||||
fe.evaluateAll();
|
fe.evaluateAll();
|
||||||
assertEquals(1.0, a2.getNumericCellValue());
|
assertEquals(1.0, a2.getNumericCellValue(), 0);
|
||||||
assertEquals(1.0, a3.getNumericCellValue());
|
assertEquals(1.0, a3.getNumericCellValue(), 0);
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void confirmExpectedResult(FormulaEvaluator evaluator, String msg, Cell cell, double expected) {
|
private static void confirmExpectedResult(FormulaEvaluator evaluator, String msg, Cell cell, double expected) {
|
||||||
@ -316,16 +345,17 @@ public final class TestSubtotal extends TestCase {
|
|||||||
CellValue value = evaluator.evaluate(cell);
|
CellValue value = evaluator.evaluate(cell);
|
||||||
if (value.getErrorValue() != 0)
|
if (value.getErrorValue() != 0)
|
||||||
throw new RuntimeException(msg + ": " + value.formatAsString());
|
throw new RuntimeException(msg + ": " + value.formatAsString());
|
||||||
assertEquals(msg, expected, value.getNumberValue());
|
assertEquals(msg, expected, value.getNumberValue(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFunctionsFromTestSpreadsheet() {
|
@Test
|
||||||
|
public void testFunctionsFromTestSpreadsheet() throws IOException {
|
||||||
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SubtotalsNested.xls");
|
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SubtotalsNested.xls");
|
||||||
HSSFSheet sheet = workbook.getSheetAt(0);
|
HSSFSheet sheet = workbook.getSheetAt(0);
|
||||||
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
|
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
|
||||||
|
|
||||||
assertEquals("B2", 10.0, sheet.getRow(1).getCell(1).getNumericCellValue());
|
assertEquals("B2", 10.0, sheet.getRow(1).getCell(1).getNumericCellValue(), 0);
|
||||||
assertEquals("B3", 20.0, sheet.getRow(2).getCell(1).getNumericCellValue());
|
assertEquals("B3", 20.0, sheet.getRow(2).getCell(1).getNumericCellValue(), 0);
|
||||||
|
|
||||||
//Test simple subtotal over one area
|
//Test simple subtotal over one area
|
||||||
Cell cellA3 = sheet.getRow(3).getCell(1);
|
Cell cellA3 = sheet.getRow(3).getCell(1);
|
||||||
@ -333,7 +363,7 @@ public final class TestSubtotal extends TestCase {
|
|||||||
|
|
||||||
//Test existence of the second area
|
//Test existence of the second area
|
||||||
assertNotNull("C2 must not be null", sheet.getRow(1).getCell(2));
|
assertNotNull("C2 must not be null", sheet.getRow(1).getCell(2));
|
||||||
assertEquals("C2", 7.0, sheet.getRow(1).getCell(2).getNumericCellValue());
|
assertEquals("C2", 7.0, sheet.getRow(1).getCell(2).getNumericCellValue(), 0);
|
||||||
|
|
||||||
Cell cellC1 = sheet.getRow(1).getCell(3);
|
Cell cellC1 = sheet.getRow(1).getCell(3);
|
||||||
Cell cellC2 = sheet.getRow(2).getCell(3);
|
Cell cellC2 = sheet.getRow(2).getCell(3);
|
||||||
@ -345,70 +375,48 @@ public final class TestSubtotal extends TestCase {
|
|||||||
confirmExpectedResult(evaluator, "SUBTOTAL(SUM;B2:B8;C2:C8)", cellC1, 37.0);
|
confirmExpectedResult(evaluator, "SUBTOTAL(SUM;B2:B8;C2:C8)", cellC1, 37.0);
|
||||||
confirmExpectedResult(evaluator, "SUBTOTAL(COUNT;B2:B8,C2:C8)", cellC2, 3.0);
|
confirmExpectedResult(evaluator, "SUBTOTAL(COUNT;B2:B8,C2:C8)", cellC2, 3.0);
|
||||||
confirmExpectedResult(evaluator, "SUBTOTAL(COUNTA;B2:B8,C2:C8)", cellC3, 5.0);
|
confirmExpectedResult(evaluator, "SUBTOTAL(COUNTA;B2:B8,C2:C8)", cellC3, 5.0);
|
||||||
|
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUnimplemented(){
|
@Test
|
||||||
|
public void testUnimplemented() throws IOException {
|
||||||
Workbook wb = new HSSFWorkbook();
|
Workbook wb = new HSSFWorkbook();
|
||||||
|
|
||||||
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
|
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
|
||||||
|
|
||||||
Sheet sh = wb.createSheet();
|
Sheet sh = wb.createSheet();
|
||||||
Cell a3 = sh.createRow(3).createCell(1);
|
Cell a3 = sh.createRow(3).createCell(1);
|
||||||
a3.setCellFormula("SUBTOTAL(8,B2:B3)");
|
|
||||||
|
|
||||||
|
// formula, throws NotImplemnted?
|
||||||
|
String[][] formulas = {
|
||||||
|
{ "SUBTOTAL(8,B2:B3)", NotImplementedException.class.getName() },
|
||||||
|
{ "SUBTOTAL(10,B2:B3)", NotImplementedException.class.getName() },
|
||||||
|
{ "SUBTOTAL(11,B2:B3)", NotImplementedException.class.getName() },
|
||||||
|
{ "SUBTOTAL(107,B2:B3)", NotImplementedException.class.getName() },
|
||||||
|
{ "SUBTOTAL(0,B2:B3)", null },
|
||||||
|
{ "SUBTOTAL(9)", FormulaParseException.class.getName() },
|
||||||
|
{ "SUBTOTAL()", FormulaParseException.class.getName() },
|
||||||
|
};
|
||||||
|
|
||||||
|
for (String[] f : formulas) {
|
||||||
|
Exception actualEx = null;
|
||||||
try {
|
try {
|
||||||
fe.evaluateAll();
|
a3.setCellFormula(f[0]);
|
||||||
fail("Should catch an NotImplementedFunctionException here, adjust these tests if it was actually implemented");
|
|
||||||
} catch (NotImplementedException e) {
|
|
||||||
// expected here
|
|
||||||
}
|
|
||||||
|
|
||||||
a3.setCellFormula("SUBTOTAL(10,B2:B3)");
|
|
||||||
|
|
||||||
try {
|
|
||||||
fe.evaluateAll();
|
|
||||||
fail("Should catch an NotImplementedFunctionException here, adjust these tests if it was actually implemented");
|
|
||||||
} catch (NotImplementedException e) {
|
|
||||||
// expected here
|
|
||||||
}
|
|
||||||
|
|
||||||
a3.setCellFormula("SUBTOTAL(11,B2:B3)");
|
|
||||||
|
|
||||||
try {
|
|
||||||
fe.evaluateAll();
|
|
||||||
fail("Should catch an NotImplementedFunctionException here, adjust these tests if it was actually implemented");
|
|
||||||
} catch (NotImplementedException e) {
|
|
||||||
// expected here
|
|
||||||
}
|
|
||||||
|
|
||||||
a3.setCellFormula("SUBTOTAL(107,B2:B3)");
|
|
||||||
|
|
||||||
try {
|
|
||||||
fe.evaluateAll();
|
|
||||||
fail("Should catch an NotImplementedFunctionException here, adjust these tests if it was actually implemented");
|
|
||||||
} catch (NotImplementedException e) {
|
|
||||||
// expected here
|
|
||||||
}
|
|
||||||
|
|
||||||
a3.setCellFormula("SUBTOTAL(0,B2:B3)");
|
|
||||||
fe.evaluateAll();
|
fe.evaluateAll();
|
||||||
assertEquals(FormulaError.VALUE.getCode(), a3.getErrorCellValue());
|
assertEquals(FormulaError.VALUE.getCode(), a3.getErrorCellValue());
|
||||||
|
} catch (Exception e) {
|
||||||
try {
|
actualEx = e;
|
||||||
a3.setCellFormula("SUBTOTAL(9)");
|
|
||||||
fail("Should catch an exception here");
|
|
||||||
} catch (FormulaParseException e) {
|
|
||||||
// expected here
|
|
||||||
}
|
}
|
||||||
|
String msg =
|
||||||
try {
|
"Check "+(f[1] == null ? "unexpected exception" : f[1])+" here, "+
|
||||||
a3.setCellFormula("SUBTOTAL()");
|
"adjust these tests if it was actually implemented - "+f[0];
|
||||||
fail("Should catch an exception here");
|
assertEquals(msg, f[1], (actualEx == null ? null : actualEx.getClass().getName()));
|
||||||
} catch (FormulaParseException e) {
|
|
||||||
// expected here
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Subtotal subtotal = new Subtotal();
|
Subtotal subtotal = new Subtotal();
|
||||||
assertEquals(ErrorEval.VALUE_INVALID, subtotal.evaluate(new ValueEval[] {}, 0, 0));
|
assertEquals(ErrorEval.VALUE_INVALID, subtotal.evaluate(new ValueEval[] {}, 0, 0));
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user