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 import org.junit.After;
31 import org.junit.AfterClass;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.junit.runners.Parameterized;
37 import org.junit.runners.Parameterized.Parameters;
38 import org.openoffice.test.uno.UnoApp;
39 import org.openoffice.test.common.FileUtil;
40 import org.openoffice.test.common.Testspace;
41 
42 import testlib.uno.SDUtil;
43 
44 import com.sun.star.awt.Point;
45 import com.sun.star.awt.Size;
46 import com.sun.star.drawing.XDrawPage;
47 import com.sun.star.drawing.XShape;
48 import com.sun.star.lang.XComponent;
49 import com.sun.star.uno.UnoRuntime;
50 
51 @RunWith(Parameterized.class)
52 public class GraphicPro_Position {
53 
54 	private static final UnoApp app = new UnoApp();
55 
56 	private XComponent m_xSDComponent = null;
57 	private XDrawPage m_xCurrentPage=null;
58 	private Point m_position=null;
59 	private Point m_expectedPosition=null;
60 	private String m_fileType = null;
61 
GraphicPro_Position(Point position, String fileType, Point expectedPosition)62 	public GraphicPro_Position(Point position, String fileType, Point expectedPosition){
63 		m_position = position;
64 		m_fileType = fileType;
65 		m_expectedPosition = expectedPosition;
66 	}
67 	@Parameters
data()68     public static Collection<Object[]> data() {
69         Point pNegative2 = new Point(-28000,-28000); //minimum
70         Point pNegative3 = new Point(-1000,-1000);
71         Point pZero = new Point(0,0);
72         Point pPositive1 = new Point(1000,1000);
73         Point pPositive2 = new Point(34833,34833); //maximum
74     	return Arrays.asList(new Object[][]{
75         		{pNegative2, "odp", pNegative2},
76         		{pNegative2, "ppt", pNegative2},
77         		{pNegative3, "odp", pNegative3},
78         		{pNegative3, "ppt", pNegative3},
79         		{pZero, "odp", pZero},
80         		{pZero, "ppt", pZero},
81         		{pPositive1, "odp", pPositive1},
82         		{pPositive1, "ppt", pPositive1},
83         		{pPositive2, "odp", pPositive2},
84         		{pPositive2, "ppt", pPositive2}
85         });
86     }
87 
88 	@Before
setUpDocument()89 	public void setUpDocument() throws Exception {
90 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(
91 				XComponent.class, app.newDocument("simpress"));
92 		Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0);
93 		m_xCurrentPage = (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage);
94 		String graphicURL = FileUtil.getUrl(Testspace.prepareData("uno/sd/36.gif"));
95 
96 		Size orgSize = getSizePixelOfGraphicFile(app,graphicURL);
97 	    Size newSize = new Size(orgSize.Width*2645/100, orgSize.Height*2645/100);
98 		insertGraphic(m_xSDComponent, m_xCurrentPage, graphicURL, newSize, new Point(5000, 5000));
99 	}
100 
101 	@After
tearDownDocument()102 	public void tearDownDocument() {
103 		app.closeDocument(m_xSDComponent);
104 
105 	}
106 
107 	@BeforeClass
setUpConnection()108 	public static void setUpConnection() throws Exception {
109 		app.start();
110 	}
111 
112 	@AfterClass
tearDownConnection()113 	public static void tearDownConnection() throws InterruptedException,
114 			Exception {
115 		app.close();
116 		//remove the temp file
117 		FileUtil.deleteFile(Testspace.getPath("temp"));
118 	}
119 
120 
load(String filePath)121 	private XDrawPage load(String filePath) throws Exception{
122 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
123 				app.loadDocument(filePath));
124 		Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0);
125 		return (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage);
126 	}
127 
128 	@Test
testPosition()129 	public void testPosition() throws Exception {
130 		String fileName = "GraphicPro_Position";
131 		String filePath = Testspace.getPath("temp/"+fileName+"."+m_fileType);
132 		Object[] graphics = getGraphicsOfPage(m_xCurrentPage);
133 		Object oGraphic = graphics[0];
134 		XShape xGraphicShape = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic);
135 
136 		xGraphicShape.setPosition(m_position);
137 
138 		saveFileAs(m_xSDComponent, fileName, m_fileType);
139 		app.closeDocument(m_xSDComponent);
140 
141 		XDrawPage CurrentPage = load(filePath);
142 		Object oGraphic2 = getGraphicsOfPage(CurrentPage)[0];
143 		XShape xGraphicShape2 = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic2);
144 
145 		assertEquals("Position X of graphic error", m_expectedPosition.X, xGraphicShape2.getPosition().X, 2);
146 		assertEquals("Position Y of graphic error", m_expectedPosition.Y, xGraphicShape2.getPosition().Y, 2);
147 	}
148 }
149