xref: /AOO41X/test/testuno/source/fvt/uno/sd/graphic/GraphicPro_Border.java (revision d3e0dd8eb215533c15e891ee35bd141abe9397ee)
11fc5ddf8SLi Feng Wang /**************************************************************
21fc5ddf8SLi Feng Wang  *
31fc5ddf8SLi Feng Wang  * Licensed to the Apache Software Foundation (ASF) under one
41fc5ddf8SLi Feng Wang  * or more contributor license agreements.  See the NOTICE file
51fc5ddf8SLi Feng Wang  * distributed with this work for additional information
61fc5ddf8SLi Feng Wang  * regarding copyright ownership.  The ASF licenses this file
71fc5ddf8SLi Feng Wang  * to you under the Apache License, Version 2.0 (the
81fc5ddf8SLi Feng Wang  * "License"); you may not use this file except in compliance
91fc5ddf8SLi Feng Wang  * with the License.  You may obtain a copy of the License at
101fc5ddf8SLi Feng Wang  *
111fc5ddf8SLi Feng Wang  *   http://www.apache.org/licenses/LICENSE-2.0
121fc5ddf8SLi Feng Wang  *
131fc5ddf8SLi Feng Wang  * Unless required by applicable law or agreed to in writing,
141fc5ddf8SLi Feng Wang  * software distributed under the License is distributed on an
151fc5ddf8SLi Feng Wang  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
161fc5ddf8SLi Feng Wang  * KIND, either express or implied.  See the License for the
171fc5ddf8SLi Feng Wang  * specific language governing permissions and limitations
181fc5ddf8SLi Feng Wang  * under the License.
191fc5ddf8SLi Feng Wang  *
201fc5ddf8SLi Feng Wang  *************************************************************/
211fc5ddf8SLi Feng Wang package fvt.uno.sd.graphic;
221fc5ddf8SLi Feng Wang import static org.junit.Assert.*;
231fc5ddf8SLi Feng Wang import static testlib.uno.GraphicUtil.getGraphicsOfPage;
241fc5ddf8SLi Feng Wang import static testlib.uno.GraphicUtil.getSizePixelOfGraphicFile;
251fc5ddf8SLi Feng Wang import static testlib.uno.GraphicUtil.insertGraphic;
261fc5ddf8SLi Feng Wang import static testlib.uno.SDUtil.saveFileAs;
271fc5ddf8SLi Feng Wang 
281fc5ddf8SLi Feng Wang import java.util.Arrays;
291fc5ddf8SLi Feng Wang import java.util.Collection;
301fc5ddf8SLi Feng Wang 
311fc5ddf8SLi Feng Wang import org.junit.After;
321fc5ddf8SLi Feng Wang import org.junit.AfterClass;
331fc5ddf8SLi Feng Wang import org.junit.Before;
341fc5ddf8SLi Feng Wang import org.junit.BeforeClass;
351fc5ddf8SLi Feng Wang import org.junit.Ignore;
361fc5ddf8SLi Feng Wang import org.junit.Test;
371fc5ddf8SLi Feng Wang import org.junit.runner.RunWith;
381fc5ddf8SLi Feng Wang import org.junit.runners.Parameterized;
391fc5ddf8SLi Feng Wang import org.junit.runners.Parameterized.Parameters;
401fc5ddf8SLi Feng Wang import org.openoffice.test.uno.UnoApp;
411fc5ddf8SLi Feng Wang import org.openoffice.test.common.FileUtil;
421fc5ddf8SLi Feng Wang import org.openoffice.test.common.Testspace;
431fc5ddf8SLi Feng Wang 
441fc5ddf8SLi Feng Wang import testlib.uno.SDUtil;
451fc5ddf8SLi Feng Wang import testlib.uno.TestUtil;
461fc5ddf8SLi Feng Wang 
471fc5ddf8SLi Feng Wang import com.sun.star.awt.Point;
481fc5ddf8SLi Feng Wang import com.sun.star.awt.Size;
491fc5ddf8SLi Feng Wang import com.sun.star.beans.XPropertySet;
501fc5ddf8SLi Feng Wang import com.sun.star.drawing.LineStyle;
511fc5ddf8SLi Feng Wang import com.sun.star.drawing.XDrawPage;
521fc5ddf8SLi Feng Wang import com.sun.star.drawing.XShape;
531fc5ddf8SLi Feng Wang import com.sun.star.lang.XComponent;
541fc5ddf8SLi Feng Wang import com.sun.star.uno.UnoRuntime;
551fc5ddf8SLi Feng Wang @RunWith(Parameterized.class)
561fc5ddf8SLi Feng Wang public class GraphicPro_Border {
571fc5ddf8SLi Feng Wang 
581fc5ddf8SLi Feng Wang 	private static final UnoApp app = new UnoApp();
591fc5ddf8SLi Feng Wang 
601fc5ddf8SLi Feng Wang 	private XComponent m_xSDComponent = null;
611fc5ddf8SLi Feng Wang 	private XDrawPage m_xCurrentPage=null;
621fc5ddf8SLi Feng Wang 
631fc5ddf8SLi Feng Wang 	private LineStyle m_LineStyle;
641fc5ddf8SLi Feng Wang 	private String m_LineDashName = null;
651fc5ddf8SLi Feng Wang 	private int m_LineColor = 0;
661fc5ddf8SLi Feng Wang 	private LineStyle m_expLineStyle;
671fc5ddf8SLi Feng Wang 	private String m_expLineDashName = null;
681fc5ddf8SLi Feng Wang 	private int m_expLineColor = 0;
691fc5ddf8SLi Feng Wang 
GraphicPro_Border(LineStyle lineStyle, String lineDashName, int lineColor, LineStyle expLineStyle, String expLineDashName, int expLineColor)701fc5ddf8SLi Feng Wang 	public GraphicPro_Border(LineStyle lineStyle, String lineDashName, int lineColor, LineStyle expLineStyle, String expLineDashName, int expLineColor){
711fc5ddf8SLi Feng Wang 		m_LineStyle = lineStyle;
721fc5ddf8SLi Feng Wang 		m_LineDashName = lineDashName;
731fc5ddf8SLi Feng Wang 		m_LineColor = lineColor;
741fc5ddf8SLi Feng Wang 		m_expLineStyle = expLineStyle;
751fc5ddf8SLi Feng Wang 		m_expLineDashName = expLineDashName;
761fc5ddf8SLi Feng Wang 		m_expLineColor = expLineColor;
771fc5ddf8SLi Feng Wang 	}
781fc5ddf8SLi Feng Wang 
791fc5ddf8SLi Feng Wang 	@Parameters
data()801fc5ddf8SLi Feng Wang 	public static Collection<Object[]> data() throws Exception {
811fc5ddf8SLi Feng Wang 		int[] colorList = TestUtil.randColorList(13);
821fc5ddf8SLi Feng Wang 
831fc5ddf8SLi Feng Wang 		return Arrays.asList(new Object[][] {
841fc5ddf8SLi Feng Wang 			//{lineStyle, LineDashName, line Color, file type, expLineStyle, expLineDashName, expLineColor}
851fc5ddf8SLi Feng Wang 			{LineStyle.NONE, "Invisible", colorList[0], LineStyle.NONE, "Invisible", colorList[0]},
861fc5ddf8SLi Feng Wang 			{LineStyle.SOLID,"Continuous", colorList[1], LineStyle.SOLID,"Continuous", colorList[1]},
871fc5ddf8SLi Feng Wang 			{LineStyle.DASH,"Ultrafine Dashed", colorList[2], LineStyle.DASH,"Ultrafine Dashed", colorList[2]},
881fc5ddf8SLi Feng Wang 			{LineStyle.DASH,"Fine Dashed", colorList[3], LineStyle.DASH,"Fine Dashed", colorList[3]},
89*2c0d454cSHerbert Dürr 			{LineStyle.DASH,"Ultrafine 2 Dots 3 Dashes", colorList[4], LineStyle.DASH,"Ultrafine 2 Dots 3 Dashes", colorList[4]},
901fc5ddf8SLi Feng Wang 			{LineStyle.DASH,"Fine Dotted", colorList[5],  LineStyle.DASH,"Fine Dotted", colorList[5]},
911fc5ddf8SLi Feng Wang 			{LineStyle.DASH,"Line with Fine Dots", colorList[6], LineStyle.DASH,"Line with Fine Dots", colorList[6]},
921fc5ddf8SLi Feng Wang 			{LineStyle.DASH,"Fine Dashed (var)", colorList[7], LineStyle.DASH,"Fine Dashed (var)", colorList[7]},
931fc5ddf8SLi Feng Wang 			{LineStyle.DASH,"3 Dashes 3 Dots (var)", colorList[8], LineStyle.DASH,"3 Dashes 3 Dots (var)", colorList[8]},
941fc5ddf8SLi Feng Wang 			{LineStyle.DASH,"Ultrafine Dotted (var)", colorList[9], LineStyle.DASH,"Ultrafine Dotted (var)", colorList[9]},
951fc5ddf8SLi Feng Wang 			{LineStyle.DASH,"Line Style 9", colorList[10], LineStyle.DASH,"Line Style 9", colorList[10]},
961fc5ddf8SLi Feng Wang 			{LineStyle.DASH,"2 Dots 1 Dash", colorList[11], LineStyle.DASH,"2 Dots 1 Dash", colorList[11]},
971fc5ddf8SLi Feng Wang 			{LineStyle.DASH,"Dashed (var)", colorList[12], LineStyle.DASH,"Dashed (var)", colorList[12]},
981fc5ddf8SLi Feng Wang 		});
991fc5ddf8SLi Feng Wang 	}
1001fc5ddf8SLi Feng Wang 
1011fc5ddf8SLi Feng Wang 	@Before
setUpDocument()1021fc5ddf8SLi Feng Wang 	public void setUpDocument() throws Exception {
1031fc5ddf8SLi Feng Wang 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(
1041fc5ddf8SLi Feng Wang 				XComponent.class, app.newDocument("simpress"));
1051fc5ddf8SLi Feng Wang 		Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0);
1061fc5ddf8SLi Feng Wang 		m_xCurrentPage = (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage);
1071fc5ddf8SLi Feng Wang 		String graphicURL = FileUtil.getUrl(Testspace.prepareData("uno/sd/36.gif"));
1081fc5ddf8SLi Feng Wang 
1091fc5ddf8SLi Feng Wang 		Size orgSize = getSizePixelOfGraphicFile(app,graphicURL);
1101fc5ddf8SLi Feng Wang 	    Size newSize = new Size(orgSize.Width*2645/100, orgSize.Height*2645/100);
1111fc5ddf8SLi Feng Wang 		insertGraphic(m_xSDComponent, m_xCurrentPage, graphicURL, newSize, new Point(5000, 5000));
1121fc5ddf8SLi Feng Wang 	}
1131fc5ddf8SLi Feng Wang 
1141fc5ddf8SLi Feng Wang 	@After
tearDownDocument()1151fc5ddf8SLi Feng Wang 	public void tearDownDocument() {
1161fc5ddf8SLi Feng Wang 		app.closeDocument(m_xSDComponent);
1171fc5ddf8SLi Feng Wang 
1181fc5ddf8SLi Feng Wang 	}
1191fc5ddf8SLi Feng Wang 
1201fc5ddf8SLi Feng Wang 	@BeforeClass
setUpConnection()1211fc5ddf8SLi Feng Wang 	public static void setUpConnection() throws Exception {
1221fc5ddf8SLi Feng Wang 		app.start();
1231fc5ddf8SLi Feng Wang 	}
1241fc5ddf8SLi Feng Wang 
1251fc5ddf8SLi Feng Wang 	@AfterClass
tearDownConnection()1261fc5ddf8SLi Feng Wang 	public static void tearDownConnection() throws InterruptedException,
1271fc5ddf8SLi Feng Wang 			Exception {
1281fc5ddf8SLi Feng Wang 		app.close();
1291fc5ddf8SLi Feng Wang 		//remove the temp file
1301fc5ddf8SLi Feng Wang 		FileUtil.deleteFile(Testspace.getPath("temp"));
1311fc5ddf8SLi Feng Wang 	}
1321fc5ddf8SLi Feng Wang 
load(String filePath)1331fc5ddf8SLi Feng Wang 	private XDrawPage load(String filePath) throws Exception{
1341fc5ddf8SLi Feng Wang 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
1351fc5ddf8SLi Feng Wang 				app.loadDocument(filePath));
1361fc5ddf8SLi Feng Wang 		Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0);
1371fc5ddf8SLi Feng Wang 		return (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage);
1381fc5ddf8SLi Feng Wang 	}
1391fc5ddf8SLi Feng Wang 
1401fc5ddf8SLi Feng Wang 	@Test
testGraphicBorder_ODP()1411fc5ddf8SLi Feng Wang 	public void testGraphicBorder_ODP() throws Exception {
1421fc5ddf8SLi Feng Wang 		String fileName = "GraphicPro_LineColor";
1431fc5ddf8SLi Feng Wang 		String fileType = ".odp";
1441fc5ddf8SLi Feng Wang 		String filePath = Testspace.getPath("temp/"+fileName+"."+fileType);
1451fc5ddf8SLi Feng Wang 		Object[] graphics = getGraphicsOfPage(m_xCurrentPage);
1461fc5ddf8SLi Feng Wang 		Object oGraphic = graphics[0];
1471fc5ddf8SLi Feng Wang 		XShape xGraphicShape = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic);
1481fc5ddf8SLi Feng Wang 
1491fc5ddf8SLi Feng Wang 		XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(
1501fc5ddf8SLi Feng Wang 			     XPropertySet.class, xGraphicShape );
1511fc5ddf8SLi Feng Wang 
1521fc5ddf8SLi Feng Wang 		xPropSet.setPropertyValue( "LineStyle", this.m_LineStyle);
1531fc5ddf8SLi Feng Wang 		if(m_LineStyle == LineStyle.DASH)
1541fc5ddf8SLi Feng Wang 		{
1551fc5ddf8SLi Feng Wang 			xPropSet.setPropertyValue( "LineDashName", this.m_LineDashName);
1561fc5ddf8SLi Feng Wang 		}
1571fc5ddf8SLi Feng Wang 		if(m_LineStyle != LineStyle.NONE)
1581fc5ddf8SLi Feng Wang 			xPropSet.setPropertyValue( "LineColor", this.m_LineColor);
1591fc5ddf8SLi Feng Wang 
1601fc5ddf8SLi Feng Wang 		saveFileAs(m_xSDComponent, fileName, fileType);
1611fc5ddf8SLi Feng Wang 		app.closeDocument(m_xSDComponent);
1621fc5ddf8SLi Feng Wang 
1631fc5ddf8SLi Feng Wang 		XDrawPage CurrentPage = load(filePath);
1641fc5ddf8SLi Feng Wang 		Object oGraphic2 = getGraphicsOfPage(CurrentPage)[0];
1651fc5ddf8SLi Feng Wang 		XShape xGraphicShape2 = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic2);
1661fc5ddf8SLi Feng Wang 		XPropertySet xPropSet2 = (XPropertySet)UnoRuntime.queryInterface(
1671fc5ddf8SLi Feng Wang 			     XPropertySet.class, xGraphicShape2 );
1681fc5ddf8SLi Feng Wang 
1691fc5ddf8SLi Feng Wang 		assertEquals("line style changed", this.m_expLineStyle, xPropSet2.getPropertyValue("LineStyle"));
1701fc5ddf8SLi Feng Wang 		if(m_LineStyle != LineStyle.NONE)
1711fc5ddf8SLi Feng Wang 			assertEquals("line color changed", this.m_expLineColor, xPropSet2.getPropertyValue("LineColor"));
1721fc5ddf8SLi Feng Wang 		if(m_LineStyle == LineStyle.DASH)
1731fc5ddf8SLi Feng Wang 			assertEquals("line DashName changed", this.m_expLineDashName, xPropSet2.getPropertyValue("LineDashName"));
1741fc5ddf8SLi Feng Wang 	}
1751fc5ddf8SLi Feng Wang 
1761fc5ddf8SLi Feng Wang 	@Ignore("Bug #120982 - [From Symphony]graphic border missing after open .ppt file in Aoo")
1771fc5ddf8SLi Feng Wang 	@Test
testGraphicBorder_PPT()1781fc5ddf8SLi Feng Wang 	public void testGraphicBorder_PPT() throws Exception {
1791fc5ddf8SLi Feng Wang 		String fileName = "GraphicPro_LineColor";
1801fc5ddf8SLi Feng Wang 		String fileType = ".ppt";
1811fc5ddf8SLi Feng Wang 		String filePath = Testspace.getPath("temp/"+fileName+"."+fileType);
1821fc5ddf8SLi Feng Wang 		Object[] graphics = getGraphicsOfPage(m_xCurrentPage);
1831fc5ddf8SLi Feng Wang 		Object oGraphic = graphics[0];
1841fc5ddf8SLi Feng Wang 		XShape xGraphicShape = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic);
1851fc5ddf8SLi Feng Wang 
1861fc5ddf8SLi Feng Wang 		XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(
1871fc5ddf8SLi Feng Wang 			     XPropertySet.class, xGraphicShape );
1881fc5ddf8SLi Feng Wang 
1891fc5ddf8SLi Feng Wang 		xPropSet.setPropertyValue( "LineStyle", this.m_LineStyle);
1901fc5ddf8SLi Feng Wang 		if(m_LineStyle == LineStyle.DASH)
1911fc5ddf8SLi Feng Wang 		{
1921fc5ddf8SLi Feng Wang 			xPropSet.setPropertyValue( "LineDashName", this.m_LineDashName);
1931fc5ddf8SLi Feng Wang 		}
1941fc5ddf8SLi Feng Wang 		if(m_LineStyle != LineStyle.NONE)
1951fc5ddf8SLi Feng Wang 			xPropSet.setPropertyValue( "LineColor", this.m_LineColor);
1961fc5ddf8SLi Feng Wang 
1971fc5ddf8SLi Feng Wang 		saveFileAs(m_xSDComponent, fileName, fileType);
1981fc5ddf8SLi Feng Wang 		app.closeDocument(m_xSDComponent);
1991fc5ddf8SLi Feng Wang 
2001fc5ddf8SLi Feng Wang 		XDrawPage CurrentPage = load(filePath);
2011fc5ddf8SLi Feng Wang 		Object oGraphic2 = getGraphicsOfPage(CurrentPage)[0];
2021fc5ddf8SLi Feng Wang 		XShape xGraphicShape2 = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic2);
2031fc5ddf8SLi Feng Wang 		XPropertySet xPropSet2 = (XPropertySet)UnoRuntime.queryInterface(
2041fc5ddf8SLi Feng Wang 			     XPropertySet.class, xGraphicShape2 );
2051fc5ddf8SLi Feng Wang 
2061fc5ddf8SLi Feng Wang 		assertEquals("line style changed", this.m_expLineStyle, xPropSet2.getPropertyValue("LineStyle"));
2071fc5ddf8SLi Feng Wang 		if(m_LineStyle != LineStyle.NONE)
2081fc5ddf8SLi Feng Wang 			assertEquals("line color changed", this.m_expLineColor, xPropSet2.getPropertyValue("LineColor"));
2091fc5ddf8SLi Feng Wang 		if(m_LineStyle == LineStyle.DASH)
2101fc5ddf8SLi Feng Wang 			assertEquals("line DashName changed", this.m_expLineDashName, xPropSet2.getPropertyValue("LineDashName"));
2111fc5ddf8SLi Feng Wang 	}
2121fc5ddf8SLi Feng Wang 
2131fc5ddf8SLi Feng Wang }
214