View | Details | Raw Unified | Return to issue 120645
Collapse All | Expand All

(-)source/testcase/uno/sd/ParagraphStyle.java (-11 / +5 lines)
Lines 93-99 Link Here
93
		 XPropertySet xTextPropSet2 = addPortion(xRectangle, "And another text paragraph", true);
93
		 XPropertySet xTextPropSet2 = addPortion(xRectangle, "And another text paragraph", true);
94
		 xTextPropSet2.setPropertyValue("CharColor", new Integer(0xff0000));
94
		 xTextPropSet2.setPropertyValue("CharColor", new Integer(0xff0000));
95
		 
95
		 
96
		 xRectangle = saveAndLoadShape(po, "com.sun.star.drawing.EllipseShape");
96
		 xRectangle = saveAndLoadShape(1, 0);
97
		
97
		
98
98
99
		 Assert.assertEquals("Paragraph Left Margin is 1000",1000, xTextPropSet1.getPropertyValue("ParaLeftMargin"));
99
		 Assert.assertEquals("Paragraph Left Margin is 1000",1000, xTextPropSet1.getPropertyValue("ParaLeftMargin"));
Lines 164-180 Link Here
164
	 * @return
164
	 * @return
165
	 * @throws Exception
165
	 * @throws Exception
166
	 */
166
	 */
167
	public XShape saveAndLoadShape(Point po, String shapeType) throws Exception {
167
	public XShape saveAndLoadShape(int pageIndex, int shapeIndex) throws Exception {
168
		reLoadFile = saveAndReloadDoc(impressDocument,
168
		reLoadFile = saveAndReloadDoc(impressDocument,
169
				"StarOffice XML (Impress)", "odp");
169
				"impress8", "odp");
170
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
170
		xShapes=ShapeUtil.getShapes(reLoadFile, pageIndex);
171
				XDrawPagesSupplier.class, reLoadFile);
171
		return  (XShape) UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(shapeIndex));
172
		drawpages = drawsupplier.getDrawPages();
173
		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
174
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
175
		XShape shap = ShapeUtil.getShape(impressDocument, po,
176
				"com.sun.star.drawing.EllipseShape");
177
		return shap;
178
	}
172
	}
179
173
180
	/**
174
	/**
(-)source/testlib/uno/ShapeUtil.java (-21 / +38 lines)
Lines 37-43 Link Here
37
import com.sun.star.container.NoSuchElementException;
37
import com.sun.star.container.NoSuchElementException;
38
import com.sun.star.container.XEnumeration;
38
import com.sun.star.container.XEnumeration;
39
import com.sun.star.container.XEnumerationAccess;
39
import com.sun.star.container.XEnumerationAccess;
40
40
import com.sun.star.drawing.XDrawPage;
41
import com.sun.star.drawing.XDrawPages;
42
import com.sun.star.drawing.XDrawPagesSupplier;
41
import com.sun.star.drawing.XShape;
43
import com.sun.star.drawing.XShape;
42
import com.sun.star.drawing.XShapes;
44
import com.sun.star.drawing.XShapes;
43
45
Lines 75-100 Link Here
75
		return xShape;
77
		return xShape;
76
	}
78
	}
77
79
78
	/**
79
	 * try to get shape according position
80
	 * 
81
	 * @param aPos
82
	 * @return
83
	 */
84
	public static XShape getShape(XComponent xDrawDoc, Point aPos,
85
			String sShapeType) {
86
		XShape xShape = null;
87
		try {
88
			XMultiServiceFactory xFactory = (XMultiServiceFactory) UnoRuntime
89
					.queryInterface(XMultiServiceFactory.class, xDrawDoc);
90
			Object xObj = xFactory.createInstance(sShapeType);
91
			xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xObj);
92
		} catch (Exception e) {
93
			// TODO Auto-generated catch block
94
			e.printStackTrace();
95
		}
96
		return xShape;
97
	}
98
80
99
	/**
81
	/**
100
	 * add text to a shape. the return value is the PropertySet of the text
82
	 * add text to a shape. the return value is the PropertySet of the text
Lines 187-190 Link Here
187
			}
169
			}
188
		}
170
		}
189
	}
171
	}
172
	/**
173
	 * Get shapes in specific page
174
	 * @param impressDocument
175
	 * @param pageIndex
176
	 * @return
177
	 * @throws Exception
178
	 */
