poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r653822 [3/3] - in /poi/branches/ooxml: ./ src/documentation/ src/documentation/content/xdocs/ src/java/org/apache/poi/ddf/ src/java/org/apache/poi/hssf/dev/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/...
Date Tue, 06 May 2008 16:00:38 GMT
Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java Tue May  6 09:00:36 2008
@@ -17,6 +17,7 @@
 package org.apache.poi.hslf.model;
 
 import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.record.TextRulerAtom;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.util.POILogFactory;
 
@@ -38,6 +39,13 @@
 public class TextPainter {
     protected POILogger logger = POILogFactory.getLogger(this.getClass());
 
+    /**
+     * Display unicode square if a bullet char can't be displayed,
+     * for example, if Wingdings font is used.
+     * TODO: map Wingdngs and Symbol to unicode Arial
+     */
+    protected static final char DEFAULT_BULLET_CHAR = '\u25a0';
+
     protected TextShape _shape;
 
     public TextPainter(TextShape shape){
@@ -49,6 +57,10 @@
      */
     public AttributedString getAttributedString(TextRun txrun){
         String text = txrun.getText();
+        //TODO: properly process tabs
+        text = text.replace('\t', ' ');
+        text = text.replace((char)160, ' ');
+
         AttributedString at = new AttributedString(text);
         RichTextRun[] rt = txrun.getRichTextRuns();
         for (int i = 0; i < rt.length; i++) {
@@ -109,7 +121,24 @@
             }
 
             float wrappingWidth = (float)anchor.getWidth() - _shape.getMarginLeft() - _shape.getMarginRight();
-            wrappingWidth -= rt.getTextOffset();
+            int bulletOffset = rt.getBulletOffset();
+            int textOffset = rt.getTextOffset();
+            int indent = rt.getIndentLevel();
+
+            TextRulerAtom ruler = run.getTextRuler();
+            if(ruler != null) {
+                int bullet_val = ruler.getBulletOffsets()[indent]*Shape.POINT_DPI/Shape.MASTER_DPI;
+                int text_val = ruler.getTextOffsets()[indent]*Shape.POINT_DPI/Shape.MASTER_DPI;
+                if(bullet_val > text_val){
+                    int a = bullet_val;
+                    bullet_val = text_val;
+                    text_val = a;
+                }
+                if(bullet_val != 0 ) bulletOffset = bullet_val;
+                if(text_val != 0) textOffset = text_val;
+            }
+
+            wrappingWidth -= textOffset;
 
             if (_shape.getWordWrap() == TextShape.WrapNone) {
                 wrappingWidth = _shape.getSheet().getSlideShow().getPageSize().width;
@@ -141,8 +170,9 @@
             }
 
             el._align = rt.getAlignment();
-            el._text = textLayout;
-            el._textOffset = rt.getTextOffset();
+            el.advance = textLayout.getAdvance();
+            el._textOffset = textOffset;
+            el._text = new AttributedString(it, startIndex, endIndex);
 
             if (prStart){
                 int sp = rt.getSpaceBefore();
@@ -182,13 +212,25 @@
                 Color clr = rt.getBulletColor();
                 if (clr != null) bat.addAttribute(TextAttribute.FOREGROUND, clr);
                 else bat.addAttribute(TextAttribute.FOREGROUND, it.getAttribute(TextAttribute.FOREGROUND));
-                bat.addAttribute(TextAttribute.FAMILY, it.getAttribute(TextAttribute.FAMILY));
-                bat.addAttribute(TextAttribute.SIZE, it.getAttribute(TextAttribute.SIZE));
 
-                TextLayout bulletLayout = new TextLayout(bat.getIterator(), graphics.getFontRenderContext());
+                int fontIdx = rt.getBulletFont();
+                if(fontIdx == -1) fontIdx = rt.getFontIndex();
+                PPFont bulletFont = _shape.getSheet().getSlideShow().getFont(fontIdx);
+                bat.addAttribute(TextAttribute.FAMILY, bulletFont.getFontName());
+
+                int bulletSize = rt.getBulletSize();
+                int fontSize = rt.getFontSize();
+                if(bulletSize != -1) fontSize = Math.round(fontSize*bulletSize*0.01f);
+                bat.addAttribute(TextAttribute.SIZE, new Float(fontSize));
+
+                if(!new Font(bulletFont.getFontName(), Font.PLAIN, 1).canDisplay(rt.getBulletChar())){
+                    bat.addAttribute(TextAttribute.FAMILY, "Arial");
+                    bat = new AttributedString("" + DEFAULT_BULLET_CHAR, bat.getIterator().getAttributes());
+                }
+
                 if(text.substring(startIndex, endIndex).length() > 1){
-                    el._bullet = bulletLayout;
-                    el._bulletOffset = rt.getBulletOffset();
+                    el._bullet = bat;
+                    el._bulletOffset = bulletOffset;
                 }
             }
             lines.add(el);
@@ -225,29 +267,32 @@
                     break;
                 case TextShape.AlignCenter:
                     pen.x = anchor.getX() + _shape.getMarginLeft() +
-                            (anchor.getWidth() - elem._text.getAdvance() - _shape.getMarginLeft() - _shape.getMarginRight()) / 2;
+                            (anchor.getWidth() - elem.advance - _shape.getMarginLeft() - _shape.getMarginRight()) / 2;
                     break;
                 case TextShape.AlignRight:
                     pen.x = anchor.getX() + _shape.getMarginLeft() +
-                            (anchor.getWidth() - elem._text.getAdvance() - _shape.getMarginLeft() - _shape.getMarginRight());
+                            (anchor.getWidth() - elem.advance - _shape.getMarginLeft() - _shape.getMarginRight());
                     break;
             }
             if(elem._bullet != null){
-                elem._bullet.draw(graphics, (float)(pen.x + elem._bulletOffset), (float)pen.y);
+                graphics.drawString(elem._bullet.getIterator(), (float)(pen.x + elem._bulletOffset), (float)pen.y);
+            }
+            AttributedCharacterIterator chIt = elem._text.getIterator();
+            if(chIt.getEndIndex() > chIt.getBeginIndex()) {
+                graphics.drawString(chIt, (float)(pen.x + elem._textOffset), (float)pen.y);
             }
-            elem._text.draw(graphics, (float)(pen.x + elem._textOffset), (float)pen.y);
-
             y0 += elem.descent;
         }
     }
 
 
