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 ifc.util; 29 30 import lib.MultiMethodTest; 31 32 import com.sun.star.lang.XServiceInfo; 33 import com.sun.star.lang.XTypeProvider; 34 import com.sun.star.uno.UnoRuntime; 35 import com.sun.star.uno.XInterface; 36 import com.sun.star.util.XCloneable; 37 38 /** 39 * Testing <code>com.sun.star.util.XCloneable</code> 40 * interface methods : 41 * <ul> 42 * <li><code> createClone()</code></li> 43 * </ul> <p> 44 * @see com.sun.star.util.XCloneable 45 */ 46 public class _XCloneable extends MultiMethodTest { 47 48 // oObj filled by MultiMethodTest 49 public XCloneable oObj = null ; 50 protected XCloneable clone = null; 51 52 /** 53 * calls the method. <p> 54 * Has <b>OK</b> status if no exception has occured. <p> 55 */ 56 public void _createClone() { 57 boolean result = true; 58 clone = oObj.createClone(); 59 60 //check if the implementaionname equals 61 result &= checkImplementationName(oObj,clone); 62 63 //check ImplementationID 64 result &= checkImplementationID(oObj, clone); 65 66 tRes.tested("createClone()", result) ; 67 } 68 69 protected byte[] getImplementationID(XInterface ifc) { 70 byte[] res = new byte[0]; 71 XTypeProvider provider = (XTypeProvider) 72 UnoRuntime.queryInterface(XTypeProvider.class, ifc); 73 if (provider != null) { 74 res = provider.getImplementationId(); 75 } 76 return res; 77 } 78 79 protected boolean checkImplementationID(XInterface org, XInterface clone) { 80 boolean res = getImplementationID(org).equals( 81 getImplementationID(clone)); 82 if (res && getImplementationID(org).length > 0) { 83 log.println("ImplementationID equals the clone has the same id as the original Object"); 84 log.println("------------------------------------------------------------------------"); 85 } 86 return !res; 87 } 88 89 protected String getImplementationName(XInterface ifc) { 90 String res = ""; 91 XServiceInfo info = (XServiceInfo) 92 UnoRuntime.queryInterface(XServiceInfo.class, ifc); 93 if (info != null) { 94 res = info.getImplementationName(); 95 } 96 return res; 97 } 98 99 protected boolean checkImplementationName(XInterface org, XInterface clone) { 100 boolean res = getImplementationName(org).equals( 101 getImplementationName(clone)); 102 if (!res) { 103 log.println("ImplementationName differs: "); 104 log.println("Expected: "+getImplementationName(org)); 105 log.println("Gained: "+getImplementationName(clone)); 106 log.println("----------------------------------------"); 107 } 108 return res; 109 } 110 111 } // finish class _XCloneable 112 113