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.textbox;
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.DashStyle;
40 import com.sun.star.drawing.LineDash;
41 import com.sun.star.drawing.LineStyle;
42 import com.sun.star.drawing.XDrawPage;
43 import com.sun.star.drawing.XDrawPages;
44 import com.sun.star.drawing.XDrawPagesSupplier;
45 import com.sun.star.drawing.XShape;
46 import com.sun.star.drawing.XShapes;
47 import com.sun.star.frame.XStorable;
48 import com.sun.star.lang.XComponent;
49 import com.sun.star.presentation.XPresentation;
50 import com.sun.star.presentation.XPresentationSupplier;
51 import com.sun.star.uno.UnoRuntime;
52 
53 public class LineProperties {
54 	UnoApp unoApp = new UnoApp();
55 	XPresentationSupplier sdDocument = null;
56 	XPresentation pre = null;
57 	XComponent precomp = null;
58 	XComponent impressDocument = null;
59 	XComponent reLoadFile = null;
60 	XDrawPagesSupplier drawsupplier = null;
61 	XDrawPages drawpages = null;
62 	XShapes xShapes = null;
63 	XDrawPage xpage = null;
64 	String filePath = null;
65 
66 	@Before
setUp()67 	public void setUp() throws Exception {
68 		unoApp.start();
69 		createDocumentAndSlide();
70 	}
71 
72 	@After
tearDown()73 	public void tearDown() throws Exception {
74 		unoApp.closeDocument(impressDocument);
75 		unoApp.closeDocument(reLoadFile);
76 		unoApp.close();
77 		 if (filePath != null)
78 		 FileUtil.deleteFile(filePath);
79 	}
80 
81 
82 	/**
83 	 * test Textbox Line style DASH
84 	 *
85 	 * @throws Exception
86 	 */
87 	 @Test
testShapeLineStyle()88 	 public void testShapeLineStyle() throws Exception {
89 	 Point po = new Point(1000, 8000);
90 	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
91 	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
92 	 5000, 5000), "com.sun.star.drawing.TextShape");
93 	 xShapes.add(xShape);
94 	 ShapeUtil.addPortion(xShape, "test", false);
95 	 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
96 	 XPropertySet.class, xShape);
97 	 xPropSet.setPropertyValue("LineStyle", LineStyle.DASH);
98 
99 	 LineDash aLineDash=new LineDash();
100 	 aLineDash.Style=DashStyle.ROUND;
101 	 aLineDash.Dots=2;
102 	 aLineDash.DashLen=100;
103 	 aLineDash.Distance=50;
104 	 xPropSet.setPropertyValue("LineDash", aLineDash);
105 
106 	 // --------------------------
107 	 xShape=saveAndLoadShape(1,0);
108 	 xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape);
109 	 // ----------------------------
110 	 assertEquals("Not Dash Line Style",LineStyle.DASH,xPropSet.getPropertyValue("LineStyle"));
111 	 aLineDash=(LineDash) xPropSet.getPropertyValue("LineDash");
112 	 assertEquals("Not Round Dash Style", DashStyle.ROUND ,aLineDash.Style);
113 	 }
114 
115 	 /**
116 	 * test Textbox Line Color
117 	 * @throws Exception
118 	 */
119 
120 	 @Test
testShapeLineColor()121 	 public void testShapeLineColor() throws Exception {
122 	 Point po = new Point(1000, 8000);
123 	 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
124 	 XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
125 	 5000, 5000), "com.sun.star.drawing.TextShape");
126 	 xShapes.add(xShape);
127 	 ShapeUtil.addPortion(xShape, "test", false);
128 	 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
129 	 XPropertySet.class, xShape);
130 	 xPropSet.setPropertyValue("LineStyle", LineStyle.DASH);
131 	 xPropSet.setPropertyValue("LineColor", 0x00ff00);
132 	 xShape=saveAndLoadShape(1,0);
133 	 xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape);
134 	 // ----------------------------
135 	 assertEquals("Not Dash Line Style",LineStyle.DASH,xPropSet.getPropertyValue("LineStyle"));
136 	 assertEquals("wrong line color", 0x00ff00,xPropSet.getPropertyValue("LineColor"));
137 	 }
138 
139 	/**
140 	 * create a new presentation document and insert a new slide.
141 	 *
142 	 * @throws Exception
143 	 */
createDocumentAndSlide()144 	public void createDocumentAndSlide() throws Exception {
145 		impressDocument = (XComponent) UnoRuntime.queryInterface(
146 				XComponent.class, unoApp.newDocument("simpress"));
147 		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
148 				XDrawPagesSupplier.class, impressDocument);
149 		drawpages = drawsupplier.getDrawPages();
150 		drawpages.insertNewByIndex(1);
151 		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
152 	}
153 
154 	/**
155 	 * Save presentation and reLoad the presentation and shape in it.
156 	 *
157 	 * @param po
158 	 * @param shapeType
159 	 * @return
160 	 * @throws Exception
161 	 */
saveAndLoadShape(int pageIndex, int shapeIndex)162 	public XShape saveAndLoadShape(int pageIndex, int shapeIndex)
163 			throws Exception {
164 		reLoadFile = saveAndReloadDoc(impressDocument, "impress8", "odp");
165 		xShapes = ShapeUtil.getShapes(reLoadFile, pageIndex);
166 		return (XShape) UnoRuntime.queryInterface(XShape.class,
167 				xShapes.getByIndex(shapeIndex));
168 	}
169 
170 	/**
171 	 * save and reload Presentation document.
172 	 *
173 	 * @param presentationDocument
174 	 * @param sFilter
175 	 * @param sExtension
176 	 * @return
177 	 * @throws Exception
178 	 */
saveAndReloadDoc(XComponent presentationDocument, String sFilter, String sExtension)179 	private XComponent saveAndReloadDoc(XComponent presentationDocument,
180 			String sFilter, String sExtension) throws Exception {
181 		filePath = Testspace.getPath("tmp/textboxline." + sExtension);
182 		PropertyValue[] aStoreProperties = new PropertyValue[2];
183 		aStoreProperties[0] = new PropertyValue();
184 		aStoreProperties[1] = new PropertyValue();
185 		aStoreProperties[0].Name = "Override";
186 		aStoreProperties[0].Value = true;
187 		aStoreProperties[1].Name = "FilterName";
188 		aStoreProperties[1].Value = sFilter;
189 		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
190 				XStorable.class, presentationDocument);
191 		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
192 
193 		return (XComponent) UnoRuntime.queryInterface(XComponent.class,
194 				unoApp.loadDocument(filePath));
195 	}
196 }
197 
198 
199