-    static class TextElement {
-        public TextLayout _text;
+    public static class TextElement {
+        public AttributedString _text;
         public int _textOffset;
-        public TextLayout _bullet;
+        public AttributedString _bullet;
         public int _bulletOffset;
         public int _align;
         public float ascent, descent;
+        public float advance;
     }
 }

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java Tue May  6 09:00:36 2008
@@ -535,9 +535,13 @@
 		//  them to \n
 		String text = rawText.replace('\r','\n');
 
-        //0xB acts like cariage return in page titles
-        text = text.replace((char) 0x0B, '\n');
-
+        int type = _headerAtom == null ? 0 : _headerAtom.getTextType();
+        if(type == TextHeaderAtom.TITLE_TYPE || type == TextHeaderAtom.CENTER_TITLE_TYPE){
+            //0xB acts like cariage return in page titles and like blank in the others
+            text = text.replace((char) 0x0B, '\n');
+        } else {
+            text = text.replace((char) 0x0B, ' ');
+        }
 		return text;
 	}
 
@@ -655,4 +659,11 @@
         return null;
     }
 
+    public TextRulerAtom getTextRuler(){
+        for (int i = 0; i < _records.length; i++) {
+            if(_records[i] instanceof TextRulerAtom) return (TextRulerAtom)_records[i];
+        }
+        return null;
+
+    }
 }

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java Tue May  6 09:00:36 2008
@@ -261,17 +261,28 @@
     public int getVerticalAlignment(){
         EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
         EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);
