diff options
author | Glen Stampoultzis <glens@apache.org> | 2004-04-09 12:22:22 +0000 |
---|---|---|
committer | Glen Stampoultzis <glens@apache.org> | 2004-04-09 12:22:22 +0000 |
commit | 2a18a0a3c6bdaa3b8cd20722ddbd183774c38ff4 (patch) | |
tree | 5b77e3b0c2f0f48f4d79f190ef90d1b5db7c3aa1 /src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java | |
parent | 6473d8f7883f0d30da86a935e52cc66a9ed6aae1 (diff) | |
download | poi-2a18a0a3c6bdaa3b8cd20722ddbd183774c38ff4.tar.gz poi-2a18a0a3c6bdaa3b8cd20722ddbd183774c38ff4.zip |
Moved some tests that were added to the wrong source branch.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353544 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java new file mode 100644 index 0000000000..3f77c8b955 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java @@ -0,0 +1,79 @@ +package org.apache.poi.hssf.usermodel; + +import junit.framework.TestCase; + +import java.awt.*; +import java.io.FileOutputStream; + +/** + * Tests the Graphics2d drawing capability. + * + * @author Glen Stampoultzis (glens at apache.org) + */ +public class TestEscherGraphics2d extends TestCase +{ + private HSSFShapeGroup escherGroup; + private EscherGraphics2d graphics; + + protected void setUp() throws Exception + { + super.setUp(); + + HSSFWorkbook workbook = new HSSFWorkbook(); + HSSFSheet sheet = workbook.createSheet("test"); + escherGroup = sheet.createDrawingPatriarch().createGroup(new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short) 0,0)); + escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor()); + EscherGraphics g = new EscherGraphics(this.escherGroup, workbook, Color.black, 1.0f); + graphics = new EscherGraphics2d(g); + + } + + public void testDrawString() throws Exception + { + graphics.drawString("This is a test", 10, 10); + HSSFTextbox t = (HSSFTextbox) escherGroup.getChildren().get(0); + assertEquals("This is a test", t.getString().toString()); + } + + public void testFillRect() throws Exception + { + graphics.fillRect( 10, 10, 20, 20 ); + HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0); + assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.getShapeType()); + assertEquals(10, s.getAnchor().getDx1()); + assertEquals(10, s.getAnchor().getDy1()); + assertEquals(30, s.getAnchor().getDy2()); + assertEquals(30, s.getAnchor().getDx2()); + } + + public void testGetFontMetrics() throws Exception + { + FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont()); + if (graphics.getFont().toString().indexOf("dialog") != -1) // if dialog is returned we can't run the test properly. + return; + assertEquals(7, fontMetrics.charWidth('X')); + assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString()); + } + + public void testSetFont() throws Exception + { + Font f = new Font("Helvetica", 0, 12); + graphics.setFont(f); + assertEquals(f, graphics.getFont()); + } + + public void testSetColor() throws Exception + { + graphics.setColor(Color.red); + assertEquals(Color.red, graphics.getColor()); + } + + public void testGetFont() throws Exception + { + Font f = graphics.getFont(); + if (graphics.getFont().toString().indexOf("dialog") != -1) // if dialog is returned we can't run the test properly. + return; + + assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString()); + } +} |