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._i18n;
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.SOfficeFactory;
33 import util.utils;
34 
35 import com.sun.star.lang.Locale;
36 import com.sun.star.lang.XComponent;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.text.XTextDocument;
39 import com.sun.star.text.XTextRange;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.i18n.BreakIterator</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 *  <li> <code>com::sun::star::i18n::XBreakIterator</code></li>
49 * </ul>
50 * This object test <b> is NOT </b> designed to be run in several
51 * threads concurently.
52 * @see ifc.i18n._XBreakIterator
53 */
54 public class BreakIterator extends TestCase {
55 
56     XComponent xTextDoc;
57 
58     /**
59      * Loads a Text document with name 'Iterator.sxw' from test
60      * documents directory
61      */
initialize( TestParameters tParam, PrintWriter log )62     protected void initialize( TestParameters tParam, PrintWriter log ) {
63 
64         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
65 
66         try {
67             log.println( "creating a drawdoc" );
68             xTextDoc = SOF.loadDocument(utils.getFullTestURL("Iterator.sxw"));
69         } catch ( com.sun.star.uno.Exception e ) {
70             // Some exception occured.FAILED
71             e.printStackTrace( log );
72             throw new StatusException( "Couldn't load document", e );
73         }
74     }
75 
76     /**
77     * Creating a Testenvironment for the interfaces to be tested.
78     * Creates an instance of the service
79     * <code>com.sun.star.i18n.BreakIterator</code>.
80     */
createTestEnvironment( TestParameters Param, PrintWriter log )81     public TestEnvironment createTestEnvironment( TestParameters Param,
82                                                   PrintWriter log )
83                                                     throws StatusException {
84         XInterface oObj = null;
85         Object oInterface = null;
86 
87         try {
88             XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
89             oInterface = xMSF.createInstance( "com.sun.star.i18n.BreakIterator" );
90         }
91         catch( com.sun.star.uno.Exception e ) {
92             log.println("Can't create an object." );
93             throw new StatusException( "Can't create an object", e );
94         }
95 
96         oObj = (XInterface) oInterface;
97 
98         TestEnvironment tEnv = new TestEnvironment( oObj );
99 
100         tEnv.addObjRelation("Locale",  new Locale("en", "US", ""));
101 
102         XTextDocument xDoc = (XTextDocument)UnoRuntime.queryInterface
103             (XTextDocument.class, xTextDoc);
104         XTextRange xTextRange = (XTextRange)xDoc.getText();
105         tEnv.addObjRelation("UnicodeString", xTextRange.getString());
106 
107         return tEnv;
108     } // finish method getTestEnvironment
109 
110     /**
111     * Disposes the Text document loaded before.
112     */
cleanup( TestParameters tParam, PrintWriter log )113     protected void cleanup( TestParameters tParam, PrintWriter log ) {
114         log.println( "    disposing xTextDoc " );
115         xTextDoc.dispose();
116     }
117 
118 }    // finish class BreakIterator
119 
120