-        int valign;
+        int valign = TextShape.AnchorTop;
         if (prop == null){
+            /**
+             * If vertical alignment was not found in the shape properties then try to
+             * fetch the master shape and search for the align property there.
+             */
             int type = getTextRun().getRunType();
-            switch (type){
-                case TextHeaderAtom.TITLE_TYPE:
-                case TextHeaderAtom.CENTER_TITLE_TYPE:
-                    valign = TextShape.AnchorMiddle;
-                    break;
-                default:
-                    valign = TextShape.AnchorTop;
-                    break;
+            MasterSheet master = getSheet().getMasterSheet();
+            if(master != null){
+                TextShape masterShape = master.getPlaceholder(type);
+                if(masterShape != null) valign = masterShape.getVerticalAlignment();
+            } else {
+                //not found in the master sheet. Use the hardcoded defaults.
+                switch (type){
+                     case TextHeaderAtom.TITLE_TYPE:
+                     case TextHeaderAtom.CENTER_TITLE_TYPE:
+                         valign = TextShape.AnchorMiddle;
+                         break;
+                     default:
+                         valign = TextShape.AnchorTop;
+                         break;
+                 }
             }
         } else {
             valign = prop.getPropertyValue();

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java Tue May  6 09:00:36 2008
@@ -24,11 +24,13 @@
 
 import org.apache.poi.ddf.*;
 import org.apache.poi.hslf.model.ShapeTypes;
+import org.apache.poi.hslf.model.Shape;
 
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.List;
 import java.util.Vector;
+import java.util.Iterator;
 
 /**
  * These are actually wrappers onto Escher drawings. Make use of
@@ -52,6 +54,8 @@
 	private EscherRecord[] childRecords;
 	private EscherTextboxWrapper[] textboxWrappers;
 
+    //cached EscherDgRecord
+    private EscherDgRecord dg;
 
 	/**
 	 * Get access to the underlying Escher Records
@@ -296,4 +300,24 @@
 		tw[textboxWrappers.length] = txtbox;
 		textboxWrappers = tw;
 	}
+
+    /**
+     * Return EscherDgRecord which keeps track of the number of shapes and shapeId in this drawing group
+     *
+     * @return EscherDgRecord
+     */
+    public EscherDgRecord getEscherDgRecord(){
+        if(dg == null){
+            EscherContainerRecord dgContainer = (EscherContainerRecord)childRecords[0];
+            for(Iterator it = dgContainer.getChildRecords().iterator(); it.hasNext();){
+                EscherRecord r = (EscherRecord) it.next();
+                if(r instanceof EscherDgRecord){
+                    dg = (EscherDgRecord)r;
+                    break;
+                }
+            }
+        }
+        return dg;
+    }
+
 }

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java Tue May  6 09:00:36 2008
@@ -89,7 +89,7 @@
     public static final Type TxMasterStyleAtom = new Type(4003,TxMasterStyleAtom.class);
     public static final Type TxCFStyleAtom = new Type(4004,null);
     public static final Type TxPFStyleAtom = new Type(4005,null);
-    public static final Type TextRulerAtom = new Type(4006,null);
+    public static final Type TextRulerAtom = new Type(4006,TextRulerAtom.class);
     public static final Type TextBookmarkAtom = new Type(4007,null);
     public static final Type TextBytesAtom = new Type(4008,TextBytesAtom.class);
     public static final Type TxSIStyleAtom = new Type(4009,null);

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java Tue May  6 09:00:36 2008
@@ -127,8 +127,8 @@
 				new ParagraphFlagsTextProp(),
                 new TextProp(2, 0x80, "bullet.char"),
 				new TextProp(2, 0x10, "bullet.font"),
+                new TextProp(2, 0x40, "bullet.size"),
 				new TextProp(4, 0x20, "bullet.color"),
-				new TextProp(2, 0x40, "bullet.size"),
                 new AlignmentTextProp(),
                 new TextProp(2, 0x100, "text.offset"),
 				new TextProp(2, 0x200, "para_unknown_2"),

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java Tue May  6 09:00:36 2008
@@ -32,6 +32,8 @@
 import org.apache.poi.hslf.model.textproperties.TextProp;
 import org.apache.poi.hslf.model.textproperties.TextPropCollection;
 import org.apache.poi.hslf.record.ColorSchemeAtom;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.POILogFactory;
 
 
 /**
@@ -39,6 +41,8 @@
  * 
  */
 public class RichTextRun {
+    protected POILogger logger = POILogFactory.getLogger(this.getClass());
+
 	/** The TextRun we belong to */
 	private TextRun parentRun;
 	/** The SlideShow we belong to */
@@ -199,10 +203,15 @@
         }
         if (prop == null){
             Sheet sheet = parentRun.getSheet();
-            int txtype = parentRun.getRunType();
-            MasterSheet master = sheet.getMasterSheet();
-            if (master != null)
-                prop = (BitMaskTextProp)master.getStyleAttribute(txtype, getIndentLevel(), propname, isCharacter);
+            if(sheet != null){
+                int txtype = parentRun.getRunType();
+                MasterSheet master = sheet.getMasterSheet();
+                if (master != null){
+                    prop = (BitMaskTextProp)master.getStyleAttribute(txtype, getIndentLevel(), propname, isCharacter);
+                }
+            } else {
+                logger.log(POILogger.WARN, "MasterSheet is not available");
+            }
         }
 
         return prop == null ? false : prop.getSubValue(index);
@@ -213,7 +222,7 @@
 	 *  it if required. 
 	 */
 	private void setCharFlagsTextPropVal(int index, boolean value) {
-        setFlag(true, index, value);
+        if(getFlag(true, index) != value) setFlag(true, index, value);
 	}
 
     public void setFlag(boolean isCharacter, int index, boolean value) {
@@ -281,10 +290,14 @@
 	 */
 	private int getParaTextPropVal(String propName) {
         TextProp prop = null;
+        boolean hardAttribute = false;
         if (paragraphStyle != null){
             prop = paragraphStyle.findByName(propName);
+
+            BitMaskTextProp maskProp = (BitMaskTextProp)paragraphStyle.findByName(ParagraphFlagsTextProp.NAME);
+            hardAttribute = maskProp != null && maskProp.getValue() == 0;
         }
-        if (prop == null){
+        if (prop == null && !hardAttribute){
             Sheet sheet = parentRun.getSheet();
             int txtype = parentRun.getRunType();
             MasterSheet master = sheet.getMasterSheet();
@@ -575,6 +588,13 @@
     }
 
     /**
+     * Returns whether this rich text run has bullets
+     */
+    public boolean isBulletHard() {
+        return getFlag(false, ParagraphFlagsTextProp.BULLET_IDX);
+    }
+
+    /**
      * Sets the bullet character
      */
     public void setBulletChar(char c) {

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java Tue May  6 09:00:36 2008
@@ -24,10 +24,7 @@
 import java.awt.Dimension;
 import java.io.*;
 
-import org.apache.poi.ddf.EscherBSERecord;
-import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherOptRecord;
-import org.apache.poi.ddf.EscherRecord;
+import org.apache.poi.ddf.*;
 import org.apache.poi.hslf.*;
 import org.apache.poi.hslf.model.*;
 import org.apache.poi.hslf.model.Notes;
@@ -66,9 +63,7 @@
   // Lookup between the PersitPtr "sheet" IDs, and the position
   //  in the mostRecentCoreRecords array
   private Hashtable _sheetIdToCoreRecordsLookup;
-  // Used when adding new core records
-  private int _highestSheetId;
-  
+
   // Records that are interesting
   private Document _documentRecord;
 
@@ -203,8 +198,6 @@
 	for(int i=0; i<allIDs.length; i++) {
 		_sheetIdToCoreRecordsLookup.put(new Integer(allIDs[i]), new Integer(i));
 	}
-	// Capture the ID of the highest sheet
-	_highestSheetId = allIDs[(allIDs.length-1)];
 
 	// Now convert the byte offsets back into record offsets
 	for(int i=0; i<_records.length; i++) {
@@ -612,38 +605,35 @@
   				}
   			}
   		}
-  		
-  		// Set up a new  SlidePersistAtom for this slide 
+
+  		// Set up a new  SlidePersistAtom for this slide
   		SlidePersistAtom sp = new SlidePersistAtom();
 
-  		// Reference is the 1-based index of the slide container in 
-  		//  the PersistPtr root.
-  		// It always starts with 3 (1 is Document, 2 is MainMaster, 3 is 
-  		//  the first slide), but quicksaves etc can leave gaps
-  		_highestSheetId++;
-  		sp.setRefID(_highestSheetId);
   		// First slideId is always 256
   		sp.setSlideIdentifier(prev == null ? 256 : (prev.getSlideIdentifier() + 1));
-  		
+
   		// Add this new SlidePersistAtom to the SlideListWithText
   		slist.addSlidePersistAtom(sp);
-  		
-  		
+
+
   		// Create a new Slide
   		Slide slide = new Slide(sp.getSlideIdentifier(), sp.getRefID(), _slides.length+1);
+        slide.setSlideShow(this);
+        slide.onCreate();
+
   		// Add in to the list of Slides
   		Slide[] s = new Slide[_slides.length+1];
   		System.arraycopy(_slides, 0, s, 0, _slides.length);
   		s[_slides.length] = slide;
   		_slides = s;
   		logger.log(POILogger.INFO, "Added slide " + _slides.length + " with ref " + sp.getRefID() + " and identifier " + sp.getSlideIdentifier());
-  		
+
   		// Add the core records for this new Slide to the record tree
   		org.apache.poi.hslf.record.Slide slideRecord = slide.getSlideRecord();
-  		slideRecord.setSheetId(sp.getRefID());
   		int slideRecordPos = _hslfSlideShow.appendRootLevelRecord(slideRecord);
   		_records = _hslfSlideShow.getRecords();
 
+
   		// Add the new Slide into the PersistPtr stuff
   		int offset = 0;
   		int slideOffset = 0;
@@ -653,7 +643,7 @@
   			Record record = _records[i];
   			ByteArrayOutputStream out = new ByteArrayOutputStream();
   			record.writeOut(out);
-  			
+
   			// Grab interesting records as they come past
   			if(_records[i].getRecordType() == RecordTypes.PersistPtrIncrementalBlock.typeID){
   				ptr = (PersistPtrHolder)_records[i];
@@ -661,25 +651,29 @@
   			if(_records[i].getRecordType() == RecordTypes.UserEditAtom.typeID) {
   				usr = (UserEditAtom)_records[i];
   			}
-  			
+
   			if(i == slideRecordPos) {
   				slideOffset = offset;
   			}
   			offset += out.size();
   		}
-  		
+
+        // persist ID is UserEditAtom.maxPersistWritten + 1
+        int psrId = usr.getMaxPersistWritten() + 1;
+        sp.setRefID(psrId);
+        slideRecord.setSheetId(psrId);
+
+        // Last view is now of the slide
+        usr.setLastViewType((short)UserEditAtom.LAST_VIEW_SLIDE_VIEW);
+        usr.setMaxPersistWritten(psrId);    //increment the number of persit objects
+
 		// Add the new slide into the last PersistPtr
   		// (Also need to tell it where it is)
 		slideRecord.setLastOnDiskOffset(slideOffset);
 		ptr.addSlideLookup(sp.getRefID(), slideOffset);
 		logger.log(POILogger.INFO, "New slide ended up at " + slideOffset);
 
-		// Last view is now of the slide
-  		usr.setLastViewType((short)UserEditAtom.LAST_VIEW_SLIDE_VIEW);
-  		usr.setMaxPersistWritten(_highestSheetId);
-
   		// All done and added
-  		slide.setSlideShow(this);
   		return slide;
 	}
 

Modified: poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java (original)
+++ poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java Tue May  6 09:00:36 2008
@@ -52,7 +52,7 @@
         Freeform p = new Freeform();
         p.setPath(path1);
 
-        GeneralPath path2 = p.getPath();
+        java.awt.Shape path2 = p.getOutline();
         assertTrue(new Area(path1).equals(new Area(path2)));
     }
 
@@ -63,7 +63,7 @@
         Freeform p = new Freeform();
         p.setPath(path1);
 
-        GeneralPath path2 = p.getPath();
+        java.awt.Shape path2 = p.getOutline();
         assertTrue(new Area(path1).equals(new Area(path2)));
     }
 
