1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.util;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
29cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider;
30cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
31cdf0e10cSrcweir import com.sun.star.uno.XInterface;
32cdf0e10cSrcweir import com.sun.star.util.XCloneable;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir /**
35cdf0e10cSrcweir * Testing <code>com.sun.star.util.XCloneable</code>
36cdf0e10cSrcweir * interface methods :
37cdf0e10cSrcweir * <ul>
38cdf0e10cSrcweir *  <li><code> createClone()</code></li>
39cdf0e10cSrcweir * </ul> <p>
40cdf0e10cSrcweir * @see com.sun.star.util.XCloneable
41cdf0e10cSrcweir */
42cdf0e10cSrcweir public class _XCloneable extends MultiMethodTest {
43cdf0e10cSrcweir 
44cdf0e10cSrcweir     // oObj filled by MultiMethodTest
45cdf0e10cSrcweir     public XCloneable oObj = null ;
46cdf0e10cSrcweir     protected XCloneable clone = null;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     /**
49cdf0e10cSrcweir      * calls the method. <p>
50cdf0e10cSrcweir      * Has <b>OK</b> status if no exception has occured. <p>
51cdf0e10cSrcweir      */
_createClone()52cdf0e10cSrcweir     public void _createClone() {
53cdf0e10cSrcweir         boolean result = true;
54cdf0e10cSrcweir         clone = oObj.createClone();
55cdf0e10cSrcweir 
56cdf0e10cSrcweir         //check if the implementaionname equals
57cdf0e10cSrcweir         result &= checkImplementationName(oObj,clone);
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         //check ImplementationID
60cdf0e10cSrcweir         result &= checkImplementationID(oObj, clone);
61cdf0e10cSrcweir 
62cdf0e10cSrcweir         tRes.tested("createClone()", result) ;
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir 
getImplementationID(XInterface ifc)65cdf0e10cSrcweir     protected byte[] getImplementationID(XInterface ifc) {
66cdf0e10cSrcweir         byte[] res = new byte[0];
67cdf0e10cSrcweir         XTypeProvider provider = (XTypeProvider)
68cdf0e10cSrcweir                     UnoRuntime.queryInterface(XTypeProvider.class, ifc);
69cdf0e10cSrcweir         if (provider != null) {
70cdf0e10cSrcweir             res = provider.getImplementationId();
71cdf0e10cSrcweir         }
72cdf0e10cSrcweir         return res;
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir 
checkImplementationID(XInterface org, XInterface clone)75cdf0e10cSrcweir     protected boolean checkImplementationID(XInterface org, XInterface clone) {
76cdf0e10cSrcweir         boolean res = getImplementationID(org).equals(
77cdf0e10cSrcweir                                             getImplementationID(clone));
78cdf0e10cSrcweir         if (res && getImplementationID(org).length > 0) {
79cdf0e10cSrcweir             log.println("ImplementationID equals the clone has the same id as the original Object");
80cdf0e10cSrcweir             log.println("------------------------------------------------------------------------");
81cdf0e10cSrcweir         }
82cdf0e10cSrcweir         return !res;
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir 
getImplementationName(XInterface ifc)85cdf0e10cSrcweir     protected String getImplementationName(XInterface ifc) {
86cdf0e10cSrcweir         String res = "";
87cdf0e10cSrcweir         XServiceInfo info = (XServiceInfo)
88cdf0e10cSrcweir                     UnoRuntime.queryInterface(XServiceInfo.class, ifc);
89cdf0e10cSrcweir         if (info != null) {
90cdf0e10cSrcweir             res = info.getImplementationName();
91cdf0e10cSrcweir         }
92cdf0e10cSrcweir         return res;
93cdf0e10cSrcweir     }
94cdf0e10cSrcweir 
checkImplementationName(XInterface org, XInterface clone)95cdf0e10cSrcweir     protected boolean checkImplementationName(XInterface org, XInterface clone) {
96cdf0e10cSrcweir         boolean res = getImplementationName(org).equals(
97cdf0e10cSrcweir                                             getImplementationName(clone));
98cdf0e10cSrcweir         if (!res) {
99cdf0e10cSrcweir             log.println("ImplementationName differs: ");
100cdf0e10cSrcweir             log.println("Expected: "+getImplementationName(org));
101cdf0e10cSrcweir             log.println("Gained: "+getImplementationName(clone));
102cdf0e10cSrcweir             log.println("----------------------------------------");
103cdf0e10cSrcweir         }
104cdf0e10cSrcweir         return res;
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir }  // finish class _XCloneable
108cdf0e10cSrcweir 
109