1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._svx;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.DrawTools;
37 import util.SOfficeFactory;
38 
39 import com.sun.star.container.XEnumerationAccess;
40 import com.sun.star.drawing.XShape;
41 import com.sun.star.lang.XComponent;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.text.ControlCharacter;
44 import com.sun.star.text.XSimpleText;
45 import com.sun.star.text.XTextCursor;
46 import com.sun.star.uno.AnyConverter;
47 import com.sun.star.uno.Type;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
50 
51 public class SvxUnoTextRangeEnumeration extends TestCase {
52 
53     static XComponent xDrawDoc;
54 
55     /**
56      * in general this method creates a testdocument
57      *
58      *  @param tParam    class which contains additional test parameters
59      *  @param log        class to log the test state and result
60      *
61      *
62      *  @see TestParameters
63      *    @see PrintWriter
64      *
65      */
66     protected void initialize( TestParameters tParam, PrintWriter log ) {
67         try {
68             log.println( "creating a drawdoc" );
69             xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
70         } catch ( Exception e ) {
71             // Some exception occures.FAILED
72             e.printStackTrace( log );
73             throw new StatusException( "Couldn't create document", e );
74         }
75     }
76 
77     /**
78      * in general this method disposes the testenvironment and document
79      *
80      *  @param tParam    class which contains additional test parameters
81      *  @param log        class to log the test state and result
82      *
83      *
84      *  @see TestParameters
85      *    @see PrintWriter
86      *
87      */
88     protected void cleanup( TestParameters tParam, PrintWriter log ) {
89         log.println( "    disposing xDrawDoc " );
90         util.DesktopTools.closeDoc(xDrawDoc);
91     }
92 
93 
94     /**
95      *    creating a Testenvironment for the interfaces to be tested
96      *
97      *  @param tParam    class which contains additional test parameters
98      *  @param log        class to log the test state and result
99      *
100      *  @return    Status class
101      *
102      *  @see TestParameters
103      *    @see PrintWriter
104      */
105     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
106 
107         XInterface oObj = null;
108         // create testobject here
109 
110         XEnumerationAccess xEA = null ;
111         try {
112             SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
113             XShape oShape = SOF.createShape
114                 (xDrawDoc,5000,3500,7500,5000,"Text");
115             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
116 
117             XSimpleText text = (XSimpleText) UnoRuntime.queryInterface
118                 (XSimpleText.class, oShape) ;
119 
120             XTextCursor cursor = text.createTextCursor() ;
121 
122             text.insertString(cursor, "Paragraph 1", false) ;
123             text.insertControlCharacter(cursor,
124                 ControlCharacter.PARAGRAPH_BREAK, false) ;
125             text.insertString(cursor, "Paragraph 2", false) ;
126             text.insertControlCharacter(cursor,
127                 ControlCharacter.PARAGRAPH_BREAK, false) ;
128             text.insertString(cursor, "Paragraph 3", false) ;
129             text.insertControlCharacter(cursor,
130                 ControlCharacter.PARAGRAPH_BREAK, false) ;
131 
132             xEA = (XEnumerationAccess) UnoRuntime.queryInterface
133                 (XEnumerationAccess.class, text) ;
134 
135             XInterface oTextContent = (XInterface) AnyConverter.toObject(
136                 new Type(XInterface.class),xEA.createEnumeration().nextElement());
137 
138             xEA = (XEnumerationAccess) UnoRuntime.queryInterface
139                 (XEnumerationAccess.class, oTextContent) ;
140 
141             oObj = xEA.createEnumeration();
142 
143         } catch (Exception e) {
144             log.println("Can't create test object") ;
145             e.printStackTrace(log) ;
146         }
147 
148         // create test environment here
149          TestEnvironment tEnv = new TestEnvironment( oObj );
150 
151         tEnv.addObjRelation("ENUM", xEA);
152 
153         return tEnv;
154     } // finish method getTestEnvironment
155 
156 }
157 
158