2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
23 import java
.util
.Arrays
;
25 import com
.sun
.star
.lang
.XComponent
;
26 import com
.sun
.star
.lang
.XServiceInfo
;
27 import com
.sun
.star
.lang
.XTypeProvider
;
28 import com
.sun
.star
.uno
.UnoRuntime
;
29 import com
.sun
.star
.uno
.XInterface
;
30 import com
.sun
.star
.util
.XCloneable
;
33 * Testing <code>com.sun.star.util.XCloneable</code>
36 * <li><code> createClone()</code></li>
38 * @see com.sun.star.util.XCloneable
40 public class _XCloneable
extends MultiMethodTest
{
42 // oObj filled by MultiMethodTest
43 public XCloneable oObj
= null ;
44 protected XCloneable clone
= null;
47 * calls the method. <p>
48 * Has <b>OK</b> status if no exception has occurred. <p>
50 public void _createClone() {
51 boolean result
= true;
52 clone
= oObj
.createClone();
54 //check if the implementationname equals
55 result
&= checkImplementationName(oObj
,clone
);
57 //check ImplementationID
58 result
&= checkImplementationID(oObj
, clone
);
60 tRes
.tested("createClone()", result
) ;
62 XComponent comp
= UnoRuntime
.queryInterface(XComponent
.class, clone
);
68 protected byte[] getImplementationID(XInterface ifc
) {
69 byte[] res
= new byte[0];
70 XTypeProvider provider
= UnoRuntime
.queryInterface(XTypeProvider
.class, ifc
);
71 if (provider
!= null) {
72 res
= provider
.getImplementationId();
77 protected boolean checkImplementationID(XInterface org
, XInterface clone
) {
78 boolean res
= Arrays
.equals(getImplementationID(org
), getImplementationID(clone
));
79 if (res
&& getImplementationID(org
).length
> 0) {
80 log
.println("ImplementationID equals the clone has the same id as the original Object");
81 log
.println("------------------------------------------------------------------------");
86 protected String
getImplementationName(XInterface ifc
) {
88 XServiceInfo info
= UnoRuntime
.queryInterface(XServiceInfo
.class, ifc
);
90 res
= info
.getImplementationName();
95 protected boolean checkImplementationName(XInterface org
, XInterface clone
) {
96 boolean res
= getImplementationName(org
).equals(
97 getImplementationName(clone
));
99 log
.println("ImplementationName differs: ");
100 log
.println("Expected: "+getImplementationName(org
));
101 log
.println("Gained: "+getImplementationName(clone
));
102 log
.println("----------------------------------------");
107 } // finish class _XCloneable