Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxShapeGroup.java
blobd49200a00aef74ea6d8f30d4430b635e718a6f21
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._svx;
21 import java.io.PrintWriter;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.InstCreator;
27 import util.SOfficeFactory;
28 import util.ShapeDsc;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.container.XIndexAccess;
32 import com.sun.star.drawing.XDrawPage;
33 import com.sun.star.drawing.XDrawPages;
34 import com.sun.star.drawing.XDrawPagesSupplier;
35 import com.sun.star.drawing.XShape;
36 import com.sun.star.drawing.XShapeGrouper;
37 import com.sun.star.drawing.XShapes;
38 import com.sun.star.lang.XComponent;
39 import com.sun.star.style.XStyle;
40 import com.sun.star.uno.AnyConverter;
41 import com.sun.star.uno.Type;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
45 /**
47 * initial description
49 * @see com.sun.star.drawing._XDrawPage
53 public class SvxShapeGroup extends TestCase {
55 static XComponent xDrawDoc;
57 /**
58 * in general this method initializes the document
60 @Override
61 protected void initialize(TestParameters Param, PrintWriter log)
62 throws Exception {
63 // get a soffice factory object
64 SOfficeFactory SOF = SOfficeFactory.getFactory(Param.getMSF());
65 log.println("creating a draw document");
66 xDrawDoc = SOF.createDrawDoc(null);
69 /**
70 * in general this method disposes the document
72 @Override
73 protected void cleanup(TestParameters Param, PrintWriter log) {
75 log.println("disposing xDrawDoc");
76 util.DesktopTools.closeDoc(xDrawDoc);
80 /**
81 * creating a TestEnvironment for the interfaces to be tested
83 @Override
84 public TestEnvironment createTestEnvironment(TestParameters Param,
85 PrintWriter log) throws Exception {
87 XInterface oObj = null;
88 XShapes oShapes = null;
90 // creation of testobject here
91 // first we write what we are intend to do to log file
92 log.println("creating a test environment");
94 SOfficeFactory SOF = SOfficeFactory.getFactory(Param.getMSF());
96 // get the drawpage of drawing here
97 log.println("getting Drawpage");
98 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(
99 XDrawPagesSupplier.class, xDrawDoc);
100 XDrawPages oDPn = oDPS.getDrawPages();
101 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class, oDPn);
102 oObj = (XDrawPage) AnyConverter.toObject(new Type(XDrawPage.class),
103 oDPi.getByIndex(0));
105 if (oObj == null) {
106 System.out.println("**************************");
107 System.out.println(" XDrawPage is NULL");
108 System.out.println("**************************");
111 // put something on the drawpage
112 log.println("inserting some Shapes");
113 oShapes = UnoRuntime.queryInterface(XShapes.class, oObj);
114 XShape Shape1 = SOF.createShape(xDrawDoc, 3000, 4500, 15000, 1000,
115 "Ellipse");
116 oShapes.add(SOF.createShape(xDrawDoc, 2000, 1500, 1000, 1000, "Line"));
117 oShapes.add(Shape1);
118 XShape Shape2 = SOF.createShape(xDrawDoc, 5000, 3500, 7500, 5000,
119 "Rectangle");
120 oShapes.add(Shape2);
122 log.println("adding two style as ObjRelation for ShapeDescriptor");
123 XPropertySet oShapeProps = UnoRuntime.queryInterface(
124 XPropertySet.class, Shape1);
125 XStyle aStyle1 = null;
126 try {
127 aStyle1 = (XStyle) AnyConverter.toObject(new Type(XStyle.class),
128 oShapeProps.getPropertyValue("Style"));
129 } catch (Exception e) {
131 oShapeProps = UnoRuntime.queryInterface(XPropertySet.class, Shape2);
132 XStyle aStyle2 = null;
133 try {
134 aStyle2 = (XStyle) AnyConverter.toObject(new Type(XStyle.class),
135 oShapeProps.getPropertyValue("Style"));
136 } catch (Exception e) {
139 // get the XShapeGrouper
140 log.println("get XShapeGroup");
141 XShapeGrouper oSG = UnoRuntime
142 .queryInterface(XShapeGrouper.class, oObj);
143 oObj = oSG.group(oShapes);
145 log.println("creating a new environment for drawpage object");
146 TestEnvironment tEnv = new TestEnvironment(oObj);
148 ShapeDsc sDsc = new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle");
149 log.println("adding Shape as mod relation to environment");
150 tEnv.addObjRelation("Shape", new InstCreator(xDrawDoc, sDsc));
152 tEnv.addObjRelation("Style1", aStyle1);
153 tEnv.addObjRelation("Style2", aStyle2);
154 for (int i = 0; i < 6; i++) {
155 Shape2 = SOF.createShape(xDrawDoc, 5000 + 100 * i, 3500 + 100 * i,
156 7500 + 100 * i, 5000 + 100 * i, "Rectangle");
157 oShapes.add(Shape2);
159 return tEnv;
160 } // finish method createTestEnvironment
162 } // finish class SvxShapeGroup