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._sw;
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.SOfficeFactory;
33 
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.text.XTextDocument;
36 import com.sun.star.text.XTextViewCursorSupplier;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 /**
40  *
41  * initial description
42  * @see com.sun.star.beans.XPropertySet
43  * @see com.sun.star.beans.XPropertyState
44  * @see com.sun.star.document.XDocumentInsertable
45  * @see com.sun.star.style.CharacterProperties
46  * @see com.sun.star.style.ParagraphProperties
47  * @see com.sun.star.text.XPageCursor
48  * @see com.sun.star.text.XParagraphCursor
49  * @see com.sun.star.text.XSentenceCursor
50  * @see com.sun.star.text.XTextCursor
51  * @see com.sun.star.text.XTextRange
52  * @see com.sun.star.text.XWordCursor
53  * @see com.sun.star.util.XSortable
54  * @see com.sun.star.view.XScreenCursor
55  *
56  */
57 public class SwXTextViewCursor extends TestCase {
58     XTextDocument xTextDoc;
59 
initialize( TestParameters tParam, PrintWriter log )60     protected void initialize( TestParameters tParam, PrintWriter log ) {
61         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
62 
63         try {
64             log.println( "creating a textdocument" );
65             xTextDoc = SOF.createTextDoc( null );
66         } catch ( com.sun.star.uno.Exception e ) {
67             // Some exception occures.FAILED
68             e.printStackTrace( log );
69             throw new StatusException( "Couldn't create document", e );
70         }
71     }
72 
cleanup( TestParameters tParam, PrintWriter log )73     protected void cleanup( TestParameters tParam, PrintWriter log ) {
74         log.println( "    disposing xTextDoc " );
75         util.DesktopTools.closeDoc(xTextDoc);
76     }
77 
78 
79     /**
80      *    creating a Testenvironment for the interfaces to be tested
81      *
82      *  @param tParam    class which contains additional test parameters
83      *  @param log        class to log the test state and result
84      *
85      *  @return    Status class
86      *
87      *  @see TestParameters
88      *    @see PrintWriter
89      */
createTestEnvironment(TestParameters tParam, PrintWriter log)90     public synchronized TestEnvironment createTestEnvironment
91             (TestParameters tParam, PrintWriter log) {
92 
93         XInterface oObj = null;
94 
95         // creation of testobject here
96         // first we write what we are intend to do to log file
97         log.println( "creating a test environment" );
98 
99         // create testobject here
100         oObj = xTextDoc.getCurrentController();
101 
102         XTextViewCursorSupplier oTVCSupp = (XTextViewCursorSupplier)
103             UnoRuntime.queryInterface(XTextViewCursorSupplier.class, oObj);
104 
105         oObj = oTVCSupp.getViewCursor();
106 
107         log.println( "creating a new environment for TextViewCursor object" );
108         TestEnvironment tEnv = new TestEnvironment( oObj );
109 
110         log.println( "adding TextDocument as mod relation to environment" );
111         tEnv.addObjRelation("TEXTDOC", xTextDoc);
112         tEnv.addObjRelation("XTEXT", xTextDoc.getText());
113 
114         return tEnv;
115     } // finish method getTestEnvironment
116 
117 
118 }    // finish class SwXTextViewCursor
119