179
	public static XShapes getShapes(XComponent impressDocument, int pageIndex) throws Exception{
180
181
		XDrawPagesSupplier drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
182
				XDrawPagesSupplier.class, impressDocument);
183
		XDrawPages drawpages = drawsupplier.getDrawPages();
184
		XDrawPage xpage=(XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawpages.getByIndex(pageIndex));
185
		XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
186
		return xShapes;
187
188
	}
189
	
190
	/**
191
	 * Remove the specific shape in specific page
192
	 * @param impressDocument
193
	 * @param pageIndex
194
	 * @param shapeIndex
195
	 * @throws Exception
196
	 */
197
	public static void removeOneShape(XComponent impressDocument, int pageIndex, int shapeIndex) throws Exception{
198
		XDrawPagesSupplier drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
199
				XDrawPagesSupplier.class, impressDocument);
200
		XDrawPages drawpages = drawsupplier.getDrawPages();
201
		XDrawPage xpage=(XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawpages.getByIndex(pageIndex));
202
		XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
203
		XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(shapeIndex));
204
		xShapes.remove(xShape);
205
206
	}
190
}
207
}
(-)source/testcase/uno/sd/ShapeProperties.java (-280 lines)
Lines 1-280 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;
22
23
import java.io.File;
24
import java.io.IOException;
25
26
import org.junit.After;
27
import static org.junit.Assert.*;
28
29
import org.junit.AfterClass;
30
import org.junit.Before;
31
import org.junit.Test;
32
import org.openoffice.test.uno.UnoApp;
33
import org.openoffice.test.common.FileUtil;
34
import org.openoffice.test.common.Testspace;
35
36
import testlib.uno.PageUtil;
37
import testlib.uno.ShapeUtil;
38
39
import com.sun.star.uno.UnoRuntime;
40
import com.sun.star.presentation.XPresentation;
41
import com.sun.star.presentation.XPresentationSupplier;
42
import com.sun.star.awt.Gradient;
43
import com.sun.star.awt.GradientStyle;
44
import com.sun.star.awt.Size;
45
import com.sun.star.awt.Point;
46
import com.sun.star.beans.PropertyValue;
47
import com.sun.star.beans.XPropertySet;
48
import com.sun.star.drawing.FillStyle;
49
import com.sun.star.drawing.Hatch;
50
import com.sun.star.drawing.HatchStyle;
51
import com.sun.star.drawing.XDrawPage;
52
import com.sun.star.drawing.XDrawPages;
53
import com.sun.star.drawing.XDrawPagesSupplier;
54
import com.sun.star.drawing.XShape;
55
import com.sun.star.drawing.XShapes;
56
import com.sun.star.frame.XComponentLoader;
57
import com.sun.star.frame.XStorable;
58
import com.sun.star.lang.XComponent;
59
import com.sun.star.lang.XMultiServiceFactory;
60
61
public class ShapeProperties {
62
	UnoApp unoApp = new UnoApp();
63
	XPresentationSupplier sdDocument = null;
64
	XPresentation pre = null;
65
	XComponent precomp = null;
66
	XComponent impressDocument = null;
67
	XComponent reLoadFile = null;
68
	XDrawPagesSupplier drawsupplier = null;
69
	XDrawPages drawpages = null;
70
	XShapes xShapes = null;
71
	XDrawPage xpage = null;
72
	String filePath=null;
73
74
	@Before
75
	public void setUp() throws Exception {
76
		unoApp.start();
77
		createDocumentAndSlide();
78
	}
79
80
	@After
81
	public void tearDown() throws Exception {
82
		unoApp.closeDocument(impressDocument);
83
		unoApp.closeDocument(reLoadFile);
84
		unoApp.close();
85
		if(filePath!=null)
86
			FileUtil.deleteFile(filePath);
87
	}
88
89
	/**
90
	 * test Insert a new slide and Insert a new EllipseShape
91
	 * 
92
	 * @throws Exception
93
	 */
94
	@Test
95
	public void testInsertShape() throws Exception {
96
		Point po = new Point(1000, 8000);
97
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
98
		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
99
				5000, 5000), "com.sun.star.drawing.EllipseShape");
100
		xShapes.add(xShape);
101
		XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
102
				XPropertySet.class, xShape);
103
		xPropSet.setPropertyValue("Name", "test");
