From 57ebf6b13357128924a7c9d10ce16f4aae4bb59d Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Thu, 18 Feb 2016 03:33:25 +0000 Subject: [PATCH] bug 58896: add unit test to time Sheet.autoSizeColumn git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1730997 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/SXSSFITestDataProvider.java | 14 +++++ .../poi/xssf/XSSFITestDataProvider.java | 9 +++ .../poi/hssf/HSSFITestDataProvider.java | 9 +++ .../org/apache/poi/ss/ITestDataProvider.java | 11 ++++ .../ss/usermodel/BaseTestBugzillaIssues.java | 60 +++++++++++++++++++ 5 files changed, 103 insertions(+) diff --git a/src/ooxml/testcases/org/apache/poi/xssf/SXSSFITestDataProvider.java b/src/ooxml/testcases/org/apache/poi/xssf/SXSSFITestDataProvider.java index 04da561e0..5b5fe3f44 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/SXSSFITestDataProvider.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/SXSSFITestDataProvider.java @@ -87,6 +87,14 @@ public final class SXSSFITestDataProvider implements ITestDataProvider { return wb; } + //************ SXSSF-specific methods ***************// + @Override + public SXSSFWorkbook createWorkbook(int rowAccessWindowSize) { + SXSSFWorkbook wb = new SXSSFWorkbook(rowAccessWindowSize); + instances.add(wb); + return wb; + } + @Override public void trackColumnsForAutosizing(Sheet sheet, int...columns) { for (int cn : columns) { @@ -94,6 +102,12 @@ public final class SXSSFITestDataProvider implements ITestDataProvider { } } + @Override + public void trackAllColumnsForAutosizing(Sheet sheet) { + ((SXSSFSheet)sheet).trackAllColumnsForAutoSizing(); + } + //************ End SXSSF-specific methods ***************// + @Override public FormulaEvaluator createFormulaEvaluator(Workbook wb) { return new XSSFFormulaEvaluator(((SXSSFWorkbook) wb).getXSSFWorkbook()); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/XSSFITestDataProvider.java b/src/ooxml/testcases/org/apache/poi/xssf/XSSFITestDataProvider.java index ef9e8836f..b8eb9ebb1 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/XSSFITestDataProvider.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/XSSFITestDataProvider.java @@ -54,8 +54,17 @@ public final class XSSFITestDataProvider implements ITestDataProvider { return new XSSFWorkbook(); } + //************ SXSSF-specific methods ***************// + @Override + public XSSFWorkbook createWorkbook(int rowAccessWindowSize) { + return createWorkbook(); + } + @Override public void trackColumnsForAutosizing(Sheet sheet, int...columns) {} + @Override + public void trackAllColumnsForAutosizing(Sheet sheet) {} + //************ End SXSSF-specific methods ***************// @Override public FormulaEvaluator createFormulaEvaluator(Workbook wb) { diff --git a/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java b/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java index ffbb828d2..58e6327eb 100644 --- a/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java +++ b/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java @@ -60,8 +60,17 @@ public final class HSSFITestDataProvider implements ITestDataProvider { return new HSSFWorkbook(); } + //************ SXSSF-specific methods ***************// + @Override + public HSSFWorkbook createWorkbook(int rowAccessWindowSize) { + return createWorkbook(); + } + @Override public void trackColumnsForAutosizing(Sheet sheet, int...columns) {} + @Override + public void trackAllColumnsForAutosizing(Sheet sheet) {} + //************ End SXSSF-specific methods ***************// @Override public FormulaEvaluator createFormulaEvaluator(Workbook wb) { diff --git a/src/testcases/org/apache/poi/ss/ITestDataProvider.java b/src/testcases/org/apache/poi/ss/ITestDataProvider.java index 4be5d25a2..c88794854 100644 --- a/src/testcases/org/apache/poi/ss/ITestDataProvider.java +++ b/src/testcases/org/apache/poi/ss/ITestDataProvider.java @@ -47,11 +47,22 @@ public interface ITestDataProvider { */ Workbook createWorkbook(); + + //************ SXSSF-specific methods ***************// + /** + * Provides way of creating a SXSSFWorkbook with a specific row access window size. + * Equivalent to createWorkbook on others. + * @return an instance of Workbook + */ + Workbook createWorkbook(int rowAccessWindowSize); + /** * Only matters for SXSSF - enables tracking of the column * widths so that autosizing can work. No-op on others. */ void trackColumnsForAutosizing(Sheet sheet, int...columns); + void trackAllColumnsForAutosizing(Sheet sheet); + //************ End SXSSF-specific methods ***************// /** * Creates the corresponding {@link FormulaEvaluator} for the diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java index e7860e50d..e5991adf9 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java @@ -1427,4 +1427,64 @@ public abstract class BaseTestBugzillaIssues { assertEquals("12-312-345-123", formatter.formatCellValue(cell)); } + + @Test + public void test58896() throws IOException { + final int nrows = 160; + final int ncols = 139; + final java.io.PrintStream out = System.out; + + // Create a workbook + final Workbook wb = _testDataProvider.createWorkbook(nrows+1); + final Sheet sh = wb.createSheet(); + out.println(wb.getClass().getName() + " column autosizing timing..."); + + final long t0 = time(); + _testDataProvider.trackAllColumnsForAutosizing(sh); + for (int r=0; r 50000) { + // fail("Best fit width time per cell exceeded 50000 ns: " + bestFitWidthTimePerCell_ns + " ns"); + //} + + if (totalTime_s > 10) { + fail("Total time exceeded 10 seconds: " + totalTime_s + " s"); + } + } + + public long time() { + final long currentTime = System.currentTimeMillis(); + return currentTime; + } + public double delta(long startTimeMillis) { + return time() - startTimeMillis; + } }