@@ -74,7 +74,7 @@
         Freeform p = new Freeform();
         p.setPath(path1);
 
-        GeneralPath path2 = p.getPath();
+        java.awt.Shape path2 = p.getOutline();
         assertTrue(new Area(path1).equals(new Area(path2)));
-    }
+   }
 }

Modified: poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java (original)
+++ poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java Tue May  6 09:00:36 2008
@@ -20,6 +20,8 @@
 import org.apache.poi.hslf.usermodel.SlideShow;
 import org.apache.poi.hslf.usermodel.RichTextRun;
 import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.ddf.EscherDggRecord;
+import org.apache.poi.ddf.EscherDgRecord;
 
 import java.awt.*;
 import java.awt.Rectangle;
@@ -311,18 +313,49 @@
     public void testShapeId() throws IOException {
         SlideShow ppt = new SlideShow();
         Slide slide = ppt.createSlide();
-        Shape shape;
+        Shape shape = null;
 
-        shape = new Line();
-        assertEquals(0, shape.getShapeId());
-        slide.addShape(shape);
-        assertTrue(shape.getShapeId() > 0);
-
-        int shapeId = shape.getShapeId();
-
-        shape = new Line();
-        assertEquals(0, shape.getShapeId());
-        slide.addShape(shape);
-        assertEquals(shapeId + 1, shape.getShapeId());
+        //EscherDgg is a document-level record which keeps track of the drawing groups
+        EscherDggRecord dgg = ppt.getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
+        EscherDgRecord dg = slide.getSheetContainer().getPPDrawing().getEscherDgRecord();
+
+        int dggShapesUsed = dgg.getNumShapesSaved();   //total number of shapes in the ppt
+        int dggMaxId = dgg.getShapeIdMax();            //max number of shapeId
+
+        int dgMaxId = dg.getLastMSOSPID();   //max shapeId in the slide
+        int dgShapesUsed = dg.getNumShapes();          // number of shapes in the slide
+        //insert 3 shapes and make sure the Ids are properly incremented
+        for (int i = 0; i < 3; i++) {
+            shape = new Line();
+            assertEquals(0, shape.getShapeId());
+            slide.addShape(shape);
+            assertTrue(shape.getShapeId() > 0);
+
+            //check that EscherDgRecord is updated
+            assertEquals(shape.getShapeId(), dg.getLastMSOSPID());
+            assertEquals(dgMaxId + 1, dg.getLastMSOSPID());
+            assertEquals(dgShapesUsed + 1, dg.getNumShapes());
+
+            //check that EscherDggRecord is updated
+            assertEquals(shape.getShapeId() + 1, dgg.getShapeIdMax());
+            assertEquals(dggMaxId + 1, dgg.getShapeIdMax());
+            assertEquals(dggShapesUsed + 1, dgg.getNumShapesSaved());
+
+            dggShapesUsed = dgg.getNumShapesSaved();
+            dggMaxId = dgg.getShapeIdMax();
+            dgMaxId = dg.getLastMSOSPID();
+            dgShapesUsed = dg.getNumShapes();
+        }
+
+
+        //For each drawing group PPT allocates clusters with size=1024
+        //if the number of shapes is greater that 1024 a new cluster is allocated
+        //make sure it is so
+        int numClusters = dgg.getNumIdClusters();
+        for (int i = 0; i < 1025; i++) {
+            shape = new Line();
+            slide.addShape(shape);
+        }
+        assertEquals(numClusters + 1, dgg.getNumIdClusters());
     }
 }