104
		XShape shap = ShapeUtil.getShape(impressDocument, po,
105
				"com.sun.star.drawing.EllipseShape");
106
		XPropertySet xPropSet2 = (XPropertySet) UnoRuntime.queryInterface(
107
				XPropertySet.class, xShape);
108
		assertEquals("Not the same shape","test",xPropSet2.getPropertyValue("Name"));
109
		assertEquals("Not EllopseShape","com.sun.star.drawing.EllipseShape",shap.getShapeType());
110
	}
111
112
	/**
113
	 * test Insert text to an EllopseShape
114
	 * 
115
	 * @throws Exception
116
	 */
117
	@Test
118
	public void testInsertTextToShape() throws Exception {
119
		Point po = new Point(1000, 8000);
120
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
121
		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
122
				5000, 5000), "com.sun.star.drawing.EllipseShape");
123
		xShapes.add(xShape);
124
		ShapeUtil.addPortion(xShape, "test", false);
125
		assertEquals("Not put text correctly","test",ShapeUtil.getPortion(xShape));
126
	}
127
128
	/**
129
	 * test Shape fill with Gradient
130
	 * 
131
	 * @throws Exception
132
	 */
133
	@Test
134
	public void testShapeFillGradient() throws Exception {
135
		Point po = new Point(1000, 8000);
136
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
137
		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
138
				5000, 5000), "com.sun.star.drawing.EllipseShape");
139
		xShapes.add(xShape);
140
		XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
141
				XPropertySet.class, xShape);
142
		xPropSet.setPropertyValue("FillStyle", FillStyle.GRADIENT);
143
		Gradient aGradient = new Gradient();
144
		aGradient.Style = GradientStyle.LINEAR;
145
		aGradient.StartColor = 0x00ff00;
146
		aGradient.EndColor = 0xffff00;
147
		aGradient.Angle = 450;
148
		aGradient.Border = 0;
149
		aGradient.XOffset = 0;
150
		aGradient.YOffset = 0;
151
		aGradient.StartIntensity = 100;
152
		aGradient.EndIntensity = 100;
153
		aGradient.StepCount = 10;
154
		xPropSet.setPropertyValue("FillGradient", aGradient);
155
		// --------------------------
156
		xShape = saveAndLoadShape(po, "com.sun.star.drawing.EllipseShape");
157
		// ----------------------------
158
		assertEquals("Not Gradient Fill Style",FillStyle.GRADIENT,xPropSet.getPropertyValue("FillStyle"));
159
		aGradient=(Gradient) xPropSet.getPropertyValue("FillGradient");
160
		assertEquals("Not Linear Gradient",GradientStyle.LINEAR,aGradient.Style);
161
	}
162
163
	/**
164
	 * test Shape fill with yellow color
165
	 * 
166
	 * @throws Exception
167
	 */
168
	@Test
169
	public void testShapeFillColor() throws Exception {
170
		Point po = new Point(1000, 8000);
171
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
172
		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
173
				5000, 5000), "com.sun.star.drawing.EllipseShape");
174
		xShapes.add(xShape);
175
		XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
176
				XPropertySet.class, xShape);
177
		xPropSet.setPropertyValue("FillStyle", FillStyle.SOLID);
178
		xPropSet.setPropertyValue("FillColor", 0xffff00);
179
		// --------------------------
180
		xShape = saveAndLoadShape(po, "com.sun.star.drawing.EllipseShape");
181
		// ----------------------------------------------------
182
		assertEquals("Not Color Fill Style",FillStyle.SOLID,xPropSet.getPropertyValue("FillStyle"));
183
		assertEquals("Not Yellow Color Fill",0xffff00,xPropSet.getPropertyValue("FillColor"));
184
	}
185
	
186
	/**
187
	 * test shape fill with Hatch Style(Pattern in MS)
188
	 * @throws Exception
189
	 */
190
	@Test
191
	public void testShapeFillHatch() throws Exception {
192
		Point po = new Point(1000, 8000);
193
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
194
		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
195
				5000, 5000), "com.sun.star.drawing.EllipseShape");
196
		xShapes.add(xShape);
197
		XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
198
				XPropertySet.class, xShape);
199
		xPropSet.setPropertyValue("FillStyle", FillStyle.HATCH);
200
		Hatch aHatch=new Hatch();
201
		aHatch.Style=HatchStyle.DOUBLE;
202
		aHatch.Color=0x00ff00;
