bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxUnoTextContent.java
blob0d839870f409267f6d4c3361e23b6ccc9efb77d9
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.container.XEnumerationAccess;
31 import com.sun.star.drawing.XShape;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.lang.XMultiServiceFactory;
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.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 public class SvxUnoTextContent 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 protected void initialize( TestParameters tParam, PrintWriter log ) {
58 try {
59 log.println( "creating a drawdoc" );
60 xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
61 } catch ( Exception e ) {
62 // Some exception occurs.FAILED
63 e.printStackTrace( log );
64 throw new StatusException( "Couldn't create document", e );
68 /**
69 * in general this method disposes the testenvironment and document
71 * @param tParam class which contains additional test parameters
72 * @param log class to log the test state and result
75 * @see TestParameters
76 * @see PrintWriter
79 protected void cleanup( TestParameters tParam, PrintWriter log ) {
80 log.println( " disposing xDrawDoc " );
81 util.DesktopTools.closeDoc(xDrawDoc);
85 /**
86 * creating a Testenvironment for the interfaces to be tested
88 * @param tParam class which contains additional test parameters
89 * @param log class to log the test state and result
91 * @return Status class
93 * @see TestParameters
94 * @see PrintWriter
96 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
98 XInterface oObj = null;
99 // create testobject here
101 XEnumerationAccess xEA = null ;
102 try {
103 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
104 XShape oShape = SOF.createShape(xDrawDoc,
105 5000,3500,7500,5000,"Text");
106 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
108 XSimpleText text = UnoRuntime.queryInterface
109 (XSimpleText.class, oShape) ;
111 XTextCursor cursor = text.createTextCursor() ;
113 text.insertString(cursor, "Paragraph 1", false) ;
114 text.insertControlCharacter(cursor,
115 ControlCharacter.PARAGRAPH_BREAK, false) ;
116 text.insertString(cursor, "Paragraph 2", false) ;
117 text.insertControlCharacter(cursor,
118 ControlCharacter.PARAGRAPH_BREAK, false) ;
119 text.insertString(cursor, "Paragraph 3", false) ;
120 text.insertControlCharacter(cursor,
121 ControlCharacter.PARAGRAPH_BREAK, false) ;
123 xEA = UnoRuntime.queryInterface
124 (XEnumerationAccess.class, text) ;
126 oObj = (XInterface) AnyConverter.toObject(
127 new Type(XInterface.class),xEA.createEnumeration().nextElement());
128 } catch (Exception e) {
129 log.println("Can't create test object") ;
130 e.printStackTrace(log) ;
131 throw new StatusException("Unexpected exception", e);
134 // create test environment here
135 TestEnvironment tEnv = new TestEnvironment( oObj );
137 return tEnv;
138 } // finish method getTestEnvironment