minor improvements to junits
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@696401 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bb1235e2e5
commit
e2c8b4f4d4
@ -17,12 +17,14 @@
|
|||||||
|
|
||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
import junit.framework.AssertionFailedError;
|
import junit.framework.AssertionFailedError;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.record.formula.eval.TestFormulasFromSpreadsheet;
|
import org.apache.poi.hssf.record.formula.eval.TestFormulasFromSpreadsheet;
|
||||||
import org.apache.poi.hssf.record.formula.functions.TestMathX;
|
import org.apache.poi.hssf.record.formula.functions.TestMathX;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
@ -113,15 +115,6 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
|
|||||||
throw new AssertionFailedError(msg + " - actual value was null");
|
throw new AssertionFailedError(msg + " - actual value was null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expected.getCellType() == Cell.CELL_TYPE_STRING) {
|
|
||||||
String value = expected.getRichStringCellValue().getString();
|
|
||||||
if (value.startsWith("#")) {
|
|
||||||
// TODO - this code never called
|
|
||||||
expected.setCellType(Cell.CELL_TYPE_ERROR);
|
|
||||||
// expected.setCellErrorValue(...?);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (expected.getCellType()) {
|
switch (expected.getCellType()) {
|
||||||
case Cell.CELL_TYPE_BLANK:
|
case Cell.CELL_TYPE_BLANK:
|
||||||
assertEquals(msg, Cell.CELL_TYPE_BLANK, actual.getCellType());
|
assertEquals(msg, Cell.CELL_TYPE_BLANK, actual.getCellType());
|
||||||
@ -147,7 +140,7 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
|
|||||||
break;
|
break;
|
||||||
case Cell.CELL_TYPE_STRING:
|
case Cell.CELL_TYPE_STRING:
|
||||||
assertEquals(msg, Cell.CELL_TYPE_STRING, actual.getCellType());
|
assertEquals(msg, Cell.CELL_TYPE_STRING, actual.getCellType());
|
||||||
assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getRichTextStringValue().getString());
|
assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getStringValue());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,8 +148,8 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
|
|||||||
|
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
if (workbook == null) {
|
if (workbook == null) {
|
||||||
String filePath = System.getProperty("HSSF.testdata.path")+ "/" + SS.FILENAME;
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(SS.FILENAME);
|
||||||
Package pkg = Package.open(filePath);
|
Package pkg = Package.open(is);
|
||||||
workbook = new XSSFWorkbook( pkg );
|
workbook = new XSSFWorkbook( pkg );
|
||||||
sheet = workbook.getSheetAt( 0 );
|
sheet = workbook.getSheetAt( 0 );
|
||||||
}
|
}
|
||||||
@ -206,7 +199,7 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
|
|||||||
*/
|
*/
|
||||||
private void processFunctionGroup(int startRowIndex, String testFocusFunctionName) {
|
private void processFunctionGroup(int startRowIndex, String testFocusFunctionName) {
|
||||||
|
|
||||||
FormulaEvaluator evaluator = new FormulaEvaluator(sheet, workbook);
|
FormulaEvaluator evaluator = new FormulaEvaluator(workbook);
|
||||||
|
|
||||||
int rowIndex = startRowIndex;
|
int rowIndex = startRowIndex;
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -252,7 +245,6 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
|
|||||||
|
|
||||||
int result = Result.NO_EVALUATIONS_FOUND; // so far
|
int result = Result.NO_EVALUATIONS_FOUND; // so far
|
||||||
short endcolnum = formulasRow.getLastCellNum();
|
short endcolnum = formulasRow.getLastCellNum();
|
||||||
evaluator.setCurrentRow(formulasRow);
|
|
||||||
|
|
||||||
// iterate across the row for all the evaluation cases
|
// iterate across the row for all the evaluation cases
|
||||||
for (short colnum=SS.COLUMN_INDEX_FIRST_TEST_VALUE; colnum < endcolnum; colnum++) {
|
for (short colnum=SS.COLUMN_INDEX_FIRST_TEST_VALUE; colnum < endcolnum; colnum++) {
|
||||||
@ -341,7 +333,6 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
|
|||||||
for(int i=startIx; i<endIx; i++) {
|
for(int i=startIx; i<endIx; i++) {
|
||||||
ps.println("\tat " + stes[i].toString());
|
ps.println("\tat " + stes[i].toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +29,11 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
|||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
|
||||||
|
|
||||||
public class TestColumnHelper extends TestCase {
|
/**
|
||||||
|
* Tests for {@link ColumnHelper}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public final class TestColumnHelper extends TestCase {
|
||||||
|
|
||||||
public void testCleanColumns() {
|
public void testCleanColumns() {
|
||||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||||
@ -182,7 +186,14 @@ public class TestColumnHelper extends TestCase {
|
|||||||
col9.setMax(27);
|
col9.setMax(27);
|
||||||
helper.addCleanColIntoCols(cols1, col9);
|
helper.addCleanColIntoCols(cols1, col9);
|
||||||
|
|
||||||
System.err.println(cols1);
|
if (false) {
|
||||||
|
System.err.println(cols1);
|
||||||
|
}
|
||||||
|
// TODO - assert something interesting
|
||||||
|
CTCol[] colArray = cols1.getColArray();
|
||||||
|
assertEquals(12, colArray.length);
|
||||||
|
assertEquals(1, colArray[0].getMin());
|
||||||
|
assertEquals(16750, colArray[11].getMax());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetColumn() {
|
public void testGetColumn() {
|
||||||
@ -230,7 +241,7 @@ public class TestColumnHelper extends TestCase {
|
|||||||
|
|
||||||
public void testGetOrCreateColumn() {
|
public void testGetOrCreateColumn() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
|
XSSFSheet sheet = workbook.createSheet("Sheet 1");
|
||||||
ColumnHelper columnHelper = sheet.getColumnHelper();
|
ColumnHelper columnHelper = sheet.getColumnHelper();
|
||||||
|
|
||||||
// Check POI 0 based, OOXML 1 based
|
// Check POI 0 based, OOXML 1 based
|
||||||
@ -250,10 +261,10 @@ public class TestColumnHelper extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testGetSetColDefaultStyle() {
|
public void testGetSetColDefaultStyle() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
|
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook);
|
||||||
ColumnHelper columnHelper = sheet.getColumnHelper();
|
ColumnHelper columnHelper = sheet.getColumnHelper();
|
||||||
|
|
||||||
// POI column 3, OOXML column 4
|
// POI column 3, OOXML column 4
|
||||||
@ -283,7 +294,7 @@ public class TestColumnHelper extends TestCase {
|
|||||||
assertEquals(1, columnHelper.getColDefaultStyle(10));
|
assertEquals(1, columnHelper.getColDefaultStyle(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int countColumns(CTWorksheet worksheet) {
|
private static int countColumns(CTWorksheet worksheet) {
|
||||||
int count;
|
int count;
|
||||||
count = 0;
|
count = 0;
|
||||||
for (int i = 0; i < worksheet.sizeOfColsArray(); i++) {
|
for (int i = 0; i < worksheet.sizeOfColsArray(); i++) {
|
||||||
@ -296,5 +307,4 @@ public class TestColumnHelper extends TestCase {
|
|||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user