203
		aHatch.Distance=100;
204
		aHatch.Angle=450;
205
		xPropSet.setPropertyValue("FillHatch", aHatch);
206
		
207
		// --------------------------
208
		xShape = saveAndLoadShape(po, "com.sun.star.drawing.EllipseShape");
209
		// ----------------------------
210
		assertEquals("Not Gradient Fill Style",FillStyle.HATCH,xPropSet.getPropertyValue("FillStyle"));
211
	
212
		aHatch=(Hatch) xPropSet.getPropertyValue("FillHatch");
213
		assertEquals("Not Double Hatch",HatchStyle.DOUBLE,aHatch.Style);
214
	}
215
	
216
	/**
217
	 * create a new presentation document and insert a new slide.
218
	 * 
219
	 * @throws Exception
220
	 */
221
	public void createDocumentAndSlide() throws Exception {
222
		impressDocument = (XComponent) UnoRuntime.queryInterface(
223
				XComponent.class, unoApp.newDocument("simpress"));
224
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
225
				XDrawPagesSupplier.class, impressDocument);
226
		drawpages = drawsupplier.getDrawPages();
227
		drawpages.insertNewByIndex(1);
228
		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
229
	}
230
231
	/**
232
	 * Save presentation and reLoad the presentation and shape in it.
233
	 * 
234
	 * @param po
235
	 * @param shapeType
236
	 * @return
237
	 * @throws Exception
238
	 */
239
	public XShape saveAndLoadShape(Point po, String shapeType) throws Exception {
240
		reLoadFile = saveAndReloadDoc(impressDocument,
241
				"StarOffice XML (Impress)", "odp");
242
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
243
				XDrawPagesSupplier.class, reLoadFile);
244
		drawpages = drawsupplier.getDrawPages();
245
		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
246
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
247
		XShape shap = ShapeUtil.getShape(impressDocument, po,
248
				"com.sun.star.drawing.EllipseShape");
249
		return shap;
250
	}
251
252
	/**
253
	 * save and reload Presentation document.
254
	 * 
255
	 * @param presentationDocument
256
	 * @param sFilter
257
	 * @param sExtension
258
	 * @return
259
	 * @throws Exception
260
	 */
261
	private XComponent saveAndReloadDoc(XComponent presentationDocument,
262
			String sFilter, String sExtension) throws Exception {
263
		filePath = Testspace.getPath("tmp/presentationtest."
264
				+ sExtension);
265
		PropertyValue[] aStoreProperties = new PropertyValue[2];
266
		aStoreProperties[0] = new PropertyValue();
267
		aStoreProperties[1] = new PropertyValue();
268
		aStoreProperties[0].Name = "Override";
269
		aStoreProperties[0].Value = true;
270
		aStoreProperties[1].Name = "FilterName";
271
		aStoreProperties[1].Value = sFilter;
272
		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
273
				XStorable.class, presentationDocument);
274
		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
275
276
		return UnoRuntime.queryInterface(XComponent.class,
277
				unoApp.loadDocument(filePath));
278
	}
279
280
}
(-)source/testcase/uno/sd/ParagraphTextProperty.java (-11 / +5 lines)
Lines 83-89 Link Here
83
		 XPropertySet xTextPropSet = addPortion(xRectangle, "using TextFitToSize", false);
83
		 XPropertySet xTextPropSet = addPortion(xRectangle, "using TextFitToSize", false);
84
		 xTextPropSet = addPortion(xRectangle, "and a Border distance of 2,5 cm", true);
84
		 xTextPropSet = addPortion(xRectangle, "and a Border distance of 2,5 cm", true);
85
		 
85
		 
86
		 xRectangle = saveAndLoadShape(po, "com.sun.star.drawing.EllipseShape");
86
		 xRectangle = saveAndLoadShape(1,0);
87
		 
87
		 
88
		 Assert.assertEquals("TextLeftDistance is 2500", 2500, xShapePropSet.getPropertyValue("TextLeftDistance"));
88
		 Assert.assertEquals("TextLeftDistance is 2500", 2500, xShapePropSet.getPropertyValue("TextLeftDistance"));
89
		 Assert.assertEquals("TextRightDistance is 2500", 2500, xShapePropSet.getPropertyValue("TextRightDistance"));
89
		 Assert.assertEquals("TextRightDistance is 2500", 2500, xShapePropSet.getPropertyValue("TextRightDistance"));
