Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxUnoTextCursor.java
blob4aabb846eb23f1c4d2d8d0f326db0425bba19d5b
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 java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.DrawTools;
28 import util.SOfficeFactory;
30 import com.sun.star.drawing.XShape;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.text.ControlCharacter;
33 import com.sun.star.text.XText;
34 import com.sun.star.text.XTextCursor;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
38 public class SvxUnoTextCursor extends TestCase {
40 static XComponent xDrawDoc;
42 /**
43 * in general this method creates a testdocument
45 * @param tParam class which contains additional test parameters
46 * @param log class to log the test state and result
49 * @see TestParameters
50 * @see PrintWriter
53 @Override
54 protected void initialize( TestParameters tParam, PrintWriter log ) {
55 try {
56 log.println( "creating a drawdoc" );
57 xDrawDoc = DrawTools.createDrawDoc(tParam.getMSF());
58 } catch ( Exception e ) {
59 // Some exception occurs.FAILED
60 e.printStackTrace( log );
61 throw new StatusException( "Couldn't create document", e );
65 /**
66 * in general this method disposes the testenvironment and document
68 * @param tParam class which contains additional test parameters
69 * @param log class to log the test state and result
72 * @see TestParameters
73 * @see PrintWriter
76 @Override
77 protected void cleanup( TestParameters tParam, PrintWriter log ) {
78 log.println( " disposing xDrawDoc " );
79 util.DesktopTools.closeDoc(xDrawDoc);
83 /**
84 * creating a Testenvironment for the interfaces to be tested
86 * @param tParam class which contains additional test parameters
87 * @param log class to log the test state and result
89 * @return Status class
91 * @see TestParameters
92 * @see PrintWriter
94 @Override
95 public TestEnvironment createTestEnvironment( TestParameters tParam,
96 PrintWriter log )
97 throws StatusException {
99 XInterface oObj = null;
100 // create testobject here
102 try {
103 SOfficeFactory SOF = SOfficeFactory.getFactory(tParam.getMSF()) ;
104 XShape oShape = SOF.createShape
105 (xDrawDoc,5000,3500,7500,5000,"Text");
106 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
108 XText text = UnoRuntime.queryInterface(XText.class, oShape) ;
110 XTextCursor cursor = text.createTextCursor() ;
112 text.insertString(cursor, "Paragraph 1", false) ;
113 text.insertControlCharacter(cursor,
114 ControlCharacter.PARAGRAPH_BREAK, false) ;
115 text.insertString(cursor, "Paragraph 2", false) ;
116 text.insertControlCharacter(cursor,
117 ControlCharacter.PARAGRAPH_BREAK, false) ;
118 text.insertString(cursor, "Paragraph 3", false) ;
119 text.insertControlCharacter(cursor,
120 ControlCharacter.PARAGRAPH_BREAK, false) ;
122 oObj = cursor ;
124 } catch (Exception e) {
125 log.println("Can't create test object") ;
126 e.printStackTrace(log) ;
129 // create test environment here
130 TestEnvironment tEnv = new TestEnvironment( oObj );
133 return tEnv;
134 } // finish method getTestEnvironment
136 } // finish class SvxUnoTextCursor