Modified: poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java (original)
+++ poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java Tue May  6 09:00:36 2008
@@ -90,9 +90,11 @@
 		
 		// Now set it to not bold
 		rtr.setBold(false);
-		assertNotNull(rtr._getRawCharacterStyle());
-		assertNotNull(rtr._getRawParagraphStyle());
-		assertFalse(rtr.isBold());
+		//setting bold=false doesn't change the internal state
+        assertNull(rtr._getRawCharacterStyle());
+		assertNull(rtr._getRawParagraphStyle());
+
+        assertFalse(rtr.isBold());
 		
 		// And now make it bold
 		rtr.setBold(true);

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/ddf/AllPOIDDFTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/ddf/AllPOIDDFTests.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/ddf/AllPOIDDFTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/ddf/AllPOIDDFTests.java Tue May  6 09:00:36 2008
@@ -42,6 +42,7 @@
         result.addTestSuite(TestEscherSplitMenuColorsRecord.class);
         result.addTestSuite(TestEscherSpRecord.class);
         result.addTestSuite(TestUnknownEscherRecord.class);
+        result.addTestSuite(TestEscherBlipRecord.class);
         return result;
     }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java Tue May  6 09:00:36 2008
@@ -18,13 +18,24 @@
         
 package org.apache.poi.ddf;
 
+import java.io.File;
+import java.io.FileInputStream;
+
 import junit.framework.TestCase;
 import org.apache.poi.util.HexRead;
 import org.apache.poi.util.HexDump;
+import org.apache.poi.util.IOUtils;
 
 public class TestEscherContainerRecord extends TestCase
 {
-    public void testFillFields() throws Exception
+	private String ESCHER_DATA_PATH;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		ESCHER_DATA_PATH = System.getProperty("DDF.testdata.path");
+	}
+
+	public void testFillFields() throws Exception
     {
         EscherRecordFactory f = new DefaultEscherRecordFactory();
         byte[] data = HexRead.readFromString( "0F 02 11 F1 00 00 00 00" );
@@ -137,4 +148,19 @@
         assertEquals(18, r.getRecordSize());
     }
 
+    /**
+     * We were having problems with reading too much data on an UnknownEscherRecord,
+     *  but hopefully we now read the correct size.
+     */
+    public void testBug44857() throws Exception {
+    	File f = new File(ESCHER_DATA_PATH, "Container.dat");
+    	assertTrue(f.exists());
+    	
+    	FileInputStream finp = new FileInputStream(f);
+    	byte[] data = IOUtils.toByteArray(finp);
+    	
+    	// This used to fail with an OutOfMemory
+    	EscherContainerRecord record = new EscherContainerRecord();
+    	record.fillFields(data, 0, new DefaultEscherRecordFactory());
+    }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java Tue May  6 09:00:36 2008
@@ -172,4 +172,28 @@
 			throw new RuntimeException(e);
 		}
 	}