Lines 131-147 Link Here
131
	 * @return
131
	 * @return
132
	 * @throws Exception
132
	 * @throws Exception
133
	 */
133
	 */
134
	public XShape saveAndLoadShape(Point po, String shapeType) throws Exception {
134
	public XShape saveAndLoadShape(int pageIndex, int shapeIndex) throws Exception {
135
		reLoadFile = saveAndReloadDoc(impressDocument,
135
		reLoadFile = saveAndReloadDoc(impressDocument,
136
				"StarOffice XML (Impress)", "odp");
136
				"impress8", "odp");
137
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
137
		xShapes=ShapeUtil.getShapes(reLoadFile, pageIndex);
138
				XDrawPagesSupplier.class, reLoadFile);
138
		return  (XShape) UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(shapeIndex));
139
		drawpages = drawsupplier.getDrawPages();
140
		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
141
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
142
		XShape shap = ShapeUtil.getShape(impressDocument, po,
143
				"com.sun.star.drawing.EllipseShape");
144
		return shap;
145
	}
139
	}
146
140
147
	/**
141
	/**
(-)source/testcase/uno/sd/shape/ShapeProperties.java (+405 lines)
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 java.awt.geom.AffineTransform;
24
import java.io.File;
25
import java.io.IOException;
26
27
import org.junit.After;
28
import static org.junit.Assert.*;
29
30
import org.junit.AfterClass;
31
import org.junit.Before;
32
import org.junit.Test;
33
import org.openoffice.test.uno.UnoApp;
34
import org.openoffice.test.common.FileUtil;
35
import org.openoffice.test.common.Testspace;
36
37
import testlib.uno.PageUtil;
38
import testlib.uno.ShapeUtil;
39
import testlib.uno.TestUtil;
40
41
import com.sun.star.text.WrapTextMode;
42
import com.sun.star.text.XText;
43
import com.sun.star.text.XTextContent;
44
import com.sun.star.uno.UnoRuntime;
45
import com.sun.star.presentation.XPresentation;
46
import com.sun.star.presentation.XPresentationSupplier;
47
import com.sun.star.awt.Gradient;
48
import com.sun.star.awt.GradientStyle;
49
import com.sun.star.awt.Size;
50
import com.sun.star.awt.Point;
51
import com.sun.star.beans.PropertyValue;
52
import com.sun.star.beans.XPropertySet;
53
import com.sun.star.drawing.DashStyle;
54
import com.sun.star.drawing.FillStyle;
55
import com.sun.star.drawing.Hatch;
56
import com.sun.star.drawing.HatchStyle;
57
import com.sun.star.drawing.HomogenMatrix3;
58
import com.sun.star.drawing.LineDash;
59
import com.sun.star.drawing.LineStyle;
60
import com.sun.star.drawing.XDrawPage;
61
import com.sun.star.drawing.XDrawPages;
62
import com.sun.star.drawing.XDrawPagesSupplier;
63
import com.sun.star.drawing.XShape;
64
import com.sun.star.drawing.XShapes;
65
import com.sun.star.frame.XComponentLoader;
66
import com.sun.star.frame.XStorable;
67
import com.sun.star.lang.XComponent;
68
import com.sun.star.lang.XMultiServiceFactory;
69
70
public class ShapeProperties {
71
	UnoApp unoApp = new UnoApp();
72
	XPresentationSupplier sdDocument = null;
73
	XPresentation pre = null;
74
	XComponent precomp = null;
75
	XComponent impressDocument = null;
76
	XComponent reLoadFile = null;
77
	XDrawPagesSupplier drawsupplier = null;
78
	XDrawPages drawpages = null;
79
	XShapes xShapes = null;
80
	XDrawPage xpage = null;
81
	String filePath = null;
82
83
	@Before
84
	public void setUp() throws Exception {
85
		unoApp.start();
86
		createDocumentAndSlide();
87
	}
88
89
	@After
90
	public void tearDown() throws Exception {
91
		unoApp.closeDocument(impressDocument);
92
		unoApp.closeDocument(reLoadFile);
93
		unoApp.close();
94
		if (filePath != null)
95
			FileUtil.deleteFile(filePath);
96
	}
97
98
	/**
99
	 * test Insert a new slide and Insert a new EllipseShape
100
	 * 
101
	 * @throws Exception
102
	 */
