Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxUnoText.java
blobac8bf08c1e5559fcc34e3374d48524a605f547fa
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.StatusException;
25 import lib.TestCase;
26 import lib.TestEnvironment;
27 import lib.TestParameters;
28 import util.DefaultDsc;
29 import util.DrawTools;
30 import util.InstCreator;
31 import util.SOfficeFactory;
33 import com.sun.star.drawing.XShape;
34 import com.sun.star.lang.XComponent;
35 import com.sun.star.text.ControlCharacter;
36 import com.sun.star.text.XSimpleText;
37 import com.sun.star.text.XTextCursor;
38 import com.sun.star.text.XTextRange;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 public class SvxUnoText extends TestCase {
44 static XComponent xDrawDoc;
46 /**
47 * in general this method creates a testdocument
49 * @param tParam class which contains additional test parameters
50 * @param log class to log the test state and result
53 * @see TestParameters
54 * * @see PrintWriter
57 @Override
58 protected void initialize( TestParameters tParam, PrintWriter log ) {
59 try {
60 log.println( "creating a drawdoc" );
61 xDrawDoc = DrawTools.createDrawDoc(tParam.getMSF());
62 } catch ( Exception e ) {
63 // Some exception occurs.FAILED
64 e.printStackTrace( log );
65 throw new StatusException( "Couldn't create document", e );
69 /**
70 * in general this method disposes the testenvironment and document
72 * @param tParam class which contains additional test parameters
73 * @param log class to log the test state and result
76 * @see TestParameters
77 * * @see PrintWriter
80 @Override
81 protected void cleanup( TestParameters tParam, PrintWriter log ) {
82 log.println( " disposing xDrawDoc " );
83 util.DesktopTools.closeDoc(xDrawDoc);
87 /**
88 * * creating a Testenvironment for the interfaces to be tested
90 * @param tParam class which contains additional test parameters
91 * @param log class to log the test state and result
93 * @return Status class
94 * Object relations created :
95 * <ul>
96 * <li> <code>'RangeForMove'</code> for
97 * {@link ifc.text._XTextRangeMover} (the range to be moved)</li>
98 * <li> <code>'XTextRange'</code> for
99 * {@link ifc.text._XTextRangeMover} (the range that includes moving
100 * range)</li>
101 * </ul>
102 * @see TestParameters
103 * * @see PrintWriter
105 @Override
106 protected TestEnvironment createTestEnvironment
107 (TestParameters tParam, PrintWriter log) {
109 XInterface oObj = null;
110 // create testobject here
111 XTextRange aRange = null;
112 XShape oShape = null;
114 try {
115 SOfficeFactory SOF = SOfficeFactory.getFactory(tParam.getMSF()) ;
116 oShape = SOF.createShape
117 (xDrawDoc,5000,3500,7500,5000,"Text");
118 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
120 XSimpleText text = UnoRuntime.queryInterface
121 (XSimpleText.class, oShape) ;
123 XTextCursor cursor = text.createTextCursor() ;
124 text.insertString(cursor, "Paragraph 1", false) ;
125 text.insertControlCharacter(cursor,
126 ControlCharacter.PARAGRAPH_BREAK, false) ;
127 cursor.setString("TextForMove");
128 aRange = cursor;
129 XTextCursor cursor1 = text.createTextCursorByRange(text.getEnd());
130 text.insertControlCharacter(cursor1,
131 ControlCharacter.PARAGRAPH_BREAK, false) ;
132 text.insertString(cursor1, "Paragraph 2", false);
133 text.insertControlCharacter(cursor1,
134 ControlCharacter.PARAGRAPH_BREAK, false) ;
135 text.insertString(cursor1, "Paragraph 3", false) ;
136 text.insertControlCharacter(cursor1,
137 ControlCharacter.PARAGRAPH_BREAK, false) ;
138 oObj = text.getText() ;
139 } catch (Exception e) {
140 log.println("Can't create test object") ;
141 e.printStackTrace(log) ;
144 // create test environment here
145 TestEnvironment tEnv = new TestEnvironment( oObj );
146 // adding relation for XText
147 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
148 "com.sun.star.text.TextField.DateTime");
149 log.println( " adding InstCreator object" );
150 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
152 // adding relation for XTextRangeMover
153 tEnv.addObjRelation("RangeForMove", aRange);
154 tEnv.addObjRelation("XTextRange", oObj);
156 // adding relation for XTextRangeComapre
157 tEnv.addObjRelation("TEXT", UnoRuntime.queryInterface(XText.class, oShape)) ;
159 return tEnv;
160 } // finish method getTestEnvironment
162 } // finish class SvxUnoText