merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwXTextFrameText.java
blobe6c44a130ff7ff52022f3672b0328e6d8f451916
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextFrameText.java,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sw;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.InstCreator;
40 import util.ParagraphDsc;
41 import util.SOfficeFactory;
42 import util.TableDsc;
44 import com.sun.star.beans.XPropertySet;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.text.XText;
47 import com.sun.star.text.XTextCursor;
48 import com.sun.star.text.XTextDocument;
49 import com.sun.star.text.XTextFrame;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
53 /**
55 * initial description
56 * @see com.sun.star.container.XElementAccess
57 * @see com.sun.star.container.XEnumerationAccess
58 * @see com.sun.star.text.XSimpleText
59 * @see com.sun.star.text.XText
60 * @see com.sun.star.text.XTextRange
61 * @see com.sun.star.text.XTextRangeMover
64 public class SwXTextFrameText extends TestCase {
65 XTextDocument xTextDoc;
67 protected void initialize( TestParameters tParam, PrintWriter log ) {
68 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
70 try {
71 log.println( "creating a textdocument" );
72 xTextDoc = SOF.createTextDoc( null );
73 } catch ( com.sun.star.uno.Exception e ) {
74 // Some exception occures.FAILED
75 e.printStackTrace( log );
76 throw new StatusException( "Couldn't create document", e );
80 protected void cleanup( TestParameters tParam, PrintWriter log ) {
81 log.println( " disposing xTextDoc " );
82 util.DesktopTools.closeDoc(xTextDoc);
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 public synchronized TestEnvironment createTestEnvironment
97 (TestParameters tParam, PrintWriter log ) {
99 XInterface oObj = null;
100 XTextFrame oFrame1 = null;
101 XPropertySet oPropSet = null;
102 XText oText = null;
103 XTextCursor oCursor = null;
105 // creation of testobject here
106 // first we write what we are intend to do to log file
107 log.println( "creating a test environment" );
109 // get a soffice factory object
110 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
112 // create testobject here
113 ////////////////////////////////////
115 try {
116 oFrame1 = SOF.createTextFrame(xTextDoc, 500, 500);
117 oPropSet = (XPropertySet)UnoRuntime.queryInterface
118 (XPropertySet.class, oFrame1 );
119 //AnchorTypes: 0 = paragraph, 1 = as char, 2 = page,
120 // 3 = frame/paragraph 4= at char
121 oPropSet.setPropertyValue("AnchorType", new Integer(2));
122 oText = xTextDoc.getText();
123 oCursor = oText.createTextCursor();
125 log.println( "inserting Frame1" );
126 oText.insertTextContent(oCursor,oFrame1, false);
128 } catch (Exception Ex ) {
129 Ex.printStackTrace(log);
130 throw new StatusException("Couldn't insert TextFrame ", Ex);
133 XText oFText = (XText)UnoRuntime.queryInterface(XText.class, oFrame1);
134 XTextCursor oFCursor = oFText.createTextCursor();
135 oFText.insertString(oFCursor, "SwXTextFrameText", false);
137 oObj = oFText.getText();
139 log.println( "creating a new environment for TextFrameText object" );
140 TestEnvironment tEnv = new TestEnvironment( oObj );
142 log.println( "adding TextDocument as mod relation to environment" );
143 tEnv.addObjRelation("TEXT", (XText) oObj);
145 log.println( "adding InstDescriptor object" );
146 TableDsc tDsc = new TableDsc( 6, 4 );
148 log.println( "adding InstCreator object" );
149 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
151 log.println( " adding Paragraph" );
152 ParagraphDsc pDsc = new ParagraphDsc();
153 tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) );
155 return tEnv;
156 } // finish method getTestEnvironment
158 } // finish class SwXTextFrameText