Update git submodules
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxUnoText.java
blob19fb1ef3269cbd849e60018a73d4e55aa642c58d
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._svx;
21 import com.sun.star.text.XText;
22 import java.io.PrintWriter;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.DefaultDsc;
28 import util.DrawTools;
29 import util.InstCreator;
30 import util.SOfficeFactory;
32 import com.sun.star.drawing.XShape;
33 import com.sun.star.lang.XComponent;
34 import com.sun.star.text.ControlCharacter;
35 import com.sun.star.text.XSimpleText;
36 import com.sun.star.text.XTextCursor;
37 import com.sun.star.text.XTextRange;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
41 public class SvxUnoText extends TestCase {
43 static XComponent xDrawDoc;
45 /**
46 * in general this method creates a testdocument
48 * @param tParam class which contains additional test parameters
49 * @param log class to log the test state and result
52 * @see TestParameters
53 * * @see PrintWriter
56 @Override
57 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
58 log.println( "creating a drawdoc" );
59 xDrawDoc = DrawTools.createDrawDoc(tParam.getMSF());
62 /**
63 * in general this method disposes the testenvironment and document
65 * @param tParam class which contains additional test parameters
66 * @param log class to log the test state and result
69 * @see TestParameters
70 * * @see PrintWriter
73 @Override
74 protected void cleanup( TestParameters tParam, PrintWriter log ) {
75 log.println( " disposing xDrawDoc " );
76 util.DesktopTools.closeDoc(xDrawDoc);
80 /**
81 * * creating a TestEnvironment for the interfaces to be tested
83 * @param tParam class which contains additional test parameters
84 * @param log class to log the test state and result
86 * @return Status class
87 * Object relations created :
88 * <ul>
89 * <li> <code>'RangeForMove'</code> for
90 * {@link ifc.text._XTextRangeMover} (the range to be moved)</li>
91 * <li> <code>'XTextRange'</code> for
92 * {@link ifc.text._XTextRangeMover} (the range that includes moving
93 * range)</li>
94 * </ul>
95 * @see TestParameters
96 * * @see PrintWriter
98 @Override
99 protected TestEnvironment createTestEnvironment
100 (TestParameters tParam, PrintWriter log) {
102 XInterface oObj = null;
103 // create testobject here
104 XTextRange aRange = null;
105 XShape oShape = null;
107 try {
108 SOfficeFactory SOF = SOfficeFactory.getFactory(tParam.getMSF()) ;
109 oShape = SOF.createShape
110 (xDrawDoc,5000,3500,7500,5000,"Text");
111 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
113 XSimpleText text = UnoRuntime.queryInterface
114 (XSimpleText.class, oShape) ;
116 XTextCursor cursor = text.createTextCursor() ;
117 text.insertString(cursor, "Paragraph 1", false) ;
118 text.insertControlCharacter(cursor,
119 ControlCharacter.PARAGRAPH_BREAK, false) ;
120 cursor.setString("TextForMove");
121 aRange = cursor;
122 XTextCursor cursor1 = text.createTextCursorByRange(text.getEnd());
123 text.insertControlCharacter(cursor1,
124 ControlCharacter.PARAGRAPH_BREAK, false) ;
125 text.insertString(cursor1, "Paragraph 2", false);
126 text.insertControlCharacter(cursor1,
127 ControlCharacter.PARAGRAPH_BREAK, false) ;
128 text.insertString(cursor1, "Paragraph 3", false) ;
129 text.insertControlCharacter(cursor1,
130 ControlCharacter.PARAGRAPH_BREAK, false) ;
131 oObj = text.getText() ;
132 } catch (Exception e) {
133 log.println("Can't create test object") ;
134 e.printStackTrace(log) ;
137 // create test environment here
138 TestEnvironment tEnv = new TestEnvironment( oObj );
139 // adding relation for XText
140 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
141 "com.sun.star.text.TextField.DateTime");
142 log.println( " adding InstCreator object" );
143 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
145 // adding relation for XTextRangeMover
146 tEnv.addObjRelation("RangeForMove", aRange);
147 tEnv.addObjRelation("XTextRange", oObj);
149 // adding relation for XTextRangeCompare
150 tEnv.addObjRelation("TEXT", UnoRuntime.queryInterface(XText.class, oShape)) ;
152 return tEnv;
153 } // finish method getTestEnvironment
155 } // finish class SvxUnoText