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