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 
22 
23 
24 package mod._svx;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.DrawTools;
33 import util.SOfficeFactory;
34 
35 import com.sun.star.container.XEnumerationAccess;
36 import com.sun.star.drawing.XShape;
37 import com.sun.star.lang.XComponent;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.text.ControlCharacter;
40 import com.sun.star.text.XSimpleText;
41 import com.sun.star.text.XTextCursor;
42 import com.sun.star.uno.AnyConverter;
43 import com.sun.star.uno.Type;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 
47 public class SvxUnoTextRangeEnumeration extends TestCase {
48 
49     static XComponent xDrawDoc;
50 
51     /**
52      * in general this method creates a testdocument
53      *
54      *  @param tParam    class which contains additional test parameters
55      *  @param log        class to log the test state and result
56      *
57      *
58      *  @see TestParameters
59      *    @see PrintWriter
60      *
61      */
initialize( TestParameters tParam, PrintWriter log )62     protected void initialize( TestParameters tParam, PrintWriter log ) {
63         try {
64             log.println( "creating a drawdoc" );
65             xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
66         } catch ( Exception e ) {
67             // Some exception occures.FAILED
68             e.printStackTrace( log );
69             throw new StatusException( "Couldn't create document", e );
70         }
71     }
72 
73     /**
74      * in general this method disposes the testenvironment and document
75      *
76      *  @param tParam    class which contains additional test parameters
77      *  @param log        class to log the test state and result
78      *
79      *
80      *  @see TestParameters
81      *    @see PrintWriter
82      *
83      */
cleanup( TestParameters tParam, PrintWriter log )84     protected void cleanup( TestParameters tParam, PrintWriter log ) {
85         log.println( "    disposing xDrawDoc " );
86         util.DesktopTools.closeDoc(xDrawDoc);
87     }
88 
89 
90     /**
91      *    creating a Testenvironment for the interfaces to be tested
92      *
93      *  @param tParam    class which contains additional test parameters
94      *  @param log        class to log the test state and result
95      *
96      *  @return    Status class
97      *
98      *  @see TestParameters
99      *    @see PrintWriter
100      */
createTestEnvironment(TestParameters tParam, PrintWriter log)101     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
102 
103         XInterface oObj = null;
104         // create testobject here
105 
106         XEnumerationAccess xEA = null ;
107         try {
108             SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
109             XShape oShape = SOF.createShape
110                 (xDrawDoc,5000,3500,7500,5000,"Text");
111             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
112 
113             XSimpleText text = (XSimpleText) UnoRuntime.queryInterface
114                 (XSimpleText.class, oShape) ;
115 
116             XTextCursor cursor = text.createTextCursor() ;
117 
118             text.insertString(cursor, "Paragraph 1", false) ;
119             text.insertControlCharacter(cursor,
120                 ControlCharacter.PARAGRAPH_BREAK, false) ;
121             text.insertString(cursor, "Paragraph 2", false) ;
122             text.insertControlCharacter(cursor,
123                 ControlCharacter.PARAGRAPH_BREAK, false) ;
124             text.insertString(cursor, "Paragraph 3", false) ;
125             text.insertControlCharacter(cursor,
126                 ControlCharacter.PARAGRAPH_BREAK, false) ;
127 
128             xEA = (XEnumerationAccess) UnoRuntime.queryInterface
129                 (XEnumerationAccess.class, text) ;
130 
131             XInterface oTextContent = (XInterface) AnyConverter.toObject(
132                 new Type(XInterface.class),xEA.createEnumeration().nextElement());
133 
134             xEA = (XEnumerationAccess) UnoRuntime.queryInterface
135                 (XEnumerationAccess.class, oTextContent) ;
136 
137             oObj = xEA.createEnumeration();
138 
139         } catch (Exception e) {
140             log.println("Can't create test object") ;
141             e.printStackTrace(log) ;
142         }
143 
144         // create test environment here
145          TestEnvironment tEnv = new TestEnvironment( oObj );
146 
147         tEnv.addObjRelation("ENUM", xEA);
148 
149         return tEnv;
150     } // finish method getTestEnvironment
151 
152 }
153 
154