1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 package fvt.uno.sd.graphic;
22 import static org.junit.Assert.*;
23 import static testlib.uno.GraphicUtil.getGraphicsOfPage;
24 import static testlib.uno.GraphicUtil.getSizePixelOfGraphicFile;
25 import static testlib.uno.GraphicUtil.insertGraphic;
26 import static testlib.uno.SDUtil.saveFileAs;
27 
28 import java.util.Arrays;
29 import java.util.Collection;
30 
31 import org.junit.After;
32 import org.junit.AfterClass;
33 import org.junit.Before;
34 import org.junit.BeforeClass;
35 import org.junit.Ignore;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.junit.runners.Parameterized;
39 import org.junit.runners.Parameterized.Parameters;
40 import org.openoffice.test.uno.UnoApp;
41 import org.openoffice.test.common.FileUtil;
42 import org.openoffice.test.common.Testspace;
43 
44 import testlib.uno.SDUtil;
45 import testlib.uno.TestUtil;
46 
47 import com.sun.star.awt.Point;
48 import com.sun.star.awt.Size;
49 import com.sun.star.beans.XPropertySet;
50 import com.sun.star.drawing.LineStyle;
51 import com.sun.star.drawing.XDrawPage;
52 import com.sun.star.drawing.XShape;
53 import com.sun.star.lang.XComponent;
54 import com.sun.star.uno.UnoRuntime;
55 @RunWith(Parameterized.class)
56 public class GraphicPro_Border {
57 
58 	private static final UnoApp app = new UnoApp();
59 
60 	private XComponent m_xSDComponent = null;
61 	private XDrawPage m_xCurrentPage=null;
62 
63 	private LineStyle m_LineStyle;
64 	private String m_LineDashName = null;
65 	private int m_LineColor = 0;
66 	private LineStyle m_expLineStyle;
67 	private String m_expLineDashName = null;
68 	private int m_expLineColor = 0;
69 
GraphicPro_Border(LineStyle lineStyle, String lineDashName, int lineColor, LineStyle expLineStyle, String expLineDashName, int expLineColor)70 	public GraphicPro_Border(LineStyle lineStyle, String lineDashName, int lineColor, LineStyle expLineStyle, String expLineDashName, int expLineColor){
71 		m_LineStyle = lineStyle;
72 		m_LineDashName = lineDashName;
73 		m_LineColor = lineColor;
74 		m_expLineStyle = expLineStyle;
75 		m_expLineDashName = expLineDashName;
76 		m_expLineColor = expLineColor;
77 	}
78 
79 	@Parameters
data()80 	public static Collection<Object[]> data() throws Exception {
81 		int[] colorList = TestUtil.randColorList(13);
82 
83 		return Arrays.asList(new Object[][] {
84 			//{lineStyle, LineDashName, line Color, file type, expLineStyle, expLineDashName, expLineColor}
85 			{LineStyle.NONE, "Invisible", colorList[0], LineStyle.NONE, "Invisible", colorList[0]},
86 			{LineStyle.SOLID,"Continuous", colorList[1], LineStyle.SOLID,"Continuous", colorList[1]},
87 			{LineStyle.DASH,"Ultrafine Dashed", colorList[2], LineStyle.DASH,"Ultrafine Dashed", colorList[2]},
88 			{LineStyle.DASH,"Fine Dashed", colorList[3], LineStyle.DASH,"Fine Dashed", colorList[3]},
89 			{LineStyle.DASH,"Ultrafine 2 Dots 3 Dashes", colorList[4], LineStyle.DASH,"Ultrafine 2 Dots 3 Dashes", colorList[4]},
90 			{LineStyle.DASH,"Fine Dotted", colorList[5],  LineStyle.DASH,"Fine Dotted", colorList[5]},
91 			{LineStyle.DASH,"Line with Fine Dots", colorList[6], LineStyle.DASH,"Line with Fine Dots", colorList[6]},
92 			{LineStyle.DASH,"Fine Dashed (var)", colorList[7], LineStyle.DASH,"Fine Dashed (var)", colorList[7]},
93 			{LineStyle.DASH,"3 Dashes 3 Dots (var)", colorList[8], LineStyle.DASH,"3 Dashes 3 Dots (var)", colorList[8]},
94 			{LineStyle.DASH,"Ultrafine Dotted (var)", colorList[9], LineStyle.DASH,"Ultrafine Dotted (var)", colorList[9]},
95 			{LineStyle.DASH,"Line Style 9", colorList[10], LineStyle.DASH,"Line Style 9", colorList[10]},
96 			{LineStyle.DASH,"2 Dots 1 Dash", colorList[11], LineStyle.DASH,"2 Dots 1 Dash", colorList[11]},
97 			{LineStyle.DASH,"Dashed (var)", colorList[12], LineStyle.DASH,"Dashed (var)", colorList[12]},
98 		});
99 	}
100 
101 	@Before
setUpDocument()102 	public void setUpDocument() throws Exception {
103 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(
104 				XComponent.class, app.newDocument("simpress"));
105 		Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0);
106 		m_xCurrentPage = (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage);
107 		String graphicURL = FileUtil.getUrl(Testspace.prepareData("uno/sd/36.gif"));
108 
109 		Size orgSize = getSizePixelOfGraphicFile(app,graphicURL);
110 	    Size newSize = new Size(orgSize.Width*2645/100, orgSize.Height*2645/100);
111 		insertGraphic(m_xSDComponent, m_xCurrentPage, graphicURL, newSize, new Point(5000, 5000));
112 	}
113 
114 	@After
tearDownDocument()115 	public void tearDownDocument() {
116 		app.closeDocument(m_xSDComponent);
117 
118 	}
119 
120 	@BeforeClass
setUpConnection()121 	public static void setUpConnection() throws Exception {
122 		app.start();
123 	}
124 
125 	@AfterClass
tearDownConnection()126 	public static void tearDownConnection() throws InterruptedException,
127 			Exception {
128 		app.close();
129 		//remove the temp file
130 		FileUtil.deleteFile(Testspace.getPath("temp"));
131 	}
132 
load(String filePath)133 	private XDrawPage load(String filePath) throws Exception{
134 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
135 				app.loadDocument(filePath));
136 		Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0);
137 		return (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage);
138 	}
139 
140 	@Test
testGraphicBorder_ODP()141 	public void testGraphicBorder_ODP() throws Exception {
142 		String fileName = "GraphicPro_LineColor";
143 		String fileType = ".odp";
144 		String filePath = Testspace.getPath("temp/"+fileName+"."+fileType);
145 		Object[] graphics = getGraphicsOfPage(m_xCurrentPage);
146 		Object oGraphic = graphics[0];
147 		XShape xGraphicShape = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic);
148 
149 		XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(
150 			     XPropertySet.class, xGraphicShape );
151 
152 		xPropSet.setPropertyValue( "LineStyle", this.m_LineStyle);
153 		if(m_LineStyle == LineStyle.DASH)
154 		{
155 			xPropSet.setPropertyValue( "LineDashName", this.m_LineDashName);
156 		}
157 		if(m_LineStyle != LineStyle.NONE)
158 			xPropSet.setPropertyValue( "LineColor", this.m_LineColor);
159 
160 		saveFileAs(m_xSDComponent, fileName, fileType);
161 		app.closeDocument(m_xSDComponent);
162 
163 		XDrawPage CurrentPage = load(filePath);
164 		Object oGraphic2 = getGraphicsOfPage(CurrentPage)[0];
165 		XShape xGraphicShape2 = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic2);
166 		XPropertySet xPropSet2 = (XPropertySet)UnoRuntime.queryInterface(
167 			     XPropertySet.class, xGraphicShape2 );
168 
169 		assertEquals("line style changed", this.m_expLineStyle, xPropSet2.getPropertyValue("LineStyle"));
170 		if(m_LineStyle != LineStyle.NONE)
171 			assertEquals("line color changed", this.m_expLineColor, xPropSet2.getPropertyValue("LineColor"));
172 		if(m_LineStyle == LineStyle.DASH)
173 			assertEquals("line DashName changed", this.m_expLineDashName, xPropSet2.getPropertyValue("LineDashName"));
174 	}
175 
176 	@Ignore("Bug #120982 - [From Symphony]graphic border missing after open .ppt file in Aoo")
177 	@Test
testGraphicBorder_PPT()178 	public void testGraphicBorder_PPT() throws Exception {
179 		String fileName = "GraphicPro_LineColor";
180 		String fileType = ".ppt";
181 		String filePath = Testspace.getPath("temp/"+fileName+"."+fileType);
182 		Object[] graphics = getGraphicsOfPage(m_xCurrentPage);
183 		Object oGraphic = graphics[0];
184 		XShape xGraphicShape = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic);
185 
186 		XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(
187 			     XPropertySet.class, xGraphicShape );
188 
189 		xPropSet.setPropertyValue( "LineStyle", this.m_LineStyle);
190 		if(m_LineStyle == LineStyle.DASH)
191 		{
192 			xPropSet.setPropertyValue( "LineDashName", this.m_LineDashName);
193 		}
194 		if(m_LineStyle != LineStyle.NONE)
195 			xPropSet.setPropertyValue( "LineColor", this.m_LineColor);
196 
197 		saveFileAs(m_xSDComponent, fileName, fileType);
198 		app.closeDocument(m_xSDComponent);
199 
200 		XDrawPage CurrentPage = load(filePath);
201 		Object oGraphic2 = getGraphicsOfPage(CurrentPage)[0];
202 		XShape xGraphicShape2 = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic2);
203 		XPropertySet xPropSet2 = (XPropertySet)UnoRuntime.queryInterface(
204 			     XPropertySet.class, xGraphicShape2 );
205 
206 		assertEquals("line style changed", this.m_expLineStyle, xPropSet2.getPropertyValue("LineStyle"));
207 		if(m_LineStyle != LineStyle.NONE)
208 			assertEquals("line color changed", this.m_expLineColor, xPropSet2.getPropertyValue("LineColor"));
209 		if(m_LineStyle == LineStyle.DASH)
210 			assertEquals("line DashName changed", this.m_expLineDashName, xPropSet2.getPropertyValue("LineDashName"));
211 	}
212 
213 }
214