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