Line 0
Link Here
|
|
|
1 |
package testcase.uno.sd; |
2 |
|
3 |
import junit.framework.Assert; |
4 |
|
5 |
import org.junit.After; |
6 |
import org.junit.Before; |
7 |
import org.junit.Test; |
8 |
import org.openoffice.test.common.FileUtil; |
9 |
import org.openoffice.test.common.Testspace; |
10 |
import org.openoffice.test.uno.UnoApp; |
11 |
|
12 |
import testlib.uno.ShapeUtil; |
13 |
|
14 |
import com.sun.star.awt.Point; |
15 |
import com.sun.star.awt.Size; |
16 |
import com.sun.star.beans.PropertyValue; |
17 |
import com.sun.star.beans.XPropertySet; |
18 |
import com.sun.star.container.XIndexContainer; |
19 |
import com.sun.star.container.XNameContainer; |
20 |
import com.sun.star.container.XNamed; |
21 |
import com.sun.star.drawing.XDrawPage; |
22 |
import com.sun.star.drawing.XDrawPages; |
23 |
import com.sun.star.drawing.XDrawPagesSupplier; |
24 |
import com.sun.star.drawing.XShape; |
25 |
import com.sun.star.drawing.XShapes; |
26 |
import com.sun.star.frame.XStorable; |
27 |
import com.sun.star.lang.XComponent; |
28 |
import com.sun.star.lang.XSingleServiceFactory; |
29 |
import com.sun.star.presentation.AnimationEffect; |
30 |
import com.sun.star.presentation.XCustomPresentationSupplier; |
31 |
import com.sun.star.presentation.XPresentation; |
32 |
import com.sun.star.presentation.XPresentationSupplier; |
33 |
import com.sun.star.table.XCell; |
34 |
import com.sun.star.text.ControlCharacter; |
35 |
import com.sun.star.text.XText; |
36 |
import com.sun.star.text.XTextCursor; |
37 |
import com.sun.star.text.XTextRange; |
38 |
import com.sun.star.uno.UnoRuntime; |
39 |
|
40 |
public class ShapeAnimation { |
41 |
XPresentationSupplier sdDocument = null; |
42 |
XPresentation pre = null; |
43 |
XComponent precomp = null; |
44 |
XComponent impressDocument = null; |
45 |
XComponent reLoadFile = null; |
46 |
XDrawPagesSupplier drawsupplier = null; |
47 |
XDrawPages drawpages = null; |
48 |
|
49 |
String filePath = null; |
50 |
|
51 |
UnoApp unoApp = new UnoApp(); |
52 |
|
53 |
/** |
54 |
* @throws java.lang.Exception |
55 |
*/ |
56 |
@Before |
57 |
public void setUp() throws Exception { |
58 |
unoApp.start(); |
59 |
createDocumentAndSlide(); |
60 |
} |
61 |
|
62 |
@After |
63 |
public void tearDown() throws Exception { |
64 |
unoApp.closeDocument(impressDocument); |
65 |
unoApp.closeDocument(reLoadFile); |
66 |
unoApp.close(); |
67 |
} |
68 |
|
69 |
@Test |
70 |
public void testShapeAnimation() throws Exception { |
71 |
|
72 |
XShapes xShapes = null; |
73 |
XPropertySet xShapePropSet[] = new XPropertySet[23]; |
74 |
|
75 |
drawpages.insertNewByIndex(0); |
76 |
|
77 |
String aNameArray[] = { "Page 1", "Page 2", "Page 3", "Page 4", |
78 |
"Page 5", "Page 6", "Page 7", "Page 8", "Page 9", "Page 10", |
79 |
"Page 11", "Page 12", "Page 13", "Page 14", "Page 15", |
80 |
"Page 16", "Page 17", "Page 18", "Page 19", "Page 20", |
81 |
"Page 21", "Page 22", "Page 23", }; |
82 |
AnimationEffect AnimationEffectArray[] = { |
83 |
AnimationEffect.NONE, |
84 |
AnimationEffect.FADE_FROM_LEFT, |
85 |
AnimationEffect.FADE_FROM_TOP, |
86 |
AnimationEffect.FADE_FROM_RIGHT, |
87 |
AnimationEffect.FADE_FROM_BOTTOM, |
88 |
AnimationEffect.FADE_TO_CENTER, |
89 |
AnimationEffect.FADE_FROM_CENTER, |
90 |
AnimationEffect.MOVE_FROM_LEFT, |
91 |
AnimationEffect.MOVE_FROM_TOP, |
92 |
AnimationEffect.MOVE_FROM_RIGHT, |
93 |
AnimationEffect.MOVE_FROM_BOTTOM, |
94 |
AnimationEffect.VERTICAL_STRIPES, |
95 |
AnimationEffect.HORIZONTAL_STRIPES, |
96 |
AnimationEffect.CLOCKWISE, |
97 |
AnimationEffect.COUNTERCLOCKWISE, |
98 |
AnimationEffect.FADE_FROM_UPPERLEFT, |
99 |
AnimationEffect.FADE_FROM_UPPERRIGHT, |
100 |
AnimationEffect.FADE_FROM_LOWERLEFT, |
101 |
AnimationEffect.FADE_FROM_LOWERRIGHT, |
102 |
AnimationEffect.CLOSE_VERTICAL, |
103 |
AnimationEffect.CLOSE_HORIZONTAL, |
104 |
AnimationEffect.OPEN_VERTICAL, |
105 |
AnimationEffect.OPEN_HORIZONTAL, |
106 |
AnimationEffect.PATH, |
107 |
/* AnimationEffect.MOVE_TO_LEFT, |
108 |
AnimationEffect.MOVE_TO_TOP, |
109 |
AnimationEffect.MOVE_TO_RIGHT, |
110 |
AnimationEffect.MOVE_TO_BOTTOM, |
111 |
AnimationEffect.SPIRALIN_LEFT, |
112 |
AnimationEffect.SPIRALIN_RIGHT, |
113 |
AnimationEffect.SPIRALOUT_LEFT, |
114 |
AnimationEffect.SPIRALOUT_RIGHT, |
115 |
AnimationEffect.DISSOLVE, |
116 |
AnimationEffect.WAVYLINE_FROM_LEFT, |
117 |
AnimationEffect.RANDOM, |
118 |
AnimationEffect.VERTICAL_LINES, |
119 |
AnimationEffect.LASER_FROM_LEFT, |
120 |
AnimationEffect.APPEAR, |
121 |
AnimationEffect.HIDE, |
122 |
AnimationEffect.MOVE_FROM_UPPERLEFT, |
123 |
AnimationEffect.VERTICAL_CHECKERBOARD, |
124 |
AnimationEffect.HORIZONTAL_ROTATE, |
125 |
AnimationEffect.VERTICAL_STRETCH, |
126 |
AnimationEffect.ZOOM_IN, |
127 |
AnimationEffect.ZOOM_OUT_FROM_LEFT, */ |
128 |
}; |
129 |
|
130 |
// insert pages |
131 |
while (drawpages.getCount() < aNameArray.length) |
132 |
drawpages.insertNewByIndex(0); |
133 |
|
134 |
// add text shape to each page |
135 |
for (int i = 0; i < aNameArray.length; i++) { |
136 |
XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface( |
137 |
XDrawPage.class, drawpages.getByIndex(i)); |
138 |
XNamed xPageName = (XNamed) UnoRuntime.queryInterface(XNamed.class, |
139 |
xDrawPage); |
140 |
xPageName.setName(aNameArray[i]); |
141 |
|
142 |
xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, |
143 |
drawpages.getByIndex(i)); |
144 |
|
145 |
// create a rectangle that is placed on the top left of the page |
146 |
xShapePropSet[i] = ShapeUtil.createAndInsertShape(impressDocument, |
147 |
xShapes, new Point(1000, 1000), new Size(5000, 5000), |
148 |
"com.sun.star.drawing.RectangleShape"); |
149 |
} |
150 |
|
151 |
for (int i = 0; i < aNameArray.length; i++) { |
152 |
// set an object animation for each slide |
153 |
xShapePropSet[i] |
154 |
.setPropertyValue("Effect", AnimationEffectArray[i]); |
155 |
} |
156 |
|
157 |
// If this property and the property DimPrevious are both true, the shape is hidden on the next click after the AnimationEffect has finished. |
158 |
xShapePropSet[1].setPropertyValue("DimHide", new Boolean(false)); |
159 |
// If true, this shape is painted using DimColor on the next click after finishing the AnimationEffect. |
160 |
xShapePropSet[1].setPropertyValue("DimPrevious", new Boolean(true)); |
161 |
// his color is used to paint the shape on the next click after the animation effect has finished |
162 |
xShapePropSet[1].setPropertyValue("DimColor", new Integer(0xff0000)); |
163 |
// the sound file specified in Sound is played while the animation effect is executed |
164 |
xShapePropSet[1].setPropertyValue("SoundOn", new Boolean(false)); |
165 |
// the sound specified in the Sound property of this shape is played completely |
166 |
xShapePropSet[1].setPropertyValue("PlayFull", new Boolean(false)); |
167 |
|
168 |
saveAndLoadSlide(); |
169 |
|
170 |
for (int i = 0; i < aNameArray.length; i++) { |
171 |
// assert if Shape Animation is set |
172 |
Assert.assertEquals( |
173 |
"Text Animation Effect is AnimationEffectArray[]", |
174 |
AnimationEffectArray[i], |
175 |
xShapePropSet[i].getPropertyValue("Effect")); |
176 |
} |
177 |
// assert if DimHide is false |
178 |
Assert.assertEquals("Shape Animation DimHide is false", Boolean.FALSE, |
179 |
xShapePropSet[1].getPropertyValue("DimHide")); |
180 |
// assert if DimPrevious is true |
181 |
Assert.assertEquals("Shape Animation DimPrevious is true", |
182 |
Boolean.TRUE, xShapePropSet[1].getPropertyValue("DimPrevious")); |
183 |
// assert if DimColor is red |
184 |
Assert.assertEquals("Shape Animation DimColor is Red", 0xff0000, |
185 |
xShapePropSet[1].getPropertyValue("DimColor")); |
186 |
// assert the sound file specified in Sound don't play while the |
187 |
// animation effect is executed. |
188 |
Assert.assertEquals("Shape SoundOn is false", Boolean.FALSE, |
189 |
xShapePropSet[1].getPropertyValue("SoundOn")); |
190 |
// assert the sound specified in the Sound property of this shape is |
191 |
// played completely |
192 |
Assert.assertEquals("Shape PlayFull is false", Boolean.FALSE, |
193 |
xShapePropSet[1].getPropertyValue("PlayFull")); |
194 |
|
195 |
} |
196 |
|
197 |
public XPropertySet addPortion(XShape xShape, String sText, |
198 |
boolean bNewParagraph) |
199 |
throws com.sun.star.lang.IllegalArgumentException { |
200 |
XText xText = (XText) UnoRuntime.queryInterface(XText.class, xShape); |
201 |
|
202 |
XTextCursor xTextCursor = xText.createTextCursor(); |
203 |
xTextCursor.gotoEnd(false); |
204 |
if (bNewParagraph == true) { |
205 |
xText.insertControlCharacter(xTextCursor, |
206 |
ControlCharacter.PARAGRAPH_BREAK, false); |
207 |
xTextCursor.gotoEnd(false); |
208 |
} |
209 |
XTextRange xTextRange = (XTextRange) UnoRuntime.queryInterface( |
210 |
XTextRange.class, xTextCursor); |
211 |
xTextRange.setString(sText); |
212 |
xTextCursor.gotoEnd(true); |
213 |
XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( |
214 |
XPropertySet.class, xText); |
215 |
return xPropSet; |
216 |
} |
217 |
|
218 |
/** |
219 |
* create a new presentation document and insert a new slide. |
220 |
* |
221 |
* @throws Exception |
222 |
*/ |
223 |
public void createDocumentAndSlide() throws Exception { |
224 |
impressDocument = (XComponent) UnoRuntime.queryInterface( |
225 |
XComponent.class, unoApp.newDocument("simpress")); |
226 |
drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( |
227 |
XDrawPagesSupplier.class, impressDocument); |
228 |
drawpages = drawsupplier.getDrawPages(); |
229 |
|
230 |
sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface( |
231 |
XPresentationSupplier.class, impressDocument); |
232 |
pre = sdDocument.getPresentation(); |
233 |
} |
234 |
|
235 |
/** |
236 |
* Save presentation and reLoad the slide. |
237 |
* |
238 |
* @param no |
239 |
* @return void |
240 |
* @throws Exception |
241 |
*/ |
242 |
public void saveAndLoadSlide() throws Exception { |
243 |
reLoadFile = saveAndReloadDoc(impressDocument, |
244 |
"StarOffice XML (Impress)", "odp"); |
245 |
drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( |
246 |
XDrawPagesSupplier.class, reLoadFile); |
247 |
drawpages = drawsupplier.getDrawPages(); |
248 |
|
249 |
sdDocument = (XPresentationSupplier) UnoRuntime.queryInterface( |
250 |
XPresentationSupplier.class, reLoadFile); |
251 |
pre = sdDocument.getPresentation(); |
252 |
} |
253 |
|
254 |
/** |
255 |
* save and reload Presentation document. |
256 |
* |
257 |
* @param presentationDocument |
258 |
* @param sFilter |
259 |
* @param sExtension |
260 |
* @return |
261 |
* @throws Exception |
262 |
*/ |
263 |
private XComponent saveAndReloadDoc(XComponent presentationDocument, |
264 |
String sFilter, String sExtension) throws Exception { |
265 |
filePath = Testspace.getPath("tmp/shapeanimation." + sExtension); |
266 |
PropertyValue[] aStoreProperties = new PropertyValue[2]; |
267 |
aStoreProperties[0] = new PropertyValue(); |
268 |
aStoreProperties[1] = new PropertyValue(); |
269 |
aStoreProperties[0].Name = "Override"; |
270 |
aStoreProperties[0].Value = true; |
271 |
aStoreProperties[1].Name = "FilterName"; |
272 |
aStoreProperties[1].Value = sFilter; |
273 |
XStorable xStorable = (XStorable) UnoRuntime.queryInterface( |
274 |
XStorable.class, presentationDocument); |
275 |
xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties); |
276 |
|
277 |
return UnoRuntime.queryInterface(XComponent.class, |
278 |
unoApp.loadDocument(filePath)); |
279 |
} |
280 |
} |