Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextFrameText.java
blob19394f728eb854bc2bc054d794f7f8c9de69776b
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.text.XText;
34 import com.sun.star.text.XTextCursor;
35 import com.sun.star.text.XTextDocument;
36 import com.sun.star.text.XTextFrame;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
40 /**
42 * initial description
43 * @see com.sun.star.container.XElementAccess
44 * @see com.sun.star.container.XEnumerationAccess
45 * @see com.sun.star.text.XSimpleText
46 * @see com.sun.star.text.XText
47 * @see com.sun.star.text.XTextRange
48 * @see com.sun.star.text.XTextRangeMover
51 public class SwXTextFrameText extends TestCase {
52 XTextDocument xTextDoc;
54 @Override
55 protected void initialize( TestParameters tParam, PrintWriter log ) {
56 SOfficeFactory SOF = SOfficeFactory.getFactory( 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 @Override
69 protected void cleanup( TestParameters tParam, PrintWriter log ) {
70 log.println( " disposing xTextDoc " );
71 util.DesktopTools.closeDoc(xTextDoc);
74 /**
75 * creating a Testenvironment for the interfaces to be tested
77 * @param tParam class which contains additional test parameters
78 * @param log class to log the test state and result
80 * @return Status class
82 * @see TestParameters
83 * @see PrintWriter
85 @Override
86 public synchronized TestEnvironment createTestEnvironment
87 (TestParameters tParam, PrintWriter log ) {
89 XInterface oObj = null;
90 XTextFrame oFrame1 = null;
91 XPropertySet oPropSet = null;
92 XText oText = null;
93 XTextCursor oCursor = null;
95 // creation of testobject here
96 // first we write what we are intend to do to log file
97 log.println( "creating a test environment" );
99 // get a soffice factory object
100 SOfficeFactory.getFactory( tParam.getMSF() );
102 // create testobject here
105 try {
106 oFrame1 = SOfficeFactory.createTextFrame(xTextDoc, 500, 500);
107 oPropSet = UnoRuntime.queryInterface
108 (XPropertySet.class, oFrame1 );
109 //AnchorTypes: 0 = paragraph, 1 = as char, 2 = page,
110 // 3 = frame/paragraph 4= at char
111 oPropSet.setPropertyValue("AnchorType", Integer.valueOf(2));
112 oText = xTextDoc.getText();
113 oCursor = oText.createTextCursor();
115 log.println( "inserting Frame1" );
116 oText.insertTextContent(oCursor,oFrame1, false);
118 } catch (Exception Ex ) {
119 Ex.printStackTrace(log);
120 throw new StatusException("Couldn't insert TextFrame ", Ex);
123 XText oFText = UnoRuntime.queryInterface(XText.class, oFrame1);
124 XTextCursor oFCursor = oFText.createTextCursor();
125 oFText.insertString(oFCursor, "SwXTextFrameText", false);
127 oObj = oFText.getText();
129 log.println( "creating a new environment for TextFrameText object" );
130 TestEnvironment tEnv = new TestEnvironment( oObj );
132 log.println( "adding TextDocument as mod relation to environment" );
133 tEnv.addObjRelation("TEXT", oObj);
135 log.println( "adding InstDescriptor object" );
136 TableDsc tDsc = new TableDsc( 6, 4 );
138 log.println( "adding InstCreator object" );
139 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
141 log.println( " adding Paragraph" );
142 ParagraphDsc pDsc = new ParagraphDsc();
143 tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) );
145 return tEnv;
146 } // finish method getTestEnvironment
148 } // finish class SwXTextFrameText