1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SvxUnoTextContent.java,v $
10 * $Revision: 1.7.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 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
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
.AnyConverter
;
50 import com
.sun
.star
.uno
.Type
;
51 import com
.sun
.star
.uno
.UnoRuntime
;
52 import com
.sun
.star
.uno
.XInterface
;
54 public class SvxUnoTextContent
extends TestCase
{
56 static XComponent xDrawDoc
;
59 * in general this method creates a testdocument
61 * @param tParam class which contains additional test parameters
62 * @param log class to log the test state and result
69 protected void initialize( TestParameters tParam
, PrintWriter log
) {
71 log
.println( "creating a drawdoc" );
72 xDrawDoc
= DrawTools
.createDrawDoc((XMultiServiceFactory
)tParam
.getMSF());
73 } catch ( Exception e
) {
74 // Some exception occures.FAILED
75 e
.printStackTrace( log
);
76 throw new StatusException( "Couldn't create document", e
);
81 * in general this method disposes the testenvironment and document
83 * @param tParam class which contains additional test parameters
84 * @param log class to log the test state and result
91 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
92 log
.println( " disposing xDrawDoc " );
93 util
.DesktopTools
.closeDoc(xDrawDoc
);
98 * creating a Testenvironment for the interfaces to be tested
100 * @param tParam class which contains additional test parameters
101 * @param log class to log the test state and result
103 * @return Status class
105 * @see TestParameters
108 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
110 XInterface oObj
= null;
111 // create testobject here
113 XEnumerationAccess xEA
= null ;
115 SOfficeFactory SOF
= SOfficeFactory
.getFactory((XMultiServiceFactory
)tParam
.getMSF()) ;
116 XShape oShape
= SOF
.createShape(xDrawDoc
,
117 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
= (XInterface
) AnyConverter
.toObject(
139 new Type(XInterface
.class),xEA
.createEnumeration().nextElement());
140 } catch (Exception e
) {
141 log
.println("Can't create test object") ;
142 e
.printStackTrace(log
) ;
143 throw new StatusException("Unexpected exception", e
);
146 // create test environment here
147 TestEnvironment tEnv
= new TestEnvironment( oObj
);
150 } // finish method getTestEnvironment