103
	 @Test
104
	 public void testInsertShape() throws Exception {
105
	 Point po = new Point(1000, 8000);
106
	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
107
	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
108
	 5000, 5000), "com.sun.star.drawing.EllipseShape");
109
	 xShapes.add(xShape);
110
	 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
111
	 XPropertySet.class, xShape);
112
	 xPropSet.setPropertyValue("Name", "test");
113
	 
114
	 xShape=saveAndLoadShape(1,0);
115
	 XPropertySet xPropSet2 = (XPropertySet) UnoRuntime.queryInterface(
116
	 XPropertySet.class, xShape);
117
	 assertEquals("Not the same shape","test",xPropSet2.getPropertyValue("Name"));
118
	 assertEquals("Not EllopseShape","com.sun.star.drawing.EllipseShape",xShape.getShapeType());
119
	 }
120
	
121
	 /**
122
	 * test Insert text to an EllopseShape
123
	 *
124
	 * @throws Exception
125
	 */
126
	 @Test
127
	 public void testInsertTextToShape() throws Exception {
128
	 Point po = new Point(1000, 8000);
129
	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
130
	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
131
	 5000, 5000), "com.sun.star.drawing.EllipseShape");
132
	 xShapes.add(xShape);
133
	 xShape=saveAndLoadShape(1,0);
134
	 ShapeUtil.addPortion(xShape, "test", false);
135
	 assertEquals("Not put text correctly","test",ShapeUtil.getPortion(xShape));
136
	 }
137
	
138
	 /**
139
	 * test Shape fill with Gradient
140
	 *
141
	 * @throws Exception
142
	 */
143
	 @Test
144
	 public void testShapeFillGradient() throws Exception {
145
	 Point po = new Point(1000, 8000);
146
	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
147
	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
148
	 5000, 5000), "com.sun.star.drawing.EllipseShape");
149
	 xShapes.add(xShape);
150
	 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
151
	 XPropertySet.class, xShape);
152
	 xPropSet.setPropertyValue("FillStyle", FillStyle.GRADIENT);
153
	 Gradient aGradient = new Gradient();
154
	 aGradient.Style = GradientStyle.LINEAR;
155
	 aGradient.StartColor = 0x00ff00;
156
	 aGradient.EndColor = 0xffff00;
157
	 aGradient.Angle = 450;
158
	 aGradient.Border = 0;
159
	 aGradient.XOffset = 0;
160
	 aGradient.YOffset = 0;
161
	 aGradient.StartIntensity = 100;
162
	 aGradient.EndIntensity = 100;
163
	 aGradient.StepCount = 10;
164
	 xPropSet.setPropertyValue("FillGradient", aGradient);
165
	 // --------------------------
166
	 xShape=saveAndLoadShape(1,0);
167
	 xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape);
168
	 // ----------------------------
169
	 assertEquals("Not Gradient Fill Style",FillStyle.GRADIENT,xPropSet.getPropertyValue("FillStyle"));
170
	 aGradient=(Gradient) xPropSet.getPropertyValue("FillGradient");
171
	 assertEquals("Not Linear Gradient",GradientStyle.LINEAR,aGradient.Style);
172
	 }
173
	
174
	 /**
175
	 * test Shape fill with yellow color
176
	 *
177
	 * @throws Exception
178
	 */
179
	 @Test
180
	 public void testShapeFillColor() throws Exception {
181
	 Point po = new Point(1000, 8000);
182
	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
183
	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
184
	 5000, 5000), "com.sun.star.drawing.EllipseShape");
185
	 xShapes.add(xShape);
186
	 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
187
	 XPropertySet.class, xShape);
188
	 xPropSet.setPropertyValue("FillStyle", FillStyle.SOLID);
189
	 xPropSet.setPropertyValue("FillColor", 0xffff00);
190
	 // --------------------------
191
	 xShape=saveAndLoadShape(1,0);
192
	 xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape);
193
	 // ----------------------------------------------------
194
	 assertEquals("Not Color Fill Style",FillStyle.SOLID,xPropSet.getPropertyValue("FillStyle"));
195
	 assertEquals("Not Yellow Color Fill",0xffff00,xPropSet.getPropertyValue("FillColor"));
196
	 }
197
	
198
	 /**
199
	 * test shape fill with Hatch Style(Pattern in MS)
200
	 * @throws Exception
201
	 */
