bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextFrameText.java
blob5839796356868bace8d31d1fa53dc3d50ce19465
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._sw;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.InstCreator;
28 import util.ParagraphDsc;
29 import util.SOfficeFactory;
30 import util.TableDsc;
32 import com.sun.star.beans.XPropertySet;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.text.XText;
35 import com.sun.star.text.XTextCursor;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.text.XTextFrame;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
41 /**
43 * initial description
44 * @see com.sun.star.container.XElementAccess
45 * @see com.sun.star.container.XEnumerationAccess
46 * @see com.sun.star.text.XSimpleText
47 * @see com.sun.star.text.XText
48 * @see com.sun.star.text.XTextRange
49 * @see com.sun.star.text.XTextRangeMover
52 public class SwXTextFrameText extends TestCase {
53 XTextDocument xTextDoc;
55 protected void initialize( TestParameters tParam, PrintWriter log ) {
56 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
58 try {
59 log.println( "creating a textdocument" );
60 xTextDoc = SOF.createTextDoc( null );
61 } catch ( com.sun.star.uno.Exception e ) {
62 // Some exception occurs.FAILED
63 e.printStackTrace( log );
64 throw new StatusException( "Couldn't create document", e );
68 protected void cleanup( TestParameters tParam, PrintWriter log ) {
69 log.println( " disposing xTextDoc " );
70 util.DesktopTools.closeDoc(xTextDoc);
73 /**
74 * creating a Testenvironment for the interfaces to be tested
76 * @param tParam class which contains additional test parameters
77 * @param log class to log the test state and result
79 * @return Status class
81 * @see TestParameters
82 * @see PrintWriter
84 public synchronized TestEnvironment createTestEnvironment
85 (TestParameters tParam, PrintWriter log ) {
87 XInterface oObj = null;
88 XTextFrame oFrame1 = null;
89 XPropertySet oPropSet = null;
90 XText oText = null;
91 XTextCursor oCursor = null;
93 // creation of testobject here
94 // first we write what we are intend to do to log file
95 log.println( "creating a test environment" );
97 // get a soffice factory object
98 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
100 // create testobject here
101 ////////////////////////////////////
103 try {
104 oFrame1 = SOfficeFactory.createTextFrame(xTextDoc, 500, 500);
105 oPropSet = UnoRuntime.queryInterface
106 (XPropertySet.class, oFrame1 );
107 //AnchorTypes: 0 = paragraph, 1 = as char, 2 = page,
108 // 3 = frame/paragraph 4= at char
109 oPropSet.setPropertyValue("AnchorType", new Integer(2));
110 oText = xTextDoc.getText();
111 oCursor = oText.createTextCursor();
113 log.println( "inserting Frame1" );
114 oText.insertTextContent(oCursor,oFrame1, false);
116 } catch (Exception Ex ) {
117 Ex.printStackTrace(log);
118 throw new StatusException("Couldn't insert TextFrame ", Ex);
121 XText oFText = UnoRuntime.queryInterface(XText.class, oFrame1);
122 XTextCursor oFCursor = oFText.createTextCursor();
123 oFText.insertString(oFCursor, "SwXTextFrameText", false);
125 oObj = oFText.getText();
127 log.println( "creating a new environment for TextFrameText object" );
128 TestEnvironment tEnv = new TestEnvironment( oObj );
130 log.println( "adding TextDocument as mod relation to environment" );
131 tEnv.addObjRelation("TEXT", oObj);
133 log.println( "adding InstDescriptor object" );
134 TableDsc tDsc = new TableDsc( 6, 4 );
136 log.println( "adding InstCreator object" );
137 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
139 log.println( " adding Paragraph" );
140 ParagraphDsc pDsc = new ParagraphDsc();
141 tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) );
143 return tEnv;
144 } // finish method getTestEnvironment
146 } // finish class SwXTextFrameText