Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / util / _XCloneable.java
blobf08d593cae989c9724e54aa576e6446c286fb405
1 /*
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 .
19 package ifc.util;
21 import lib.MultiMethodTest;
23 import com.sun.star.lang.XServiceInfo;
24 import com.sun.star.lang.XTypeProvider;
25 import com.sun.star.uno.UnoRuntime;
26 import com.sun.star.uno.XInterface;
27 import com.sun.star.util.XCloneable;
29 /**
30 * Testing <code>com.sun.star.util.XCloneable</code>
31 * interface methods :
32 * <ul>
33 * <li><code> createClone()</code></li>
34 * </ul> <p>
35 * @see com.sun.star.util.XCloneable
37 public class _XCloneable extends MultiMethodTest {
39 // oObj filled by MultiMethodTest
40 public XCloneable oObj = null ;
41 protected XCloneable clone = null;
43 /**
44 * calls the method. <p>
45 * Has <b>OK</b> status if no exception has occurred. <p>
47 public void _createClone() {
48 boolean result = true;
49 clone = oObj.createClone();
51 //check if the implementaionname equals
52 result &= checkImplementationName(oObj,clone);
54 //check ImplementationID
55 result &= checkImplementationID(oObj, clone);
57 tRes.tested("createClone()", result) ;
60 protected byte[] getImplementationID(XInterface ifc) {
61 byte[] res = new byte[0];
62 XTypeProvider provider = UnoRuntime.queryInterface(XTypeProvider.class, ifc);
63 if (provider != null) {
64 res = provider.getImplementationId();
66 return res;
69 protected boolean checkImplementationID(XInterface org, XInterface clone) {
70 boolean res = getImplementationID(org).equals(
71 getImplementationID(clone));
72 if (res && getImplementationID(org).length > 0) {
73 log.println("ImplementationID equals the clone has the same id as the original Object");
74 log.println("------------------------------------------------------------------------");
76 return !res;
79 protected String getImplementationName(XInterface ifc) {
80 String res = "";
81 XServiceInfo info = UnoRuntime.queryInterface(XServiceInfo.class, ifc);
82 if (info != null) {
83 res = info.getImplementationName();
85 return res;
88 protected boolean checkImplementationName(XInterface org, XInterface clone) {
89 boolean res = getImplementationName(org).equals(
90 getImplementationName(clone));
91 if (!res) {
92 log.println("ImplementationName differs: ");
93 log.println("Expected: "+getImplementationName(org));
94 log.println("Gained: "+getImplementationName(clone));
95 log.println("----------------------------------------");
97 return res;
100 } // finish class _XCloneable