1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._svx;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.DrawTools;
37 import util.SOfficeFactory;
38 
39 import com.sun.star.drawing.XShape;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.text.ControlCharacter;
43 import com.sun.star.text.XText;
44 import com.sun.star.text.XTextCursor;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
47 
48 public class SvxUnoTextCursor extends TestCase {
49 
50     static XComponent xDrawDoc;
51 
52     /**
53      * in general this method creates a testdocument
54      *
55      *  @param tParam    class which contains additional test parameters
56      *  @param log        class to log the test state and result
57      *
58      *
59      *  @see TestParameters
60      *    @see PrintWriter
61      *
62      */
63     protected void initialize( TestParameters tParam, PrintWriter log ) {
64         try {
65             log.println( "creating a drawdoc" );
66             xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
67         } catch ( Exception e ) {
68             // Some exception occures.FAILED
69             e.printStackTrace( log );
70             throw new StatusException( "Couldn't create document", e );
71         }
72     }
73 
74     /**
75      * in general this method disposes the testenvironment and document
76      *
77      *  @param tParam    class which contains additional test parameters
78      *  @param log        class to log the test state and result
79      *
80      *
81      *  @see TestParameters
82      *    @see PrintWriter
83      *
84      */
85     protected void cleanup( TestParameters tParam, PrintWriter log ) {
86         log.println( "    disposing xDrawDoc " );
87         util.DesktopTools.closeDoc(xDrawDoc);
88     }
89 
90 
91     /**
92      *    creating a Testenvironment for the interfaces to be tested
93      *
94      *  @param tParam    class which contains additional test parameters
95      *  @param log        class to log the test state and result
96      *
97      *  @return    Status class
98      *
99      *  @see TestParameters
100      *    @see PrintWriter
101      */
102     public TestEnvironment createTestEnvironment( TestParameters tParam,
103                                                   PrintWriter log )
104                                                     throws StatusException {
105 
106         XInterface oObj = null;
107         // create testobject here
108 
109         try {
110             SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
111             XShape oShape = SOF.createShape
112                 (xDrawDoc,5000,3500,7500,5000,"Text");
113             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
114 
115             XText text = (XText) UnoRuntime.queryInterface(XText.class, oShape) ;
116 
117             XTextCursor cursor = text.createTextCursor() ;
118 
119             text.insertString(cursor, "Paragraph 1", false) ;
120             text.insertControlCharacter(cursor,
121                 ControlCharacter.PARAGRAPH_BREAK, false) ;
122             text.insertString(cursor, "Paragraph 2", false) ;
123             text.insertControlCharacter(cursor,
124                 ControlCharacter.PARAGRAPH_BREAK, false) ;
125             text.insertString(cursor, "Paragraph 3", false) ;
126             text.insertControlCharacter(cursor,
127                 ControlCharacter.PARAGRAPH_BREAK, false) ;
128 
129             oObj = cursor ;
130 
131         } catch (Exception e) {
132             log.println("Can't create test object") ;
133             e.printStackTrace(log) ;
134         }
135 
136         // create test environment here
137          TestEnvironment tEnv = new TestEnvironment( oObj );
138 
139 
140         return tEnv;
141     } // finish method getTestEnvironment
142 
143 }    // finish class SvxUnoTextCursor
144 
145