1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._svx;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.DrawTools;
33 import util.SOfficeFactory;
34 
35 import com.sun.star.container.XEnumerationAccess;
36 import com.sun.star.drawing.XShape;
37 import com.sun.star.lang.XComponent;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.text.ControlCharacter;
40 import com.sun.star.text.XSimpleText;
41 import com.sun.star.text.XTextCursor;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 
45 public class SvxUnoTextContentEnum extends TestCase {
46 
47     static XComponent xDrawDoc;
48 
49     /**
50      * in general this method creates a testdocument
51      *
52      *  @param tParam    class which contains additional test parameters
53      *  @param log        class to log the test state and result
54      *
55      *
56      *  @see TestParameters
57      *    @see PrintWriter
58      *
59      */
initialize( TestParameters tParam, PrintWriter log )60     protected void initialize( TestParameters tParam, PrintWriter log ) {
61         try {
62             log.println( "creating a drawdoc" );
63             xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
64         } catch ( Exception e ) {
65             // Some exception occures.FAILED
66             e.printStackTrace( log );
67             throw new StatusException( "Couldn't create document", e );
68         }
69     }
70 
71     /**
72      * in general this method disposes the testenvironment and document
73      *
74      *  @param tParam    class which contains additional test parameters
75      *  @param log        class to log the test state and result
76      *
77      *
78      *  @see TestParameters
79      *    @see PrintWriter
80      *
81      */
cleanup( TestParameters tParam, PrintWriter log )82     protected void cleanup( TestParameters tParam, PrintWriter log ) {
83         log.println( "    disposing xDrawDoc " );
84         util.DesktopTools.closeDoc(xDrawDoc);
85     }
86 
87 
88     /**
89      *    creating a Testenvironment for the interfaces to be tested
90      *
91      *  @param tParam    class which contains additional test parameters
92      *  @param log        class to log the test state and result
93      *
94      *  @return    Status class
95      *
96      *  @see TestParameters
97      *    @see PrintWriter
98      */
createTestEnvironment( TestParameters tParam, PrintWriter log )99     public TestEnvironment createTestEnvironment( TestParameters tParam,
100                                                   PrintWriter log )
101                                                     throws StatusException {
102 
103         XInterface oObj = null;
104         // create testobject here
105 
106         XEnumerationAccess xEA = null ;
107         try {
108             SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
109             XShape oShape = SOF.createShape
110                 (xDrawDoc,5000,3500,7500,5000,"Text");
111             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
112 
113             XSimpleText text = (XSimpleText) UnoRuntime.queryInterface
114                 (XSimpleText.class, oShape) ;
115 
116             XTextCursor cursor = text.createTextCursor() ;
117 
118             text.insertString(cursor, "Paragraph 1", false) ;
119             text.insertControlCharacter(cursor,
120                 ControlCharacter.PARAGRAPH_BREAK, false) ;
121             text.insertString(cursor, "Paragraph 2", false) ;
122             text.insertControlCharacter(cursor,
123                 ControlCharacter.PARAGRAPH_BREAK, false) ;
124             text.insertString(cursor, "Paragraph 3", false) ;
125             text.insertControlCharacter(cursor,
126                 ControlCharacter.PARAGRAPH_BREAK, false) ;
127 
128             xEA = (XEnumerationAccess) UnoRuntime.queryInterface
129                 (XEnumerationAccess.class, text) ;
130 
131             oObj = xEA.createEnumeration() ;
132         } catch (Exception e) {
133             log.println("Can't create test object") ;
134             e.printStackTrace(log) ;
135             throw new StatusException("Unexpected exception", e);
136         }
137 
138         // create test environment here
139          TestEnvironment tEnv = new TestEnvironment( oObj );
140 
141         // adding relation for XEnumeration test
142         tEnv.addObjRelation("ENUM", xEA) ;
143 
144         return tEnv;
145     } // finish method getTestEnvironment
146 
147 }
148 
149