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