+
+	/**
+	 * @return byte array of sample file content from file found in standard hssf test data dir 
+	 */
+	public static byte[] getTestDataFileContent(String fileName) {
+		ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+		try {
+			InputStream fis = HSSFTestDataSamples.openSampleFileStream(fileName);
+
+			byte[] buf = new byte[512];
+			while (true) {
+				int bytesRead = fis.read(buf);
+				if (bytesRead < 1) {
+					break;
+				}
+				bos.write(buf, 0, bytesRead);
+			}
+			fis.close();
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+		return bos.toByteArray();
+	}
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java Tue May  6 09:00:36 2008
@@ -65,6 +65,7 @@
      * @return parsed token array already confirmed not <code>null</code>
      */
     private static Ptg[] parseFormula(String s) {
+    	// TODO - replace multiple copies of this code with calls to this method
         FormulaParser fp = new FormulaParser(s, null);
         fp.parse();
         Ptg[] result = fp.getRPNPtg();
@@ -86,7 +87,6 @@
         assertTrue("",(ptgs[0] instanceof IntPtg));
         assertTrue("",(ptgs[1] instanceof IntPtg));
         assertTrue("",(ptgs[2] instanceof AddPtg));
-
     }
 
     public void testFormulaWithSpace2() {
@@ -169,8 +169,6 @@
 		assertEquals("If FALSE offset", (short)7, ifPtg.getData());
 		
 		FuncVarPtg funcPtg = (FuncVarPtg)asts[8];
-		
-		
 	}
 
 	/**
@@ -190,8 +188,6 @@
 		assertTrue("It is not an if", ifFunc.isOptimizedIf());
 		
 		assertTrue("Average Function set correctly", (asts[5] instanceof FuncVarPtg));
-		
-				    	
 	}
 	
 	public void testIfSingleCondition(){
@@ -213,8 +209,6 @@
 		assertTrue("Ptg is not a Variable Function", (asts[6] instanceof FuncVarPtg));
 		FuncVarPtg funcPtg = (FuncVarPtg)asts[6];
 		assertEquals("Arguments", 2, funcPtg.getNumberOfOperands());
-		
-		
 	}
 
 	public void testSumIf() {
@@ -223,7 +217,6 @@
 		fp.parse();
 		Ptg[] asts = fp.getRPNPtg();
 		assertEquals("4 Ptgs expected", 4, asts.length);
-		
 	}
 	
 	/**
@@ -235,51 +228,35 @@
 		String currencyCell = "F3";
 		String function="\"TOTAL[\"&"+currencyCell+"&\"]\"";
 
-		FormulaParser fp = new FormulaParser(function, null);
-		fp.parse();
-		Ptg[] asts = fp.getRPNPtg();
+		Ptg[] asts = parseFormula(function);
 		assertEquals("5 ptgs expected", 5, asts.length);
 		assertTrue ("Ptg[0] is a string", (asts[0] instanceof StringPtg));
 		StringPtg firstString = (StringPtg)asts[0];		
 		
 		assertEquals("TOTAL[", firstString.getValue());
 		//the PTG order isn't 100% correct but it still works - dmui
-		
-					
 	}
 
 	public void testSimpleLogical() {
-		FormulaParser fp=new FormulaParser("IF(A1<A2,B1,B2)",null);
-		fp.parse();
-      Ptg[] ptgs = fp.getRPNPtg();
-      assertTrue("Ptg array should not be null", ptgs !=null);
+      Ptg[] ptgs = parseFormula("IF(A1<A2,B1,B2)");
       assertEquals("Ptg array length", 9, ptgs.length);
-      assertEquals("3rd Ptg is less than",LessThanPtg.class,ptgs[2].getClass());
-
-
+      assertEquals("3rd Ptg is less than", LessThanPtg.class, ptgs[2].getClass());
 	}
 	
 	public void testParenIf() {
-		FormulaParser fp=new FormulaParser("IF((A1+A2)<=3,\"yes\",\"no\")",null);
-		fp.parse();
-		Ptg[] ptgs = fp.getRPNPtg();
-		assertTrue("Ptg array should not be null", ptgs !=null);
+		Ptg[] ptgs = parseFormula("IF((A1+A2)<=3,\"yes\",\"no\")");
 		assertEquals("Ptg array length", 12, ptgs.length);
 		assertEquals("6th Ptg is less than equal",LessEqualPtg.class,ptgs[5].getClass());
 		assertEquals("11th Ptg is not a goto (Attr) ptg",AttrPtg.class,ptgs[10].getClass());
 	}
 	
 	public void testEmbeddedIf() {
-		FormulaParser fp=new FormulaParser("IF(3>=1,\"*\",IF(4<>1,\"first\",\"second\"))",null);
-		fp.parse();
-		Ptg[] ptgs = fp.getRPNPtg();
-		assertTrue("Ptg array should not be null", ptgs !=null);
+		Ptg[] ptgs = parseFormula("IF(3>=1,\"*\",IF(4<>1,\"first\",\"second\"))");
 		assertEquals("Ptg array length", 17, ptgs.length);
 		
 		assertEquals("6th Ptg is not a goto (Attr) ptg",AttrPtg.class,ptgs[5].getClass());
 		assertEquals("9th Ptg is not a not equal ptg",NotEqualPtg.class,ptgs[8].getClass());
 		assertEquals("15th Ptg is not the inner IF variable function ptg",FuncVarPtg.class,ptgs[14].getClass());
-		
 	}
 	
     public void testMacroFunction() {
@@ -302,16 +279,15 @@
         Ptg[] ptg = fp.getRPNPtg();
         assertTrue("first ptg is string",ptg[0] instanceof StringPtg);
         assertTrue("second ptg is string",ptg[1] instanceof StringPtg);
-
     }
 
-    public void testConcatenate(){
-         FormulaParser fp = new FormulaParser("CONCATENATE(\"first\",\"second\")",null);
-         fp.parse();
-         Ptg[] ptg = fp.getRPNPtg();
-        assertTrue("first ptg is string",ptg[0] instanceof StringPtg);
-        assertTrue("second ptg is string",ptg[1] instanceof StringPtg);
-    }
+    public void testConcatenate() {
+		FormulaParser fp = new FormulaParser("CONCATENATE(\"first\",\"second\")", null);
+		fp.parse();
+		Ptg[] ptg = fp.getRPNPtg();
+		assertTrue("first ptg is string", ptg[0] instanceof StringPtg);
+		assertTrue("second ptg is string", ptg[1] instanceof StringPtg);
+	}
 
     public void testWorksheetReferences()
     {
@@ -395,16 +371,16 @@
 
 	/** bug 33160, testcase by Amol Deshmukh*/
 	public void testSimpleLongFormula() {
-		        FormulaParser fp = new FormulaParser("40000/2", null);
-		        fp.parse();
-		        Ptg[] ptgs = fp.getRPNPtg();
-		        assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3);
-		        assertTrue("IntPtg",(ptgs[0] instanceof IntPtg));
-		        assertTrue("IntPtg",(ptgs[1] instanceof IntPtg));
-		        assertTrue("DividePtg",(ptgs[2] instanceof DividePtg));
+		FormulaParser fp = new FormulaParser("40000/2", null);
+		fp.parse();
+		Ptg[] ptgs = fp.getRPNPtg();
+		assertTrue("three tokens expected, got " + ptgs.length, ptgs.length == 3);
+		assertTrue("IntPtg", (ptgs[0] instanceof IntPtg));
+		assertTrue("IntPtg", (ptgs[1] instanceof IntPtg));
+		assertTrue("DividePtg", (ptgs[2] instanceof DividePtg));
 	}
 	
-	/** bug 35027, underscore in sheet name*/
+	/** bug 35027, underscore in sheet name */
 	public void testUnderscore() {
 		HSSFWorkbook wb = new HSSFWorkbook();
     	
@@ -592,7 +568,7 @@
     	HSSFWorkbook book = new HSSFWorkbook();
 
         Ptg[] ptgs = {
-                new FuncPtg(10, 0),
+                new FuncPtg(10),
         };
         assertEquals("NA()", FormulaParser.toFormulaString(book, ptgs));
     }
@@ -775,8 +751,34 @@
         StringPtg sp = (StringPtg) parseSingleToken(formula, StringPtg.class);
         assertEquals(expectedValue, sp.getValue());
     }
+    public void testParseStringLiterals_bug28754() {
+
+        StringPtg sp;
+        try {
+            sp = (StringPtg) parseSingleToken("\"test\"\"ing\"", StringPtg.class);
+        } catch (RuntimeException e) {
+            if(e.getMessage().startsWith("Cannot Parse")) {
+                throw new AssertionFailedError("Identified bug 28754a");
+            }
+            throw e;
+        }
+        assertEquals("test\"ing", sp.getValue());
+
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sheet = wb.createSheet();
+        wb.setSheetName(0, "Sheet1");
+
+        HSSFRow row = sheet.createRow(0);
+        HSSFCell cell = row.createCell((short)0);
+        cell.setCellFormula("right(\"test\"\"ing\", 3)");
+        String actualCellFormula = cell.getCellFormula();
+        if("RIGHT(\"test\"ing\",3)".equals(actualCellFormula)) {
+            throw new AssertionFailedError("Identified bug 28754b");
+        }
+        assertEquals("RIGHT(\"test\"\"ing\",3)", actualCellFormula);
+    }
 