202
	 @Test
203
	 public void testShapeFillHatch() throws Exception {
204
	 Point po = new Point(1000, 8000);
205
	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
206
	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
207
	 5000, 5000), "com.sun.star.drawing.EllipseShape");
208
	 xShapes.add(xShape);
209
	 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
210
	 XPropertySet.class, xShape);
211
	 xPropSet.setPropertyValue("FillStyle", FillStyle.HATCH);
212
	 Hatch aHatch=new Hatch();
213
	 aHatch.Style=HatchStyle.DOUBLE;
214
	 aHatch.Color=0x00ff00;
215
	 aHatch.Distance=100;
216
	 aHatch.Angle=450;
217
	 xPropSet.setPropertyValue("FillHatch", aHatch);
218
	
219
	 // --------------------------
220
	 xShape=saveAndLoadShape(1,0);
221
	 xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape);
222
	 // ----------------------------
223
	 assertEquals("Not Gradient Fill Style",FillStyle.HATCH,xPropSet.getPropertyValue("FillStyle"));
224
	 aHatch=(Hatch) xPropSet.getPropertyValue("FillHatch");
225
	 assertEquals("Not Double Hatch",HatchStyle.DOUBLE,aHatch.Style);
226
	 }
227
228
	// ------------Shape Line-----------------------------
229
	/**
230
	 * test Shape Line style DASH
231
	 * 
232
	 * @throws Exception
233
	 */
234
	 @Test
235
	 public void testShapeLineStyle() throws Exception {
236
	 Point po = new Point(1000, 8000);
237
	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
238
	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
239
	 5000, 5000), "com.sun.star.drawing.EllipseShape");
240
	 xShapes.add(xShape);
241
	
242
	 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
243
	 XPropertySet.class, xShape);
244
	 xPropSet.setPropertyValue("LineStyle", LineStyle.DASH);
245
	
246
	 LineDash aLineDash=new LineDash();
247
	 aLineDash.Style=DashStyle.ROUND;
248
	 aLineDash.Dots=2;
249
	 aLineDash.DashLen=100;
250
	 aLineDash.Distance=50;
251
	 xPropSet.setPropertyValue("LineDash", aLineDash);
252
	
253
	 // --------------------------
254
	 xShape=saveAndLoadShape(1,0);
255
	 xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape);
256
	 // ----------------------------
257
	 assertEquals("Not Dash Line Style",LineStyle.DASH,xPropSet.getPropertyValue("LineStyle"));
258
	 aLineDash=(LineDash) xPropSet.getPropertyValue("LineDash");
259
	 assertEquals("Not Round Dash Style", DashStyle.ROUND ,aLineDash.Style);
260
	 }
261
	
262
	 /**
263
	 * test Shape Line Color
264
	 * @throws Exception
265
	 */
266
	
267
	 @Test
268
	 public void testShapeLineColor() throws Exception {
269
	 Point po = new Point(1000, 8000);
270
	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
271
	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
272
	 5000, 5000), "com.sun.star.drawing.EllipseShape");
273
	 xShapes.add(xShape);
274
	 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
275
	 XPropertySet.class, xShape);
276
	 xPropSet.setPropertyValue("LineStyle", LineStyle.DASH);
277
	 xPropSet.setPropertyValue("LineColor", 0x00ff00);
278
	 xShape=saveAndLoadShape(1,0);
279
	 xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape);
280
	 // ----------------------------
281
	 assertEquals("Not Dash Line Style",LineStyle.DASH,xPropSet.getPropertyValue("LineStyle"));
282
	 assertEquals("wrong line color", 0x00ff00,xPropSet.getPropertyValue("LineColor"));
283
	 }
284
285
	/**
286
	 * test Shape position and size
287
	 * 
288
	 * @throws Exception
289
	 */
290
	 @Test
291
	 public void testShapePositionSize() throws Exception {
292
	 Point po = new Point(1000, 8000);
293
	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
294
	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
295
	 5000, 5000), "com.sun.star.drawing.EllipseShape");
296
	 xShapes.add(xShape);
297
	 xShape=saveAndLoadShape(1,0);
298
	 assertEquals("wrong shape position",1000,xShape.getPosition().X);
299
	 assertEquals("wrong shape Height", 5000 ,xShape.getSize().Height);
300
	 }
