merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _svx / SvxUnoTextContentEnum.java
blob39122fe24c1b875cffe4b0e78ffcb3b745fea108
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: SvxUnoTextContentEnum.java,v $
10 * $Revision: 1.6.8.1 $
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._svx;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.DrawTools;
40 import util.SOfficeFactory;
42 import com.sun.star.container.XEnumerationAccess;
43 import com.sun.star.drawing.XShape;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.text.ControlCharacter;
47 import com.sun.star.text.XSimpleText;
48 import com.sun.star.text.XTextCursor;
49 import com.sun.star.uno.UnoRuntime;
50 import com.sun.star.uno.XInterface;
52 public class SvxUnoTextContentEnum extends TestCase {
54 static XComponent xDrawDoc;
56 /**
57 * in general this method creates a testdocument
59 * @param tParam class which contains additional test parameters
60 * @param log class to log the test state and result
63 * @see TestParameters
64 * @see PrintWriter
67 protected void initialize( TestParameters tParam, PrintWriter log ) {
68 try {
69 log.println( "creating a drawdoc" );
70 xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
71 } catch ( Exception e ) {
72 // Some exception occures.FAILED
73 e.printStackTrace( log );
74 throw new StatusException( "Couldn't create document", e );
78 /**
79 * in general this method disposes the testenvironment and document
81 * @param tParam class which contains additional test parameters
82 * @param log class to log the test state and result
85 * @see TestParameters
86 * @see PrintWriter
89 protected void cleanup( TestParameters tParam, PrintWriter log ) {
90 log.println( " disposing xDrawDoc " );
91 util.DesktopTools.closeDoc(xDrawDoc);
95 /**
96 * creating a Testenvironment for the interfaces to be tested
98 * @param tParam class which contains additional test parameters
99 * @param log class to log the test state and result
101 * @return Status class
103 * @see TestParameters
104 * @see PrintWriter
106 public TestEnvironment createTestEnvironment( TestParameters tParam,
107 PrintWriter log )
108 throws StatusException {
110 XInterface oObj = null;
111 // create testobject here
113 XEnumerationAccess xEA = null ;
114 try {
115 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
116 XShape oShape = SOF.createShape
117 (xDrawDoc,5000,3500,7500,5000,"Text");
118 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
120 XSimpleText text = (XSimpleText) UnoRuntime.queryInterface
121 (XSimpleText.class, oShape) ;
123 XTextCursor cursor = text.createTextCursor() ;
125 text.insertString(cursor, "Paragraph 1", false) ;
126 text.insertControlCharacter(cursor,
127 ControlCharacter.PARAGRAPH_BREAK, false) ;
128 text.insertString(cursor, "Paragraph 2", false) ;
129 text.insertControlCharacter(cursor,
130 ControlCharacter.PARAGRAPH_BREAK, false) ;
131 text.insertString(cursor, "Paragraph 3", false) ;
132 text.insertControlCharacter(cursor,
133 ControlCharacter.PARAGRAPH_BREAK, false) ;
135 xEA = (XEnumerationAccess) UnoRuntime.queryInterface
136 (XEnumerationAccess.class, text) ;
138 oObj = xEA.createEnumeration() ;
139 } catch (Exception e) {
140 log.println("Can't create test object") ;
141 e.printStackTrace(log) ;
142 throw new StatusException("Unexpected exception", e);
145 // create test environment here
146 TestEnvironment tEnv = new TestEnvironment( oObj );
148 // adding relation for XEnumeration test
149 tEnv.addObjRelation("ENUM", xEA) ;
151 return tEnv;
152 } // finish method getTestEnvironment