-    public void testPaseStringLiterals() {
+    public void testParseStringLiterals() {
         confirmStringParse("goto considered harmful");
 
         confirmStringParse("goto 'considered' harmful");
@@ -810,10 +812,8 @@
         parseExpectedException("#DIV/ 0+2");
 
 
-        if (false) { // TODO - add functionality to detect func arg count mismatch
-            parseExpectedException("IF(TRUE)");
-            parseExpectedException("countif(A1:B5, C1, D1)");
-        }
+        parseExpectedException("IF(TRUE)");
+        parseExpectedException("countif(A1:B5, C1, D1)");
     }
 
     private static void parseExpectedException(String formula) {
@@ -887,8 +887,16 @@
             assertTrue(e.getMessage().startsWith("Too few arguments suppled to operation token"));
         }
     }
+    /**
+     * Make sure that POI uses the right Func Ptg when encoding formulas.  Functions with variable
+     * number of args should get FuncVarPtg, functions with fixed args should get FuncPtg.<p/>
+     * 
+     * Prior to the fix for bug 44675 POI would encode FuncVarPtg for all functions.  In many cases
+     * Excel tolerates the wrong Ptg and evaluates the formula OK (e.g. SIN), but in some cases 
+     * (e.g. COUNTIF) Excel fails to evaluate the formula, giving '#VALUE!' instead. 
+     */
     public void testFuncPtgSelection() {
-    	HSSFWorkbook book = new HSSFWorkbook();
+        HSSFWorkbook book = new HSSFWorkbook();
         Ptg[] ptgs;
         ptgs = FormulaParser.parse("countif(A1:A2, 1)", book);
         assertEquals(3, ptgs.length);
@@ -900,4 +908,21 @@
         assertEquals(2, ptgs.length);
         assertEquals(FuncPtg.class, ptgs[1].getClass());
     }
+    
+    public void testWrongNumberOfFunctionArgs() {
+        confirmArgCountMsg("sin()", "Too few arguments to function 'SIN'. Expected 1 but got 0.");
+        confirmArgCountMsg("countif(1, 2, 3, 4)", "Too many arguments to function 'COUNTIF'. Expected 2 but got 4.");
+        confirmArgCountMsg("index(1, 2, 3, 4, 5, 6)", "Too many arguments to function 'INDEX'. At most 4 were expected but got 6.");
+        confirmArgCountMsg("vlookup(1, 2)", "Too few arguments to function 'VLOOKUP'. At least 3 were expected but got 2.");
+    }
+
+    private static void confirmArgCountMsg(String formula, String expectedMessage) {
+        HSSFWorkbook book = new HSSFWorkbook();
+        try {
+            FormulaParser.parse(formula, book);
+            throw new AssertionFailedError("Didn't get parse exception as expected");
+        } catch (FormulaParseException e) {
+            assertEquals(expectedMessage, e.getMessage());
+        }
+    }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java Tue May  6 09:00:36 2008
@@ -67,6 +67,7 @@
 		result.addTestSuite(TestFormulaRecord.class);
 		result.addTestSuite(TestFrameRecord.class);
 		result.addTestSuite(TestHyperlinkRecord.class);
+		result.addTestSuite(TestLabelRecord.class);
 		result.addTestSuite(TestLegendRecord.class);
 		result.addTestSuite(TestLineFormatRecord.class);
 		result.addTestSuite(TestLinkedDataRecord.class);

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java Tue May  6 09:00:36 2008
@@ -40,9 +40,11 @@
 		result.addTestSuite(TestArea3DPtg.class);
 		result.addTestSuite(TestAreaErrPtg.class);
 		result.addTestSuite(TestAreaPtg.class);
+		result.addTestSuite(TestArrayPtg.class);
 		result.addTestSuite(TestErrPtg.class);
 		result.addTestSuite(TestExternalFunctionFormulas.class);
 		result.addTestSuite(TestFuncPtg.class);
+		result.addTestSuite(TestFuncVarPtg.class);
 		result.addTestSuite(TestIntersectionPtg.class);
 		result.addTestSuite(TestPercentPtg.class);
 		result.addTestSuite(TestRangePtg.class);

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java Tue May  6 09:00:36 2008
@@ -1,4 +1,3 @@
-        
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -18,20 +17,22 @@
 
 package org.apache.poi.hssf.record.formula;
 
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
  * Tests for {@link ReferencePtg}.
  */
