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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.DrawTools
;
28 import util
.SOfficeFactory
;
30 import com
.sun
.star
.container
.XEnumerationAccess
;
31 import com
.sun
.star
.drawing
.XShape
;
32 import com
.sun
.star
.lang
.XComponent
;
33 import com
.sun
.star
.text
.ControlCharacter
;
34 import com
.sun
.star
.text
.XSimpleText
;
35 import com
.sun
.star
.text
.XTextCursor
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
39 public class SvxUnoTextContentEnum
extends TestCase
{
41 static XComponent xDrawDoc
;
44 * in general this method creates a testdocument
46 * @param tParam class which contains additional test parameters
47 * @param log class to log the test state and result
55 protected void initialize( TestParameters tParam
, PrintWriter log
) {
57 log
.println( "creating a drawdoc" );
58 xDrawDoc
= DrawTools
.createDrawDoc(tParam
.getMSF());
59 } catch ( Exception e
) {
60 // Some exception occurs.FAILED
61 e
.printStackTrace( log
);
62 throw new StatusException( "Couldn't create document", e
);
67 * in general this method disposes the testenvironment and document
69 * @param tParam class which contains additional test parameters
70 * @param log class to log the test state and result
78 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
79 log
.println( " disposing xDrawDoc " );
80 util
.DesktopTools
.closeDoc(xDrawDoc
);
85 * creating a Testenvironment for the interfaces to be tested
87 * @param tParam class which contains additional test parameters
88 * @param log class to log the test state and result
90 * @return Status class
96 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
98 throws StatusException
{
100 XInterface oObj
= null;
101 // create testobject here
103 XEnumerationAccess xEA
= null ;
105 SOfficeFactory SOF
= SOfficeFactory
.getFactory(tParam
.getMSF()) ;
106 XShape oShape
= SOF
.createShape
107 (xDrawDoc
,5000,3500,7500,5000,"Text");
108 DrawTools
.getShapes(DrawTools
.getDrawPage(xDrawDoc
,0)).add(oShape
) ;
110 XSimpleText text
= UnoRuntime
.queryInterface
111 (XSimpleText
.class, oShape
) ;
113 XTextCursor cursor
= text
.createTextCursor() ;
115 text
.insertString(cursor
, "Paragraph 1", false) ;
116 text
.insertControlCharacter(cursor
,
117 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
118 text
.insertString(cursor
, "Paragraph 2", false) ;
119 text
.insertControlCharacter(cursor
,
120 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
121 text
.insertString(cursor
, "Paragraph 3", false) ;
122 text
.insertControlCharacter(cursor
,
123 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
125 xEA
= UnoRuntime
.queryInterface
126 (XEnumerationAccess
.class, text
) ;
128 oObj
= xEA
.createEnumeration() ;
129 } catch (Exception e
) {
130 log
.println("Can't create test object") ;
131 e
.printStackTrace(log
) ;
132 throw new StatusException("Unexpected exception", e
);
135 // create test environment here
136 TestEnvironment tEnv
= new TestEnvironment( oObj
);
138 // adding relation for XEnumeration test
139 tEnv
.addObjRelation("ENUM", xEA
) ;
142 } // finish method getTestEnvironment