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