xref: /AOO41X/test/testuno/source/fvt/uno/sd/textbox/LineProperties.java (revision eba4d44a33e5be0b2528d5a9a6f0dcbf65adaa0d)
1*eba4d44aSLiu Zhe /**************************************************************
2*eba4d44aSLiu Zhe  *
3*eba4d44aSLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4*eba4d44aSLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5*eba4d44aSLiu Zhe  * distributed with this work for additional information
6*eba4d44aSLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7*eba4d44aSLiu Zhe  * to you under the Apache License, Version 2.0 (the
8*eba4d44aSLiu Zhe  * "License"); you may not use this file except in compliance
9*eba4d44aSLiu Zhe  * with the License.  You may obtain a copy of the License at
10*eba4d44aSLiu Zhe  *
11*eba4d44aSLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12*eba4d44aSLiu Zhe  *
13*eba4d44aSLiu Zhe  * Unless required by applicable law or agreed to in writing,
14*eba4d44aSLiu Zhe  * software distributed under the License is distributed on an
15*eba4d44aSLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*eba4d44aSLiu Zhe  * KIND, either express or implied.  See the License for the
17*eba4d44aSLiu Zhe  * specific language governing permissions and limitations
18*eba4d44aSLiu Zhe  * under the License.
19*eba4d44aSLiu Zhe  *
20*eba4d44aSLiu Zhe  *************************************************************/
21*eba4d44aSLiu Zhe package fvt.uno.sd.textbox;
22*eba4d44aSLiu Zhe 
23*eba4d44aSLiu Zhe import static org.junit.Assert.assertEquals;
24*eba4d44aSLiu Zhe 
25*eba4d44aSLiu Zhe import org.junit.After;
26*eba4d44aSLiu Zhe import org.junit.Before;
27*eba4d44aSLiu Zhe import org.junit.Test;
28*eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil;
29*eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace;
30*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
31*eba4d44aSLiu Zhe 
32*eba4d44aSLiu Zhe import testlib.uno.PageUtil;
33*eba4d44aSLiu Zhe import testlib.uno.ShapeUtil;
34*eba4d44aSLiu Zhe 
35*eba4d44aSLiu Zhe import com.sun.star.awt.Point;
36*eba4d44aSLiu Zhe import com.sun.star.awt.Size;
37*eba4d44aSLiu Zhe import com.sun.star.beans.PropertyValue;
38*eba4d44aSLiu Zhe import com.sun.star.beans.XPropertySet;
39*eba4d44aSLiu Zhe import com.sun.star.drawing.DashStyle;
40*eba4d44aSLiu Zhe import com.sun.star.drawing.LineDash;
41*eba4d44aSLiu Zhe import com.sun.star.drawing.LineStyle;
42*eba4d44aSLiu Zhe import com.sun.star.drawing.XDrawPage;
43*eba4d44aSLiu Zhe import com.sun.star.drawing.XDrawPages;
44*eba4d44aSLiu Zhe import com.sun.star.drawing.XDrawPagesSupplier;
45*eba4d44aSLiu Zhe import com.sun.star.drawing.XShape;
46*eba4d44aSLiu Zhe import com.sun.star.drawing.XShapes;
47*eba4d44aSLiu Zhe import com.sun.star.frame.XStorable;
48*eba4d44aSLiu Zhe import com.sun.star.lang.XComponent;
49*eba4d44aSLiu Zhe import com.sun.star.presentation.XPresentation;
50*eba4d44aSLiu Zhe import com.sun.star.presentation.XPresentationSupplier;
51*eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime;
52*eba4d44aSLiu Zhe 
53*eba4d44aSLiu Zhe public class LineProperties {
54*eba4d44aSLiu Zhe 	UnoApp unoApp = new UnoApp();
55*eba4d44aSLiu Zhe 	XPresentationSupplier sdDocument = null;
56*eba4d44aSLiu Zhe 	XPresentation pre = null;
57*eba4d44aSLiu Zhe 	XComponent precomp = null;
58*eba4d44aSLiu Zhe 	XComponent impressDocument = null;
59*eba4d44aSLiu Zhe 	XComponent reLoadFile = null;
60*eba4d44aSLiu Zhe 	XDrawPagesSupplier drawsupplier = null;
61*eba4d44aSLiu Zhe 	XDrawPages drawpages = null;
62*eba4d44aSLiu Zhe 	XShapes xShapes = null;
63*eba4d44aSLiu Zhe 	XDrawPage xpage = null;
64*eba4d44aSLiu Zhe 	String filePath = null;
65*eba4d44aSLiu Zhe 
66*eba4d44aSLiu Zhe 	@Before
setUp()67*eba4d44aSLiu Zhe 	public void setUp() throws Exception {
68*eba4d44aSLiu Zhe 		unoApp.start();
69*eba4d44aSLiu Zhe 		createDocumentAndSlide();
70*eba4d44aSLiu Zhe 	}
71*eba4d44aSLiu Zhe 
72*eba4d44aSLiu Zhe 	@After
tearDown()73*eba4d44aSLiu Zhe 	public void tearDown() throws Exception {
74*eba4d44aSLiu Zhe 		unoApp.closeDocument(impressDocument);
75*eba4d44aSLiu Zhe 		unoApp.closeDocument(reLoadFile);
76*eba4d44aSLiu Zhe 		unoApp.close();
77*eba4d44aSLiu Zhe 		 if (filePath != null)
78*eba4d44aSLiu Zhe 		 FileUtil.deleteFile(filePath);
79*eba4d44aSLiu Zhe 	}
80*eba4d44aSLiu Zhe 
81*eba4d44aSLiu Zhe 
82*eba4d44aSLiu Zhe 	/**
83*eba4d44aSLiu Zhe 	 * test Textbox Line style DASH
84*eba4d44aSLiu Zhe 	 *
85*eba4d44aSLiu Zhe 	 * @throws Exception
86*eba4d44aSLiu Zhe 	 */
87*eba4d44aSLiu Zhe 	 @Test
testShapeLineStyle()88*eba4d44aSLiu Zhe 	 public void testShapeLineStyle() throws Exception {
89*eba4d44aSLiu Zhe 	 Point po = new Point(1000, 8000);
90*eba4d44aSLiu Zhe 	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
91*eba4d44aSLiu Zhe 	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
92*eba4d44aSLiu Zhe 	 5000, 5000), "com.sun.star.drawing.TextShape");
93*eba4d44aSLiu Zhe 	 xShapes.add(xShape);
94*eba4d44aSLiu Zhe 	 ShapeUtil.addPortion(xShape, "test", false);
95*eba4d44aSLiu Zhe 	 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
96*eba4d44aSLiu Zhe 	 XPropertySet.class, xShape);
97*eba4d44aSLiu Zhe 	 xPropSet.setPropertyValue("LineStyle", LineStyle.DASH);
98*eba4d44aSLiu Zhe 
99*eba4d44aSLiu Zhe 	 LineDash aLineDash=new LineDash();
100*eba4d44aSLiu Zhe 	 aLineDash.Style=DashStyle.ROUND;
101*eba4d44aSLiu Zhe 	 aLineDash.Dots=2;
102*eba4d44aSLiu Zhe 	 aLineDash.DashLen=100;
103*eba4d44aSLiu Zhe 	 aLineDash.Distance=50;
104*eba4d44aSLiu Zhe 	 xPropSet.setPropertyValue("LineDash", aLineDash);
105*eba4d44aSLiu Zhe 
106*eba4d44aSLiu Zhe 	 // --------------------------
107*eba4d44aSLiu Zhe 	 xShape=saveAndLoadShape(1,0);
108*eba4d44aSLiu Zhe 	 xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape);
109*eba4d44aSLiu Zhe 	 // ----------------------------
110*eba4d44aSLiu Zhe 	 assertEquals("Not Dash Line Style",LineStyle.DASH,xPropSet.getPropertyValue("LineStyle"));
111*eba4d44aSLiu Zhe 	 aLineDash=(LineDash) xPropSet.getPropertyValue("LineDash");
112*eba4d44aSLiu Zhe 	 assertEquals("Not Round Dash Style", DashStyle.ROUND ,aLineDash.Style);
113*eba4d44aSLiu Zhe 	 }
114*eba4d44aSLiu Zhe 
115*eba4d44aSLiu Zhe 	 /**
116*eba4d44aSLiu Zhe 	 * test Textbox Line Color
117*eba4d44aSLiu Zhe 	 * @throws Exception
118*eba4d44aSLiu Zhe 	 */
119*eba4d44aSLiu Zhe 
120*eba4d44aSLiu Zhe 	 @Test
testShapeLineColor()121*eba4d44aSLiu Zhe 	 public void testShapeLineColor() throws Exception {
122*eba4d44aSLiu Zhe 	 Point po = new Point(1000, 8000);
123*eba4d44aSLiu Zhe 	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
124*eba4d44aSLiu Zhe 	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
125*eba4d44aSLiu Zhe 	 5000, 5000), "com.sun.star.drawing.TextShape");
126*eba4d44aSLiu Zhe 	 xShapes.add(xShape);
127*eba4d44aSLiu Zhe 	 ShapeUtil.addPortion(xShape, "test", false);
128*eba4d44aSLiu Zhe 	 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
129*eba4d44aSLiu Zhe 	 XPropertySet.class, xShape);
130*eba4d44aSLiu Zhe 	 xPropSet.setPropertyValue("LineStyle", LineStyle.DASH);
131*eba4d44aSLiu Zhe 	 xPropSet.setPropertyValue("LineColor", 0x00ff00);
132*eba4d44aSLiu Zhe 	 xShape=saveAndLoadShape(1,0);
133*eba4d44aSLiu Zhe 	 xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape);
134*eba4d44aSLiu Zhe 	 // ----------------------------
135*eba4d44aSLiu Zhe 	 assertEquals("Not Dash Line Style",LineStyle.DASH,xPropSet.getPropertyValue("LineStyle"));
136*eba4d44aSLiu Zhe 	 assertEquals("wrong line color", 0x00ff00,xPropSet.getPropertyValue("LineColor"));
137*eba4d44aSLiu Zhe 	 }
138*eba4d44aSLiu Zhe 
139*eba4d44aSLiu Zhe 	/**
140*eba4d44aSLiu Zhe 	 * create a new presentation document and insert a new slide.
141*eba4d44aSLiu Zhe 	 *
142*eba4d44aSLiu Zhe 	 * @throws Exception
143*eba4d44aSLiu Zhe 	 */
createDocumentAndSlide()144*eba4d44aSLiu Zhe 	public void createDocumentAndSlide() throws Exception {
145*eba4d44aSLiu Zhe 		impressDocument = (XComponent) UnoRuntime.queryInterface(
146*eba4d44aSLiu Zhe 				XComponent.class, unoApp.newDocument("simpress"));
147*eba4d44aSLiu Zhe 		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
148*eba4d44aSLiu Zhe 				XDrawPagesSupplier.class, impressDocument);
149*eba4d44aSLiu Zhe 		drawpages = drawsupplier.getDrawPages();
150*eba4d44aSLiu Zhe 		drawpages.insertNewByIndex(1);
151*eba4d44aSLiu Zhe 		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
152*eba4d44aSLiu Zhe 	}
153*eba4d44aSLiu Zhe 
154*eba4d44aSLiu Zhe 	/**
155*eba4d44aSLiu Zhe 	 * Save presentation and reLoad the presentation and shape in it.
156*eba4d44aSLiu Zhe 	 *
157*eba4d44aSLiu Zhe 	 * @param po
158*eba4d44aSLiu Zhe 	 * @param shapeType
159*eba4d44aSLiu Zhe 	 * @return
160*eba4d44aSLiu Zhe 	 * @throws Exception
161*eba4d44aSLiu Zhe 	 */
saveAndLoadShape(int pageIndex, int shapeIndex)162*eba4d44aSLiu Zhe 	public XShape saveAndLoadShape(int pageIndex, int shapeIndex)
163*eba4d44aSLiu Zhe 			throws Exception {
164*eba4d44aSLiu Zhe 		reLoadFile = saveAndReloadDoc(impressDocument, "impress8", "odp");
165*eba4d44aSLiu Zhe 		xShapes = ShapeUtil.getShapes(reLoadFile, pageIndex);
166*eba4d44aSLiu Zhe 		return (XShape) UnoRuntime.queryInterface(XShape.class,
167*eba4d44aSLiu Zhe 				xShapes.getByIndex(shapeIndex));
168*eba4d44aSLiu Zhe 	}
169*eba4d44aSLiu Zhe 
170*eba4d44aSLiu Zhe 	/**
171*eba4d44aSLiu Zhe 	 * save and reload Presentation document.
172*eba4d44aSLiu Zhe 	 *
173*eba4d44aSLiu Zhe 	 * @param presentationDocument
174*eba4d44aSLiu Zhe 	 * @param sFilter
175*eba4d44aSLiu Zhe 	 * @param sExtension
176*eba4d44aSLiu Zhe 	 * @return
177*eba4d44aSLiu Zhe 	 * @throws Exception
178*eba4d44aSLiu Zhe 	 */
saveAndReloadDoc(XComponent presentationDocument, String sFilter, String sExtension)179*eba4d44aSLiu Zhe 	private XComponent saveAndReloadDoc(XComponent presentationDocument,
180*eba4d44aSLiu Zhe 			String sFilter, String sExtension) throws Exception {
181*eba4d44aSLiu Zhe 		filePath = Testspace.getPath("tmp/textboxline." + sExtension);
182*eba4d44aSLiu Zhe 		PropertyValue[] aStoreProperties = new PropertyValue[2];
183*eba4d44aSLiu Zhe 		aStoreProperties[0] = new PropertyValue();
184*eba4d44aSLiu Zhe 		aStoreProperties[1] = new PropertyValue();
185*eba4d44aSLiu Zhe 		aStoreProperties[0].Name = "Override";
186*eba4d44aSLiu Zhe 		aStoreProperties[0].Value = true;
187*eba4d44aSLiu Zhe 		aStoreProperties[1].Name = "FilterName";
188*eba4d44aSLiu Zhe 		aStoreProperties[1].Value = sFilter;
189*eba4d44aSLiu Zhe 		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
190*eba4d44aSLiu Zhe 				XStorable.class, presentationDocument);
191*eba4d44aSLiu Zhe 		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
192*eba4d44aSLiu Zhe 
193*eba4d44aSLiu Zhe 		return (XComponent) UnoRuntime.queryInterface(XComponent.class,
194*eba4d44aSLiu Zhe 				unoApp.loadDocument(filePath));
195*eba4d44aSLiu Zhe 	}
196*eba4d44aSLiu Zhe }
197*eba4d44aSLiu Zhe 
198*eba4d44aSLiu Zhe 
199