301
302
	/**
303
	 * test Shape rotate with 25 degree.
304
	 * @throws Exception
305
	 */
306
	@Test
307
	public void testShapeRotation() throws Exception {
308
		Point po = new Point(1000, 8000);
309
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
310
		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
311
				5000, 5000), "com.sun.star.drawing.RectangleShape");
312
		xShapes.add(xShape);
313
		XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
314
				XPropertySet.class, xShape);
315
		xPropSet.setPropertyValue("RotateAngle", 2500);
316
		xShape=saveAndLoadShape(1,0);
317
		xPropSet = (XPropertySet) UnoRuntime.queryInterface(
318
				 XPropertySet.class, xShape);
319
		assertEquals("RotateAngle is not 2500", 2500 , xPropSet.getPropertyValue("RotateAngle"));
320
	}
321
322
323
	// ------------------Shape Remove----------------------------
324
	/**
325
	 * test Remove shape from impress Document
326
	 * 
327
	 * @throws Exception
328
	 */
329
	 @Test
330
	 public void testShapeRemove() throws Exception {
331
	 Point aPos=null;
332
	 Size aSize=new Size(4000,4000);
333
	 for(int i=0;i<=4;i++){
334
	 aPos=new Point(1000, 3000*i);
335
	 xShapes=ShapeUtil.getShapes(impressDocument, 0);
336
	 ShapeUtil.createAndInsertShape(impressDocument, xShapes, aPos, aSize,
337
	 "com.sun.star.drawing.EllipseShape");
338
	 }
339
	 int countBeforeRemove=ShapeUtil.getShapes(impressDocument, 0).getCount();
340
	 ShapeUtil.removeOneShape(impressDocument, 0, 2);
341
	 int countAfterRemove=ShapeUtil.getShapes(impressDocument, 0).getCount();
342
	 assertEquals("Not remove shape successfully",1,countBeforeRemove-countAfterRemove);
343
	 reLoadFile = saveAndReloadDoc(impressDocument,
344
	 "impress8", "odp");
345
	 xShapes=ShapeUtil.getShapes(reLoadFile, 0);
346
	 assertEquals("Shape count is wrong after reload",6,xShapes.getCount());
347
	 }
348
349
	/**
350
	 * create a new presentation document and insert a new slide.
351
	 * 
352
	 * @throws Exception
353
	 */
354
	public void createDocumentAndSlide() throws Exception {
355
		impressDocument = (XComponent) UnoRuntime.queryInterface(
356
				XComponent.class, unoApp.newDocument("simpress"));
357
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
358
				XDrawPagesSupplier.class, impressDocument);
359
		drawpages = drawsupplier.getDrawPages();
360
		drawpages.insertNewByIndex(1);
361
		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
362
	}
363
364
	/**
365
	 * Save presentation and reLoad the presentation and shape in it.
366
	 * 
367
	 * @param po
368
	 * @param shapeType
369
	 * @return
370
	 * @throws Exception
371
	 */
372
	public XShape saveAndLoadShape(int pageIndex, int shapeIndex) throws Exception {
373
		reLoadFile = saveAndReloadDoc(impressDocument,
374
				"impress8", "odp");
375
		xShapes=ShapeUtil.getShapes(reLoadFile, pageIndex);
376
		return  (XShape) UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(shapeIndex));
377
	}
378
	/**
379
	 * save and reload Presentation document.
380
	 * 
381
	 * @param presentationDocument
382
	 * @param sFilter
383
	 * @param sExtension
384
	 * @return
385
	 * @throws Exception
386
	 */
387
	private XComponent saveAndReloadDoc(XComponent presentationDocument,
388
			String sFilter, String sExtension) throws Exception {
389
		filePath = Testspace.getPath("tmp/presentationtest." + sExtension);
390
		PropertyValue[] aStoreProperties = new PropertyValue[2];
391
		aStoreProperties[0] = new PropertyValue();
392
		aStoreProperties[1] = new PropertyValue();
393
		aStoreProperties[0].Name = "Override";
394
		aStoreProperties[0].Value = true;
395
		aStoreProperties[1].Name = "FilterName";
396
		aStoreProperties[1].Value = sFilter;
397
		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
398
				XStorable.class, presentationDocument);
399
		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
400
401
		return UnoRuntime.queryInterface(XComponent.class,
402
				unoApp.loadDocument(filePath));
403
	}
404
405
}

Return to issue 120645