fix eclipse warning - mostly generics cosmetics
close resources in tests junit4 conversions convert spreadsheet based formular test to junit parameterized tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1702659 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
768060a8ff
commit
5f94d8b533
@ -25,6 +25,7 @@ import javax.swing.table.*;
|
|||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,7 +44,7 @@ public class SVTableModel extends AbstractTableModel {
|
|||||||
|
|
||||||
public SVTableModel(HSSFSheet st) {
|
public SVTableModel(HSSFSheet st) {
|
||||||
this.st = st;
|
this.st = st;
|
||||||
Iterator i = st.rowIterator();
|
Iterator<Row> i = st.rowIterator();
|
||||||
|
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
HSSFRow row = (HSSFRow)i.next();
|
HSSFRow row = (HSSFRow)i.next();
|
||||||
@ -69,7 +70,7 @@ public class SVTableModel extends AbstractTableModel {
|
|||||||
return st.getLastRowNum() + 1;
|
return st.getLastRowNum() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getColumnClass(int c) {
|
public Class<?> getColumnClass(int c) {
|
||||||
return HSSFCell.class;
|
return HSSFCell.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,18 +43,18 @@ public class ExtendableTreeCellRenderer implements TreeCellRenderer
|
|||||||
/**
|
/**
|
||||||
* <p>Maps classes to renderers.</p>
|
* <p>Maps classes to renderers.</p>
|
||||||
*/
|
*/
|
||||||
protected Map renderers;
|
protected Map<Class<?>,TreeCellRenderer> renderers;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ExtendableTreeCellRenderer()
|
public ExtendableTreeCellRenderer()
|
||||||
{
|
{
|
||||||
renderers = new HashMap();
|
renderers = new HashMap<Class<?>,TreeCellRenderer>();
|
||||||
register(Object.class, new DefaultTreeCellRenderer()
|
register(Object.class, new DefaultTreeCellRenderer()
|
||||||
{
|
{
|
||||||
public Component getTreeCellRendererComponent
|
public Component getTreeCellRendererComponent
|
||||||
(JTree tree, Object value, boolean selected,
|
(JTree tree, Object value, boolean selectedCell,
|
||||||
boolean expanded, boolean leaf, int row, boolean hasFocus)
|
boolean expanded, boolean leaf, int row, boolean hasCellFocus)
|
||||||
{
|
{
|
||||||
final String s = value.toString();
|
final String s = value.toString();
|
||||||
final JLabel l = new JLabel(s + " ");
|
final JLabel l = new JLabel(s + " ");
|
||||||
@ -73,7 +73,7 @@ public class ExtendableTreeCellRenderer implements TreeCellRenderer
|
|||||||
/**
|
/**
|
||||||
* <p>Registers a renderer for a class.</p>
|
* <p>Registers a renderer for a class.</p>
|
||||||
**/
|
**/
|
||||||
public void register(final Class c, final TreeCellRenderer renderer)
|
public void register(final Class<?> c, final TreeCellRenderer renderer)
|
||||||
{
|
{
|
||||||
renderers.put(c, renderer);
|
renderers.put(c, renderer);
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ public class ExtendableTreeCellRenderer implements TreeCellRenderer
|
|||||||
* <p>Unregisters a renderer for a class. The renderer for the
|
* <p>Unregisters a renderer for a class. The renderer for the
|
||||||
* {@link Object} class cannot be unregistered.</p>
|
* {@link Object} class cannot be unregistered.</p>
|
||||||
*/
|
*/
|
||||||
public void unregister(final Class c)
|
public void unregister(final Class<?> c)
|
||||||
{
|
{
|
||||||
if (c == Object.class)
|
if (c == Object.class)
|
||||||
throw new IllegalArgumentException
|
throw new IllegalArgumentException
|
||||||
@ -127,15 +127,15 @@ public class ExtendableTreeCellRenderer implements TreeCellRenderer
|
|||||||
/**
|
/**
|
||||||
* <p>Find the renderer for the specified class.</p>
|
* <p>Find the renderer for the specified class.</p>
|
||||||
*/
|
*/
|
||||||
protected TreeCellRenderer findRenderer(final Class c)
|
protected TreeCellRenderer findRenderer(final Class<?> c)
|
||||||
{
|
{
|
||||||
final TreeCellRenderer r = (TreeCellRenderer) renderers.get(c);
|
final TreeCellRenderer r = renderers.get(c);
|
||||||
if (r != null)
|
if (r != null)
|
||||||
/* The class has a renderer. */
|
/* The class has a renderer. */
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
/* The class has no renderer, try the superclass, if any. */
|
/* The class has no renderer, try the superclass, if any. */
|
||||||
final Class superclass = c.getSuperclass();
|
final Class<?> superclass = c.getSuperclass();
|
||||||
if (superclass != null) {
|
if (superclass != null) {
|
||||||
return findRenderer(superclass);
|
return findRenderer(superclass);
|
||||||
}
|
}
|
||||||
|
@ -89,19 +89,16 @@ public class POIBrowser extends JFrame
|
|||||||
for (int i = 0; i < args.length; i++)
|
for (int i = 0; i < args.length; i++)
|
||||||
{
|
{
|
||||||
final String filename = args[i];
|
final String filename = args[i];
|
||||||
try
|
try {
|
||||||
{
|
FileInputStream fis = new FileInputStream(filename);
|
||||||
POIFSReader r = new POIFSReader();
|
POIFSReader r = new POIFSReader();
|
||||||
r.registerListener(new TreeReaderListener(filename, rootNode));
|
r.registerListener(new TreeReaderListener(filename, rootNode));
|
||||||
r.read(new FileInputStream(filename));
|
r.read(fis);
|
||||||
|
fis.close();
|
||||||
displayedFiles++;
|
displayedFiles++;
|
||||||
}
|
} catch (IOException ex) {
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
System.err.println(filename + ": " + ex);
|
System.err.println(filename + ": " + ex);
|
||||||
}
|
} catch (Exception t) {
|
||||||
catch (Exception t)
|
|
||||||
{
|
|
||||||
System.err.println("Unexpected exception while reading \"" +
|
System.err.println("Unexpected exception while reading \"" +
|
||||||
filename + "\":");
|
filename + "\":");
|
||||||
t.printStackTrace(System.err);
|
t.printStackTrace(System.err);
|
||||||
|
@ -45,11 +45,11 @@ public class PropertySetDescriptorRenderer extends DocumentDescriptorRenderer
|
|||||||
|
|
||||||
public Component getTreeCellRendererComponent(final JTree tree,
|
public Component getTreeCellRendererComponent(final JTree tree,
|
||||||
final Object value,
|
final Object value,
|
||||||
final boolean selected,
|
final boolean selectedCell,
|
||||||
final boolean expanded,
|
final boolean expanded,
|
||||||
final boolean leaf,
|
final boolean leaf,
|
||||||
final int row,
|
final int row,
|
||||||
final boolean hasFocus)
|
final boolean hasCellFocus)
|
||||||
{
|
{
|
||||||
final PropertySetDescriptor d = (PropertySetDescriptor)
|
final PropertySetDescriptor d = (PropertySetDescriptor)
|
||||||
((DefaultMutableTreeNode) value).getUserObject();
|
((DefaultMutableTreeNode) value).getUserObject();
|
||||||
@ -96,7 +96,7 @@ public class PropertySetDescriptorRenderer extends DocumentDescriptorRenderer
|
|||||||
text.append("\nSecurity: " + si.getSecurity());
|
text.append("\nSecurity: " + si.getSecurity());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selected)
|
if (selectedCell)
|
||||||
Util.invert(text);
|
Util.invert(text);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -107,13 +107,13 @@ public class PropertySetDescriptorRenderer extends DocumentDescriptorRenderer
|
|||||||
* <p>Returns a string representation of a list of {@link
|
* <p>Returns a string representation of a list of {@link
|
||||||
* Section}s.</p>
|
* Section}s.</p>
|
||||||
*/
|
*/
|
||||||
protected String sectionsToString(final List sections)
|
protected String sectionsToString(final List<Section> sections)
|
||||||
{
|
{
|
||||||
final StringBuffer b = new StringBuffer();
|
final StringBuffer b = new StringBuffer();
|
||||||
int count = 1;
|
int count = 1;
|
||||||
for (Iterator i = sections.iterator(); i.hasNext();)
|
for (Iterator<Section> i = sections.iterator(); i.hasNext();)
|
||||||
{
|
{
|
||||||
Section s = (Section) i.next();
|
Section s = i.next();
|
||||||
String d = toString(s, "Section " + count++);
|
String d = toString(s, "Section " + count++);
|
||||||
b.append(d);
|
b.append(d);
|
||||||
}
|
}
|
||||||
|
@ -254,12 +254,12 @@ public final class InternalSheet {
|
|||||||
|
|
||||||
if (recSid == BOFRecord.sid) {
|
if (recSid == BOFRecord.sid) {
|
||||||
ChartSubstreamRecordAggregate chartAgg = new ChartSubstreamRecordAggregate(rs);
|
ChartSubstreamRecordAggregate chartAgg = new ChartSubstreamRecordAggregate(rs);
|
||||||
if (false) {
|
// if (false) {
|
||||||
// TODO - would like to keep the chart aggregate packed, but one unit test needs attention
|
// // TODO - would like to keep the chart aggregate packed, but one unit test needs attention
|
||||||
records.add(chartAgg);
|
// records.add(chartAgg);
|
||||||
} else {
|
// } else {
|
||||||
spillAggregate(chartAgg, records);
|
spillAggregate(chartAgg, records);
|
||||||
}
|
// }
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,14 +62,14 @@ public abstract class Record extends RecordBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
if (false) {
|
// if (false) {
|
||||||
// TODO - implement clone in a more standardised way
|
// // TODO - implement clone in a more standardised way
|
||||||
try {
|
// try {
|
||||||
return super.clone();
|
// return super.clone();
|
||||||
} catch (CloneNotSupportedException e) {
|
// } catch (CloneNotSupportedException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
throw new RuntimeException("The class "+getClass().getName()+" needs to define a clone method");
|
throw new RuntimeException("The class "+getClass().getName()+" needs to define a clone method");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,9 +54,9 @@ public class HSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public HSSFFormulaEvaluator(HSSFSheet sheet, HSSFWorkbook workbook) {
|
public HSSFFormulaEvaluator(HSSFSheet sheet, HSSFWorkbook workbook) {
|
||||||
this(workbook);
|
this(workbook);
|
||||||
if (false) {
|
// if (false) {
|
||||||
sheet.toString(); // suppress unused parameter compiler warning
|
// sheet.toString(); // suppress unused parameter compiler warning
|
||||||
}
|
// }
|
||||||
this._book = workbook;
|
this._book = workbook;
|
||||||
}
|
}
|
||||||
public HSSFFormulaEvaluator(HSSFWorkbook workbook) {
|
public HSSFFormulaEvaluator(HSSFWorkbook workbook) {
|
||||||
@ -122,9 +122,9 @@ public class HSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public void setCurrentRow(HSSFRow row) {
|
public void setCurrentRow(HSSFRow row) {
|
||||||
// do nothing
|
// do nothing
|
||||||
if (false) {
|
// if (false) {
|
||||||
row.getClass(); // suppress unused parameter compiler warning
|
// row.getClass(); // suppress unused parameter compiler warning
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,14 +90,14 @@ public class HSSFColor implements Color {
|
|||||||
// most colors don't have a second index
|
// most colors don't have a second index
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (result.containsKey(index2)) {
|
// if (result.containsKey(index2)) {
|
||||||
if (false) { // Many of the second indexes clash
|
// if (false) { // Many of the second indexes clash
|
||||||
HSSFColor prevColor = (HSSFColor)result.get(index2);
|
// HSSFColor prevColor = (HSSFColor)result.get(index2);
|
||||||
throw new RuntimeException("Dup color index (" + index2
|
// throw new RuntimeException("Dup color index (" + index2
|
||||||
+ ") for colors (" + prevColor.getClass().getName()
|
// + ") for colors (" + prevColor.getClass().getName()
|
||||||
+ "),(" + color.getClass().getName() + ")");
|
// + "),(" + color.getClass().getName() + ")");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
result.put(index2, color);
|
result.put(index2, color);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -36,20 +36,20 @@ class POIFSReaderRegistry
|
|||||||
{
|
{
|
||||||
|
|
||||||
// the POIFSReaderListeners who listen to all POIFSReaderEvents
|
// the POIFSReaderListeners who listen to all POIFSReaderEvents
|
||||||
private Set omnivorousListeners;
|
private Set<POIFSReaderListener> omnivorousListeners;
|
||||||
|
|
||||||
// Each mapping in this Map has a key consisting of a
|
// Each mapping in this Map has a key consisting of a
|
||||||
// POIFSReaderListener and a value cosisting of a Set of
|
// POIFSReaderListener and a value cosisting of a Set of
|
||||||
// DocumentDescriptors for the documents that POIFSReaderListener
|
// DocumentDescriptors for the documents that POIFSReaderListener
|
||||||
// is interested in; used to efficiently manage the registry
|
// is interested in; used to efficiently manage the registry
|
||||||
private Map selectiveListeners;
|
private Map<POIFSReaderListener, Set<DocumentDescriptor>> selectiveListeners;
|
||||||
|
|
||||||
// Each mapping in this Map has a key consisting of a
|
// Each mapping in this Map has a key consisting of a
|
||||||
// DocumentDescriptor and a value consisting of a Set of
|
// DocumentDescriptor and a value consisting of a Set of
|
||||||
// POIFSReaderListeners for the document matching that
|
// POIFSReaderListeners for the document matching that
|
||||||
// DocumentDescriptor; used when a document is found, to quickly
|
// DocumentDescriptor; used when a document is found, to quickly
|
||||||
// get the listeners interested in that document
|
// get the listeners interested in that document
|
||||||
private Map chosenDocumentDescriptors;
|
private Map<DocumentDescriptor,Set<POIFSReaderListener>> chosenDocumentDescriptors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the registry
|
* Construct the registry
|
||||||
@ -57,9 +57,9 @@ class POIFSReaderRegistry
|
|||||||
|
|
||||||
POIFSReaderRegistry()
|
POIFSReaderRegistry()
|
||||||
{
|
{
|
||||||
omnivorousListeners = new HashSet();
|
omnivorousListeners = new HashSet<POIFSReaderListener>();
|
||||||
selectiveListeners = new HashMap();
|
selectiveListeners = new HashMap<POIFSReaderListener, Set<DocumentDescriptor>>();
|
||||||
chosenDocumentDescriptors = new HashMap();
|
chosenDocumentDescriptors = new HashMap<DocumentDescriptor,Set<POIFSReaderListener>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,13 +79,13 @@ class POIFSReaderRegistry
|
|||||||
|
|
||||||
// not an omnivorous listener (if it was, this method is a
|
// not an omnivorous listener (if it was, this method is a
|
||||||
// no-op)
|
// no-op)
|
||||||
Set descriptors = ( Set ) selectiveListeners.get(listener);
|
Set<DocumentDescriptor> descriptors = selectiveListeners.get(listener);
|
||||||
|
|
||||||
if (descriptors == null)
|
if (descriptors == null)
|
||||||
{
|
{
|
||||||
|
|
||||||
// this listener has not registered before
|
// this listener has not registered before
|
||||||
descriptors = new HashSet();
|
descriptors = new HashSet<DocumentDescriptor>();
|
||||||
selectiveListeners.put(listener, descriptors);
|
selectiveListeners.put(listener, descriptors);
|
||||||
}
|
}
|
||||||
DocumentDescriptor descriptor = new DocumentDescriptor(path,
|
DocumentDescriptor descriptor = new DocumentDescriptor(path,
|
||||||
@ -97,14 +97,14 @@ class POIFSReaderRegistry
|
|||||||
// this listener wasn't already listening for this
|
// this listener wasn't already listening for this
|
||||||
// document -- add the listener to the set of
|
// document -- add the listener to the set of
|
||||||
// listeners for this document
|
// listeners for this document
|
||||||
Set listeners =
|
Set<POIFSReaderListener> listeners =
|
||||||
( Set ) chosenDocumentDescriptors.get(descriptor);
|
chosenDocumentDescriptors.get(descriptor);
|
||||||
|
|
||||||
if (listeners == null)
|
if (listeners == null)
|
||||||
{
|
{
|
||||||
|
|
||||||
// nobody was listening for this document before
|
// nobody was listening for this document before
|
||||||
listeners = new HashSet();
|
listeners = new HashSet<POIFSReaderListener>();
|
||||||
chosenDocumentDescriptors.put(descriptor, listeners);
|
chosenDocumentDescriptors.put(descriptor, listeners);
|
||||||
}
|
}
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
@ -141,31 +141,30 @@ class POIFSReaderRegistry
|
|||||||
* @return an Iterator POIFSReaderListeners; may be empty
|
* @return an Iterator POIFSReaderListeners; may be empty
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Iterator getListeners(final POIFSDocumentPath path, final String name)
|
Iterator<POIFSReaderListener> getListeners(final POIFSDocumentPath path, final String name)
|
||||||
{
|
{
|
||||||
Set rval = new HashSet(omnivorousListeners);
|
Set<POIFSReaderListener> rval = new HashSet<POIFSReaderListener>(omnivorousListeners);
|
||||||
Set selectiveListeners =
|
Set<POIFSReaderListener> selectiveListenersInner =
|
||||||
( Set ) chosenDocumentDescriptors.get(new DocumentDescriptor(path,
|
chosenDocumentDescriptors.get(new DocumentDescriptor(path, name));
|
||||||
name));
|
|
||||||
|
|
||||||
if (selectiveListeners != null)
|
if (selectiveListenersInner != null)
|
||||||
{
|
{
|
||||||
rval.addAll(selectiveListeners);
|
rval.addAll(selectiveListenersInner);
|
||||||
}
|
}
|
||||||
return rval.iterator();
|
return rval.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeSelectiveListener(final POIFSReaderListener listener)
|
private void removeSelectiveListener(final POIFSReaderListener listener)
|
||||||
{
|
{
|
||||||
Set selectedDescriptors = ( Set ) selectiveListeners.remove(listener);
|
Set<DocumentDescriptor> selectedDescriptors = selectiveListeners.remove(listener);
|
||||||
|
|
||||||
if (selectedDescriptors != null)
|
if (selectedDescriptors != null)
|
||||||
{
|
{
|
||||||
Iterator iter = selectedDescriptors.iterator();
|
Iterator<DocumentDescriptor> iter = selectedDescriptors.iterator();
|
||||||
|
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
dropDocument(listener, ( DocumentDescriptor ) iter.next());
|
dropDocument(listener, iter.next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,7 +172,7 @@ class POIFSReaderRegistry
|
|||||||
private void dropDocument(final POIFSReaderListener listener,
|
private void dropDocument(final POIFSReaderListener listener,
|
||||||
final DocumentDescriptor descriptor)
|
final DocumentDescriptor descriptor)
|
||||||
{
|
{
|
||||||
Set listeners = ( Set ) chosenDocumentDescriptors.get(descriptor);
|
Set<POIFSReaderListener> listeners = chosenDocumentDescriptors.get(descriptor);
|
||||||
|
|
||||||
listeners.remove(listener);
|
listeners.remove(listener);
|
||||||
if (listeners.size() == 0)
|
if (listeners.size() == 0)
|
||||||
|
@ -29,7 +29,9 @@ import java.util.regex.Pattern;
|
|||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class ExpressionParser {
|
public class ExpressionParser {
|
||||||
static final HashMap<String, Class> impls = new HashMap<String, Class>();
|
static final HashMap<String, Class<? extends Expression>> impls =
|
||||||
|
new HashMap<String, Class<? extends Expression>>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
impls.put("\\*/ +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", MultiplyDivideExpression.class);
|
impls.put("\\*/ +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", MultiplyDivideExpression.class);
|
||||||
impls.put("\\+- +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)( 0)?", AddSubtractExpression.class);
|
impls.put("\\+- +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)( 0)?", AddSubtractExpression.class);
|
||||||
@ -56,9 +58,9 @@ public class ExpressionParser {
|
|||||||
Pattern ptrn = Pattern.compile(regexp);
|
Pattern ptrn = Pattern.compile(regexp);
|
||||||
Matcher m = ptrn.matcher(str);
|
Matcher m = ptrn.matcher(str);
|
||||||
if(m.matches()) {
|
if(m.matches()) {
|
||||||
Class c = impls.get(regexp);
|
Class<? extends Expression> c = impls.get(regexp);
|
||||||
try {
|
try {
|
||||||
return (Expression)c.getDeclaredConstructor(Matcher.class).newInstance(m);
|
return c.getDeclaredConstructor(Matcher.class).newInstance(m);
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -44,19 +44,19 @@ public class Formula {
|
|||||||
private Formula(byte[] byteEncoding, int encodedTokenLen) {
|
private Formula(byte[] byteEncoding, int encodedTokenLen) {
|
||||||
_byteEncoding = byteEncoding;
|
_byteEncoding = byteEncoding;
|
||||||
_encodedTokenLen = encodedTokenLen;
|
_encodedTokenLen = encodedTokenLen;
|
||||||
if (false) { // set to true to eagerly check Ptg decoding
|
// if (false) { // set to true to eagerly check Ptg decoding
|
||||||
LittleEndianByteArrayInputStream in = new LittleEndianByteArrayInputStream(byteEncoding);
|
// LittleEndianByteArrayInputStream in = new LittleEndianByteArrayInputStream(byteEncoding);
|
||||||
Ptg.readTokens(encodedTokenLen, in);
|
// Ptg.readTokens(encodedTokenLen, in);
|
||||||
int nUnusedBytes = _byteEncoding.length - in.getReadIndex();
|
// int nUnusedBytes = _byteEncoding.length - in.getReadIndex();
|
||||||
if (nUnusedBytes > 0) {
|
// if (nUnusedBytes > 0) {
|
||||||
// TODO - this seems to occur when IntersectionPtg is present
|
// // TODO - this seems to occur when IntersectionPtg is present
|
||||||
// This example file "IntersectionPtg.xls"
|
// // This example file "IntersectionPtg.xls"
|
||||||
// used by test: TestIntersectionPtg.testReading()
|
// // used by test: TestIntersectionPtg.testReading()
|
||||||
// has 10 bytes unused at the end of the formula
|
// // has 10 bytes unused at the end of the formula
|
||||||
// 10 extra bytes are just 0x01 and 0x00
|
// // 10 extra bytes are just 0x01 and 0x00
|
||||||
System.out.println(nUnusedBytes + " unused bytes at end of formula");
|
// System.out.println(nUnusedBytes + " unused bytes at end of formula");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Convenience method for {@link #read(int, LittleEndianInput, int)}
|
* Convenience method for {@link #read(int, LittleEndianInput, int)}
|
||||||
|
@ -130,28 +130,28 @@ public final class OperandResolver {
|
|||||||
private static ValueEval chooseSingleElementFromAreaInternal(AreaEval ae,
|
private static ValueEval chooseSingleElementFromAreaInternal(AreaEval ae,
|
||||||
int srcCellRow, int srcCellCol) throws EvaluationException {
|
int srcCellRow, int srcCellCol) throws EvaluationException {
|
||||||
|
|
||||||
if(false) {
|
// if(false) {
|
||||||
// this is too simplistic
|
// // this is too simplistic
|
||||||
if(ae.containsRow(srcCellRow) && ae.containsColumn(srcCellCol)) {
|
// if(ae.containsRow(srcCellRow) && ae.containsColumn(srcCellCol)) {
|
||||||
throw new EvaluationException(ErrorEval.CIRCULAR_REF_ERROR);
|
// throw new EvaluationException(ErrorEval.CIRCULAR_REF_ERROR);
|
||||||
}
|
// }
|
||||||
/*
|
// /*
|
||||||
Circular references are not dealt with directly here, but it is worth noting some issues.
|
// Circular references are not dealt with directly here, but it is worth noting some issues.
|
||||||
|
//
|
||||||
ANY one of the return statements in this method could return a cell that is identical
|
// ANY one of the return statements in this method could return a cell that is identical
|
||||||
to the one immediately being evaluated. The evaluating cell is identified by srcCellRow,
|
// to the one immediately being evaluated. The evaluating cell is identified by srcCellRow,
|
||||||
srcCellRow AND sheet. The sheet is not available in any nearby calling method, so that's
|
// srcCellRow AND sheet. The sheet is not available in any nearby calling method, so that's
|
||||||
one reason why circular references are not easy to detect here. (The sheet of the returned
|
// one reason why circular references are not easy to detect here. (The sheet of the returned
|
||||||
cell can be obtained from ae if it is an Area3DEval.)
|
// cell can be obtained from ae if it is an Area3DEval.)
|
||||||
|
//
|
||||||
Another reason there's little value in attempting to detect circular references here is
|
// Another reason there's little value in attempting to detect circular references here is
|
||||||
that only direct circular references could be detected. If the cycle involved two or more
|
// that only direct circular references could be detected. If the cycle involved two or more
|
||||||
cells this method could not detect it.
|
// cells this method could not detect it.
|
||||||
|
//
|
||||||
Logic to detect evaluation cycles of all kinds has been coded in EvaluationCycleDetector
|
// Logic to detect evaluation cycles of all kinds has been coded in EvaluationCycleDetector
|
||||||
(and FormulaEvaluator).
|
// (and FormulaEvaluator).
|
||||||
*/
|
// */
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (ae.isColumn()) {
|
if (ae.isColumn()) {
|
||||||
if(ae.isRow()) {
|
if(ae.isRow()) {
|
||||||
|
@ -17,25 +17,27 @@
|
|||||||
|
|
||||||
package org.apache.poi.openxml4j.opc;
|
package org.apache.poi.openxml4j.opc;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import org.apache.poi.openxml4j.opc.internal.FileHelper;
|
import org.apache.poi.openxml4j.opc.internal.FileHelper;
|
||||||
|
import org.junit.Test;
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test TestFileHelper class.
|
* Test TestFileHelper class.
|
||||||
*
|
*
|
||||||
* @author Julien Chable
|
* @author Julien Chable
|
||||||
*/
|
*/
|
||||||
public final class TestFileHelper extends TestCase {
|
public final class TestFileHelper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO - use simple JDK methods on {@link File} instead:<br/>
|
* TODO - use simple JDK methods on {@link File} instead:<br/>
|
||||||
* {@link File#getParentFile()} instead of {@link FileHelper#getDirectory(File)
|
* {@link File#getParentFile()} instead of {@link FileHelper#getDirectory(File)
|
||||||
* {@link File#getName()} instead of {@link FileHelper#getFilename(File)
|
* {@link File#getName()} instead of {@link FileHelper#getFilename(File)
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetDirectory() {
|
public void testGetDirectory() {
|
||||||
TreeMap<String, String> expectedValue = new TreeMap<String, String>();
|
TreeMap<String, String> expectedValue = new TreeMap<String, String>();
|
||||||
expectedValue.put("/dir1/test.doc", "/dir1");
|
expectedValue.put("/dir1/test.doc", "/dir1");
|
||||||
@ -45,11 +47,11 @@ public final class TestFileHelper extends TestCase {
|
|||||||
File f1 = new File(expectedValue.get(filename));
|
File f1 = new File(expectedValue.get(filename));
|
||||||
File f2 = FileHelper.getDirectory(new File(filename));
|
File f2 = FileHelper.getDirectory(new File(filename));
|
||||||
|
|
||||||
if (false) {
|
// if (false) {
|
||||||
// YK: The original version asserted expected values against File#getAbsolutePath():
|
// // YK: The original version asserted expected values against File#getAbsolutePath():
|
||||||
assertTrue(expectedValue.get(filename).equalsIgnoreCase(f2.getAbsolutePath()));
|
// assertTrue(expectedValue.get(filename).equalsIgnoreCase(f2.getAbsolutePath()));
|
||||||
// This comparison is platform dependent. A better approach is below
|
// // This comparison is platform dependent. A better approach is below
|
||||||
}
|
// }
|
||||||
assertTrue(f1.equals(f2));
|
assertTrue(f1.equals(f2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xssf.streaming;
|
package org.apache.poi.xssf.streaming;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.BaseTestDataValidation;
|
import org.apache.poi.ss.usermodel.BaseTestDataValidation;
|
||||||
@ -25,6 +27,7 @@ import org.apache.poi.ss.usermodel.DataValidationHelper;
|
|||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||||
import org.apache.poi.xssf.SXSSFITestDataProvider;
|
import org.apache.poi.xssf.SXSSFITestDataProvider;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TestSXSSFDataValidation extends BaseTestDataValidation {
|
public class TestSXSSFDataValidation extends BaseTestDataValidation {
|
||||||
|
|
||||||
@ -32,6 +35,7 @@ public class TestSXSSFDataValidation extends BaseTestDataValidation {
|
|||||||
super(SXSSFITestDataProvider.instance);
|
super(SXSSFITestDataProvider.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void test53965() throws Exception {
|
public void test53965() throws Exception {
|
||||||
SXSSFWorkbook wb = new SXSSFWorkbook();
|
SXSSFWorkbook wb = new SXSSFWorkbook();
|
||||||
try {
|
try {
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -34,6 +36,7 @@ import org.apache.poi.ss.util.CellRangeAddressList;
|
|||||||
import org.apache.poi.ss.util.CellReference;
|
import org.apache.poi.ss.util.CellReference;
|
||||||
import org.apache.poi.xssf.XSSFITestDataProvider;
|
import org.apache.poi.xssf.XSSFITestDataProvider;
|
||||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TestXSSFDataValidation extends BaseTestDataValidation {
|
public class TestXSSFDataValidation extends BaseTestDataValidation {
|
||||||
|
|
||||||
@ -41,9 +44,10 @@ public class TestXSSFDataValidation extends BaseTestDataValidation {
|
|||||||
super(XSSFITestDataProvider.instance);
|
super(XSSFITestDataProvider.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddValidations() throws Exception {
|
public void testAddValidations() throws Exception {
|
||||||
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("DataValidations-49244.xlsx");
|
XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("DataValidations-49244.xlsx");
|
||||||
Sheet sheet = workbook.getSheetAt(0);
|
Sheet sheet = wb1.getSheetAt(0);
|
||||||
List<XSSFDataValidation> dataValidations = ((XSSFSheet)sheet).getDataValidations();
|
List<XSSFDataValidation> dataValidations = ((XSSFSheet)sheet).getDataValidations();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -232,9 +236,11 @@ public class TestXSSFDataValidation extends BaseTestDataValidation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
|
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1);
|
||||||
Sheet sheetAt = workbook.getSheetAt(0);
|
wb1.close();
|
||||||
|
Sheet sheetAt = wb2.getSheetAt(0);
|
||||||
assertEquals(lastKnownNumValidations,((XSSFSheet)sheetAt).getDataValidations().size());
|
assertEquals(lastKnownNumValidations,((XSSFSheet)sheetAt).getDataValidations().size());
|
||||||
|
wb2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setOtherValidationParameters(DataValidation validation) {
|
protected void setOtherValidationParameters(DataValidation validation) {
|
||||||
@ -247,6 +253,7 @@ public class TestXSSFDataValidation extends BaseTestDataValidation {
|
|||||||
validation.setSuppressDropDownArrow(yesNo);
|
validation.setSuppressDropDownArrow(yesNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void test53965() throws Exception {
|
public void test53965() throws Exception {
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
try {
|
try {
|
||||||
@ -271,6 +278,7 @@ public class TestXSSFDataValidation extends BaseTestDataValidation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDefaultAllowBlank() throws IOException {
|
public void testDefaultAllowBlank() throws IOException {
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
try {
|
try {
|
||||||
@ -286,6 +294,7 @@ public class TestXSSFDataValidation extends BaseTestDataValidation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSetAllowBlankToFalse() throws IOException {
|
public void testSetAllowBlankToFalse() throws IOException {
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
try {
|
try {
|
||||||
@ -303,6 +312,7 @@ public class TestXSSFDataValidation extends BaseTestDataValidation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSetAllowBlankToTrue() throws IOException {
|
public void testSetAllowBlankToTrue() throws IOException {
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
try {
|
try {
|
||||||
|
@ -18,7 +18,11 @@
|
|||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
import org.apache.poi.xssf.XSSFITestDataProvider;
|
import org.apache.poi.xssf.XSSFITestDataProvider;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.BaseTestNamedRange;
|
import org.apache.poi.ss.usermodel.BaseTestNamedRange;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
|
||||||
@ -32,7 +36,8 @@ public final class TestXSSFName extends BaseTestNamedRange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO combine testRepeatingRowsAndColums() for HSSF and XSSF
|
//TODO combine testRepeatingRowsAndColums() for HSSF and XSSF
|
||||||
public void testRepeatingRowsAndColums() {
|
@Test
|
||||||
|
public void testRepeatingRowsAndColums() throws Exception {
|
||||||
// First test that setting RR&C for same sheet more than once only creates a
|
// First test that setting RR&C for same sheet more than once only creates a
|
||||||
// single Print_Titles built-in record
|
// single Print_Titles built-in record
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
@ -69,6 +74,7 @@ public final class TestXSSFName extends BaseTestNamedRange {
|
|||||||
|
|
||||||
// Save and re-open
|
// Save and re-open
|
||||||
XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||||
|
wb.close();
|
||||||
|
|
||||||
assertEquals(1, nwb.getNumberOfNames());
|
assertEquals(1, nwb.getNumberOfNames());
|
||||||
nr1 = nwb.getNameAt(0);
|
nr1 = nwb.getNameAt(0);
|
||||||
@ -90,5 +96,6 @@ public final class TestXSSFName extends BaseTestNamedRange {
|
|||||||
|
|
||||||
sheet2.setRepeatingRows(null);
|
sheet2.setRepeatingRows(null);
|
||||||
sheet2.setRepeatingColumns(null);
|
sheet2.setRepeatingColumns(null);
|
||||||
|
nwb.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,7 +244,7 @@ public final class SlideShowRecordDumper {
|
|||||||
String rHexType = reverseHex(hexType);
|
String rHexType = reverseHex(hexType);
|
||||||
|
|
||||||
// Grab the hslf.record type
|
// Grab the hslf.record type
|
||||||
Class c = r.getClass();
|
Class<? extends Record> c = r.getClass();
|
||||||
String cname = c.toString();
|
String cname = c.toString();
|
||||||
if(cname.startsWith("class ")) {
|
if(cname.startsWith("class ")) {
|
||||||
cname = cname.substring(6);
|
cname = cname.substring(6);
|
||||||
|
@ -17,22 +17,18 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.eventusermodel;
|
package org.apache.poi.hssf.eventusermodel;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import org.junit.runner.RunWith;
|
||||||
import junit.framework.TestSuite;
|
import org.junit.runners.Suite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects all tests for <tt>org.apache.poi.hssf.eventusermodel</tt>.
|
* Collects all tests for <tt>org.apache.poi.hssf.eventusermodel</tt>.
|
||||||
*
|
|
||||||
* @author Josh Micich
|
|
||||||
*/
|
*/
|
||||||
|
@RunWith(Suite.class)
|
||||||
|
@Suite.SuiteClasses({
|
||||||
|
TestEventWorkbookBuilder.class,
|
||||||
|
TestFormatTrackingHSSFListener.class,
|
||||||
|
TestHSSFEventFactory.class,
|
||||||
|
TestMissingRecordAwareHSSFListener.class
|
||||||
|
})
|
||||||
public class AllEventUserModelTests {
|
public class AllEventUserModelTests {
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
TestSuite result = new TestSuite(AllEventUserModelTests.class.getName());
|
|
||||||
result.addTestSuite(TestEventWorkbookBuilder.class);
|
|
||||||
result.addTestSuite(TestFormatTrackingHSSFListener.class);
|
|
||||||
result.addTestSuite(TestHSSFEventFactory.class);
|
|
||||||
result.addTestSuite(TestMissingRecordAwareHSSFListener.class);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,23 +16,25 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
package org.apache.poi.hssf.eventusermodel;
|
package org.apache.poi.hssf.eventusermodel;
|
||||||
import java.io.IOException;
|
import static org.junit.Assert.assertEquals;
|
||||||
import java.io.InputStream;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.record.CellValueRecordInterface;
|
import org.apache.poi.hssf.record.CellValueRecordInterface;
|
||||||
import org.apache.poi.hssf.record.FormulaRecord;
|
import org.apache.poi.hssf.record.FormulaRecord;
|
||||||
import org.apache.poi.hssf.record.NumberRecord;
|
import org.apache.poi.hssf.record.NumberRecord;
|
||||||
import org.apache.poi.hssf.record.Record;
|
import org.apache.poi.hssf.record.Record;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
|
import org.junit.Test;
|
||||||
/**
|
/**
|
||||||
* Tests for FormatTrackingHSSFListener
|
* Tests for FormatTrackingHSSFListener
|
||||||
*/
|
*/
|
||||||
public final class TestFormatTrackingHSSFListener extends TestCase {
|
public final class TestFormatTrackingHSSFListener {
|
||||||
private FormatTrackingHSSFListener listener;
|
private FormatTrackingHSSFListener listener;
|
||||||
private MockHSSFListener mockListen;
|
private MockHSSFListener mockListen;
|
||||||
|
|
||||||
@ -42,16 +44,14 @@ public final class TestFormatTrackingHSSFListener extends TestCase {
|
|||||||
listener = new FormatTrackingHSSFListener(mockListen);
|
listener = new FormatTrackingHSSFListener(mockListen);
|
||||||
req.addListenerForAllRecords(listener);
|
req.addListenerForAllRecords(listener);
|
||||||
|
|
||||||
|
File file = HSSFTestDataSamples.getSampleFile(filename);
|
||||||
HSSFEventFactory factory = new HSSFEventFactory();
|
HSSFEventFactory factory = new HSSFEventFactory();
|
||||||
try {
|
POIFSFileSystem fs = new POIFSFileSystem(file);
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(filename);
|
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(is);
|
|
||||||
factory.processWorkbookEvents(req, fs);
|
factory.processWorkbookEvents(req, fs);
|
||||||
} catch (IOException e) {
|
fs.close();
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFormats() throws Exception {
|
public void testFormats() throws Exception {
|
||||||
processFile("MissingBits.xls");
|
processFile("MissingBits.xls");
|
||||||
|
|
||||||
@ -68,6 +68,7 @@ public final class TestFormatTrackingHSSFListener extends TestCase {
|
|||||||
* exceptions thrown, but in future we might also
|
* exceptions thrown, but in future we might also
|
||||||
* want to check the exact strings!
|
* want to check the exact strings!
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testTurnToString() throws Exception {
|
public void testTurnToString() throws Exception {
|
||||||
String[] files = new String[] {
|
String[] files = new String[] {
|
||||||
"45365.xls", "45365-2.xls", "MissingBits.xls"
|
"45365.xls", "45365-2.xls", "MissingBits.xls"
|
||||||
@ -81,8 +82,7 @@ public final class TestFormatTrackingHSSFListener extends TestCase {
|
|||||||
|
|
||||||
// Now check we can turn all the numeric
|
// Now check we can turn all the numeric
|
||||||
// cells into strings without error
|
// cells into strings without error
|
||||||
for(int i=0; i<mockListen._records.size(); i++) {
|
for(Record r : mockListen._records) {
|
||||||
Record r = (Record)mockListen._records.get(i);
|
|
||||||
CellValueRecordInterface cvr = null;
|
CellValueRecordInterface cvr = null;
|
||||||
|
|
||||||
if(r instanceof NumberRecord) {
|
if(r instanceof NumberRecord) {
|
||||||
@ -106,7 +106,7 @@ public final class TestFormatTrackingHSSFListener extends TestCase {
|
|||||||
|
|
||||||
private static final class MockHSSFListener implements HSSFListener {
|
private static final class MockHSSFListener implements HSSFListener {
|
||||||
public MockHSSFListener() {}
|
public MockHSSFListener() {}
|
||||||
private final List _records = new ArrayList();
|
private final List<Record> _records = new ArrayList<Record>();
|
||||||
|
|
||||||
public void processRecord(Record record) {
|
public void processRecord(Record record) {
|
||||||
_records.add(record);
|
_records.add(record);
|
||||||
|
@ -17,21 +17,23 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record;
|
package org.apache.poi.hssf.record;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
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.hssf.record.common.UnicodeString;
|
||||||
import org.apache.poi.util.HexRead;
|
import org.apache.poi.util.HexRead;
|
||||||
import org.apache.poi.util.IntMapper;
|
import org.apache.poi.util.IntMapper;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exercise the SSTDeserializer class.
|
* Exercise the SSTDeserializer class.
|
||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public final class TestSSTDeserializer extends TestCase {
|
public final class TestSSTDeserializer {
|
||||||
private static final int FAKE_SID = -5555;
|
private static final int FAKE_SID = -5555;
|
||||||
|
|
||||||
private static byte[] concat(byte[] a, byte[] b) {
|
private static byte[] concat(byte[] a, byte[] b) {
|
||||||
@ -41,36 +43,36 @@ public final class TestSSTDeserializer extends TestCase {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] readSampleHexData(String sampleFileName, String sectionName, int recSid) {
|
private static byte[] readSampleHexData(String sampleFileName, String sectionName, int recSid)
|
||||||
|
throws IOException {
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
|
||||||
byte[] data;
|
byte[] data = HexRead.readData(is, sectionName);
|
||||||
try {
|
byte[] result = TestcaseRecordInputStream.mergeDataAndSid(recSid, data.length, data);
|
||||||
data = HexRead.readData(is, sectionName);
|
is.close();
|
||||||
} catch (IOException e) {
|
return result;
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
return TestcaseRecordInputStream.mergeDataAndSid(recSid, data.length, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSpanRichTextToPlainText() {
|
@Test
|
||||||
|
public void testSpanRichTextToPlainText() throws IOException {
|
||||||
byte[] header = readSampleHexData("richtextdata.txt", "header", FAKE_SID);
|
byte[] header = readSampleHexData("richtextdata.txt", "header", FAKE_SID);
|
||||||
byte[] continueBytes = readSampleHexData("richtextdata.txt", "continue1", ContinueRecord.sid);
|
byte[] continueBytes = readSampleHexData("richtextdata.txt", "continue1", ContinueRecord.sid);
|
||||||
RecordInputStream in = TestcaseRecordInputStream.create(concat(header, continueBytes));
|
RecordInputStream in = TestcaseRecordInputStream.create(concat(header, continueBytes));
|
||||||
|
|
||||||
|
|
||||||
IntMapper strings = new IntMapper();
|
IntMapper<UnicodeString> strings = new IntMapper<UnicodeString>();
|
||||||
SSTDeserializer deserializer = new SSTDeserializer( strings );
|
SSTDeserializer deserializer = new SSTDeserializer( strings );
|
||||||
deserializer.manufactureStrings(1, in );
|
deserializer.manufactureStrings(1, in );
|
||||||
|
|
||||||
assertEquals( "At a dinner party orAt At At ", strings.get( 0 ) + "" );
|
assertEquals( "At a dinner party orAt At At ", strings.get( 0 ) + "" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testContinuationWithNoOverlap() {
|
@Test
|
||||||
|
public void testContinuationWithNoOverlap() throws IOException {
|
||||||
byte[] header = readSampleHexData("evencontinuation.txt", "header", FAKE_SID);
|
byte[] header = readSampleHexData("evencontinuation.txt", "header", FAKE_SID);
|
||||||
byte[] continueBytes = readSampleHexData("evencontinuation.txt", "continue1", ContinueRecord.sid);
|
byte[] continueBytes = readSampleHexData("evencontinuation.txt", "continue1", ContinueRecord.sid);
|
||||||
RecordInputStream in = TestcaseRecordInputStream.create(concat(header, continueBytes));
|
RecordInputStream in = TestcaseRecordInputStream.create(concat(header, continueBytes));
|
||||||
|
|
||||||
IntMapper strings = new IntMapper();
|
IntMapper<UnicodeString> strings = new IntMapper<UnicodeString>();
|
||||||
SSTDeserializer deserializer = new SSTDeserializer( strings );
|
SSTDeserializer deserializer = new SSTDeserializer( strings );
|
||||||
deserializer.manufactureStrings( 2, in);
|
deserializer.manufactureStrings( 2, in);
|
||||||
|
|
||||||
@ -81,14 +83,15 @@ public final class TestSSTDeserializer extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* Strings can actually span across more than one continuation.
|
* Strings can actually span across more than one continuation.
|
||||||
*/
|
*/
|
||||||
public void testStringAcross2Continuations() {
|
@Test
|
||||||
|
public void testStringAcross2Continuations() throws IOException {
|
||||||
byte[] header = readSampleHexData("stringacross2continuations.txt", "header", FAKE_SID);
|
byte[] header = readSampleHexData("stringacross2continuations.txt", "header", FAKE_SID);
|
||||||
byte[] continue1 = readSampleHexData("stringacross2continuations.txt", "continue1", ContinueRecord.sid);
|
byte[] continue1 = readSampleHexData("stringacross2continuations.txt", "continue1", ContinueRecord.sid);
|
||||||
byte[] continue2 = readSampleHexData("stringacross2continuations.txt", "continue2", ContinueRecord.sid);
|
byte[] continue2 = readSampleHexData("stringacross2continuations.txt", "continue2", ContinueRecord.sid);
|
||||||
|
|
||||||
RecordInputStream in = TestcaseRecordInputStream.create(concat(header, concat(continue1, continue2)));
|
RecordInputStream in = TestcaseRecordInputStream.create(concat(header, concat(continue1, continue2)));
|
||||||
|
|
||||||
IntMapper strings = new IntMapper();
|
IntMapper<UnicodeString> strings = new IntMapper<UnicodeString>();
|
||||||
SSTDeserializer deserializer = new SSTDeserializer( strings );
|
SSTDeserializer deserializer = new SSTDeserializer( strings );
|
||||||
deserializer.manufactureStrings( 2, in);
|
deserializer.manufactureStrings( 2, in);
|
||||||
|
|
||||||
@ -96,12 +99,13 @@ public final class TestSSTDeserializer extends TestCase {
|
|||||||
assertEquals( "At a dinner partyAt a dinner party", strings.get( 1 ) + "" );
|
assertEquals( "At a dinner partyAt a dinner party", strings.get( 1 ) + "" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExtendedStrings() {
|
@Test
|
||||||
|
public void testExtendedStrings() throws IOException {
|
||||||
byte[] header = readSampleHexData("extendedtextstrings.txt", "rich-header", FAKE_SID);
|
byte[] header = readSampleHexData("extendedtextstrings.txt", "rich-header", FAKE_SID);
|
||||||
byte[] continueBytes = readSampleHexData("extendedtextstrings.txt", "rich-continue1", ContinueRecord.sid);
|
byte[] continueBytes = readSampleHexData("extendedtextstrings.txt", "rich-continue1", ContinueRecord.sid);
|
||||||
RecordInputStream in = TestcaseRecordInputStream.create(concat(header, continueBytes));
|
RecordInputStream in = TestcaseRecordInputStream.create(concat(header, continueBytes));
|
||||||
|
|
||||||
IntMapper strings = new IntMapper();
|
IntMapper<UnicodeString> strings = new IntMapper<UnicodeString>();
|
||||||
SSTDeserializer deserializer = new SSTDeserializer( strings );
|
SSTDeserializer deserializer = new SSTDeserializer( strings );
|
||||||
deserializer.manufactureStrings( 1, in);
|
deserializer.manufactureStrings( 1, in);
|
||||||
|
|
||||||
@ -112,7 +116,7 @@ public final class TestSSTDeserializer extends TestCase {
|
|||||||
continueBytes = readSampleHexData("extendedtextstrings.txt", "norich-continue1", ContinueRecord.sid);
|
continueBytes = readSampleHexData("extendedtextstrings.txt", "norich-continue1", ContinueRecord.sid);
|
||||||
in = TestcaseRecordInputStream.create(concat(header, continueBytes));
|
in = TestcaseRecordInputStream.create(concat(header, continueBytes));
|
||||||
|
|
||||||
strings = new IntMapper();
|
strings = new IntMapper<UnicodeString>();
|
||||||
deserializer = new SSTDeserializer( strings );
|
deserializer = new SSTDeserializer( strings );
|
||||||
deserializer.manufactureStrings( 1, in);
|
deserializer.manufactureStrings( 1, in);
|
||||||
|
|
||||||
|
@ -17,22 +17,22 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.aggregates;
|
package org.apache.poi.hssf.record.aggregates;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.ColumnInfoRecord;
|
import org.apache.poi.hssf.record.ColumnInfoRecord;
|
||||||
import org.apache.poi.hssf.record.Record;
|
import org.apache.poi.hssf.record.Record;
|
||||||
import org.apache.poi.hssf.record.RecordBase;
|
import org.apache.poi.hssf.record.RecordBase;
|
||||||
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
|
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
import junit.framework.AssertionFailedError;
|
||||||
* @author Glen Stampoultzis
|
|
||||||
*/
|
|
||||||
public final class TestColumnInfoRecordsAggregate extends TestCase {
|
|
||||||
|
|
||||||
|
public final class TestColumnInfoRecordsAggregate {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetRecordSize() {
|
public void testGetRecordSize() {
|
||||||
ColumnInfoRecordsAggregate agg = new ColumnInfoRecordsAggregate();
|
ColumnInfoRecordsAggregate agg = new ColumnInfoRecordsAggregate();
|
||||||
agg.insertColumn(createColInfo(1, 3));
|
agg.insertColumn(createColInfo(1, 3));
|
||||||
@ -64,23 +64,22 @@ public final class TestColumnInfoRecordsAggregate extends TestCase {
|
|||||||
|
|
||||||
private static final class CIRCollector implements RecordVisitor {
|
private static final class CIRCollector implements RecordVisitor {
|
||||||
|
|
||||||
private List _list;
|
private List<Record> _list = new ArrayList<Record>();
|
||||||
public CIRCollector() {
|
|
||||||
_list = new ArrayList();
|
|
||||||
}
|
|
||||||
public void visitRecord(Record r) {
|
public void visitRecord(Record r) {
|
||||||
_list.add(r);
|
_list.add(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ColumnInfoRecord[] getRecords(ColumnInfoRecordsAggregate agg) {
|
public static ColumnInfoRecord[] getRecords(ColumnInfoRecordsAggregate agg) {
|
||||||
CIRCollector circ = new CIRCollector();
|
CIRCollector circ = new CIRCollector();
|
||||||
agg.visitContainedRecords(circ);
|
agg.visitContainedRecords(circ);
|
||||||
List list = circ._list;
|
ColumnInfoRecord[] result =
|
||||||
ColumnInfoRecord[] result = new ColumnInfoRecord[list.size()];
|
circ._list.toArray(new ColumnInfoRecord[circ._list.size()]);
|
||||||
list.toArray(result);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGroupColumns_bug45639() {
|
public void testGroupColumns_bug45639() {
|
||||||
ColumnInfoRecordsAggregate agg = new ColumnInfoRecordsAggregate();
|
ColumnInfoRecordsAggregate agg = new ColumnInfoRecordsAggregate();
|
||||||
agg.groupColumnRange( 7, 9, true);
|
agg.groupColumnRange( 7, 9, true);
|
||||||
@ -102,6 +101,7 @@ public final class TestColumnInfoRecordsAggregate extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* Check that an inner group remains hidden
|
* Check that an inner group remains hidden
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testHiddenAfterExpanding() {
|
public void testHiddenAfterExpanding() {
|
||||||
ColumnInfoRecordsAggregate agg = new ColumnInfoRecordsAggregate();
|
ColumnInfoRecordsAggregate agg = new ColumnInfoRecordsAggregate();
|
||||||
agg.groupColumnRange(1, 15, true);
|
agg.groupColumnRange(1, 15, true);
|
||||||
@ -134,6 +134,7 @@ public final class TestColumnInfoRecordsAggregate extends TestCase {
|
|||||||
confirmCIR(cirs, 2, 13, 15, 1, true, false);
|
confirmCIR(cirs, 2, 13, 15, 1, true, false);
|
||||||
confirmCIR(cirs, 3, 16, 16, 0, false, true);
|
confirmCIR(cirs, 3, 16, 16, 0, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void confirmCIR(ColumnInfoRecord[] cirs, int ix, int startColIx, int endColIx, int level, boolean isHidden, boolean isCollapsed) {
|
private static void confirmCIR(ColumnInfoRecord[] cirs, int ix, int startColIx, int endColIx, int level, boolean isHidden, boolean isCollapsed) {
|
||||||
ColumnInfoRecord cir = cirs[ix];
|
ColumnInfoRecord cir = cirs[ix];
|
||||||
assertEquals("startColIx", startColIx, cir.getFirstColumn());
|
assertEquals("startColIx", startColIx, cir.getFirstColumn());
|
||||||
|
@ -17,56 +17,51 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.chart;
|
package org.apache.poi.hssf.record.chart;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import org.junit.runner.RunWith;
|
||||||
import junit.framework.TestSuite;
|
import org.junit.runners.Suite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects all tests for package <tt>org.apache.poi.hssf.record.class</tt>.
|
* Collects all tests for package <tt>org.apache.poi.hssf.record.class</tt>.
|
||||||
*
|
|
||||||
* @author Josh Micich
|
|
||||||
*/
|
*/
|
||||||
public final class AllChartRecordTests {
|
@RunWith(Suite.class)
|
||||||
|
@Suite.SuiteClasses({
|
||||||
public static Test suite() {
|
TestAreaFormatRecord.class,
|
||||||
TestSuite result = new TestSuite(AllChartRecordTests.class.getName());
|
TestAreaRecord.class,
|
||||||
|
TestAxisLineFormatRecord.class,
|
||||||
result.addTestSuite(TestAreaFormatRecord.class);
|
TestAxisOptionsRecord.class,
|
||||||
result.addTestSuite(TestAreaRecord.class);
|
TestAxisParentRecord.class,
|
||||||
result.addTestSuite(TestAxisLineFormatRecord.class);
|
TestAxisRecord.class,
|
||||||
result.addTestSuite(TestAxisOptionsRecord.class);
|
TestAxisUsedRecord.class,
|
||||||
result.addTestSuite(TestAxisParentRecord.class);
|
TestBarRecord.class,
|
||||||
result.addTestSuite(TestAxisRecord.class);
|
TestCategorySeriesAxisRecord.class,
|
||||||
result.addTestSuite(TestAxisUsedRecord.class);
|
TestChartFormatRecord.class,
|
||||||
result.addTestSuite(TestBarRecord.class);
|
TestChartRecord.class,
|
||||||
result.addTestSuite(TestCategorySeriesAxisRecord.class);
|
TestChartTitleFormatRecord.class,
|
||||||
result.addTestSuite(TestChartFormatRecord.class);
|
TestDatRecord.class,
|
||||||
result.addTestSuite(TestChartRecord.class);
|
TestDataFormatRecord.class,
|
||||||
result.addTestSuite(TestChartTitleFormatRecord.class);
|
TestDefaultDataLabelTextPropertiesRecord.class,
|
||||||
result.addTestSuite(TestDatRecord.class);
|
TestFontBasisRecord.class,
|
||||||
result.addTestSuite(TestDataFormatRecord.class);
|
TestFontIndexRecord.class,
|
||||||
result.addTestSuite(TestDefaultDataLabelTextPropertiesRecord.class);
|
TestFrameRecord.class,
|
||||||
result.addTestSuite(TestFontBasisRecord.class);
|
TestLegendRecord.class,
|
||||||
result.addTestSuite(TestFontIndexRecord.class);
|
TestLineFormatRecord.class,
|
||||||
result.addTestSuite(TestFrameRecord.class);
|
TestLinkedDataRecord.class,
|
||||||
result.addTestSuite(TestLegendRecord.class);
|
TestNumberFormatIndexRecord.class,
|
||||||
result.addTestSuite(TestLineFormatRecord.class);
|
TestObjectLinkRecord.class,
|
||||||
result.addTestSuite(TestLinkedDataRecord.class);
|
TestPlotAreaRecord.class,
|
||||||
result.addTestSuite(TestNumberFormatIndexRecord.class);
|
TestPlotGrowthRecord.class,
|
||||||
result.addTestSuite(TestObjectLinkRecord.class);
|
TestSeriesChartGroupIndexRecord.class,
|
||||||
result.addTestSuite(TestPlotAreaRecord.class);
|
TestSeriesIndexRecord.class,
|
||||||
result.addTestSuite(TestPlotGrowthRecord.class);
|
TestSeriesLabelsRecord.class,
|
||||||
result.addTestSuite(TestSeriesChartGroupIndexRecord.class);
|
TestSeriesListRecord.class,
|
||||||
result.addTestSuite(TestSeriesIndexRecord.class);
|
TestSeriesRecord.class,
|
||||||
result.addTestSuite(TestSeriesLabelsRecord.class);
|
TestSeriesTextRecord.class,
|
||||||
result.addTestSuite(TestSeriesListRecord.class);
|
TestSeriesToChartGroupRecord.class,
|
||||||
result.addTestSuite(TestSeriesRecord.class);
|
TestSheetPropertiesRecord.class,
|
||||||
result.addTestSuite(TestSeriesTextRecord.class);
|
TestTextRecord.class,
|
||||||
result.addTestSuite(TestSeriesToChartGroupRecord.class);
|
TestTickRecord.class,
|
||||||
result.addTestSuite(TestSheetPropertiesRecord.class);
|
TestUnitsRecord.class,
|
||||||
result.addTestSuite(TestTextRecord.class);
|
TestValueRangeRecord.class
|
||||||
result.addTestSuite(TestTickRecord.class);
|
})
|
||||||
result.addTestSuite(TestUnitsRecord.class);
|
public class AllChartRecordTests {
|
||||||
result.addTestSuite(TestValueRangeRecord.class);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,27 +17,27 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.chart;
|
package org.apache.poi.hssf.record.chart;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
|
import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
|
||||||
import org.apache.poi.hssf.eventusermodel.HSSFListener;
|
import org.apache.poi.hssf.eventusermodel.HSSFListener;
|
||||||
import org.apache.poi.hssf.eventusermodel.HSSFRequest;
|
import org.apache.poi.hssf.eventusermodel.HSSFRequest;
|
||||||
import org.apache.poi.hssf.record.Record;
|
import org.apache.poi.hssf.record.Record;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||||
/**
|
import org.junit.Test;
|
||||||
*
|
|
||||||
*/
|
|
||||||
public final class TestChartTitleFormatRecord extends TestCase {
|
|
||||||
|
|
||||||
|
public final class TestChartTitleFormatRecord {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRecord() throws Exception {
|
public void testRecord() throws Exception {
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(
|
NPOIFSFileSystem fs = new NPOIFSFileSystem(
|
||||||
HSSFTestDataSamples.openSampleFileStream("WithFormattedGraphTitle.xls"));
|
HSSFTestDataSamples.getSampleFile("WithFormattedGraphTitle.xls"));
|
||||||
|
|
||||||
// Check we can open the file via usermodel
|
// Check we can open the file via usermodel
|
||||||
HSSFWorkbook hssf = new HSSFWorkbook(fs);
|
HSSFWorkbook hssf = new HSSFWorkbook(fs);
|
||||||
@ -55,23 +55,24 @@ public final class TestChartTitleFormatRecord extends TestCase {
|
|||||||
// Should've found one
|
// Should've found one
|
||||||
assertEquals(1, grabber.chartTitleFormatRecords.size());
|
assertEquals(1, grabber.chartTitleFormatRecords.size());
|
||||||
// And it should be of something interesting
|
// And it should be of something interesting
|
||||||
ChartTitleFormatRecord r =
|
ChartTitleFormatRecord r = grabber.chartTitleFormatRecords.get(0);
|
||||||
(ChartTitleFormatRecord)grabber.chartTitleFormatRecords.get(0);
|
|
||||||
assertEquals(3, r.getFormatCount());
|
assertEquals(3, r.getFormatCount());
|
||||||
|
|
||||||
|
hssf.close();
|
||||||
|
fs.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class ChartTitleFormatRecordGrabber implements HSSFListener {
|
private static final class ChartTitleFormatRecordGrabber implements HSSFListener {
|
||||||
private final List chartTitleFormatRecords;
|
private final List<ChartTitleFormatRecord> chartTitleFormatRecords;
|
||||||
|
|
||||||
public ChartTitleFormatRecordGrabber() {
|
public ChartTitleFormatRecordGrabber() {
|
||||||
chartTitleFormatRecords = new ArrayList();
|
chartTitleFormatRecords = new ArrayList<ChartTitleFormatRecord>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processRecord(Record record) {
|
public void processRecord(Record record) {
|
||||||
if(record instanceof ChartTitleFormatRecord) {
|
if(record instanceof ChartTitleFormatRecord) {
|
||||||
chartTitleFormatRecords.add(
|
chartTitleFormatRecords.add((ChartTitleFormatRecord)record);
|
||||||
record
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,27 +19,75 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.apache.poi.hssf.model.InternalSheet;
|
import static org.junit.Assert.fail;
|
||||||
import org.apache.poi.hssf.model.InternalWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.*;
|
|
||||||
import org.apache.poi.hssf.record.aggregates.PageSettingsBlock;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.model.InternalSheet;
|
||||||
|
import org.apache.poi.hssf.model.InternalWorkbook;
|
||||||
|
import org.apache.poi.hssf.record.BOFRecord;
|
||||||
|
import org.apache.poi.hssf.record.BackupRecord;
|
||||||
|
import org.apache.poi.hssf.record.BookBoolRecord;
|
||||||
|
import org.apache.poi.hssf.record.BoundSheetRecord;
|
||||||
|
import org.apache.poi.hssf.record.CalcModeRecord;
|
||||||
|
import org.apache.poi.hssf.record.CodepageRecord;
|
||||||
|
import org.apache.poi.hssf.record.CountryRecord;
|
||||||
|
import org.apache.poi.hssf.record.DSFRecord;
|
||||||
|
import org.apache.poi.hssf.record.DateWindow1904Record;
|
||||||
|
import org.apache.poi.hssf.record.DefaultColWidthRecord;
|
||||||
|
import org.apache.poi.hssf.record.DefaultRowHeightRecord;
|
||||||
|
import org.apache.poi.hssf.record.DeltaRecord;
|
||||||
|
import org.apache.poi.hssf.record.DimensionsRecord;
|
||||||
|
import org.apache.poi.hssf.record.EOFRecord;
|
||||||
|
import org.apache.poi.hssf.record.ExtSSTRecord;
|
||||||
|
import org.apache.poi.hssf.record.ExtendedFormatRecord;
|
||||||
|
import org.apache.poi.hssf.record.ExternSheetRecord;
|
||||||
|
import org.apache.poi.hssf.record.FnGroupCountRecord;
|
||||||
|
import org.apache.poi.hssf.record.FontRecord;
|
||||||
|
import org.apache.poi.hssf.record.FormatRecord;
|
||||||
|
import org.apache.poi.hssf.record.GridsetRecord;
|
||||||
|
import org.apache.poi.hssf.record.GutsRecord;
|
||||||
|
import org.apache.poi.hssf.record.HideObjRecord;
|
||||||
|
import org.apache.poi.hssf.record.InterfaceEndRecord;
|
||||||
|
import org.apache.poi.hssf.record.InterfaceHdrRecord;
|
||||||
|
import org.apache.poi.hssf.record.IterationRecord;
|
||||||
|
import org.apache.poi.hssf.record.MMSRecord;
|
||||||
|
import org.apache.poi.hssf.record.NameRecord;
|
||||||
|
import org.apache.poi.hssf.record.PasswordRev4Record;
|
||||||
|
import org.apache.poi.hssf.record.PrecisionRecord;
|
||||||
|
import org.apache.poi.hssf.record.PrintGridlinesRecord;
|
||||||
|
import org.apache.poi.hssf.record.PrintHeadersRecord;
|
||||||
|
import org.apache.poi.hssf.record.ProtectRecord;
|
||||||
|
import org.apache.poi.hssf.record.Record;
|
||||||
|
import org.apache.poi.hssf.record.RecordBase;
|
||||||
|
import org.apache.poi.hssf.record.RefModeRecord;
|
||||||
|
import org.apache.poi.hssf.record.RefreshAllRecord;
|
||||||
|
import org.apache.poi.hssf.record.SSTRecord;
|
||||||
|
import org.apache.poi.hssf.record.SaveRecalcRecord;
|
||||||
|
import org.apache.poi.hssf.record.SelectionRecord;
|
||||||
|
import org.apache.poi.hssf.record.StyleRecord;
|
||||||
|
import org.apache.poi.hssf.record.SupBookRecord;
|
||||||
|
import org.apache.poi.hssf.record.TabIdRecord;
|
||||||
|
import org.apache.poi.hssf.record.UseSelFSRecord;
|
||||||
|
import org.apache.poi.hssf.record.WSBoolRecord;
|
||||||
|
import org.apache.poi.hssf.record.WindowOneRecord;
|
||||||
|
import org.apache.poi.hssf.record.WindowProtectRecord;
|
||||||
|
import org.apache.poi.hssf.record.WindowTwoRecord;
|
||||||
|
import org.apache.poi.hssf.record.WriteAccessRecord;
|
||||||
|
import org.apache.poi.hssf.record.aggregates.PageSettingsBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Designed to check wither the records written actually make sense.
|
* Designed to check wither the records written actually make sense.
|
||||||
*/
|
*/
|
||||||
public class SanityChecker
|
public class SanityChecker {
|
||||||
extends Assert
|
|
||||||
{
|
|
||||||
static class CheckRecord
|
static class CheckRecord
|
||||||
{
|
{
|
||||||
Class record;
|
Class<? extends RecordBase> record;
|
||||||
char occurance; // 1 = one time, M = 1..many times, * = 0..many, 0 = optional
|
char occurance; // 1 = one time, M = 1..many times, * = 0..many, 0 = optional
|
||||||
private boolean together;
|
private boolean together;
|
||||||
|
|
||||||
public CheckRecord( Class record, char occurance )
|
public CheckRecord( Class<? extends RecordBase> record, char occurance )
|
||||||
{
|
{
|
||||||
this(record, occurance, true);
|
this(record, occurance, true);
|
||||||
}
|
}
|
||||||
@ -49,14 +97,14 @@ public class SanityChecker
|
|||||||
* @param occurance The occurance 1 = occurs once, M = occurs many times
|
* @param occurance The occurance 1 = occurs once, M = occurs many times
|
||||||
* @param together
|
* @param together
|
||||||
*/
|
*/
|
||||||
public CheckRecord(Class record, char occurance, boolean together)
|
public CheckRecord(Class<? extends RecordBase> record, char occurance, boolean together)
|
||||||
{
|
{
|
||||||
this.record = record;
|
this.record = record;
|
||||||
this.occurance = occurance;
|
this.occurance = occurance;
|
||||||
this.together = together;
|
this.together = together;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getRecord()
|
public Class<? extends RecordBase> getRecord()
|
||||||
{
|
{
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
@ -86,7 +134,7 @@ public class SanityChecker
|
|||||||
return occurance == '*' || occurance == 'M';
|
return occurance == '*' || occurance == 'M';
|
||||||
}
|
}
|
||||||
|
|
||||||
public int match( List records, int recordIdx )
|
public int match( List<? extends RecordBase> records, int recordIdx )
|
||||||
{
|
{
|
||||||
int firstRecord = findFirstRecord(records, getRecord(), recordIdx);
|
int firstRecord = findFirstRecord(records, getRecord(), recordIdx);
|
||||||
if (isRequired())
|
if (isRequired())
|
||||||
@ -96,7 +144,7 @@ public class SanityChecker
|
|||||||
return matchOptional( firstRecord, records, recordIdx );
|
return matchOptional( firstRecord, records, recordIdx );
|
||||||
}
|
}
|
||||||
|
|
||||||
private int matchOptional( int firstRecord, List records, int recordIdx )
|
private int matchOptional( int firstRecord, List<? extends RecordBase> records, int recordIdx )
|
||||||
{
|
{
|
||||||
if (firstRecord == -1)
|
if (firstRecord == -1)
|
||||||
{
|
{
|
||||||
@ -106,7 +154,7 @@ public class SanityChecker
|
|||||||
return matchOneOrMany( records, firstRecord );
|
return matchOneOrMany( records, firstRecord );
|
||||||
}
|
}
|
||||||
|
|
||||||
private int matchRequired( int firstRecord, List records, int recordIdx )
|
private int matchRequired( int firstRecord, List<? extends RecordBase> records, int recordIdx )
|
||||||
{
|
{
|
||||||
if (firstRecord == -1)
|
if (firstRecord == -1)
|
||||||
{
|
{
|
||||||
@ -116,7 +164,7 @@ public class SanityChecker
|
|||||||
return matchOneOrMany( records, firstRecord );
|
return matchOneOrMany( records, firstRecord );
|
||||||
}
|
}
|
||||||
|
|
||||||
private int matchOneOrMany( List records, int recordIdx )
|
private int matchOneOrMany( List<? extends RecordBase> records, int recordIdx )
|
||||||
{
|
{
|
||||||
if (isZeroOrOne())
|
if (isZeroOrOne())
|
||||||
{
|
{
|
||||||
@ -210,7 +258,7 @@ public class SanityChecker
|
|||||||
|
|
||||||
private void checkWorkbookRecords(InternalWorkbook workbook)
|
private void checkWorkbookRecords(InternalWorkbook workbook)
|
||||||
{
|
{
|
||||||
List records = workbook.getRecords();
|
List<Record> records = workbook.getRecords();
|
||||||
assertTrue(records.get(0) instanceof BOFRecord);
|
assertTrue(records.get(0) instanceof BOFRecord);
|
||||||
assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
|
assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
|
||||||
|
|
||||||
@ -219,7 +267,7 @@ public class SanityChecker
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkSheetRecords(InternalSheet sheet) {
|
private void checkSheetRecords(InternalSheet sheet) {
|
||||||
List records = sheet.getRecords();
|
List<RecordBase> records = sheet.getRecords();
|
||||||
assertTrue(records.get(0) instanceof BOFRecord);
|
assertTrue(records.get(0) instanceof BOFRecord);
|
||||||
assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
|
assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
|
||||||
|
|
||||||
@ -266,7 +314,7 @@ public class SanityChecker
|
|||||||
}
|
}
|
||||||
} */
|
} */
|
||||||
|
|
||||||
/* package */ static int findFirstRecord( List records, Class record, int startIndex )
|
/* package */ static int findFirstRecord( List<? extends RecordBase> records, Class<? extends RecordBase> record, int startIndex )
|
||||||
{
|
{
|
||||||
for (int i = startIndex; i < records.size(); i++)
|
for (int i = startIndex; i < records.size(); i++)
|
||||||
{
|
{
|
||||||
@ -276,7 +324,7 @@ public class SanityChecker
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkRecordOrder(List records, CheckRecord[] check)
|
void checkRecordOrder(List<? extends RecordBase> records, CheckRecord[] check)
|
||||||
{
|
{
|
||||||
int recordIdx = 0;
|
int recordIdx = 0;
|
||||||
for ( int checkIdx = 0; checkIdx < check.length; checkIdx++ )
|
for ( int checkIdx = 0; checkIdx < check.length; checkIdx++ )
|
||||||
|
@ -17,29 +17,37 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.record.FormulaRecord;
|
import org.apache.poi.hssf.record.FormulaRecord;
|
||||||
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
|
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
|
||||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
|
||||||
import org.apache.poi.hssf.util.CellReference;
|
import org.apache.poi.hssf.util.CellReference;
|
||||||
|
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||||
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.ss.usermodel.CellValue;
|
import org.apache.poi.ss.usermodel.CellValue;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class TestBug42464 extends TestCase {
|
public final class TestBug42464 {
|
||||||
|
|
||||||
public void testOKFile() {
|
@Test
|
||||||
|
public void testOKFile() throws Exception {
|
||||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("42464-ExpPtg-ok.xls");
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("42464-ExpPtg-ok.xls");
|
||||||
process(wb);
|
process(wb);
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
public void testExpSharedBadFile() {
|
|
||||||
|
@Test
|
||||||
|
public void testExpSharedBadFile() throws Exception {
|
||||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("42464-ExpPtg-bad.xls");
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("42464-ExpPtg-bad.xls");
|
||||||
process(wb);
|
process(wb);
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void process(HSSFWorkbook wb) {
|
private static void process(HSSFWorkbook wb) {
|
||||||
@ -47,7 +55,7 @@ public final class TestBug42464 extends TestCase {
|
|||||||
for(int i=0; i<wb.getNumberOfSheets(); i++) {
|
for(int i=0; i<wb.getNumberOfSheets(); i++) {
|
||||||
HSSFSheet s = wb.getSheetAt(i);
|
HSSFSheet s = wb.getSheetAt(i);
|
||||||
|
|
||||||
Iterator it = s.rowIterator();
|
Iterator<Row> it = s.rowIterator();
|
||||||
while(it.hasNext()) {
|
while(it.hasNext()) {
|
||||||
HSSFRow r = (HSSFRow)it.next();
|
HSSFRow r = (HSSFRow)it.next();
|
||||||
process(r, eval);
|
process(r, eval);
|
||||||
@ -56,7 +64,7 @@ public final class TestBug42464 extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void process(HSSFRow row, HSSFFormulaEvaluator eval) {
|
private static void process(HSSFRow row, HSSFFormulaEvaluator eval) {
|
||||||
Iterator it = row.cellIterator();
|
Iterator<Cell> it = row.cellIterator();
|
||||||
while(it.hasNext()) {
|
while(it.hasNext()) {
|
||||||
HSSFCell cell = (HSSFCell)it.next();
|
HSSFCell cell = (HSSFCell)it.next();
|
||||||
if(cell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
|
if(cell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
|
||||||
@ -67,15 +75,15 @@ public final class TestBug42464 extends TestCase {
|
|||||||
Ptg[] ptgs = r.getParsedExpression();
|
Ptg[] ptgs = r.getParsedExpression();
|
||||||
|
|
||||||
String cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex(), false, false).formatAsString();
|
String cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex(), false, false).formatAsString();
|
||||||
if(false && cellRef.equals("BP24")) { // TODO - replace System.out.println()s with asserts
|
// if(false && cellRef.equals("BP24")) { // TODO - replace System.out.println()s with asserts
|
||||||
System.out.print(cellRef);
|
// System.out.print(cellRef);
|
||||||
System.out.println(" - has " + ptgs.length + " ptgs:");
|
// System.out.println(" - has " + ptgs.length + " ptgs:");
|
||||||
for(int i=0; i<ptgs.length; i++) {
|
// for(int i=0; i<ptgs.length; i++) {
|
||||||
String c = ptgs[i].getClass().toString();
|
// String c = ptgs[i].getClass().toString();
|
||||||
System.out.println("\t" + c.substring(c.lastIndexOf('.')+1) );
|
// System.out.println("\t" + c.substring(c.lastIndexOf('.')+1) );
|
||||||
}
|
// }
|
||||||
System.out.println("-> " + cell.getCellFormula());
|
// System.out.println("-> " + cell.getCellFormula());
|
||||||
}
|
// }
|
||||||
|
|
||||||
CellValue evalResult = eval.evaluate(cell);
|
CellValue evalResult = eval.evaluate(cell);
|
||||||
assertNotNull(evalResult);
|
assertNotNull(evalResult);
|
||||||
|
@ -17,26 +17,23 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFITestDataProvider;
|
import org.apache.poi.hssf.HSSFITestDataProvider;
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.eventmodel.ERFListener;
|
|
||||||
import org.apache.poi.hssf.eventmodel.EventRecordFactory;
|
|
||||||
import org.apache.poi.hssf.record.DVRecord;
|
import org.apache.poi.hssf.record.DVRecord;
|
||||||
import org.apache.poi.hssf.record.RecordFormatException;
|
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|
||||||
import org.apache.poi.ss.usermodel.BaseTestDataValidation;
|
import org.apache.poi.ss.usermodel.BaseTestDataValidation;
|
||||||
import org.apache.poi.ss.usermodel.DataValidation;
|
import org.apache.poi.ss.usermodel.DataValidation;
|
||||||
|
import org.apache.poi.ss.usermodel.DataValidation.ErrorStyle;
|
||||||
import org.apache.poi.ss.usermodel.DataValidationConstraint;
|
import org.apache.poi.ss.usermodel.DataValidationConstraint;
|
||||||
import org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType;
|
import org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType;
|
||||||
import org.apache.poi.ss.usermodel.DataValidationConstraint.ValidationType;
|
import org.apache.poi.ss.usermodel.DataValidationConstraint.ValidationType;
|
||||||
@ -45,10 +42,8 @@ import org.apache.poi.ss.usermodel.DateUtil;
|
|||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidation.ErrorStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType;
|
|
||||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for testing Excel's data validation mechanism
|
* Class for testing Excel's data validation mechanism
|
||||||
@ -73,11 +68,11 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
}
|
}
|
||||||
byte[] generatedContent = baos.toByteArray();
|
byte[] generatedContent = baos.toByteArray();
|
||||||
boolean isSame;
|
boolean isSame;
|
||||||
if (false) {
|
// if (false) {
|
||||||
// TODO - add proof spreadsheet and compare
|
// // TODO - add proof spreadsheet and compare
|
||||||
InputStream proofStream = HSSFTestDataSamples.openSampleFileStream("TestDataValidation.xls");
|
// InputStream proofStream = HSSFTestDataSamples.openSampleFileStream("TestDataValidation.xls");
|
||||||
isSame = compareStreams(proofStream, generatedContent);
|
// isSame = compareStreams(proofStream, generatedContent);
|
||||||
}
|
// }
|
||||||
isSame = true;
|
isSame = true;
|
||||||
|
|
||||||
if (isSame) {
|
if (isSame) {
|
||||||
@ -112,26 +107,26 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean compareStreams(InputStream isA, byte[] generatedContent) {
|
// private static boolean compareStreams(InputStream isA, byte[] generatedContent) {
|
||||||
|
//
|
||||||
InputStream isB = new ByteArrayInputStream(generatedContent);
|
// InputStream isB = new ByteArrayInputStream(generatedContent);
|
||||||
|
//
|
||||||
// The allowable regions where the generated file can differ from the
|
// // The allowable regions where the generated file can differ from the
|
||||||
// proof should be small (i.e. much less than 1K)
|
// // proof should be small (i.e. much less than 1K)
|
||||||
int[] allowableDifferenceRegions = {
|
// int[] allowableDifferenceRegions = {
|
||||||
0x0228, 16, // a region of the file containing the OS username
|
// 0x0228, 16, // a region of the file containing the OS username
|
||||||
0x506C, 8, // See RootProperty (super fields _seconds_2 and _days_2)
|
// 0x506C, 8, // See RootProperty (super fields _seconds_2 and _days_2)
|
||||||
};
|
// };
|
||||||
int[] diffs = StreamUtility.diffStreams(isA, isB, allowableDifferenceRegions);
|
// int[] diffs = StreamUtility.diffStreams(isA, isB, allowableDifferenceRegions);
|
||||||
if (diffs == null) {
|
// if (diffs == null) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
System.err.println("Diff from proof: ");
|
// System.err.println("Diff from proof: ");
|
||||||
for (int i = 0; i < diffs.length; i++) {
|
// for (int i = 0; i < diffs.length; i++) {
|
||||||
System.err.println("diff at offset: 0x" + Integer.toHexString(diffs[i]));
|
// System.err.println("diff at offset: 0x" + Integer.toHexString(diffs[i]));
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -142,7 +137,8 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddToExistingSheet() {
|
@Test
|
||||||
|
public void testAddToExistingSheet() throws Exception {
|
||||||
|
|
||||||
// dvEmpty.xls is a simple one sheet workbook. With a DataValidations header record but no
|
// dvEmpty.xls is a simple one sheet workbook. With a DataValidations header record but no
|
||||||
// DataValidations. It's important that the example has one SHEETPROTECTION record.
|
// DataValidations. It's important that the example has one SHEETPROTECTION record.
|
||||||
@ -164,27 +160,23 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
sheet.addValidationData(dv);
|
sheet.addValidationData(dv);
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
try {
|
|
||||||
wb.write(baos);
|
wb.write(baos);
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] wbData = baos.toByteArray();
|
byte[] wbData = baos.toByteArray();
|
||||||
|
|
||||||
if (false) { // TODO (Jul 2008) fix EventRecordFactory to process unknown records, (and DV records for that matter)
|
// if (false) { // TODO (Jul 2008) fix EventRecordFactory to process unknown records, (and DV records for that matter)
|
||||||
|
//
|
||||||
ERFListener erfListener = null; // new MyERFListener();
|
// ERFListener erfListener = null; // new MyERFListener();
|
||||||
EventRecordFactory erf = new EventRecordFactory(erfListener, null);
|
// EventRecordFactory erf = new EventRecordFactory(erfListener, null);
|
||||||
try {
|
// try {
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
|
// POIFSFileSystem fs = new POIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
|
||||||
erf.processRecords(fs.createDocumentInputStream("Workbook"));
|
// erf.processRecords(fs.createDocumentInputStream("Workbook"));
|
||||||
} catch (RecordFormatException e) {
|
// } catch (RecordFormatException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
// else verify record ordering by navigating the raw bytes
|
// else verify record ordering by navigating the raw bytes
|
||||||
|
|
||||||
byte[] dvHeaderRecStart= { (byte)0xB2, 0x01, 0x12, 0x00, };
|
byte[] dvHeaderRecStart= { (byte)0xB2, 0x01, 0x12, 0x00, };
|
||||||
@ -199,10 +191,13 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
// and the DV records, Excel will not be able to open the workbook without error.
|
// and the DV records, Excel will not be able to open the workbook without error.
|
||||||
|
|
||||||
if (nextSid == 0x0867) {
|
if (nextSid == 0x0867) {
|
||||||
throw new AssertionFailedError("Identified bug 45519");
|
fail("Identified bug 45519");
|
||||||
}
|
}
|
||||||
assertEquals(DVRecord.sid, nextSid);
|
assertEquals(DVRecord.sid, nextSid);
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int findIndex(byte[] largeData, byte[] searchPattern) {
|
private int findIndex(byte[] largeData, byte[] searchPattern) {
|
||||||
byte firstByte = searchPattern[0];
|
byte firstByte = searchPattern[0];
|
||||||
for (int i = 0; i < largeData.length; i++) {
|
for (int i = 0; i < largeData.length; i++) {
|
||||||
@ -223,7 +218,8 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetDataValidationsAny() {
|
@Test
|
||||||
|
public void testGetDataValidationsAny() throws Exception {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet();
|
HSSFSheet sheet = wb.createSheet();
|
||||||
List<HSSFDataValidation> list = sheet.getDataValidations();
|
List<HSSFDataValidation> list = sheet.getDataValidations();
|
||||||
@ -265,9 +261,12 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
DataValidationConstraint c = dv.getValidationConstraint();
|
DataValidationConstraint c = dv.getValidationConstraint();
|
||||||
assertEquals(ValidationType.ANY, c.getValidationType());
|
assertEquals(ValidationType.ANY, c.getValidationType());
|
||||||
assertEquals(OperatorType.IGNORED, c.getOperator());
|
assertEquals(OperatorType.IGNORED, c.getOperator());
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetDataValidationsIntegerFormula() {
|
@Test
|
||||||
|
public void testGetDataValidationsIntegerFormula() throws Exception {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet();
|
HSSFSheet sheet = wb.createSheet();
|
||||||
List<HSSFDataValidation> list = sheet.getDataValidations();
|
List<HSSFDataValidation> list = sheet.getDataValidations();
|
||||||
@ -291,9 +290,12 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
assertEquals("A3", c.getFormula2());
|
assertEquals("A3", c.getFormula2());
|
||||||
assertEquals(null, c.getValue1());
|
assertEquals(null, c.getValue1());
|
||||||
assertEquals(null, c.getValue2());
|
assertEquals(null, c.getValue2());
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetDataValidationsIntegerValue() {
|
@Test
|
||||||
|
public void testGetDataValidationsIntegerValue() throws Exception {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet();
|
HSSFSheet sheet = wb.createSheet();
|
||||||
List<HSSFDataValidation> list = sheet.getDataValidations();
|
List<HSSFDataValidation> list = sheet.getDataValidations();
|
||||||
@ -317,9 +319,12 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
assertEquals(null, c.getFormula2());
|
assertEquals(null, c.getFormula2());
|
||||||
assertEquals(new Double("100"), c.getValue1());
|
assertEquals(new Double("100"), c.getValue1());
|
||||||
assertEquals(new Double("200"), c.getValue2());
|
assertEquals(new Double("200"), c.getValue2());
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetDataValidationsDecimal() {
|
@Test
|
||||||
|
public void testGetDataValidationsDecimal() throws Exception {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet();
|
HSSFSheet sheet = wb.createSheet();
|
||||||
List<HSSFDataValidation> list = sheet.getDataValidations();
|
List<HSSFDataValidation> list = sheet.getDataValidations();
|
||||||
@ -343,9 +348,12 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
assertEquals(null, c.getFormula2());
|
assertEquals(null, c.getFormula2());
|
||||||
assertEquals(null, c.getValue1());
|
assertEquals(null, c.getValue1());
|
||||||
assertEquals(new Double("200"), c.getValue2());
|
assertEquals(new Double("200"), c.getValue2());
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetDataValidationsDate() {
|
@Test
|
||||||
|
public void testGetDataValidationsDate() throws Exception {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet();
|
HSSFSheet sheet = wb.createSheet();
|
||||||
List<HSSFDataValidation> list = sheet.getDataValidations();
|
List<HSSFDataValidation> list = sheet.getDataValidations();
|
||||||
@ -367,11 +375,14 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
assertEquals(OperatorType.EQUAL, c.getOperator());
|
assertEquals(OperatorType.EQUAL, c.getOperator());
|
||||||
assertEquals(null, c.getFormula1());
|
assertEquals(null, c.getFormula1());
|
||||||
assertEquals(null, c.getFormula2());
|
assertEquals(null, c.getFormula2());
|
||||||
assertEquals(DateUtil.getExcelDate(DateUtil.parseYYYYMMDDDate("2014/10/25")), c.getValue1());
|
assertEquals(DateUtil.getExcelDate(DateUtil.parseYYYYMMDDDate("2014/10/25")), c.getValue1(), 0);
|
||||||
assertEquals(null, c.getValue2());
|
assertEquals(null, c.getValue2());
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetDataValidationsListExplicit() {
|
@Test
|
||||||
|
public void testGetDataValidationsListExplicit() throws Exception {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet();
|
HSSFSheet sheet = wb.createSheet();
|
||||||
List<HSSFDataValidation> list = sheet.getDataValidations();
|
List<HSSFDataValidation> list = sheet.getDataValidations();
|
||||||
@ -402,9 +413,12 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
assertEquals("aaa", values[0]);
|
assertEquals("aaa", values[0]);
|
||||||
assertEquals("bbb", values[1]);
|
assertEquals("bbb", values[1]);
|
||||||
assertEquals("ccc", values[2]);
|
assertEquals("ccc", values[2]);
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetDataValidationsListFormula() {
|
@Test
|
||||||
|
public void testGetDataValidationsListFormula() throws Exception {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet();
|
HSSFSheet sheet = wb.createSheet();
|
||||||
List<HSSFDataValidation> list = sheet.getDataValidations();
|
List<HSSFDataValidation> list = sheet.getDataValidations();
|
||||||
@ -429,9 +443,12 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
assertEquals(null, c.getFormula2());
|
assertEquals(null, c.getFormula2());
|
||||||
assertEquals(null, c.getValue1());
|
assertEquals(null, c.getValue1());
|
||||||
assertEquals(null, c.getValue2());
|
assertEquals(null, c.getValue2());
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetDataValidationsFormula() {
|
@Test
|
||||||
|
public void testGetDataValidationsFormula() throws Exception {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet();
|
HSSFSheet sheet = wb.createSheet();
|
||||||
List<HSSFDataValidation> list = sheet.getDataValidations();
|
List<HSSFDataValidation> list = sheet.getDataValidations();
|
||||||
@ -453,5 +470,6 @@ public final class TestDataValidation extends BaseTestDataValidation {
|
|||||||
assertEquals(null, c.getFormula2());
|
assertEquals(null, c.getFormula2());
|
||||||
assertEquals(null, c.getValue1());
|
assertEquals(null, c.getValue1());
|
||||||
assertEquals(null, c.getValue2());
|
assertEquals(null, c.getValue2());
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,20 +17,21 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import java.io.File;
|
import static org.junit.Assert.assertEquals;
|
||||||
import java.io.FileOutputStream;
|
import static org.junit.Assert.assertTrue;
|
||||||
import java.io.IOException;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFITestDataProvider;
|
import org.apache.poi.hssf.HSSFITestDataProvider;
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
||||||
import org.apache.poi.hssf.record.NameRecord;
|
import org.apache.poi.hssf.record.NameRecord;
|
||||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
|
||||||
import org.apache.poi.ss.formula.FormulaType;
|
import org.apache.poi.ss.formula.FormulaType;
|
||||||
|
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||||
import org.apache.poi.ss.usermodel.BaseTestNamedRange;
|
import org.apache.poi.ss.usermodel.BaseTestNamedRange;
|
||||||
import org.apache.poi.ss.util.AreaReference;
|
import org.apache.poi.ss.util.AreaReference;
|
||||||
import org.apache.poi.util.TempFile;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests various functionality having to do with {@link org.apache.poi.ss.usermodel.Name}.
|
* Tests various functionality having to do with {@link org.apache.poi.ss.usermodel.Name}.
|
||||||
@ -65,7 +66,8 @@ public final class TestHSSFName extends BaseTestNamedRange {
|
|||||||
super(HSSFITestDataProvider.instance);
|
super(HSSFITestDataProvider.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRepeatingRowsAndColumsNames() {
|
@Test
|
||||||
|
public void testRepeatingRowsAndColumsNames() throws Exception {
|
||||||
// First test that setting RR&C for same sheet more than once only creates a
|
// First test that setting RR&C for same sheet more than once only creates a
|
||||||
// single Print_Titles built-in record
|
// single Print_Titles built-in record
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
@ -80,15 +82,16 @@ public final class TestHSSFName extends BaseTestNamedRange {
|
|||||||
HSSFName nr1 = wb.getNameAt(0);
|
HSSFName nr1 = wb.getNameAt(0);
|
||||||
|
|
||||||
assertEquals("Print_Titles", nr1.getNameName());
|
assertEquals("Print_Titles", nr1.getNameName());
|
||||||
if (false) {
|
// if (false) {
|
||||||
// TODO - full column references not rendering properly, absolute markers not present either
|
// // TODO - full column references not rendering properly, absolute markers not present either
|
||||||
assertEquals("FirstSheet!$A:$A,FirstSheet!$1:$3", nr1.getRefersToFormula());
|
// assertEquals("FirstSheet!$A:$A,FirstSheet!$1:$3", nr1.getRefersToFormula());
|
||||||
} else {
|
// } else {
|
||||||
assertEquals("FirstSheet!A:A,FirstSheet!$A$1:$IV$3", nr1.getRefersToFormula());
|
assertEquals("FirstSheet!A:A,FirstSheet!$A$1:$IV$3", nr1.getRefersToFormula());
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Save and re-open
|
// Save and re-open
|
||||||
HSSFWorkbook nwb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
HSSFWorkbook nwb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||||
|
wb.close();
|
||||||
|
|
||||||
assertEquals(1, nwb.getNumberOfNames());
|
assertEquals(1, nwb.getNumberOfNames());
|
||||||
nr1 = nwb.getNameAt(0);
|
nr1 = nwb.getNameAt(0);
|
||||||
@ -107,29 +110,31 @@ public final class TestHSSFName extends BaseTestNamedRange {
|
|||||||
assertEquals("Print_Titles", nr2.getNameName());
|
assertEquals("Print_Titles", nr2.getNameName());
|
||||||
assertEquals("SecondSheet!B:C,SecondSheet!$A$1:$IV$1", nr2.getRefersToFormula());
|
assertEquals("SecondSheet!B:C,SecondSheet!$A$1:$IV$1", nr2.getRefersToFormula());
|
||||||
|
|
||||||
if (false) {
|
// if (false) {
|
||||||
// In case you fancy checking in excel, to ensure it
|
// // In case you fancy checking in excel, to ensure it
|
||||||
// won't complain about the file now
|
// // won't complain about the file now
|
||||||
try {
|
// try {
|
||||||
File tempFile = TempFile.createTempFile("POI-45126-", ".xls");
|
// File tempFile = TempFile.createTempFile("POI-45126-", ".xls");
|
||||||
FileOutputStream fout = new FileOutputStream(tempFile);
|
// FileOutputStream fout = new FileOutputStream(tempFile);
|
||||||
nwb.write(fout);
|
// nwb.write(fout);
|
||||||
fout.close();
|
// fout.close();
|
||||||
System.out.println("check out " + tempFile.getAbsolutePath());
|
// System.out.println("check out " + tempFile.getAbsolutePath());
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
nwb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNamedRange() {
|
@Test
|
||||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("Simple.xls");
|
public void testNamedRange() throws Exception {
|
||||||
|
HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("Simple.xls");
|
||||||
|
|
||||||
//Creating new Named Range
|
//Creating new Named Range
|
||||||
HSSFName newNamedRange = wb.createName();
|
HSSFName newNamedRange = wb1.createName();
|
||||||
|
|
||||||
//Getting Sheet Name for the reference
|
//Getting Sheet Name for the reference
|
||||||
String sheetName = wb.getSheetName(0);
|
String sheetName = wb1.getSheetName(0);
|
||||||
|
|
||||||
//Setting its name
|
//Setting its name
|
||||||
newNamedRange.setNameName("RangeTest");
|
newNamedRange.setNameName("RangeTest");
|
||||||
@ -137,18 +142,20 @@ public final class TestHSSFName extends BaseTestNamedRange {
|
|||||||
newNamedRange.setRefersToFormula(sheetName + "!$D$4:$E$8");
|
newNamedRange.setRefersToFormula(sheetName + "!$D$4:$E$8");
|
||||||
|
|
||||||
//Getting NAmed Range
|
//Getting NAmed Range
|
||||||
HSSFName namedRange1 = wb.getNameAt(0);
|
HSSFName namedRange1 = wb1.getNameAt(0);
|
||||||
//Getting it sheet name
|
//Getting it sheet name
|
||||||
sheetName = namedRange1.getSheetName();
|
sheetName = namedRange1.getSheetName();
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
SanityChecker c = new SanityChecker();
|
SanityChecker c = new SanityChecker();
|
||||||
c.checkHSSFWorkbook(wb);
|
c.checkHSSFWorkbook(wb1);
|
||||||
|
|
||||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
|
||||||
HSSFName nm =wb.getNameAt(wb.getNameIndex("RangeTest"));
|
HSSFName nm = wb2.getNameAt(wb2.getNameIndex("RangeTest"));
|
||||||
assertTrue("Name is "+nm.getNameName(),"RangeTest".equals(nm.getNameName()));
|
assertTrue("Name is "+nm.getNameName(),"RangeTest".equals(nm.getNameName()));
|
||||||
assertEquals(wb.getSheetName(0)+"!$D$4:$E$8", nm.getRefersToFormula());
|
assertEquals(wb2.getSheetName(0)+"!$D$4:$E$8", nm.getRefersToFormula());
|
||||||
|
wb2.close();
|
||||||
|
wb1.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -156,7 +163,8 @@ public final class TestHSSFName extends BaseTestNamedRange {
|
|||||||
* <p>
|
* <p>
|
||||||
* Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=9632" target="_bug">#9632</a>
|
* Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=9632" target="_bug">#9632</a>
|
||||||
*/
|
*/
|
||||||
public void testNamedRead() {
|
@Test
|
||||||
|
public void testNamedRead() throws Exception {
|
||||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("namedinput.xls");
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("namedinput.xls");
|
||||||
|
|
||||||
//Get index of the named range with the name = "NamedRangeName" , which was defined in input.xls as A1:D10
|
//Get index of the named range with the name = "NamedRangeName" , which was defined in input.xls as A1:D10
|
||||||
@ -175,6 +183,8 @@ public final class TestHSSFName extends BaseTestNamedRange {
|
|||||||
|
|
||||||
assertEquals(sheetName+"!$D$17:$G$27", namedRange2.getRefersToFormula());
|
assertEquals(sheetName+"!$D$17:$G$27", namedRange2.getRefersToFormula());
|
||||||
assertEquals("SecondNamedRange", namedRange2.getNameName());
|
assertEquals("SecondNamedRange", namedRange2.getNameName());
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,7 +192,8 @@ public final class TestHSSFName extends BaseTestNamedRange {
|
|||||||
* <p>
|
* <p>
|
||||||
* Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=16411" target="_bug">#16411</a>
|
* Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=16411" target="_bug">#16411</a>
|
||||||
*/
|
*/
|
||||||
public void testNamedReadModify() {
|
@Test
|
||||||
|
public void testNamedReadModify() throws Exception {
|
||||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("namedinput.xls");
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("namedinput.xls");
|
||||||
|
|
||||||
HSSFName name = wb.getNameAt(0);
|
HSSFName name = wb.getNameAt(0);
|
||||||
@ -195,22 +206,26 @@ public final class TestHSSFName extends BaseTestNamedRange {
|
|||||||
|
|
||||||
name.setRefersToFormula(newReference);
|
name.setRefersToFormula(newReference);
|
||||||
assertEquals(newReference, name.getRefersToFormula());
|
assertEquals(newReference, name.getRefersToFormula());
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test to see if the print area can be retrieved from an excel created file
|
* Test to see if the print area can be retrieved from an excel created file
|
||||||
*/
|
*/
|
||||||
public void testPrintAreaFileRead() {
|
@Test
|
||||||
|
public void testPrintAreaFileRead() throws Exception {
|
||||||
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPrintArea.xls");
|
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPrintArea.xls");
|
||||||
|
|
||||||
String sheetName = workbook.getSheetName(0);
|
String sheetName = workbook.getSheetName(0);
|
||||||
String reference = sheetName+"!$A$1:$C$5";
|
String reference = sheetName+"!$A$1:$C$5";
|
||||||
|
|
||||||
assertEquals(reference, workbook.getPrintArea(0));
|
assertEquals(reference, workbook.getPrintArea(0));
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDeletedReference() {
|
public void testDeletedReference() throws Exception {
|
||||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("24207.xls");
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("24207.xls");
|
||||||
assertEquals(2, wb.getNumberOfNames());
|
assertEquals(2, wb.getNumberOfNames());
|
||||||
|
|
||||||
@ -230,6 +245,7 @@ public final class TestHSSFName extends BaseTestNamedRange {
|
|||||||
} catch (IllegalArgumentException e) { // TODO - use a stronger typed exception for this condition
|
} catch (IllegalArgumentException e) { // TODO - use a stronger typed exception for this condition
|
||||||
// expected during successful test
|
// expected during successful test
|
||||||
}
|
}
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -237,7 +253,8 @@ public final class TestHSSFName extends BaseTestNamedRange {
|
|||||||
* must set the type of operands to Ptg.CLASS_REF,
|
* must set the type of operands to Ptg.CLASS_REF,
|
||||||
* otherwise created named don't appear in the drop-down to the left of formula bar in Excel
|
* otherwise created named don't appear in the drop-down to the left of formula bar in Excel
|
||||||
*/
|
*/
|
||||||
public void testTypeOfRootPtg(){
|
@Test
|
||||||
|
public void testTypeOfRootPtg() throws Exception {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
wb.createSheet("CSCO");
|
wb.createSheet("CSCO");
|
||||||
|
|
||||||
@ -245,6 +262,6 @@ public final class TestHSSFName extends BaseTestNamedRange {
|
|||||||
for (int i = 0; i < ptgs.length; i++) {
|
for (int i = 0; i < ptgs.length; i++) {
|
||||||
assertEquals('R', ptgs[i].getRVAType());
|
assertEquals('R', ptgs[i].getRVAType());
|
||||||
}
|
}
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,12 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.BOFRecord;
|
import org.apache.poi.hssf.record.BOFRecord;
|
||||||
import org.apache.poi.hssf.record.BoundSheetRecord;
|
import org.apache.poi.hssf.record.BoundSheetRecord;
|
||||||
import org.apache.poi.hssf.record.EOFRecord;
|
import org.apache.poi.hssf.record.EOFRecord;
|
||||||
@ -31,6 +30,7 @@ import org.apache.poi.hssf.record.InterfaceHdrRecord;
|
|||||||
import org.apache.poi.hssf.record.NameRecord;
|
import org.apache.poi.hssf.record.NameRecord;
|
||||||
import org.apache.poi.hssf.record.Record;
|
import org.apache.poi.hssf.record.Record;
|
||||||
import org.apache.poi.hssf.usermodel.SanityChecker.CheckRecord;
|
import org.apache.poi.hssf.usermodel.SanityChecker.CheckRecord;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Test case for a test utility class.<br/>
|
* A Test case for a test utility class.<br/>
|
||||||
@ -38,11 +38,13 @@ import org.apache.poi.hssf.usermodel.SanityChecker.CheckRecord;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public final class TestSanityChecker extends TestCase {
|
public final class TestSanityChecker {
|
||||||
private static final Record INTERFACEHDR = new InterfaceHdrRecord(InterfaceHdrRecord.CODEPAGE);
|
private static final Record INTERFACEHDR = new InterfaceHdrRecord(InterfaceHdrRecord.CODEPAGE);
|
||||||
private static BoundSheetRecord createBoundSheetRec() {
|
private static BoundSheetRecord createBoundSheetRec() {
|
||||||
return new BoundSheetRecord("Sheet1");
|
return new BoundSheetRecord("Sheet1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCheckRecordOrder() {
|
public void testCheckRecordOrder() {
|
||||||
final SanityChecker c = new SanityChecker();
|
final SanityChecker c = new SanityChecker();
|
||||||
List<Record> records = new ArrayList<Record>();
|
List<Record> records = new ArrayList<Record>();
|
||||||
@ -119,17 +121,17 @@ public final class TestSanityChecker extends TestCase {
|
|||||||
}
|
}
|
||||||
private static void confirmBadRecordOrder(final SanityChecker.CheckRecord[] check, Record[] recs) {
|
private static void confirmBadRecordOrder(final SanityChecker.CheckRecord[] check, Record[] recs) {
|
||||||
final SanityChecker c = new SanityChecker();
|
final SanityChecker c = new SanityChecker();
|
||||||
final List records = Arrays.asList(recs);
|
final List<Record> records = Arrays.asList(recs);
|
||||||
try {
|
try {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
c.checkRecordOrder(records, check);
|
c.checkRecordOrder(records, check);
|
||||||
}
|
}
|
||||||
}.run();
|
}.run();
|
||||||
} catch (AssertionFailedError pass) {
|
} catch (AssertionError pass) {
|
||||||
// expected during normal test
|
// expected during normal test
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new AssertionFailedError("Did not get failure exception as expected");
|
fail("Did not get failure exception as expected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,31 +17,27 @@
|
|||||||
|
|
||||||
package org.apache.poi.poifs.storage;
|
package org.apache.poi.poifs.storage;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import org.junit.runner.RunWith;
|
||||||
import junit.framework.TestSuite;
|
import org.junit.runners.Suite;
|
||||||
/**
|
/**
|
||||||
* Tests for org.apache.poi.poifs.storage<br/>
|
* Tests for org.apache.poi.poifs.storage<br/>
|
||||||
*
|
|
||||||
* @author Josh Micich
|
|
||||||
*/
|
*/
|
||||||
public final class AllPOIFSStorageTests {
|
@RunWith(Suite.class)
|
||||||
|
@Suite.SuiteClasses({
|
||||||
public static Test suite() {
|
TestBATBlock.class,
|
||||||
TestSuite result = new TestSuite(AllPOIFSStorageTests.class.getName());
|
TestBlockAllocationTableReader.class,
|
||||||
result.addTestSuite(TestBATBlock.class);
|
TestBlockAllocationTableWriter.class,
|
||||||
result.addTestSuite(TestBlockAllocationTableReader.class);
|
TestBlockListImpl.class,
|
||||||
result.addTestSuite(TestBlockAllocationTableWriter.class);
|
TestDocumentBlock.class,
|
||||||
result.addTestSuite(TestBlockListImpl.class);
|
TestHeaderBlockReading.class,
|
||||||
result.addTestSuite(TestDocumentBlock.class);
|
TestHeaderBlockWriting.class,
|
||||||
result.addTestSuite(TestHeaderBlockReading.class);
|
TestPropertyBlock.class,
|
||||||
result.addTestSuite(TestHeaderBlockWriting.class);
|
TestRawDataBlock.class,
|
||||||
result.addTestSuite(TestPropertyBlock.class);
|
TestRawDataBlockList.class,
|
||||||
result.addTestSuite(TestRawDataBlock.class);
|
TestSmallBlockTableReader.class,
|
||||||
result.addTestSuite(TestRawDataBlockList.class);
|
TestSmallBlockTableWriter.class,
|
||||||
result.addTestSuite(TestSmallBlockTableReader.class);
|
TestSmallDocumentBlock.class,
|
||||||
result.addTestSuite(TestSmallBlockTableWriter.class);
|
TestSmallDocumentBlockList.class
|
||||||
result.addTestSuite(TestSmallDocumentBlock.class);
|
})
|
||||||
result.addTestSuite(TestSmallDocumentBlockList.class);
|
public class AllPOIFSStorageTests {
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,24 +17,26 @@
|
|||||||
|
|
||||||
package org.apache.poi.poifs.storage;
|
package org.apache.poi.poifs.storage;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
import org.apache.poi.poifs.common.POIFSConstants;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
import org.apache.poi.util.LittleEndianConsts;
|
import org.apache.poi.util.LittleEndianConsts;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to test BlockListImpl functionality
|
* Class to test BlockListImpl functionality
|
||||||
*
|
*
|
||||||
* @author Marc Johnson
|
* @author Marc Johnson
|
||||||
*/
|
*/
|
||||||
public final class TestBlockListImpl extends TestCase {
|
public final class TestBlockListImpl {
|
||||||
private static final class BlockListTestImpl extends BlockListImpl {
|
private static final class BlockListTestImpl extends BlockListImpl {
|
||||||
public BlockListTestImpl() {
|
public BlockListTestImpl() {
|
||||||
// no extra initialisation
|
// no extra initialisation
|
||||||
@ -44,6 +46,7 @@ public final class TestBlockListImpl extends TestCase {
|
|||||||
return new BlockListTestImpl();
|
return new BlockListTestImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testZap() throws IOException {
|
public void testZap() throws IOException {
|
||||||
BlockListImpl list = create();
|
BlockListImpl list = create();
|
||||||
|
|
||||||
@ -79,7 +82,7 @@ public final class TestBlockListImpl extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRemove() throws IOException {
|
public void testRemove() throws IOException {
|
||||||
BlockListImpl list = create();
|
BlockListImpl list = create();
|
||||||
RawDataBlock[] blocks = new RawDataBlock[ 5 ];
|
RawDataBlock[] blocks = new RawDataBlock[ 5 ];
|
||||||
@ -139,6 +142,7 @@ public final class TestBlockListImpl extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSetBAT() throws IOException {
|
public void testSetBAT() throws IOException {
|
||||||
BlockListImpl list = create();
|
BlockListImpl list = create();
|
||||||
|
|
||||||
@ -154,6 +158,7 @@ public final class TestBlockListImpl extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFetchBlocks() throws IOException {
|
public void testFetchBlocks() throws IOException {
|
||||||
|
|
||||||
// strategy:
|
// strategy:
|
||||||
@ -169,7 +174,7 @@ public final class TestBlockListImpl extends TestCase {
|
|||||||
// that includes a reserved (XBAT) block, and one that
|
// that includes a reserved (XBAT) block, and one that
|
||||||
// points off into space somewhere
|
// points off into space somewhere
|
||||||
BlockListImpl list = create();
|
BlockListImpl list = create();
|
||||||
List raw_blocks = new ArrayList();
|
List<RawDataBlock> raw_blocks = new ArrayList<RawDataBlock>();
|
||||||
byte[] data = new byte[ 512 ];
|
byte[] data = new byte[ 512 ];
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
@ -227,8 +232,7 @@ public final class TestBlockListImpl extends TestCase {
|
|||||||
raw_blocks.add(
|
raw_blocks.add(
|
||||||
new RawDataBlock(new ByteArrayInputStream(new byte[ 0 ])));
|
new RawDataBlock(new ByteArrayInputStream(new byte[ 0 ])));
|
||||||
}
|
}
|
||||||
list.setBlocks(( RawDataBlock [] ) raw_blocks
|
list.setBlocks(raw_blocks.toArray(new RawDataBlock[raw_blocks.size()]));
|
||||||
.toArray(new RawDataBlock[ 0 ]));
|
|
||||||
int[] blocks =
|
int[] blocks =
|
||||||
{
|
{
|
||||||
0
|
0
|
||||||
|
@ -17,26 +17,27 @@
|
|||||||
|
|
||||||
package org.apache.poi.poifs.storage;
|
package org.apache.poi.poifs.storage;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
import org.apache.poi.poifs.common.POIFSConstants;
|
||||||
|
import org.apache.poi.poifs.property.Property;
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to test PropertyBlock functionality
|
* Class to test PropertyBlock functionality
|
||||||
*
|
|
||||||
* @author Marc Johnson
|
|
||||||
*/
|
*/
|
||||||
public final class TestPropertyBlock extends TestCase {
|
public final class TestPropertyBlock {
|
||||||
|
|
||||||
public void testCreatePropertyBlocks() {
|
@Test
|
||||||
|
public void testCreatePropertyBlocks() throws Exception {
|
||||||
|
|
||||||
// test with 0 properties
|
// test with 0 properties
|
||||||
List properties = new ArrayList();
|
List<Property> properties = new ArrayList<Property>();
|
||||||
BlockWritable[] blocks =
|
BlockWritable[] blocks =
|
||||||
PropertyBlock.createPropertyBlockArray(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,properties);
|
PropertyBlock.createPropertyBlockArray(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,properties);
|
||||||
|
|
||||||
@ -181,22 +182,18 @@ public final class TestPropertyBlock extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void verifyCorrect(BlockWritable[] blocks, byte[] testblock) {
|
private static void verifyCorrect(BlockWritable[] blocks, byte[] testblock)
|
||||||
|
throws IOException {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream(512
|
ByteArrayOutputStream stream = new ByteArrayOutputStream(512
|
||||||
* blocks.length);
|
* blocks.length);
|
||||||
|
|
||||||
for (int j = 0; j < blocks.length; j++) {
|
for (BlockWritable b : blocks) {
|
||||||
try {
|
b.writeBlocks(stream);
|
||||||
blocks[ j ].writeBlocks(stream);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
byte[] output = stream.toByteArray();
|
byte[] output = stream.toByteArray();
|
||||||
|
|
||||||
assertEquals(testblock.length, output.length);
|
assertEquals(testblock.length, output.length);
|
||||||
for (int j = 0; j < testblock.length; j++)
|
for (int j = 0; j < testblock.length; j++) {
|
||||||
{
|
|
||||||
assertEquals("mismatch at offset " + j, testblock[ j ],
|
assertEquals("mismatch at offset " + j, testblock[ j ],
|
||||||
output[ j ]);
|
output[ j ]);
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,12 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.eval;
|
package org.apache.poi.ss.formula.eval;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
|
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
|
||||||
@ -31,31 +30,25 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
|
|||||||
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.usermodel.CellValue;
|
import org.apache.poi.ss.usermodel.CellValue;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Miscellaneous tests for bugzilla entries.<p/> The test name contains the
|
* Miscellaneous tests for bugzilla entries.<p/> The test name contains the
|
||||||
* bugzilla bug id.
|
* bugzilla bug id.
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author Josh Micich
|
|
||||||
*/
|
*/
|
||||||
public final class TestFormulaBugs extends TestCase {
|
public final class TestFormulaBugs {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 27349 - VLOOKUP with reference to another sheet.<p/> This test was
|
* Bug 27349 - VLOOKUP with reference to another sheet.<p/> This test was
|
||||||
* added <em>long</em> after the relevant functionality was fixed.
|
* added <em>long</em> after the relevant functionality was fixed.
|
||||||
*/
|
*/
|
||||||
public void test27349() {
|
@Test
|
||||||
|
public void test27349() throws Exception {
|
||||||
// 27349-vlookupAcrossSheets.xls is bugzilla/attachment.cgi?id=10622
|
// 27349-vlookupAcrossSheets.xls is bugzilla/attachment.cgi?id=10622
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream("27349-vlookupAcrossSheets.xls");
|
InputStream is = HSSFTestDataSamples.openSampleFileStream("27349-vlookupAcrossSheets.xls");
|
||||||
HSSFWorkbook wb;
|
// original bug may have thrown exception here,
|
||||||
try {
|
// or output warning to stderr
|
||||||
// original bug may have thrown exception here, or output warning to
|
HSSFWorkbook wb = new HSSFWorkbook(is);
|
||||||
// stderr
|
|
||||||
wb = new HSSFWorkbook(is);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
HSSFSheet sheet = wb.getSheetAt(0);
|
HSSFSheet sheet = wb.getSheetAt(0);
|
||||||
HSSFRow row = sheet.getRow(1);
|
HSSFRow row = sheet.getRow(1);
|
||||||
@ -71,6 +64,9 @@ public final class TestFormulaBugs extends TestCase {
|
|||||||
|
|
||||||
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
|
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
|
||||||
assertEquals(3.0, cv.getNumberValue(), 0.0);
|
assertEquals(3.0, cv.getNumberValue(), 0.0);
|
||||||
|
|
||||||
|
wb.close();
|
||||||
|
is.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,7 +74,8 @@ public final class TestFormulaBugs extends TestCase {
|
|||||||
*
|
*
|
||||||
* seems to be a duplicate of 24925
|
* seems to be a duplicate of 24925
|
||||||
*/
|
*/
|
||||||
public void test27405() {
|
@Test
|
||||||
|
public void test27405() throws Exception {
|
||||||
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet("input");
|
HSSFSheet sheet = wb.createSheet("input");
|
||||||
@ -99,16 +96,16 @@ public final class TestFormulaBugs extends TestCase {
|
|||||||
cell = row.createCell(3); // D5
|
cell = row.createCell(3); // D5
|
||||||
cell.setCellFormula("IF(ISNUMBER(b1),b1,b2)");
|
cell.setCellFormula("IF(ISNUMBER(b1),b1,b2)");
|
||||||
|
|
||||||
if (false) { // set true to check excel file manually
|
// if (false) { // set true to check excel file manually
|
||||||
// bug report mentions 'Editing the formula in excel "fixes" the problem.'
|
// // bug report mentions 'Editing the formula in excel "fixes" the problem.'
|
||||||
try {
|
// try {
|
||||||
FileOutputStream fileOut = new FileOutputStream("27405output.xls");
|
// FileOutputStream fileOut = new FileOutputStream("27405output.xls");
|
||||||
wb.write(fileOut);
|
// wb.write(fileOut);
|
||||||
fileOut.close();
|
// fileOut.close();
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// use POI's evaluator as an extra sanity check
|
// use POI's evaluator as an extra sanity check
|
||||||
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
||||||
@ -120,15 +117,17 @@ public final class TestFormulaBugs extends TestCase {
|
|||||||
cv = fe.evaluate(row.getCell(1));
|
cv = fe.evaluate(row.getCell(1));
|
||||||
assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, cv.getCellType());
|
assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, cv.getCellType());
|
||||||
assertEquals(true, cv.getBooleanValue());
|
assertEquals(true, cv.getBooleanValue());
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 42448 - Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69 <p/>
|
* Bug 42448 - Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69 <p/>
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void test42448() throws IOException {
|
public void test42448() throws IOException {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
try {
|
|
||||||
HSSFSheet sheet1 = wb.createSheet("Sheet1");
|
HSSFSheet sheet1 = wb.createSheet("Sheet1");
|
||||||
|
|
||||||
HSSFRow row = sheet1.createRow(0);
|
HSSFRow row = sheet1.createRow(0);
|
||||||
@ -145,7 +144,7 @@ public final class TestFormulaBugs extends TestCase {
|
|||||||
try {
|
try {
|
||||||
cell.setCellFormula(inputFormula);
|
cell.setCellFormula(inputFormula);
|
||||||
} catch (StringIndexOutOfBoundsException e) {
|
} catch (StringIndexOutOfBoundsException e) {
|
||||||
throw new AssertionFailedError("Identified bug 42448");
|
fail("Identified bug 42448");
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals("SUMPRODUCT(A!C7:A!C67,B8:B68)/B69", cell.getCellFormula());
|
assertEquals("SUMPRODUCT(A!C7:A!C67,B8:B68)/B69", cell.getCellFormula());
|
||||||
@ -169,10 +168,9 @@ public final class TestFormulaBugs extends TestCase {
|
|||||||
|
|
||||||
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
|
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
|
||||||
assertEquals(expectedResult, cv.getNumberValue(), 0.0);
|
assertEquals(expectedResult, cv.getNumberValue(), 0.0);
|
||||||
} finally {
|
|
||||||
wb.close();
|
wb.close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static void addCell(HSSFSheet sheet, int rowIx, int colIx,
|
private static void addCell(HSSFSheet sheet, int rowIx, int colIx,
|
||||||
double value) {
|
double value) {
|
||||||
|
@ -17,21 +17,17 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.function;
|
package org.apache.poi.ss.formula.function;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import org.junit.runner.RunWith;
|
||||||
import junit.framework.TestSuite;
|
import org.junit.runners.Suite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects all tests for this <tt>org.apache.poi.hssf.record.formula.function</tt>.
|
* Collects all tests for this <tt>org.apache.poi.hssf.record.formula.function</tt>.
|
||||||
*
|
|
||||||
* @author Josh Micich
|
|
||||||
*/
|
*/
|
||||||
|
@RunWith(Suite.class)
|
||||||
|
@Suite.SuiteClasses({
|
||||||
|
TestFunctionMetadataRegistry.class,
|
||||||
|
TestParseMissingBuiltInFuncs.class,
|
||||||
|
TestReadMissingBuiltInFuncs.class
|
||||||
|
})
|
||||||
public class AllFormulaFunctionTests {
|
public class AllFormulaFunctionTests {
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
TestSuite result = new TestSuite(AllFormulaFunctionTests.class.getName());
|
|
||||||
result.addTestSuite(TestFunctionMetadataRegistry.class);
|
|
||||||
result.addTestSuite(TestParseMissingBuiltInFuncs.class);
|
|
||||||
result.addTestSuite(TestReadMissingBuiltInFuncs.class);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -621,12 +621,12 @@ public final class ExcelFileFormatDocFunctionExtractor {
|
|||||||
|
|
||||||
File outFile = new File("functionMetadata-asGenerated.txt");
|
File outFile = new File("functionMetadata-asGenerated.txt");
|
||||||
|
|
||||||
if (false) { // set true to use local file
|
// if (false) { // set true to use local file
|
||||||
File dir = new File("c:/temp");
|
// File dir = new File("c:/temp");
|
||||||
File effDocFile = new File(dir, SOURCE_DOC_FILE_NAME);
|
// File effDocFile = new File(dir, SOURCE_DOC_FILE_NAME);
|
||||||
processFile(effDocFile, outFile);
|
// processFile(effDocFile, outFile);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
File tempEFFDocFile = downloadSourceFile();
|
File tempEFFDocFile = downloadSourceFile();
|
||||||
processFile(tempEFFDocFile, outFile);
|
processFile(tempEFFDocFile, outFile);
|
||||||
|
@ -17,28 +17,34 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.function;
|
package org.apache.poi.ss.formula.function;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import static org.junit.Assert.assertEquals;
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.ss.formula.ptg.AbstractFunctionPtg;
|
import org.apache.poi.ss.formula.ptg.AbstractFunctionPtg;
|
||||||
import org.apache.poi.ss.formula.ptg.FuncPtg;
|
import org.apache.poi.ss.formula.ptg.FuncPtg;
|
||||||
import org.apache.poi.ss.formula.ptg.FuncVarPtg;
|
import org.apache.poi.ss.formula.ptg.FuncVarPtg;
|
||||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import junit.framework.AssertionFailedError;
|
||||||
/**
|
/**
|
||||||
* Tests parsing of some built-in functions that were not properly
|
* Tests parsing of some built-in functions that were not properly
|
||||||
* registered in POI as of bug #44675, #44733 (March/April 2008).
|
* registered in POI as of bug #44675, #44733 (March/April 2008).
|
||||||
*
|
|
||||||
* @author Josh Micich
|
|
||||||
*/
|
*/
|
||||||
public final class TestParseMissingBuiltInFuncs extends TestCase {
|
public final class TestParseMissingBuiltInFuncs {
|
||||||
|
|
||||||
private static Ptg[] parse(String formula) {
|
private static Ptg[] parse(String formula) throws IOException {
|
||||||
HSSFWorkbook book = new HSSFWorkbook();
|
HSSFWorkbook book = new HSSFWorkbook();
|
||||||
return HSSFFormulaParser.parse(formula, book);
|
Ptg[] ptgs = HSSFFormulaParser.parse(formula, book);
|
||||||
|
book.close();
|
||||||
|
return ptgs;
|
||||||
}
|
}
|
||||||
private static void confirmFunc(String formula, int expPtgArraySize, boolean isVarArgFunc, int funcIx) {
|
|
||||||
|
private static void confirmFunc(String formula, int expPtgArraySize, boolean isVarArgFunc, int funcIx)
|
||||||
|
throws IOException {
|
||||||
Ptg[] ptgs = parse(formula);
|
Ptg[] ptgs = parse(formula);
|
||||||
Ptg ptgF = ptgs[ptgs.length-1]; // func is last RPN token in all these formulas
|
Ptg ptgF = ptgs[ptgs.length-1]; // func is last RPN token in all these formulas
|
||||||
|
|
||||||
@ -53,38 +59,49 @@ public final class TestParseMissingBuiltInFuncs extends TestCase {
|
|||||||
}
|
}
|
||||||
assertEquals(expPtgArraySize, ptgs.length);
|
assertEquals(expPtgArraySize, ptgs.length);
|
||||||
assertEquals(funcIx, func.getFunctionIndex());
|
assertEquals(funcIx, func.getFunctionIndex());
|
||||||
Class expCls = isVarArgFunc ? FuncVarPtg.class : FuncPtg.class;
|
Class<? extends AbstractFunctionPtg> expCls = isVarArgFunc ? FuncVarPtg.class : FuncPtg.class;
|
||||||
assertEquals(expCls, ptgF.getClass());
|
assertEquals(expCls, ptgF.getClass());
|
||||||
|
|
||||||
// check that parsed Ptg array converts back to formula text OK
|
// check that parsed Ptg array converts back to formula text OK
|
||||||
HSSFWorkbook book = new HSSFWorkbook();
|
HSSFWorkbook book = new HSSFWorkbook();
|
||||||
String reRenderedFormula = HSSFFormulaParser.toFormulaString(book, ptgs);
|
String reRenderedFormula = HSSFFormulaParser.toFormulaString(book, ptgs);
|
||||||
assertEquals(formula, reRenderedFormula);
|
assertEquals(formula, reRenderedFormula);
|
||||||
|
book.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDatedif() {
|
@Test
|
||||||
|
public void testDatedif() throws IOException {
|
||||||
int expSize = 4; // NB would be 5 if POI added tAttrVolatile properly
|
int expSize = 4; // NB would be 5 if POI added tAttrVolatile properly
|
||||||
confirmFunc("DATEDIF(NOW(),NOW(),\"d\")", expSize, false, 351);
|
confirmFunc("DATEDIF(NOW(),NOW(),\"d\")", expSize, false, 351);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDdb() {
|
@Test
|
||||||
|
public void testDdb() throws IOException {
|
||||||
confirmFunc("DDB(1,1,1,1,1)", 6, true, 144);
|
confirmFunc("DDB(1,1,1,1,1)", 6, true, 144);
|
||||||
}
|
}
|
||||||
public void testAtan() {
|
|
||||||
|
@Test
|
||||||
|
public void testAtan() throws IOException {
|
||||||
confirmFunc("ATAN(1)", 2, false, 18);
|
confirmFunc("ATAN(1)", 2, false, 18);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUsdollar() {
|
@Test
|
||||||
|
public void testUsdollar() throws IOException {
|
||||||
confirmFunc("USDOLLAR(1)", 2, true, 204);
|
confirmFunc("USDOLLAR(1)", 2, true, 204);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDBCS() {
|
@Test
|
||||||
|
public void testDBCS() throws IOException {
|
||||||
confirmFunc("DBCS(\"abc\")", 2, false, 215);
|
confirmFunc("DBCS(\"abc\")", 2, false, 215);
|
||||||
}
|
}
|
||||||
public void testIsnontext() {
|
|
||||||
|
@Test
|
||||||
|
public void testIsnontext() throws IOException {
|
||||||
confirmFunc("ISNONTEXT(\"abc\")", 2, false, 190);
|
confirmFunc("ISNONTEXT(\"abc\")", 2, false, 190);
|
||||||
}
|
}
|
||||||
public void testDproduct() {
|
|
||||||
|
@Test
|
||||||
|
public void testDproduct() throws IOException {
|
||||||
confirmFunc("DPRODUCT(C1:E5,\"HarvestYield\",G1:H2)", 4, false, 189);
|
confirmFunc("DPRODUCT(C1:E5,\"HarvestYield\",G1:H2)", 4, false, 189);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Suite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Direct tests for all implementors of <code>Function</code>.
|
||||||
|
*/
|
||||||
|
@RunWith(Suite.class)
|
||||||
|
@Suite.SuiteClasses({
|
||||||
|
TestCodeFunctionsFromSpreadsheet.class,
|
||||||
|
TestComplexFunctionsFromSpreadsheet.class,
|
||||||
|
TestDeltaFunctionsFromSpreadsheet.class,
|
||||||
|
TestDGetFunctionsFromSpreadsheet.class,
|
||||||
|
TestDStarFunctionsFromSpreadsheet.class,
|
||||||
|
TestFactDoubleFunctionsFromSpreadsheet.class,
|
||||||
|
TestFixedFunctionsFromSpreadsheet.class,
|
||||||
|
TestImaginaryFunctionsFromSpreadsheet.class,
|
||||||
|
TestImRealFunctionsFromSpreadsheet.class,
|
||||||
|
TestIndexFunctionFromSpreadsheet.class,
|
||||||
|
TestIndirectFunctionFromSpreadsheet.class,
|
||||||
|
TestLookupFunctionsFromSpreadsheet.class,
|
||||||
|
TestMatchFunctionsFromSpreadsheet.class,
|
||||||
|
TestQuotientFunctionsFromSpreadsheet.class,
|
||||||
|
TestReptFunctionsFromSpreadsheet.class,
|
||||||
|
TestRomanFunctionsFromSpreadsheet.class,
|
||||||
|
TestWeekNumFunctionsFromSpreadsheet.class,
|
||||||
|
TestWeekNumFunctionsFromSpreadsheet2013.class
|
||||||
|
})
|
||||||
|
public class AllSpreadsheetBasedTests {
|
||||||
|
}
|
@ -17,198 +17,102 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import java.util.ArrayList;
|
||||||
import junit.framework.AssertionFailedError;
|
import java.util.Collection;
|
||||||
import junit.framework.TestCase;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.ss.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
|
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||||
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.hssf.util.CellReference;
|
import org.apache.poi.hssf.util.CellReference;
|
||||||
|
import org.apache.poi.ss.formula.eval.ErrorEval;
|
||||||
import org.apache.poi.ss.usermodel.CellValue;
|
import org.apache.poi.ss.usermodel.CellValue;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
import org.junit.runners.Parameterized.Parameter;
|
||||||
|
|
||||||
/**
|
@RunWith(Parameterized.class)
|
||||||
*
|
public abstract class BaseTestFunctionsFromSpreadsheet {
|
||||||
*/
|
|
||||||
public abstract class BaseTestFunctionsFromSpreadsheet extends TestCase {
|
|
||||||
|
|
||||||
private static final class Result {
|
|
||||||
public static final int SOME_EVALUATIONS_FAILED = -1;
|
|
||||||
public static final int ALL_EVALUATIONS_SUCCEEDED = +1;
|
|
||||||
public static final int NO_EVALUATIONS_FOUND = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class defines constants for navigating around the test data spreadsheet used for these tests.
|
* This class defines constants for navigating around the test data spreadsheet used for these tests.
|
||||||
*/
|
*/
|
||||||
private static final class SS {
|
interface SS {
|
||||||
|
|
||||||
/** Name of the test spreadsheet (found in the standard test data folder) */
|
/** Name of the test spreadsheet (found in the standard test data folder) */
|
||||||
|
|
||||||
|
|
||||||
/** Name of the first sheet in the spreadsheet (contains comments) */
|
/** Name of the first sheet in the spreadsheet (contains comments) */
|
||||||
public final static String README_SHEET_NAME = "Read Me";
|
String README_SHEET_NAME = "Read Me";
|
||||||
|
|
||||||
/** Row (zero-based) in each sheet where the evaluation cases start. */
|
/** Row (zero-based) in each sheet where the evaluation cases start. */
|
||||||
public static final int START_TEST_CASES_ROW_INDEX = 4; // Row '5'
|
int START_TEST_CASES_ROW_INDEX = 4; // Row '5'
|
||||||
/** Index of the column that contains the function names */
|
/** Index of the column that contains the function names */
|
||||||
public static final int COLUMN_INDEX_MARKER = 0; // Column 'A'
|
int COLUMN_INDEX_MARKER = 0; // Column 'A'
|
||||||
public static final int COLUMN_INDEX_EVALUATION = 1; // Column 'B'
|
int COLUMN_INDEX_EVALUATION = 1; // Column 'B'
|
||||||
public static final int COLUMN_INDEX_EXPECTED_RESULT = 2; // Column 'C'
|
int COLUMN_INDEX_EXPECTED_RESULT = 2; // Column 'C'
|
||||||
public static final int COLUMN_ROW_COMMENT = 3; // Column 'D'
|
int COLUMN_ROW_COMMENT = 3; // Column 'D'
|
||||||
|
|
||||||
/** Used to indicate when there are no more test cases on the current sheet */
|
/** Used to indicate when there are no more test cases on the current sheet */
|
||||||
public static final String TEST_CASES_END_MARKER = "<end>";
|
String TEST_CASES_END_MARKER = "<end>";
|
||||||
/** Used to indicate that the test on the current row should be ignored */
|
/** Used to indicate that the test on the current row should be ignored */
|
||||||
public static final String SKIP_CURRENT_TEST_CASE_MARKER = "<skip>";
|
String SKIP_CURRENT_TEST_CASE_MARKER = "<skip>";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note - multiple failures are aggregated before ending.
|
@Parameter(value = 0)
|
||||||
// If one or more functions fail, a single AssertionFailedError is thrown at the end
|
public String testName;
|
||||||
private int _sheetFailureCount;
|
@Parameter(value = 1)
|
||||||
private int _sheetSuccessCount;
|
public String filename;
|
||||||
private int _evaluationFailureCount;
|
@Parameter(value = 2)
|
||||||
private int _evaluationSuccessCount;
|
public HSSFSheet sheet;
|
||||||
|
@Parameter(value = 3)
|
||||||
|
public int formulasRowIdx;
|
||||||
|
@Parameter(value = 4)
|
||||||
|
public HSSFFormulaEvaluator evaluator;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static void confirmExpectedResult(String msg, HSSFCell expected, CellValue actual) {
|
protected static Collection<Object[]> data(Class<? extends BaseTestFunctionsFromSpreadsheet> clazz, String filename) throws Exception {
|
||||||
if (expected == null) {
|
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook(filename);
|
||||||
throw new AssertionFailedError(msg + " - Bad setup data expected value is null");
|
confirmReadMeSheet(workbook, clazz);
|
||||||
}
|
|
||||||
if(actual == null) {
|
|
||||||
throw new AssertionFailedError(msg + " - actual value was null");
|
|
||||||
}
|
|
||||||
if(expected.getCellType() == HSSFCell.CELL_TYPE_ERROR) {
|
|
||||||
confirmErrorResult(msg, expected.getErrorCellValue(), actual);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(actual.getCellType() == HSSFCell.CELL_TYPE_ERROR) {
|
|
||||||
throw unexpectedError(msg, expected, actual.getErrorValue());
|
|
||||||
}
|
|
||||||
if(actual.getCellType() != expected.getCellType()) {
|
|
||||||
throw wrongTypeError(msg, expected, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
List<Object[]> data = new ArrayList<Object[]>();
|
||||||
|
|
||||||
switch (expected.getCellType()) {
|
|
||||||
case HSSFCell.CELL_TYPE_BOOLEAN:
|
|
||||||
assertEquals(msg, expected.getBooleanCellValue(), actual.getBooleanValue());
|
|
||||||
break;
|
|
||||||
case HSSFCell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
|
|
||||||
throw new IllegalStateException("Cannot expect formula as result of formula evaluation: " + msg);
|
|
||||||
case HSSFCell.CELL_TYPE_NUMERIC:
|
|
||||||
assertEquals(expected.getNumericCellValue(), actual.getNumberValue(), 0.0);
|
|
||||||
break;
|
|
||||||
case HSSFCell.CELL_TYPE_STRING:
|
|
||||||
assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getStringValue());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static AssertionFailedError wrongTypeError(String msgPrefix, HSSFCell expectedCell, CellValue actualValue) {
|
|
||||||
return new AssertionFailedError(msgPrefix + " Result type mismatch. Evaluated result was "
|
|
||||||
+ actualValue.formatAsString()
|
|
||||||
+ " but the expected result was "
|
|
||||||
+ formatValue(expectedCell)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
private static AssertionFailedError unexpectedError(String msgPrefix, HSSFCell expected, int actualErrorCode) {
|
|
||||||
return new AssertionFailedError(msgPrefix + " Error code ("
|
|
||||||
+ ErrorEval.getText(actualErrorCode)
|
|
||||||
+ ") was evaluated, but the expected result was "
|
|
||||||
+ formatValue(expected)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static void confirmErrorResult(String msgPrefix, int expectedErrorCode, CellValue actual) {
|
|
||||||
if(actual.getCellType() != HSSFCell.CELL_TYPE_ERROR) {
|
|
||||||
throw new AssertionFailedError(msgPrefix + " Expected cell error ("
|
|
||||||
+ ErrorEval.getText(expectedErrorCode) + ") but actual value was "
|
|
||||||
+ actual.formatAsString());
|
|
||||||
}
|
|
||||||
if(expectedErrorCode != actual.getErrorValue()) {
|
|
||||||
throw new AssertionFailedError(msgPrefix + " Expected cell error code ("
|
|
||||||
+ ErrorEval.getText(expectedErrorCode)
|
|
||||||
+ ") but actual error code was ("
|
|
||||||
+ ErrorEval.getText(actual.getErrorValue())
|
|
||||||
+ ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static String formatValue(HSSFCell expecedCell) {
|
|
||||||
switch (expecedCell.getCellType()) {
|
|
||||||
case HSSFCell.CELL_TYPE_BLANK: return "<blank>";
|
|
||||||
case HSSFCell.CELL_TYPE_BOOLEAN: return String.valueOf(expecedCell.getBooleanCellValue());
|
|
||||||
case HSSFCell.CELL_TYPE_NUMERIC: return String.valueOf(expecedCell.getNumericCellValue());
|
|
||||||
case HSSFCell.CELL_TYPE_STRING: return expecedCell.getRichStringCellValue().getString();
|
|
||||||
}
|
|
||||||
throw new RuntimeException("Unexpected cell type of expected value (" + expecedCell.getCellType() + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected void setUp() {
|
|
||||||
_sheetFailureCount = 0;
|
|
||||||
_sheetSuccessCount = 0;
|
|
||||||
_evaluationFailureCount = 0;
|
|
||||||
_evaluationSuccessCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testFunctionsFromTestSpreadsheet() {
|
|
||||||
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook(this.getFilename());
|
|
||||||
|
|
||||||
confirmReadMeSheet(workbook);
|
|
||||||
int nSheets = workbook.getNumberOfSheets();
|
int nSheets = workbook.getNumberOfSheets();
|
||||||
for(int i=1; i< nSheets; i++) {
|
for(int sheetIdx=1; sheetIdx< nSheets; sheetIdx++) {
|
||||||
int sheetResult = processTestSheet(workbook, i, workbook.getSheetName(i));
|
HSSFSheet sheet = workbook.getSheetAt(sheetIdx);
|
||||||
switch(sheetResult) {
|
processFunctionGroup(data, sheet, SS.START_TEST_CASES_ROW_INDEX, null, filename);
|
||||||
case Result.ALL_EVALUATIONS_SUCCEEDED: _sheetSuccessCount ++; break;
|
|
||||||
case Result.SOME_EVALUATIONS_FAILED: _sheetFailureCount ++; break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// confirm results
|
workbook.close();
|
||||||
String successMsg = "There were "
|
|
||||||
+ _sheetSuccessCount + " successful sheets(s) and "
|
return data;
|
||||||
+ _evaluationSuccessCount + " function(s) without error";
|
|
||||||
if(_sheetFailureCount > 0) {
|
|
||||||
String msg = _sheetFailureCount + " sheets(s) failed with "
|
|
||||||
+ _evaluationFailureCount + " evaluation(s). " + successMsg;
|
|
||||||
throw new AssertionFailedError(msg);
|
|
||||||
}
|
|
||||||
if(false) { // normally no output for successful tests
|
|
||||||
System.out.println(getClass().getName() + ": " + successMsg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String getFilename();
|
private static void processFunctionGroup(List<Object[]> data, HSSFSheet sheet, final int startRowIndex, String testFocusFunctionName, String filename) {
|
||||||
|
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet.getWorkbook());
|
||||||
|
|
||||||
private int processTestSheet(HSSFWorkbook workbook, int sheetIndex, String sheetName) {
|
String currentGroupComment = "";
|
||||||
HSSFSheet sheet = workbook.getSheetAt(sheetIndex);
|
final int maxRows = sheet.getLastRowNum()+1;
|
||||||
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(workbook);
|
for(int rowIndex=startRowIndex; rowIndex<maxRows; rowIndex++) {
|
||||||
int maxRows = sheet.getLastRowNum()+1;
|
|
||||||
int result = Result.NO_EVALUATIONS_FOUND; // so far
|
|
||||||
|
|
||||||
String currentGroupComment = null;
|
|
||||||
for(int rowIndex=SS.START_TEST_CASES_ROW_INDEX; rowIndex<maxRows; rowIndex++) {
|
|
||||||
HSSFRow r = sheet.getRow(rowIndex);
|
HSSFRow r = sheet.getRow(rowIndex);
|
||||||
String newMarkerValue = getMarkerColumnValue(r);
|
|
||||||
if(r == null) {
|
if(r == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
String newMarkerValue = getCellTextValue(r, SS.COLUMN_INDEX_MARKER, "marker");
|
||||||
if(SS.TEST_CASES_END_MARKER.equalsIgnoreCase(newMarkerValue)) {
|
if(SS.TEST_CASES_END_MARKER.equalsIgnoreCase(newMarkerValue)) {
|
||||||
// normal exit point
|
// normal exit point
|
||||||
return result;
|
return;
|
||||||
}
|
}
|
||||||
if(SS.SKIP_CURRENT_TEST_CASE_MARKER.equalsIgnoreCase(newMarkerValue)) {
|
if(SS.SKIP_CURRENT_TEST_CASE_MARKER.equalsIgnoreCase(newMarkerValue)) {
|
||||||
// currently disabled test case row
|
// currently disabled test case row
|
||||||
@ -217,66 +121,66 @@ public abstract class BaseTestFunctionsFromSpreadsheet extends TestCase {
|
|||||||
if(newMarkerValue != null) {
|
if(newMarkerValue != null) {
|
||||||
currentGroupComment = newMarkerValue;
|
currentGroupComment = newMarkerValue;
|
||||||
}
|
}
|
||||||
HSSFCell c = r.getCell(SS.COLUMN_INDEX_EVALUATION);
|
HSSFCell evalCell = r.getCell(SS.COLUMN_INDEX_EVALUATION);
|
||||||
if (c == null || c.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
|
if (evalCell == null || evalCell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
CellValue actualValue = evaluator.evaluate(c);
|
String rowComment = getCellTextValue(r, SS.COLUMN_ROW_COMMENT, "row comment");
|
||||||
HSSFCell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_RESULT);
|
|
||||||
String rowComment = getRowCommentColumnValue(r);
|
|
||||||
|
|
||||||
String msgPrefix = formatTestCaseDetails(this.getFilename(),sheetName, r.getRowNum(), c, currentGroupComment, rowComment);
|
String testName = (currentGroupComment+'\n'+rowComment).replace("null", "").trim().replace("\n", " - ");
|
||||||
try {
|
if ("".equals(testName)) {
|
||||||
confirmExpectedResult(msgPrefix, expectedValueCell, actualValue);
|
testName = evalCell.getCellFormula();
|
||||||
_evaluationSuccessCount ++;
|
|
||||||
if(result != Result.SOME_EVALUATIONS_FAILED) {
|
|
||||||
result = Result.ALL_EVALUATIONS_SUCCEEDED;
|
|
||||||
}
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
_evaluationFailureCount ++;
|
|
||||||
printShortStackTrace(System.err, e);
|
|
||||||
result = Result.SOME_EVALUATIONS_FAILED;
|
|
||||||
} catch (AssertionFailedError e) {
|
|
||||||
_evaluationFailureCount ++;
|
|
||||||
printShortStackTrace(System.err, e);
|
|
||||||
result = Result.SOME_EVALUATIONS_FAILED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.add(new Object[]{testName, filename, sheet, rowIndex, evaluator});
|
||||||
}
|
}
|
||||||
throw new RuntimeException("Missing end marker '" + SS.TEST_CASES_END_MARKER
|
fail("Missing end marker '" + SS.TEST_CASES_END_MARKER + "' on sheet '" + sheet.getSheetName() + "'");
|
||||||
+ "' on sheet '" + sheetName + "'");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void processFunctionRow() throws Exception {
|
||||||
|
HSSFRow r = sheet.getRow(formulasRowIdx);
|
||||||
|
HSSFCell evalCell = r.getCell(SS.COLUMN_INDEX_EVALUATION);
|
||||||
|
HSSFCell expectedCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_RESULT);
|
||||||
|
|
||||||
private static String formatTestCaseDetails(String filename, String sheetName, int rowIndex, HSSFCell c, String currentGroupComment,
|
CellReference cr = new CellReference(sheet.getSheetName(), formulasRowIdx, evalCell.getColumnIndex(), false, false);
|
||||||
String rowComment) {
|
String msg = String.format(Locale.ROOT, "In %s %s {=%s} '%s'"
|
||||||
|
, filename, cr.formatAsString(), evalCell.getCellFormula(), testName);
|
||||||
|
|
||||||
StringBuffer sb = new StringBuffer();
|
CellValue actualValue = evaluator.evaluate(evalCell);
|
||||||
|
|
||||||
sb.append("In ").append(filename).append(" ");
|
assertNotNull(msg + " - Bad setup data expected value is null", expectedCell);
|
||||||
|
assertNotNull(msg + " - actual value was null", actualValue);
|
||||||
|
|
||||||
CellReference cr = new CellReference(sheetName, rowIndex, c.getColumnIndex(), false, false);
|
if (expectedCell.getCellType() == HSSFCell.CELL_TYPE_ERROR) {
|
||||||
sb.append(cr.formatAsString());
|
int expectedErrorCode = expectedCell.getErrorCellValue();
|
||||||
sb.append(" {=").append(c.getCellFormula()).append("}");
|
assertEquals(msg, HSSFCell.CELL_TYPE_ERROR, actualValue.getCellType());
|
||||||
|
assertEquals(msg, ErrorEval.getText(expectedErrorCode), actualValue.formatAsString());
|
||||||
if(currentGroupComment != null) {
|
assertEquals(msg, expectedErrorCode, actualValue.getErrorValue());
|
||||||
sb.append(" '");
|
assertEquals(msg, ErrorEval.getText(expectedErrorCode), ErrorEval.getText(actualValue.getErrorValue()));
|
||||||
sb.append(currentGroupComment);
|
return;
|
||||||
if(rowComment != null) {
|
|
||||||
sb.append(" - ");
|
|
||||||
sb.append(rowComment);
|
|
||||||
}
|
|
||||||
sb.append("' ");
|
|
||||||
} else {
|
|
||||||
if(rowComment != null) {
|
|
||||||
sb.append(" '");
|
|
||||||
sb.append(rowComment);
|
|
||||||
sb.append("' ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString();
|
// unexpected error
|
||||||
|
assertNotEquals(msg, HSSFCell.CELL_TYPE_ERROR, actualValue.getCellType());
|
||||||
|
assertNotEquals(msg, formatValue(expectedCell), ErrorEval.getText(actualValue.getErrorValue()));
|
||||||
|
|
||||||
|
// wrong type error
|
||||||
|
assertEquals(msg, expectedCell.getCellType(), actualValue.getCellType());
|
||||||
|
|
||||||
|
switch (expectedCell.getCellType()) {
|
||||||
|
case HSSFCell.CELL_TYPE_BOOLEAN:
|
||||||
|
assertEquals(msg, expectedCell.getBooleanCellValue(), actualValue.getBooleanValue());
|
||||||
|
break;
|
||||||
|
case HSSFCell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
|
||||||
|
fail("Cannot expect formula as result of formula evaluation: " + msg);
|
||||||
|
case HSSFCell.CELL_TYPE_NUMERIC:
|
||||||
|
assertEquals(expectedCell.getNumericCellValue(), actualValue.getNumberValue(), 0.0);
|
||||||
|
break;
|
||||||
|
case HSSFCell.CELL_TYPE_STRING:
|
||||||
|
assertEquals(msg, expectedCell.getRichStringCellValue().getString(), actualValue.getStringValue());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -284,57 +188,13 @@ public abstract class BaseTestFunctionsFromSpreadsheet extends TestCase {
|
|||||||
* cells. This back-link is to make it easy to find this class if a reader encounters the
|
* cells. This back-link is to make it easy to find this class if a reader encounters the
|
||||||
* spreadsheet first.
|
* spreadsheet first.
|
||||||
*/
|
*/
|
||||||
private void confirmReadMeSheet(HSSFWorkbook workbook) {
|
private static void confirmReadMeSheet(HSSFWorkbook workbook, Class<? extends BaseTestFunctionsFromSpreadsheet> clazz) {
|
||||||
String firstSheetName = workbook.getSheetName(0);
|
String firstSheetName = workbook.getSheetName(0);
|
||||||
if(!firstSheetName.equalsIgnoreCase(SS.README_SHEET_NAME)) {
|
assertTrue("First sheet's name was '" + firstSheetName + "' but expected '" + SS.README_SHEET_NAME + "'",
|
||||||
throw new RuntimeException("First sheet's name was '" + firstSheetName + "' but expected '" + SS.README_SHEET_NAME + "'");
|
firstSheetName.equalsIgnoreCase(SS.README_SHEET_NAME));
|
||||||
}
|
|
||||||
HSSFSheet sheet = workbook.getSheetAt(0);
|
HSSFSheet sheet = workbook.getSheetAt(0);
|
||||||
String specifiedClassName = sheet.getRow(2).getCell(0).getRichStringCellValue().getString();
|
String specifiedClassName = sheet.getRow(2).getCell(0).getRichStringCellValue().getString();
|
||||||
assertEquals("Test class name in spreadsheet comment", getClass().getName(), specifiedClassName);
|
assertEquals("Test class name in spreadsheet comment", clazz.getName(), specifiedClassName);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Useful to keep output concise when expecting many failures to be reported by this test case
|
|
||||||
*/
|
|
||||||
private static void printShortStackTrace(PrintStream ps, Throwable e) {
|
|
||||||
StackTraceElement[] stes = e.getStackTrace();
|
|
||||||
|
|
||||||
int startIx = 0;
|
|
||||||
// skip any top frames inside junit.framework.Assert
|
|
||||||
while(startIx<stes.length) {
|
|
||||||
if(!stes[startIx].getClassName().equals(Assert.class.getName())) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
startIx++;
|
|
||||||
}
|
|
||||||
// skip bottom frames (part of junit framework)
|
|
||||||
int endIx = startIx+1;
|
|
||||||
while(endIx < stes.length) {
|
|
||||||
if(stes[endIx].getClassName().equals(TestCase.class.getName())) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
endIx++;
|
|
||||||
}
|
|
||||||
if(startIx >= endIx) {
|
|
||||||
// something went wrong. just print the whole stack trace
|
|
||||||
e.printStackTrace(ps);
|
|
||||||
}
|
|
||||||
endIx -= 4; // skip 4 frames of reflection invocation
|
|
||||||
ps.println(e.toString());
|
|
||||||
for(int i=startIx; i<endIx; i++) {
|
|
||||||
ps.println("\tat " + stes[i].toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getRowCommentColumnValue(HSSFRow r) {
|
|
||||||
return getCellTextValue(r, SS.COLUMN_ROW_COMMENT, "row comment");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getMarkerColumnValue(HSSFRow r) {
|
|
||||||
return getCellTextValue(r, SS.COLUMN_INDEX_MARKER, "marker");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -355,8 +215,21 @@ public abstract class BaseTestFunctionsFromSpreadsheet extends TestCase {
|
|||||||
return cell.getRichStringCellValue().getString();
|
return cell.getRichStringCellValue().getString();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new RuntimeException("Bad cell type for '" + columnName + "' column: ("
|
fail("Bad cell type for '" + columnName + "' column: ("
|
||||||
+ cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")");
|
+ cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")");
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String formatValue(HSSFCell expecedCell) {
|
||||||
|
switch (expecedCell.getCellType()) {
|
||||||
|
case HSSFCell.CELL_TYPE_BLANK: return "<blank>";
|
||||||
|
case HSSFCell.CELL_TYPE_BOOLEAN: return Boolean.toString(expecedCell.getBooleanCellValue());
|
||||||
|
case HSSFCell.CELL_TYPE_NUMERIC: return Double.toString(expecedCell.getNumericCellValue());
|
||||||
|
case HSSFCell.CELL_TYPE_STRING: return expecedCell.getRichStringCellValue().getString();
|
||||||
|
}
|
||||||
|
fail("Unexpected cell type of expected value (" + expecedCell.getCellType() + ")");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,15 +17,16 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests CODE() as loaded from a test data spreadsheet.<p/>
|
* Tests CODE() as loaded from a test data spreadsheet.<p/>
|
||||||
*
|
|
||||||
* @author cedric dot walter @ gmail dot com
|
|
||||||
*/
|
*/
|
||||||
public class TestCodeFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public class TestCodeFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
@Override
|
public static Collection<Object[]> data() throws Exception {
|
||||||
protected String getFilename() {
|
return data(TestCodeFunctionsFromSpreadsheet.class, "CodeFunctionTestCaseData.xls");
|
||||||
return "CodeFunctionTestCaseData.xls";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,15 +17,16 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests COMPLEX() as loaded from a test data spreadsheet.<p/>
|
* Tests COMPLEX() as loaded from a test data spreadsheet.<p/>
|
||||||
*
|
|
||||||
* @author cedric dot walter @ gmail dot com
|
|
||||||
*/
|
*/
|
||||||
public class TestComplexFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public class TestComplexFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
@Override
|
public static Collection<Object[]> data() throws Exception {
|
||||||
protected String getFilename() {
|
return data(TestComplexFunctionsFromSpreadsheet.class, "ComplexFunctionTestCaseData.xls");
|
||||||
return "ComplexFunctionTestCaseData.xls";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,12 +16,16 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests DGET() as loaded from a test data spreadsheet.
|
* Tests DGET() as loaded from a test data spreadsheet.
|
||||||
*/
|
*/
|
||||||
public class TestDGetFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public class TestDGetFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
protected String getFilename() {
|
public static Collection<Object[]> data() throws Exception {
|
||||||
return "DGet.xls";
|
return data(TestDGetFunctionsFromSpreadsheet.class, "DGet.xls");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,16 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests D*() functions as loaded from a test data spreadsheet.
|
* Tests D*() functions as loaded from a test data spreadsheet.
|
||||||
*/
|
*/
|
||||||
public class TestDStarFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public class TestDStarFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
protected String getFilename() {
|
public static Collection<Object[]> data() throws Exception {
|
||||||
return "DStar.xls";
|
return data(TestDStarFunctionsFromSpreadsheet.class, "DStar.xls");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,16 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests DELTA() as loaded from a test data spreadsheet.<p/>
|
* Tests DELTA() as loaded from a test data spreadsheet.<p/>
|
||||||
*
|
|
||||||
* @author cedric dot walter @ gmail dot com
|
|
||||||
*/
|
*/
|
||||||
public class TestDeltaFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public class TestDeltaFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
protected String getFilename() {
|
public static Collection<Object[]> data() throws Exception {
|
||||||
return "DeltaFunctionTestCaseData.xls";
|
return data(TestDeltaFunctionsFromSpreadsheet.class, "DeltaFunctionTestCaseData.xls");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,16 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests FactDouble() as loaded from a test data spreadsheet.<p/>
|
* Tests FactDouble() as loaded from a test data spreadsheet.<p/>
|
||||||
*
|
|
||||||
* @author cedric dot walter @ gmail dot com
|
|
||||||
*/
|
*/
|
||||||
public class TestFactDoubleFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public class TestFactDoubleFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
protected String getFilename() {
|
public static Collection<Object[]> data() throws Exception {
|
||||||
return "FactDoubleFunctionTestCaseData.xls";
|
return data(TestFactDoubleFunctionsFromSpreadsheet.class, "FactDoubleFunctionTestCaseData.xls");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,16 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests FIXED() as loaded from a test data spreadsheet.
|
* Tests FIXED() as loaded from a test data spreadsheet.
|
||||||
*/
|
*/
|
||||||
public class TestFixedFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public class TestFixedFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
@Override
|
public static Collection<Object[]> data() throws Exception {
|
||||||
protected String getFilename() {
|
return data(TestFixedFunctionsFromSpreadsheet.class, "57003-FixedFunctionTestCaseData.xls");
|
||||||
return "57003-FixedFunctionTestCaseData.xls";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,16 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests ImReal() as loaded from a test data spreadsheet.<p/>
|
* Tests ImReal() as loaded from a test data spreadsheet.<p/>
|
||||||
*
|
|
||||||
* @author cedric dot walter @ gmail dot com
|
|
||||||
*/
|
*/
|
||||||
public class TestImRealFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public class TestImRealFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
protected String getFilename() {
|
public static Collection<Object[]> data() throws Exception {
|
||||||
return "ImRealFunctionTestCaseData.xls";
|
return data(TestImRealFunctionsFromSpreadsheet.class, "ImRealFunctionTestCaseData.xls");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,16 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests Imaginary() as loaded from a test data spreadsheet.<p/>
|
* Tests Imaginary() as loaded from a test data spreadsheet.<p/>
|
||||||
*
|
|
||||||
* @author cedric dot walter @ gmail dot com
|
|
||||||
*/
|
*/
|
||||||
public class TestImaginaryFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public class TestImaginaryFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
protected String getFilename() {
|
public static Collection<Object[]> data() throws Exception {
|
||||||
return "ImaginaryFunctionTestCaseData.xls";
|
return data(TestImaginaryFunctionsFromSpreadsheet.class, "ImaginaryFunctionTestCaseData.xls");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,16 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests INDEX() as loaded from a test data spreadsheet.<p/>
|
* Tests INDEX() as loaded from a test data spreadsheet.<p/>
|
||||||
*/
|
*/
|
||||||
public final class TestIndexFunctionFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public final class TestIndexFunctionFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
@Override
|
public static Collection<Object[]> data() throws Exception {
|
||||||
protected String getFilename() {
|
return data(TestIndexFunctionFromSpreadsheet.class, "IndexFunctionTestCaseData.xls");
|
||||||
return "IndexFunctionTestCaseData.xls";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,10 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests INDIRECT() as loaded from a test data spreadsheet.<p/>
|
* Tests INDIRECT() as loaded from a test data spreadsheet.<p/>
|
||||||
*
|
*
|
||||||
@ -25,9 +29,8 @@ package org.apache.poi.ss.formula.functions;
|
|||||||
* more easily.
|
* more easily.
|
||||||
*/
|
*/
|
||||||
public final class TestIndirectFunctionFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public final class TestIndirectFunctionFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
@Override
|
public static Collection<Object[]> data() throws Exception {
|
||||||
protected String getFilename() {
|
return data(TestIndirectFunctionFromSpreadsheet.class, "IndirectFunctionTestCaseData.xls");
|
||||||
return "IndirectFunctionTestCaseData.xls";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests lookup functions (VLOOKUP, HLOOKUP, LOOKUP, MATCH) as loaded from a test data spreadsheet.<p/>
|
* Tests lookup functions (VLOOKUP, HLOOKUP, LOOKUP, MATCH) as loaded from a test data spreadsheet.<p/>
|
||||||
@ -29,9 +31,8 @@ package org.apache.poi.ss.formula.functions;
|
|||||||
* more easily.
|
* more easily.
|
||||||
*/
|
*/
|
||||||
public final class TestLookupFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public final class TestLookupFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
@Override
|
public static Collection<Object[]> data() throws Exception {
|
||||||
protected String getFilename() {
|
return data(TestLookupFunctionsFromSpreadsheet.class, "LookupFunctionsTestCaseData.xls");
|
||||||
return "LookupFunctionsTestCaseData.xls";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests Match functions as loaded from a test data spreadsheet.<p/>
|
* Tests Match functions as loaded from a test data spreadsheet.<p/>
|
||||||
@ -27,9 +29,8 @@ package org.apache.poi.ss.formula.functions;
|
|||||||
* more easily.
|
* more easily.
|
||||||
*/
|
*/
|
||||||
public final class TestMatchFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public final class TestMatchFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
@Override
|
public static Collection<Object[]> data() throws Exception {
|
||||||
protected String getFilename() {
|
return data(TestMatchFunctionsFromSpreadsheet.class, "MatchFunctionTestCaseData.xls");
|
||||||
return "MatchFunctionTestCaseData.xls";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,15 +17,16 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests QUOTIENT() as loaded from a test data spreadsheet.<p/>
|
* Tests QUOTIENT() as loaded from a test data spreadsheet.<p/>
|
||||||
*
|
|
||||||
* @author cedric dot walter @ gmail dot com
|
|
||||||
*/
|
*/
|
||||||
public class TestQuotientFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public class TestQuotientFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
@Override
|
public static Collection<Object[]> data() throws Exception {
|
||||||
protected String getFilename() {
|
return data(TestQuotientFunctionsFromSpreadsheet.class, "QuotientFunctionTestCaseData.xls");
|
||||||
return "QuotientFunctionTestCaseData.xls";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,15 +17,16 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests REPT() as loaded from a test data spreadsheet.<p/>
|
* Tests REPT() as loaded from a test data spreadsheet.<p/>
|
||||||
*
|
|
||||||
* @author cedric dot walter @ gmail dot com
|
|
||||||
*/
|
*/
|
||||||
public class TestReptFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public class TestReptFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
@Override
|
public static Collection<Object[]> data() throws Exception {
|
||||||
protected String getFilename() {
|
return data(TestReptFunctionsFromSpreadsheet.class, "ReptFunctionTestCaseData.xls");
|
||||||
return "ReptFunctionTestCaseData.xls";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,14 +17,16 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests Roman() as loaded from a test data spreadsheet.<p/>
|
* Tests Roman() as loaded from a test data spreadsheet.<p/>
|
||||||
*
|
|
||||||
* @author cedric dot walter @ gmail dot com
|
|
||||||
*/
|
*/
|
||||||
public class TestRomanFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public class TestRomanFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
protected String getFilename() {
|
public static Collection<Object[]> data() throws Exception {
|
||||||
return "RomanFunctionTestCaseData.xls";
|
return data(TestRomanFunctionsFromSpreadsheet.class, "RomanFunctionTestCaseData.xls");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,16 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests WeekNum() as loaded from a test data spreadsheet.<p/>
|
* Tests WeekNum() as loaded from a test data spreadsheet.<p/>
|
||||||
*
|
|
||||||
* @author cedric dot walter @ gmail dot com
|
|
||||||
*/
|
*/
|
||||||
public class TestWeekNumFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
public class TestWeekNumFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
protected String getFilename() {
|
public static Collection<Object[]> data() throws Exception {
|
||||||
return "WeekNumFunctionTestCaseData.xls";
|
return data(TestWeekNumFunctionsFromSpreadsheet.class, "WeekNumFunctionTestCaseData.xls");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,15 +17,17 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests WeekNum() as loaded from a test data 2013 excel spreadsheet.<p/>
|
* Tests WeekNum() as loaded from a test data 2013 excel spreadsheet.<p/>
|
||||||
*
|
|
||||||
* @author cedric dot walter @ gmail dot com
|
|
||||||
*/
|
*/
|
||||||
public class TestWeekNumFunctionsFromSpreadsheet2013 extends BaseTestFunctionsFromSpreadsheet {
|
public class TestWeekNumFunctionsFromSpreadsheet2013 extends BaseTestFunctionsFromSpreadsheet {
|
||||||
|
@Parameters(name="{0}")
|
||||||
protected String getFilename() {
|
public static Collection<Object[]> data() throws Exception {
|
||||||
//Only open this file with Excel 2013 to keep binary specific to that version
|
//Only open this file with Excel 2013 to keep binary specific to that version
|
||||||
return "WeekNumFunctionTestCaseData2013.xls";
|
return data(TestWeekNumFunctionsFromSpreadsheet2013.class, "WeekNumFunctionTestCaseData2013.xls");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.ptg;
|
package org.apache.poi.ss.formula.ptg;
|
||||||
|
|
||||||
import org.apache.poi.util.TempFile;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
||||||
@ -32,45 +26,53 @@ import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
|
|||||||
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.usermodel.CellValue;
|
import org.apache.poi.ss.usermodel.CellValue;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for functions from external workbooks (e.g. YEARFRAC).
|
* Tests for functions from external workbooks (e.g. YEARFRAC).
|
||||||
*/
|
*/
|
||||||
public final class TestExternalFunctionFormulas extends TestCase {
|
public final class TestExternalFunctionFormulas {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tests <tt>NameXPtg.toFormulaString(Workbook)</tt> and logic in Workbook below that
|
* tests <tt>NameXPtg.toFormulaString(Workbook)</tt> and logic in Workbook below that
|
||||||
*/
|
*/
|
||||||
public void testReadFormulaContainingExternalFunction() {
|
@Test
|
||||||
|
public void testReadFormulaContainingExternalFunction() throws Exception {
|
||||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
|
||||||
|
|
||||||
String expectedFormula = "YEARFRAC(B1,C1)";
|
String expectedFormula = "YEARFRAC(B1,C1)";
|
||||||
HSSFSheet sht = wb.getSheetAt(0);
|
HSSFSheet sht = wb.getSheetAt(0);
|
||||||
String cellFormula = sht.getRow(0).getCell(0).getCellFormula();
|
String cellFormula = sht.getRow(0).getCell(0).getCellFormula();
|
||||||
assertEquals(expectedFormula, cellFormula);
|
assertEquals(expectedFormula, cellFormula);
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParse() {
|
@Test
|
||||||
|
public void testParse() throws Exception {
|
||||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
|
||||||
Ptg[] ptgs = HSSFFormulaParser.parse("YEARFRAC(B1,C1)", wb);
|
Ptg[] ptgs = HSSFFormulaParser.parse("YEARFRAC(B1,C1)", wb);
|
||||||
assertEquals(4, ptgs.length);
|
assertEquals(4, ptgs.length);
|
||||||
assertEquals(NameXPtg.class, ptgs[0].getClass());
|
assertEquals(NameXPtg.class, ptgs[0].getClass());
|
||||||
|
|
||||||
wb.getSheetAt(0).getRow(0).createCell(6).setCellFormula("YEARFRAC(C1,B1)");
|
wb.getSheetAt(0).getRow(0).createCell(6).setCellFormula("YEARFRAC(C1,B1)");
|
||||||
if (false) {
|
// if (false) {
|
||||||
// In case you fancy checking in excel
|
// // In case you fancy checking in excel
|
||||||
try {
|
// try {
|
||||||
File tempFile = TempFile.createTempFile("testExtFunc", ".xls");
|
// File tempFile = TempFile.createTempFile("testExtFunc", ".xls");
|
||||||
FileOutputStream fout = new FileOutputStream(tempFile);
|
// FileOutputStream fout = new FileOutputStream(tempFile);
|
||||||
wb.write(fout);
|
// wb.write(fout);
|
||||||
fout.close();
|
// fout.close();
|
||||||
System.out.println("check out " + tempFile.getAbsolutePath());
|
// System.out.println("check out " + tempFile.getAbsolutePath());
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEvaluate() {
|
@Test
|
||||||
|
public void testEvaluate() throws Exception {
|
||||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
|
||||||
HSSFSheet sheet = wb.getSheetAt(0);
|
HSSFSheet sheet = wb.getSheetAt(0);
|
||||||
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
||||||
@ -79,6 +81,7 @@ public final class TestExternalFunctionFormulas extends TestCase {
|
|||||||
confirmCellEval(sheet, 2, 0, fe, "YEARFRAC(B3,C3,D3)", 0.0);
|
confirmCellEval(sheet, 2, 0, fe, "YEARFRAC(B3,C3,D3)", 0.0);
|
||||||
confirmCellEval(sheet, 3, 0, fe, "IF(ISEVEN(3),1.2,1.6)", 1.6);
|
confirmCellEval(sheet, 3, 0, fe, "IF(ISEVEN(3),1.2,1.6)", 1.6);
|
||||||
confirmCellEval(sheet, 4, 0, fe, "IF(ISODD(3),1.2,1.6)", 1.2);
|
confirmCellEval(sheet, 4, 0, fe, "IF(ISODD(3),1.2,1.6)", 1.2);
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void confirmCellEval(HSSFSheet sheet, int rowIx, int colIx,
|
private static void confirmCellEval(HSSFSheet sheet, int rowIx, int colIx,
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.usermodel;
|
package org.apache.poi.ss.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.ss.ITestDataProvider;
|
import org.apache.poi.ss.ITestDataProvider;
|
||||||
import org.apache.poi.ss.usermodel.DataValidation.ErrorStyle;
|
import org.apache.poi.ss.usermodel.DataValidation.ErrorStyle;
|
||||||
import org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType;
|
import org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType;
|
||||||
@ -27,13 +25,14 @@ import org.apache.poi.ss.util.CellRangeAddress;
|
|||||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for testing Excel's data validation mechanism
|
* Class for testing Excel's data validation mechanism
|
||||||
*
|
*
|
||||||
* @author Dragos Buleandra ( dragos.buleandra@trade2b.ro )
|
* @author Dragos Buleandra ( dragos.buleandra@trade2b.ro )
|
||||||
*/
|
*/
|
||||||
public abstract class BaseTestDataValidation extends TestCase {
|
public abstract class BaseTestDataValidation {
|
||||||
private final ITestDataProvider _testDataProvider;
|
private final ITestDataProvider _testDataProvider;
|
||||||
|
|
||||||
private static final POILogger log = POILogFactory.getLogger(BaseTestDataValidation.class);
|
private static final POILogger log = POILogFactory.getLogger(BaseTestDataValidation.class);
|
||||||
@ -465,7 +464,8 @@ public abstract class BaseTestDataValidation extends TestCase {
|
|||||||
va.addValidation(OperatorType.LESS_OR_EQUAL, "4", null, ErrorStyle.STOP, "Less than or equal to 4", "-", false, true, false);
|
va.addValidation(OperatorType.LESS_OR_EQUAL, "4", null, ErrorStyle.STOP, "Less than or equal to 4", "-", false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDataValidation() {
|
@Test
|
||||||
|
public void testDataValidation() throws Exception {
|
||||||
log("\nTest no. 2 - Test Excel's Data validation mechanism");
|
log("\nTest no. 2 - Test Excel's Data validation mechanism");
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
WorkbookFormatter wf = new WorkbookFormatter(wb);
|
WorkbookFormatter wf = new WorkbookFormatter(wb);
|
||||||
@ -491,7 +491,9 @@ public abstract class BaseTestDataValidation extends TestCase {
|
|||||||
addCustomValidations(wf);
|
addCustomValidations(wf);
|
||||||
log("done !");
|
log("done !");
|
||||||
|
|
||||||
wb = _testDataProvider.writeOutAndReadBack(wb);
|
_testDataProvider.writeOutAndReadBack(wb).close();
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,19 +17,24 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.usermodel;
|
package org.apache.poi.ss.usermodel;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import static org.junit.Assert.assertEquals;
|
||||||
import junit.framework.TestCase;
|
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 static org.junit.Assert.fail;
|
||||||
|
|
||||||
import org.apache.poi.ss.ITestDataProvider;
|
import org.apache.poi.ss.ITestDataProvider;
|
||||||
import org.apache.poi.ss.util.AreaReference;
|
import org.apache.poi.ss.util.AreaReference;
|
||||||
import org.apache.poi.ss.util.CellReference;
|
import org.apache.poi.ss.util.CellReference;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of implementations of {@link org.apache.poi.ss.usermodel.Name}.
|
* Tests of implementations of {@link org.apache.poi.ss.usermodel.Name}.
|
||||||
*
|
*
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public abstract class BaseTestNamedRange extends TestCase {
|
public abstract class BaseTestNamedRange {
|
||||||
|
|
||||||
private final ITestDataProvider _testDataProvider;
|
private final ITestDataProvider _testDataProvider;
|
||||||
|
|
||||||
@ -37,11 +42,12 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
_testDataProvider = testDataProvider;
|
_testDataProvider = testDataProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void testCreate(){
|
@Test
|
||||||
|
public final void testCreate() throws Exception {
|
||||||
// Create a new workbook
|
// Create a new workbook
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
Sheet sheet1 = wb.createSheet("Test1");
|
wb.createSheet("Test1");
|
||||||
Sheet sheet2 = wb.createSheet("Testing Named Ranges");
|
wb.createSheet("Testing Named Ranges");
|
||||||
|
|
||||||
Name name1 = wb.createName();
|
Name name1 = wb.createName();
|
||||||
name1.setNameName("testOne");
|
name1.setNameName("testOne");
|
||||||
@ -101,24 +107,31 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
// expected during successful test
|
// expected during successful test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void testUnicodeNamedRange() {
|
@Test
|
||||||
Workbook workBook = _testDataProvider.createWorkbook();
|
public final void testUnicodeNamedRange() throws Exception {
|
||||||
workBook.createSheet("Test");
|
Workbook wb1 = _testDataProvider.createWorkbook();
|
||||||
Name name = workBook.createName();
|
wb1.createSheet("Test");
|
||||||
|
Name name = wb1.createName();
|
||||||
name.setNameName("\u03B1");
|
name.setNameName("\u03B1");
|
||||||
name.setRefersToFormula("Test!$D$3:$E$8");
|
name.setRefersToFormula("Test!$D$3:$E$8");
|
||||||
|
|
||||||
|
|
||||||
Workbook workBook2 = _testDataProvider.writeOutAndReadBack(workBook);
|
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
|
||||||
Name name2 = workBook2.getNameAt(0);
|
Name name2 = wb2.getNameAt(0);
|
||||||
|
|
||||||
assertEquals("\u03B1", name2.getNameName());
|
assertEquals("\u03B1", name2.getNameName());
|
||||||
assertEquals("Test!$D$3:$E$8", name2.getRefersToFormula());
|
assertEquals("Test!$D$3:$E$8", name2.getRefersToFormula());
|
||||||
|
|
||||||
|
wb2.close();
|
||||||
|
wb1.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void testAddRemove() {
|
@Test
|
||||||
|
public final void testAddRemove() throws Exception {
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
assertEquals(0, wb.getNumberOfNames());
|
assertEquals(0, wb.getNumberOfNames());
|
||||||
Name name1 = wb.createName();
|
Name name1 = wb.createName();
|
||||||
@ -138,9 +151,12 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
|
|
||||||
wb.removeName(0);
|
wb.removeName(0);
|
||||||
assertEquals(1, wb.getNumberOfNames());
|
assertEquals(1, wb.getNumberOfNames());
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void testScope() {
|
@Test
|
||||||
|
public final void testScope() throws Exception {
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
wb.createSheet();
|
wb.createSheet();
|
||||||
wb.createSheet();
|
wb.createSheet();
|
||||||
@ -186,6 +202,8 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
if("aaa".equals(wb.getNameAt(i).getNameName())) cnt++;
|
if("aaa".equals(wb.getNameAt(i).getNameName())) cnt++;
|
||||||
}
|
}
|
||||||
assertEquals(3, cnt);
|
assertEquals(3, cnt);
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -193,21 +211,22 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
* <p>
|
* <p>
|
||||||
* Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=13775" target="_bug">#13775</a>
|
* Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=13775" target="_bug">#13775</a>
|
||||||
*/
|
*/
|
||||||
public final void testMultiNamedRange() {
|
@Test
|
||||||
|
public final void testMultiNamedRange() throws Exception {
|
||||||
|
|
||||||
// Create a new workbook
|
// Create a new workbook
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb1 = _testDataProvider.createWorkbook();
|
||||||
|
|
||||||
// Create a worksheet 'sheet1' in the new workbook
|
// Create a worksheet 'sheet1' in the new workbook
|
||||||
wb.createSheet ();
|
wb1.createSheet ();
|
||||||
wb.setSheetName (0, "sheet1");
|
wb1.setSheetName (0, "sheet1");
|
||||||
|
|
||||||
// Create another worksheet 'sheet2' in the new workbook
|
// Create another worksheet 'sheet2' in the new workbook
|
||||||
wb.createSheet ();
|
wb1.createSheet ();
|
||||||
wb.setSheetName (1, "sheet2");
|
wb1.setSheetName (1, "sheet2");
|
||||||
|
|
||||||
// Create a new named range for worksheet 'sheet1'
|
// Create a new named range for worksheet 'sheet1'
|
||||||
Name namedRange1 = wb.createName();
|
Name namedRange1 = wb1.createName();
|
||||||
|
|
||||||
// Set the name for the named range for worksheet 'sheet1'
|
// Set the name for the named range for worksheet 'sheet1'
|
||||||
namedRange1.setNameName("RangeTest1");
|
namedRange1.setNameName("RangeTest1");
|
||||||
@ -216,7 +235,7 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
namedRange1.setRefersToFormula("sheet1" + "!$A$1:$L$41");
|
namedRange1.setRefersToFormula("sheet1" + "!$A$1:$L$41");
|
||||||
|
|
||||||
// Create a new named range for worksheet 'sheet2'
|
// Create a new named range for worksheet 'sheet2'
|
||||||
Name namedRange2 = wb.createName();
|
Name namedRange2 = wb1.createName();
|
||||||
|
|
||||||
// Set the name for the named range for worksheet 'sheet2'
|
// Set the name for the named range for worksheet 'sheet2'
|
||||||
namedRange2.setNameName("RangeTest2");
|
namedRange2.setNameName("RangeTest2");
|
||||||
@ -226,20 +245,24 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
|
|
||||||
// Write the workbook to a file
|
// Write the workbook to a file
|
||||||
// Read the Excel file and verify its content
|
// Read the Excel file and verify its content
|
||||||
wb = _testDataProvider.writeOutAndReadBack(wb);
|
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
|
||||||
Name nm1 =wb.getNameAt(wb.getNameIndex("RangeTest1"));
|
Name nm1 = wb2.getNameAt(wb2.getNameIndex("RangeTest1"));
|
||||||
assertTrue("Name is "+nm1.getNameName(),"RangeTest1".equals(nm1.getNameName()));
|
assertTrue("Name is "+nm1.getNameName(),"RangeTest1".equals(nm1.getNameName()));
|
||||||
assertTrue("Reference is "+nm1.getRefersToFormula(),(wb.getSheetName(0)+"!$A$1:$L$41").equals(nm1.getRefersToFormula()));
|
assertTrue("Reference is "+nm1.getRefersToFormula(),(wb2.getSheetName(0)+"!$A$1:$L$41").equals(nm1.getRefersToFormula()));
|
||||||
|
|
||||||
Name nm2 =wb.getNameAt(wb.getNameIndex("RangeTest2"));
|
Name nm2 = wb2.getNameAt(wb2.getNameIndex("RangeTest2"));
|
||||||
assertTrue("Name is "+nm2.getNameName(),"RangeTest2".equals(nm2.getNameName()));
|
assertTrue("Name is "+nm2.getNameName(),"RangeTest2".equals(nm2.getNameName()));
|
||||||
assertTrue("Reference is "+nm2.getRefersToFormula(),(wb.getSheetName(1)+"!$A$1:$O$21").equals(nm2.getRefersToFormula()));
|
assertTrue("Reference is "+nm2.getRefersToFormula(),(wb2.getSheetName(1)+"!$A$1:$O$21").equals(nm2.getRefersToFormula()));
|
||||||
|
|
||||||
|
wb2.close();
|
||||||
|
wb1.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test to see if the print areas can be retrieved/created in memory
|
* Test to see if the print areas can be retrieved/created in memory
|
||||||
*/
|
*/
|
||||||
public final void testSinglePrintArea() {
|
@Test
|
||||||
|
public final void testSinglePrintArea() throws Exception {
|
||||||
Workbook workbook = _testDataProvider.createWorkbook();
|
Workbook workbook = _testDataProvider.createWorkbook();
|
||||||
workbook.createSheet("Test Print Area");
|
workbook.createSheet("Test Print Area");
|
||||||
String sheetName = workbook.getSheetName(0);
|
String sheetName = workbook.getSheetName(0);
|
||||||
@ -251,12 +274,15 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
|
|
||||||
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
|
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
|
||||||
assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
|
assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
|
||||||
|
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For Convenience, don't force sheet names to be used
|
* For Convenience, don't force sheet names to be used
|
||||||
*/
|
*/
|
||||||
public final void testSinglePrintAreaWOSheet()
|
@Test
|
||||||
|
public final void testSinglePrintAreaWOSheet() throws Exception
|
||||||
{
|
{
|
||||||
Workbook workbook = _testDataProvider.createWorkbook();
|
Workbook workbook = _testDataProvider.createWorkbook();
|
||||||
workbook.createSheet("Test Print Area");
|
workbook.createSheet("Test Print Area");
|
||||||
@ -269,80 +295,91 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
|
|
||||||
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
|
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
|
||||||
assertEquals("'" + sheetName + "'!" + reference, retrievedPrintArea);
|
assertEquals("'" + sheetName + "'!" + reference, retrievedPrintArea);
|
||||||
|
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test to see if the print area made it to the file
|
* Test to see if the print area made it to the file
|
||||||
*/
|
*/
|
||||||
public final void testPrintAreaFile() {
|
@Test
|
||||||
Workbook workbook = _testDataProvider.createWorkbook();
|
public final void testPrintAreaFile() throws Exception {
|
||||||
workbook.createSheet("Test Print Area");
|
Workbook wb1 = _testDataProvider.createWorkbook();
|
||||||
String sheetName = workbook.getSheetName(0);
|
wb1.createSheet("Test Print Area");
|
||||||
|
String sheetName = wb1.getSheetName(0);
|
||||||
|
|
||||||
|
|
||||||
String reference = "$A$1:$B$1";
|
String reference = "$A$1:$B$1";
|
||||||
workbook.setPrintArea(0, reference);
|
wb1.setPrintArea(0, reference);
|
||||||
|
|
||||||
workbook = _testDataProvider.writeOutAndReadBack(workbook);
|
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
|
||||||
|
|
||||||
String retrievedPrintArea = workbook.getPrintArea(0);
|
String retrievedPrintArea = wb2.getPrintArea(0);
|
||||||
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
|
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
|
||||||
assertEquals("References Match", "'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
|
assertEquals("References Match", "'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
|
||||||
|
|
||||||
|
wb2.close();
|
||||||
|
wb1.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test to see if multiple print areas made it to the file
|
* Test to see if multiple print areas made it to the file
|
||||||
*/
|
*/
|
||||||
public final void testMultiplePrintAreaFile() {
|
@Test
|
||||||
Workbook workbook = _testDataProvider.createWorkbook();
|
public final void testMultiplePrintAreaFile() throws Exception {
|
||||||
|
Workbook wb1 = _testDataProvider.createWorkbook();
|
||||||
|
|
||||||
workbook.createSheet("Sheet1");
|
wb1.createSheet("Sheet1");
|
||||||
workbook.createSheet("Sheet2");
|
wb1.createSheet("Sheet2");
|
||||||
workbook.createSheet("Sheet3");
|
wb1.createSheet("Sheet3");
|
||||||
String reference1 = "$A$1:$B$1";
|
String reference1 = "$A$1:$B$1";
|
||||||
String reference2 = "$B$2:$D$5";
|
String reference2 = "$B$2:$D$5";
|
||||||
String reference3 = "$D$2:$F$5";
|
String reference3 = "$D$2:$F$5";
|
||||||
|
|
||||||
workbook.setPrintArea(0, reference1);
|
wb1.setPrintArea(0, reference1);
|
||||||
workbook.setPrintArea(1, reference2);
|
wb1.setPrintArea(1, reference2);
|
||||||
workbook.setPrintArea(2, reference3);
|
wb1.setPrintArea(2, reference3);
|
||||||
|
|
||||||
//Check created print areas
|
//Check created print areas
|
||||||
String retrievedPrintArea;
|
String retrievedPrintArea;
|
||||||
|
|
||||||
retrievedPrintArea = workbook.getPrintArea(0);
|
retrievedPrintArea = wb1.getPrintArea(0);
|
||||||
assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
|
assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
|
||||||
assertEquals("Sheet1!" + reference1, retrievedPrintArea);
|
assertEquals("Sheet1!" + reference1, retrievedPrintArea);
|
||||||
|
|
||||||
retrievedPrintArea = workbook.getPrintArea(1);
|
retrievedPrintArea = wb1.getPrintArea(1);
|
||||||
assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea);
|
assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea);
|
||||||
assertEquals("Sheet2!" + reference2, retrievedPrintArea);
|
assertEquals("Sheet2!" + reference2, retrievedPrintArea);
|
||||||
|
|
||||||
retrievedPrintArea = workbook.getPrintArea(2);
|
retrievedPrintArea = wb1.getPrintArea(2);
|
||||||
assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea);
|
assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea);
|
||||||
assertEquals("Sheet3!" + reference3, retrievedPrintArea);
|
assertEquals("Sheet3!" + reference3, retrievedPrintArea);
|
||||||
|
|
||||||
// Check print areas after re-reading workbook
|
// Check print areas after re-reading workbook
|
||||||
workbook = _testDataProvider.writeOutAndReadBack(workbook);
|
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
|
||||||
|
|
||||||
retrievedPrintArea = workbook.getPrintArea(0);
|
retrievedPrintArea = wb2.getPrintArea(0);
|
||||||
assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
|
assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
|
||||||
assertEquals("Sheet1!" + reference1, retrievedPrintArea);
|
assertEquals("Sheet1!" + reference1, retrievedPrintArea);
|
||||||
|
|
||||||
retrievedPrintArea = workbook.getPrintArea(1);
|
retrievedPrintArea = wb2.getPrintArea(1);
|
||||||
assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea);
|
assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea);
|
||||||
assertEquals("Sheet2!" + reference2, retrievedPrintArea);
|
assertEquals("Sheet2!" + reference2, retrievedPrintArea);
|
||||||
|
|
||||||
retrievedPrintArea = workbook.getPrintArea(2);
|
retrievedPrintArea = wb2.getPrintArea(2);
|
||||||
assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea);
|
assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea);
|
||||||
assertEquals("Sheet3!" + reference3, retrievedPrintArea);
|
assertEquals("Sheet3!" + reference3, retrievedPrintArea);
|
||||||
|
|
||||||
|
wb2.close();
|
||||||
|
wb1.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the setting of print areas with coordinates (Row/Column designations)
|
* Tests the setting of print areas with coordinates (Row/Column designations)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final void testPrintAreaCoords(){
|
@Test
|
||||||
|
public final void testPrintAreaCoords() throws Exception {
|
||||||
Workbook workbook = _testDataProvider.createWorkbook();
|
Workbook workbook = _testDataProvider.createWorkbook();
|
||||||
workbook.createSheet("Test Print Area");
|
workbook.createSheet("Test Print Area");
|
||||||
String sheetName = workbook.getSheetName(0);
|
String sheetName = workbook.getSheetName(0);
|
||||||
@ -353,6 +390,8 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
|
|
||||||
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
|
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
|
||||||
assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
|
assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
|
||||||
|
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -360,7 +399,8 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
* Tests the parsing of union area expressions, and re-display in the presence of sheet names
|
* Tests the parsing of union area expressions, and re-display in the presence of sheet names
|
||||||
* with special characters.
|
* with special characters.
|
||||||
*/
|
*/
|
||||||
public final void testPrintAreaUnion(){
|
@Test
|
||||||
|
public final void testPrintAreaUnion() throws Exception {
|
||||||
Workbook workbook = _testDataProvider.createWorkbook();
|
Workbook workbook = _testDataProvider.createWorkbook();
|
||||||
workbook.createSheet("Test Print Area");
|
workbook.createSheet("Test Print Area");
|
||||||
|
|
||||||
@ -369,13 +409,16 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
String retrievedPrintArea = workbook.getPrintArea(0);
|
String retrievedPrintArea = workbook.getPrintArea(0);
|
||||||
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
|
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
|
||||||
assertEquals("'Test Print Area'!$A$1:$B$1,'Test Print Area'!$D$1:$F$2", retrievedPrintArea);
|
assertEquals("'Test Print Area'!$A$1:$B$1,'Test Print Area'!$D$1:$F$2", retrievedPrintArea);
|
||||||
|
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies an existing print area is deleted
|
* Verifies an existing print area is deleted
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final void testPrintAreaRemove() {
|
@Test
|
||||||
|
public final void testPrintAreaRemove() throws Exception {
|
||||||
Workbook workbook = _testDataProvider.createWorkbook();
|
Workbook workbook = _testDataProvider.createWorkbook();
|
||||||
workbook.createSheet("Test Print Area");
|
workbook.createSheet("Test Print Area");
|
||||||
workbook.getSheetName(0);
|
workbook.getSheetName(0);
|
||||||
@ -388,47 +431,53 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
|
|
||||||
workbook.removePrintArea(0);
|
workbook.removePrintArea(0);
|
||||||
assertNull("PrintArea was not removed", workbook.getPrintArea(0));
|
assertNull("PrintArea was not removed", workbook.getPrintArea(0));
|
||||||
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that multiple named ranges can be added written and read
|
* Test that multiple named ranges can be added written and read
|
||||||
*/
|
*/
|
||||||
public final void testMultipleNamedWrite() {
|
@Test
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
public final void testMultipleNamedWrite() throws Exception {
|
||||||
|
Workbook wb1 = _testDataProvider.createWorkbook();
|
||||||
|
|
||||||
|
|
||||||
wb.createSheet("testSheet1");
|
wb1.createSheet("testSheet1");
|
||||||
String sheetName = wb.getSheetName(0);
|
String sheetName = wb1.getSheetName(0);
|
||||||
|
|
||||||
assertEquals("testSheet1", sheetName);
|
assertEquals("testSheet1", sheetName);
|
||||||
|
|
||||||
//Creating new Named Range
|
//Creating new Named Range
|
||||||
Name newNamedRange = wb.createName();
|
Name newNamedRange = wb1.createName();
|
||||||
|
|
||||||
newNamedRange.setNameName("RangeTest");
|
newNamedRange.setNameName("RangeTest");
|
||||||
newNamedRange.setRefersToFormula(sheetName + "!$D$4:$E$8");
|
newNamedRange.setRefersToFormula(sheetName + "!$D$4:$E$8");
|
||||||
|
|
||||||
//Creating another new Named Range
|
//Creating another new Named Range
|
||||||
Name newNamedRange2 = wb.createName();
|
Name newNamedRange2 = wb1.createName();
|
||||||
|
|
||||||
newNamedRange2.setNameName("AnotherTest");
|
newNamedRange2.setNameName("AnotherTest");
|
||||||
newNamedRange2.setRefersToFormula(sheetName + "!$F$1:$G$6");
|
newNamedRange2.setRefersToFormula(sheetName + "!$F$1:$G$6");
|
||||||
|
|
||||||
wb.getNameAt(0);
|
wb1.getNameAt(0);
|
||||||
|
|
||||||
wb = _testDataProvider.writeOutAndReadBack(wb);
|
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
|
||||||
Name nm =wb.getNameAt(wb.getNameIndex("RangeTest"));
|
Name nm =wb2.getNameAt(wb2.getNameIndex("RangeTest"));
|
||||||
assertTrue("Name is "+nm.getNameName(),"RangeTest".equals(nm.getNameName()));
|
assertTrue("Name is "+nm.getNameName(),"RangeTest".equals(nm.getNameName()));
|
||||||
assertTrue("Reference is "+nm.getRefersToFormula(),(wb.getSheetName(0)+"!$D$4:$E$8").equals(nm.getRefersToFormula()));
|
assertTrue("Reference is "+nm.getRefersToFormula(),(wb2.getSheetName(0)+"!$D$4:$E$8").equals(nm.getRefersToFormula()));
|
||||||
|
|
||||||
nm = wb.getNameAt(wb.getNameIndex("AnotherTest"));
|
nm = wb2.getNameAt(wb2.getNameIndex("AnotherTest"));
|
||||||
assertTrue("Name is "+nm.getNameName(),"AnotherTest".equals(nm.getNameName()));
|
assertTrue("Name is "+nm.getNameName(),"AnotherTest".equals(nm.getNameName()));
|
||||||
assertTrue("Reference is "+nm.getRefersToFormula(),newNamedRange2.getRefersToFormula().equals(nm.getRefersToFormula()));
|
assertTrue("Reference is "+nm.getRefersToFormula(),newNamedRange2.getRefersToFormula().equals(nm.getRefersToFormula()));
|
||||||
|
|
||||||
|
wb2.close();
|
||||||
|
wb1.close();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Verifies correct functioning for "single cell named range" (aka "named cell")
|
* Verifies correct functioning for "single cell named range" (aka "named cell")
|
||||||
*/
|
*/
|
||||||
public final void testNamedCell_1() {
|
@Test
|
||||||
|
public final void testNamedCell_1() throws Exception {
|
||||||
|
|
||||||
// setup for this testcase
|
// setup for this testcase
|
||||||
String sheetName = "Test Named Cell";
|
String sheetName = "Test Named Cell";
|
||||||
@ -451,6 +500,7 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
assertNotNull(aNamedCell);
|
assertNotNull(aNamedCell);
|
||||||
|
|
||||||
// retrieve the cell at the named range and test its contents
|
// retrieve the cell at the named range and test its contents
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
AreaReference aref = new AreaReference(aNamedCell.getRefersToFormula());
|
AreaReference aref = new AreaReference(aNamedCell.getRefersToFormula());
|
||||||
assertTrue("Should be exactly 1 cell in the named cell :'" +cellName+"'", aref.isSingleCell());
|
assertTrue("Should be exactly 1 cell in the named cell :'" +cellName+"'", aref.isSingleCell());
|
||||||
|
|
||||||
@ -462,12 +512,15 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
Cell c = r.getCell(cref.getCol());
|
Cell c = r.getCell(cref.getCol());
|
||||||
String contents = c.getRichStringCellValue().getString();
|
String contents = c.getRichStringCellValue().getString();
|
||||||
assertEquals("Contents of cell retrieved by its named reference", contents, cellValue);
|
assertEquals("Contents of cell retrieved by its named reference", contents, cellValue);
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies correct functioning for "single cell named range" (aka "named cell")
|
* Verifies correct functioning for "single cell named range" (aka "named cell")
|
||||||
*/
|
*/
|
||||||
public final void testNamedCell_2() {
|
@Test
|
||||||
|
public final void testNamedCell_2() throws Exception {
|
||||||
|
|
||||||
// setup for this testcase
|
// setup for this testcase
|
||||||
String sname = "TestSheet", cname = "TestName", cvalue = "TestVal";
|
String sname = "TestSheet", cname = "TestName", cvalue = "TestVal";
|
||||||
@ -491,10 +544,13 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
CellReference cref = new CellReference(aNamedCell.getRefersToFormula());
|
CellReference cref = new CellReference(aNamedCell.getRefersToFormula());
|
||||||
assertNotNull(cref);
|
assertNotNull(cref);
|
||||||
Sheet s = wb.getSheet(cref.getSheetName());
|
Sheet s = wb.getSheet(cref.getSheetName());
|
||||||
|
assertNotNull(s);
|
||||||
Row r = sheet.getRow(cref.getRow());
|
Row r = sheet.getRow(cref.getRow());
|
||||||
Cell c = r.getCell(cref.getCol());
|
Cell c = r.getCell(cref.getCol());
|
||||||
String contents = c.getRichStringCellValue().getString();
|
String contents = c.getRichStringCellValue().getString();
|
||||||
assertEquals("Contents of cell retrieved by its named reference", contents, cvalue);
|
assertEquals("Contents of cell retrieved by its named reference", contents, cvalue);
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -511,40 +567,40 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
* could do the same, but that would involve adjusting subsequent name indexes across
|
* could do the same, but that would involve adjusting subsequent name indexes across
|
||||||
* all formulas. <p/>
|
* all formulas. <p/>
|
||||||
*
|
*
|
||||||
* For the moment, POI has been made to behave more sensibly with uninitialised name
|
* For the moment, POI has been made to behave more sensibly with uninitialized name
|
||||||
* records.
|
* records.
|
||||||
*/
|
*/
|
||||||
public final void testUninitialisedNameGetRefersToFormula_bug46973() {
|
@Test
|
||||||
|
public final void testUninitialisedNameGetRefersToFormula_bug46973() throws Exception {
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
Name n = wb.createName();
|
Name n = wb.createName();
|
||||||
n.setNameName("UPSState");
|
n.setNameName("UPSState");
|
||||||
String formula;
|
String formula = n.getRefersToFormula();
|
||||||
try {
|
|
||||||
formula = n.getRefersToFormula();
|
// bug 46973: fails here with IllegalArgumentException
|
||||||
} catch (IllegalArgumentException e) {
|
// ptgs must not be null
|
||||||
if (e.getMessage().equals("ptgs must not be null")) {
|
|
||||||
throw new AssertionFailedError("Identified bug 46973");
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
assertNull(formula);
|
assertNull(formula);
|
||||||
assertFalse(n.isDeleted()); // according to exact definition of isDeleted()
|
// according to exact definition of isDeleted()
|
||||||
|
assertFalse(n.isDeleted());
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void testDeletedCell() {
|
@Test
|
||||||
|
public final void testDeletedCell() throws Exception {
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
Name n = wb.createName();
|
Name n = wb.createName();
|
||||||
n.setNameName("MyName");
|
n.setNameName("MyName");
|
||||||
// contrived example to expose bug:
|
// contrived example to expose bug:
|
||||||
n.setRefersToFormula("if(A1,\"#REF!\", \"\")");
|
n.setRefersToFormula("if(A1,\"#REF!\", \"\")");
|
||||||
|
|
||||||
if (n.isDeleted()) {
|
assertFalse("Identified bug in recoginising formulas referring to deleted cells", n.isDeleted());
|
||||||
throw new AssertionFailedError("Identified bug in recoginising formulas referring to deleted cells");
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
@Test
|
||||||
|
public final void testFunctionNames() throws Exception {
|
||||||
public final void testFunctionNames() {
|
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
Name n = wb.createName();
|
Name n = wb.createName();
|
||||||
assertFalse(n.isFunctionName());
|
assertFalse(n.isFunctionName());
|
||||||
@ -557,9 +613,12 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
|
|
||||||
n.setFunction(false);
|
n.setFunction(false);
|
||||||
assertFalse(n.isFunctionName());
|
assertFalse(n.isFunctionName());
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void testDefferedSetting() {
|
@Test
|
||||||
|
public final void testDefferedSetting() throws Exception {
|
||||||
Workbook wb = _testDataProvider.createWorkbook();
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
Name n1 = wb.createName();
|
Name n1 = wb.createName();
|
||||||
assertNull(n1.getRefersToFormula());
|
assertNull(n1.getRefersToFormula());
|
||||||
@ -582,5 +641,6 @@ public abstract class BaseTestNamedRange extends TestCase {
|
|||||||
assertEquals("The workbook already contains this name: sale_1", e.getMessage());
|
assertEquals("The workbook already contains this name: sale_1", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wb.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,11 +128,11 @@ public class NumberRenderingSpreadsheetGenerator {
|
|||||||
row.createCell(5).setCellFormula(matchExpr);
|
row.createCell(5).setCellFormula(matchExpr);
|
||||||
row.createCell(6).setCellFormula(jmExpr.replaceAll("'", "\""));
|
row.createCell(6).setCellFormula(jmExpr.replaceAll("'", "\""));
|
||||||
|
|
||||||
if (false) {
|
// if (false) {
|
||||||
// for observing arithmetic near numeric range boundaries
|
// // for observing arithmetic near numeric range boundaries
|
||||||
row.createCell(7).setCellFormula(cel0ref + " * 1.0001");
|
// row.createCell(7).setCellFormula(cel0ref + " * 1.0001");
|
||||||
row.createCell(8).setCellFormula(cel0ref + " / 1.0001");
|
// row.createCell(8).setCellFormula(cel0ref + " / 1.0001");
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String formatLongAsHex(long l) {
|
private static String formatLongAsHex(long l) {
|
||||||
@ -215,10 +215,10 @@ public class NumberRenderingSpreadsheetGenerator {
|
|||||||
bb[i+2] = (byte) (val >> 16);
|
bb[i+2] = (byte) (val >> 16);
|
||||||
bb[i+1] = (byte) (val >> 8);
|
bb[i+1] = (byte) (val >> 8);
|
||||||
bb[i+0] = (byte) (val >> 0);
|
bb[i+0] = (byte) (val >> 0);
|
||||||
if (false) {
|
// if (false) {
|
||||||
String newVal = interpretLong(bb, i);
|
// String newVal = interpretLong(bb, i);
|
||||||
System.out.println("changed offset " + i + " from " + oldVal + " to " + newVal);
|
// System.out.println("changed offset " + i + " from " + oldVal + " to " + newVal);
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user