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 package mod._qadevOOo;
24 
25 import com.sun.star.lang.XMultiServiceFactory;
26 import com.sun.star.uno.XInterface;
27 
28 import java.io.PrintWriter;
29 
30 import lib.StatusException;
31 import lib.TestCase;
32 import lib.TestEnvironment;
33 import lib.TestParameters;
34 
35 import util.SOfficeFactory;
36 
37 import com.sun.star.text.XSimpleText;
38 import com.sun.star.text.XTextCursor;
39 import com.sun.star.text.XTextDocument;
40 
41 public class SelfTest extends TestCase
42 {
43     private XTextDocument xTextDoc = null;
44 
initialize(TestParameters tParam, PrintWriter log)45     protected void initialize(TestParameters tParam, PrintWriter log)
46     {
47         // get a soffice factory object
48         SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) tParam.getMSF());
49 
50         log.println("initialize the selftest");
51         try
52         {
53             log.println("creating a textdocument");
54             xTextDoc = SOF.createTextDoc(null);
55         }
56         catch (com.sun.star.uno.Exception e)
57         {
58             e.printStackTrace(log);
59             throw new StatusException("Couldn't create document", e);
60         }
61     }
62 
63     /**
64      * Disposes text document.
65      */
cleanup(TestParameters tParam, PrintWriter log)66     protected void cleanup(TestParameters tParam, PrintWriter log)
67     {
68         log.println("    cleanup selftest");
69         util.DesktopTools.closeDoc(xTextDoc);
70     }
71 
createTestEnvironment(TestParameters tParam, PrintWriter log)72     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log)
73     {
74         XInterface oObj = null;
75         log.println("creating a test environment");
76 
77         // get the bodytext of textdocument here
78         log.println("getting the TextCursor");
79 
80         final XSimpleText aText = xTextDoc.getText();
81         final XTextCursor textCursor = aText.createTextCursor();
82         oObj = textCursor;
83 
84         TestEnvironment tEnv = new TestEnvironment(oObj);
85 
86         return tEnv;
87     }
88 }
89