-public class TestReferencePtg extends AbstractPtgTestCase
-{
+public final class TestReferencePtg extends TestCase {
     /**
      * Tests reading a file containing this ptg.
      */
-    public void testReading() throws Exception
-    {
-        HSSFWorkbook workbook = loadWorkbook("ReferencePtg.xls");
+    public void testReading() {
+        HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ReferencePtg.xls");
         HSSFSheet sheet = workbook.getSheetAt(0);
 
         // First row
@@ -72,6 +73,18 @@
         assertEquals("Wrong formula string for reference", "A32770",
                 sheet.getRow(32769).getCell((short) 1).getCellFormula());
     }
+    
+    public void testBug44921() {
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex44921-21902.xls");
+        
+        try {
+            HSSFTestDataSamples.writeOutAndReadBack(wb);
+        } catch (RuntimeException e) {
+            if(e.getMessage().equals("Coding Error: This method should never be called. This ptg should be converted")) {
+                throw new AssertionFailedError("Identified bug 44921");
+            }
+            throw e;
+        }
+    }
 }
 
-

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java Tue May  6 09:00:36 2008
@@ -14,7 +14,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-       
+
 package org.apache.poi.hssf.usermodel;
 
 import junit.framework.Test;
@@ -46,6 +46,7 @@
 		result.addTestSuite(TestHSSFHeaderFooter.class);
 		result.addTestSuite(TestHSSFHyperlink.class);
 		result.addTestSuite(TestHSSFPalette.class);
+		result.addTestSuite(TestHSSFPatriarch.class);
 		result.addTestSuite(TestHSSFPicture.class);
 		result.addTestSuite(TestHSSFPictureData.class);
 		result.addTestSuite(TestHSSFRichTextString.class);

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Tue May  6 09:00:36 2008
@@ -733,7 +733,7 @@
      *  with the NameRecord, once you get past the BOFRecord
      *  issue.
      */
-    public void DISABLEDtest42564Alt() {
+    public void test42564Alt() {
         HSSFWorkbook wb = openSample("42564-2.xls");
         writeOutAndReadBack(wb);
     }
@@ -883,10 +883,32 @@
      * Bug 28774: Excel will crash when opening xls-files with images.
      */
     public void test28774() {
-
         HSSFWorkbook wb = openSample("28774.xls");
         assertTrue("no errors reading sample xls", true);
         writeOutAndReadBack(wb);
         assertTrue("no errors writing sample xls", true);
     }
+    
+    /**
+     * Had a problem apparently, not sure what as it
+     *  works just fine...
+     */
+    public void test44891() throws Exception {
+    	HSSFWorkbook wb = openSample("44891.xls");
+        assertTrue("no errors reading sample xls", true);
+        writeOutAndReadBack(wb);
+        assertTrue("no errors writing sample xls", true);
+    }
+
+    /**
+     * Bug 44235: Ms Excel can't open save as excel file
+     *
+     * Works fine with poi-3.1-beta1.
+     */
+    public void test44235() throws Exception {
+    	HSSFWorkbook wb = openSample("44235.xls");
+        assertTrue("no errors reading sample xls", true);
+        writeOutAndReadBack(wb);
+        assertTrue("no errors writing sample xls", true);
+    }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java Tue May  6 09:00:36 2008
@@ -19,6 +19,7 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.util.Iterator;
 import java.util.List;
 
 import junit.framework.TestCase;
@@ -252,4 +253,29 @@
 		}
 		assertEquals(true, cell.getBooleanCellValue());
 	}
-}
+	
+	public void testClassCast_bug44861() throws Exception {
+		HSSFWorkbook wb = HSSFTestDataSamples.
+			openSampleWorkbook("44861.xls");
+		
+		// Check direct
+		HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
+		
+		// And via calls
+		int numSheets = wb.getNumberOfSheets();
+		for(int i=0; i<numSheets; i++) {
+			HSSFSheet s = wb.getSheetAt(i);
+			HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(s,wb);
+			
+			for(Iterator rows = s.rowIterator(); rows.hasNext();) {
+		        HSSFRow r = (HSSFRow)rows.next();
+		        eval.setCurrentRow(r);
+		        
+		        for(Iterator cells = r.cellIterator(); cells.hasNext();) {
+		        	HSSFCell c = (HSSFCell)cells.next();
+		        	eval.evaluateFormulaCell(c);
+		        }
+			}
+		}
+	}
+}
\ No newline at end of file

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java Tue May  6 09:00:36 2008
@@ -16,10 +16,6 @@
 */
 package org.apache.poi.hssf.usermodel;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -36,7 +32,7 @@
         HSSFSheet sh1 = wb.createSheet();
         HSSFPatriarch p1 = sh1.createDrawingPatriarch();
 
-        byte[] pictureData = getTestDataFileContent("logoKarmokar4.png");
+        byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png");
         int idx1 = wb.addPicture( pictureData, HSSFWorkbook.PICTURE_TYPE_PNG );
         HSSFPicture picture1 = p1.createPicture(new HSSFClientAnchor(), idx1);
         HSSFClientAnchor anchor1 = picture1.getPreferredSize();
@@ -51,28 +47,4 @@
         assertEquals(848, anchor1.getDx2());
         assertEquals(240, anchor1.getDy2());
     }
-
-    /**
-     * Copied from org.apache.poi.hssf.usermodel.examples.OfficeDrawing
-     */
-     private static byte[] getTestDataFileContent(String fileName) {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
-        try {
-            InputStream fis = HSSFTestDataSamples.openSampleFileStream(fileName);
-
-            byte[] buf = new byte[512];
-            while(true) {
-                int bytesRead = fis.read(buf);
-                if(bytesRead < 1) {
-                    break;
-                }
-                bos.write(buf, 0, bytesRead);
-            }
-            fis.close();
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-        return bos.toByteArray();
-     }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java?rev=653822&r1=653821&r2=653822&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java Tue May  6 09:00:36 2008
@@ -17,6 +17,7 @@
 
 package org.apache.poi.hssf.usermodel;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -39,7 +40,24 @@
         NameRecord nameRecord = b.getWorkbook().getNameRecord( 0 );
         assertEquals( 3, nameRecord.getIndexToSheet() );
     }
-    
+
+    public void testCaseInsensitiveNames() {
+        HSSFWorkbook b = new HSSFWorkbook( );
+        HSSFSheet originalSheet = b.createSheet("Sheet1");
+        HSSFSheet fetchedSheet = b.getSheet("sheet1");
+        if(fetchedSheet == null) {
+            throw new AssertionFailedError("Identified bug 44892");
+        }
+        assertEquals(originalSheet, fetchedSheet);
+        try {
+            b.createSheet("sHeeT1");
+            fail("should have thrown exceptiuon due to duplicate sheet name");
+        } catch (IllegalArgumentException e) {
+            // expected during successful test
+            assertEquals("The workbook already contains a sheet of this name", e.getMessage());
+        }
+    }
+
     public void testDuplicateNames() {
         HSSFWorkbook b = new HSSFWorkbook( );
         b.createSheet("Sheet1");



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message