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