Line 0
Link Here
|
|
|
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 testcase.uno.sd.shape; |
22 |
|
23 |
import static org.junit.Assert.assertEquals; |
24 |
|
25 |
import org.junit.After; |
26 |
import org.junit.Before; |
27 |
import org.junit.Test; |
28 |
import org.openoffice.test.common.FileUtil; |
29 |
import org.openoffice.test.common.Testspace; |
30 |
import org.openoffice.test.uno.UnoApp; |
31 |
|
32 |
import testlib.uno.PageUtil; |
33 |
import testlib.uno.ShapeUtil; |
34 |
|
35 |
import com.sun.star.awt.Point; |
36 |
import com.sun.star.awt.Size; |
37 |
import com.sun.star.beans.PropertyValue; |
38 |
import com.sun.star.beans.XPropertySet; |
39 |
import com.sun.star.drawing.XDrawPage; |
40 |
import com.sun.star.drawing.XDrawPages; |
41 |
import com.sun.star.drawing.XDrawPagesSupplier; |
42 |
import com.sun.star.drawing.XShape; |
43 |
import com.sun.star.drawing.XShapes; |
44 |
import com.sun.star.frame.XStorable; |
45 |
import com.sun.star.lang.XComponent; |
46 |
import com.sun.star.presentation.XPresentation; |
47 |
import com.sun.star.presentation.XPresentationSupplier; |
48 |
import com.sun.star.uno.UnoRuntime; |
49 |
|
50 |
public class ShapeTypes { |
51 |
UnoApp unoApp = new UnoApp(); |
52 |
XPresentationSupplier sdDocument = null; |
53 |
XPresentation pre = null; |
54 |
XComponent precomp = null; |
55 |
XComponent impressDocument = null; |
56 |
XComponent reLoadFile = null; |
57 |
XDrawPagesSupplier drawsupplier = null; |
58 |
XDrawPages drawpages = null; |
59 |
XShapes xShapes = null; |
60 |
XDrawPage xpage = null; |
61 |
String filePath = null; |
62 |
|
63 |
@Before |
64 |
public void setUp() throws Exception { |
65 |
unoApp.start(); |
66 |
createDocumentAndSlide(); |
67 |
} |
68 |
|
69 |
@After |
70 |
public void tearDown() throws Exception { |
71 |
unoApp.closeDocument(impressDocument); |
72 |
unoApp.closeDocument(reLoadFile); |
73 |
unoApp.close(); |
74 |
if (filePath != null) |
75 |
FileUtil.deleteFile(filePath); |
76 |
} |
77 |
|
78 |
@Test |
79 |
public void testLineShape() throws Exception { |
80 |
Point po = new Point(1000, 8000); |
81 |
xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); |
82 |
XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( |
83 |
5000, 5000), "com.sun.star.drawing.LineShape"); |
84 |
xShapes.add(xShape); |
85 |
XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( |
86 |
XPropertySet.class, xShape); |
87 |
xPropSet.setPropertyValue("Name", "test"); |
88 |
|
89 |
xShape = saveAndLoadShape(1, 0); |
90 |
XPropertySet xPropSet2 = (XPropertySet) UnoRuntime.queryInterface( |
91 |
XPropertySet.class, xShape); |
92 |
assertEquals("Not the same shape", "test", |
93 |
xPropSet2.getPropertyValue("Name")); |
94 |
assertEquals("Not LineShape", "com.sun.star.drawing.LineShape", |
95 |
xShape.getShapeType()); |
96 |
} |
97 |
|
98 |
@Test |
99 |
public void testBasicShape() throws Exception { |
100 |
Point po = new Point(1000, 8000); |
101 |
xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); |
102 |
XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( |
103 |
5000, 5000), "com.sun.star.drawing.RectangleShape"); |
104 |
xShapes.add(xShape); |
105 |
XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( |
106 |
XPropertySet.class, xShape); |
107 |
xPropSet.setPropertyValue("Name", "test"); |
108 |
|
109 |
xShape = saveAndLoadShape(1, 0); |
110 |
XPropertySet xPropSet2 = (XPropertySet) UnoRuntime.queryInterface( |
111 |
XPropertySet.class, xShape); |
112 |
assertEquals("Not the same shape", "test", |
113 |
xPropSet2.getPropertyValue("Name")); |
114 |
assertEquals("Not RectangleShape", |
115 |
"com.sun.star.drawing.RectangleShape", xShape.getShapeType()); |
116 |
} |
117 |
|
118 |
|
119 |
|
120 |
/** |
121 |
* create a new presentation document and insert a new slide. |
122 |
* |
123 |
* @throws Exception |
124 |
*/ |
125 |
public void createDocumentAndSlide() throws Exception { |
126 |
impressDocument = (XComponent) UnoRuntime.queryInterface( |
127 |
XComponent.class, unoApp.newDocument("simpress")); |
128 |
drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( |
129 |
XDrawPagesSupplier.class, impressDocument); |
130 |
drawpages = drawsupplier.getDrawPages(); |
131 |
drawpages.insertNewByIndex(1); |
132 |
xpage = PageUtil.getDrawPageByIndex(impressDocument, 1); |
133 |
} |
134 |
|
135 |
/** |
136 |
* Save presentation and reLoad the presentation and shape in it. |
137 |
* |
138 |
* @param po |
139 |
* @param shapeType |
140 |
* @return |
141 |
* @throws Exception |
142 |
*/ |
143 |
public XShape saveAndLoadShape(int pageIndex, int shapeIndex) |
144 |
throws Exception { |
145 |
reLoadFile = saveAndReloadDoc(impressDocument, |
146 |
"StarOffice XML (Impress)", "odp"); |
147 |
xShapes = ShapeUtil.getShapes(reLoadFile, pageIndex); |
148 |
return (XShape) UnoRuntime.queryInterface(XShape.class, |
149 |
xShapes.getByIndex(shapeIndex)); |
150 |
} |
151 |
|
152 |
/** |
153 |
* save and reload Presentation document. |
154 |
* |
155 |
* @param presentationDocument |
156 |
* @param sFilter |
157 |
* @param sExtension |
158 |
* @return |
159 |
* @throws Exception |
160 |
*/ |
161 |
private XComponent saveAndReloadDoc(XComponent presentationDocument, |
162 |
String sFilter, String sExtension) throws Exception { |
163 |
filePath = Testspace.getPath("tmp/presentationtest." + sExtension); |
164 |
PropertyValue[] aStoreProperties = new PropertyValue[2]; |
165 |
aStoreProperties[0] = new PropertyValue(); |
166 |
aStoreProperties[1] = new PropertyValue(); |
167 |
aStoreProperties[0].Name = "Override"; |
168 |
aStoreProperties[0].Value = true; |
169 |
aStoreProperties[1].Name = "FilterName"; |
170 |
aStoreProperties[1].Value = sFilter; |
171 |
XStorable xStorable = (XStorable) UnoRuntime.queryInterface( |
172 |
XStorable.class, presentationDocument); |
173 |
xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties); |
174 |
|
175 |
return UnoRuntime.queryInterface(XComponent.class, |
176 |
unoApp.loadDocument(filePath)); |
177 |
} |
178 |
} |