diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /qadevOOo/tests/java/ifc/container | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream.tar.xz libreoffice-upstream.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'qadevOOo/tests/java/ifc/container')
17 files changed, 2501 insertions, 0 deletions
diff --git a/qadevOOo/tests/java/ifc/container/_XChild.java b/qadevOOo/tests/java/ifc/container/_XChild.java new file mode 100644 index 000000000..fc32dc9c4 --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XChild.java @@ -0,0 +1,91 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import lib.MultiMethodTest; +import lib.Status; + +import com.sun.star.container.XChild; +import com.sun.star.container.XNamed; +import com.sun.star.uno.UnoRuntime; + +/* +* Testing <code>com.sun.star.container.XChild</code> +* interface methods : +* <ul> +* <li><code> getParent()</code></li> +* <li><code> setParent()</code></li> +* </ul> +* @see com.sun.star.container.XChild +*/ +public class _XChild extends MultiMethodTest { + + public XChild oObj = null; + public Object gotten = null; + + + /** + * Test calls the method and checks return value and that + * no exceptions were thrown. Parent returned is stored.<p> + * Has <b> OK </b> status if the method returns not null value + * and no exceptions were thrown. <p> + */ + public void _getParent() { + gotten = oObj.getParent(); + XNamed the_name = UnoRuntime.queryInterface(XNamed.class,gotten); + if (the_name != null) + log.println("Parent:"+the_name.getName()); + tRes.tested("getParent()",gotten != null); + } + + /** + * Sets existing parent and checks that + * no exceptions were thrown. <p> + * Has <b> OK </b> status if no exceptions were thrown. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> getParent() </code> : to get the parent. </li> + * </ul> + */ + public void _setParent() { + requiredMethod("getParent()") ; + + String parentComment = (String) tEnv.getObjRelation("cannotSwitchParent"); + + if (parentComment != null) { + log.println(parentComment); + tRes.tested("setParent()",Status.skipped(true)); + return; + } + + try { + oObj.setParent(gotten); + tRes.tested("setParent()",true); + } + catch (com.sun.star.lang.NoSupportException ex) { + log.println("Exception occurred during setParent()"); + ex.printStackTrace(log); + tRes.tested("setParent()",false); + } + + } + +} // finish class _XChild + + diff --git a/qadevOOo/tests/java/ifc/container/_XContainer.java b/qadevOOo/tests/java/ifc/container/_XContainer.java new file mode 100644 index 000000000..6d0d37255 --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XContainer.java @@ -0,0 +1,342 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + +import com.sun.star.awt.XControl; +import com.sun.star.awt.XControlContainer; +import com.sun.star.container.ContainerEvent; +import com.sun.star.container.XContainer; +import com.sun.star.container.XContainerListener; +import com.sun.star.container.XNameContainer; +import com.sun.star.container.XNameReplace; +import com.sun.star.lang.EventObject; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XNamingService; + + +/** +* Testing <code>com.sun.star.container.XContainer</code> +* interface methods : +* <ul> +* <li><code> addContainerListener()</code></li> +* <li><code> removeContainerListener()</code></li> +* </ul> +* This test needs the following object relations : +* <ul> +* <li> <code>'INSTANCE'</code> : Object which can be inserted into +* container.</li> +* <li> <code>'INSTANCE2'</code> : <b>(optional)</b> +* Object which can be inserted into container. The relation +* must be specified when container can't contain two +* identical objects. Replaces the first instance.</li> +* <li> <code>'XContainer.Container'</code> (of type +* <code>com.sun.star.container.XNameContainer</code>) +* <b>optional</b> : is required when the tested component +* doesn't implement <code>XNameContainer</code> and is used +* for adding and removing elements.</li> +* <ul> <p> +* Object <b>must implement</b> +* <code>com.sun.star.container.XNameContainer</code>. +* <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.container.XContainer +*/ +public class _XContainer extends MultiMethodTest { + + public XContainer oObj = null; + private boolean bElementInserted = false; + private boolean bElementRemoved = false; + private boolean bElementReplaced = false; + private XNameContainer NC = null ; + private XControlContainer CC = null ; + private XNamingService NV = null ; + private XNameReplace NR = null ; + private Object inst = null ; + private Object inst2 = null ; + + /** + * Retrieves object relations, and tries to query object for + * <code>XNameContainer</code> interface. + * @throws StatusException If one of relations not found or + * object doesn't implement <code>XNameContainer</code> interface. + */ + @Override + public void before() throws StatusException { + // do this test with a different object + Object altObj = tEnv.getObjRelation("XContainer.AlternateObject"); + if (altObj != null) { + oObj = UnoRuntime.queryInterface(XContainer.class, altObj); + } + + NC = UnoRuntime.queryInterface + (XNameContainer.class, oObj) ; + + Object container = null; + if (NC == null) { + container = tEnv.getObjRelation("XContainer.Container") ; + } + + if (container != null) { + if (container instanceof com.sun.star.awt.XControlContainer) { + CC = (XControlContainer) container; + } else if (container instanceof com.sun.star.uno.XNamingService) { + NV = (XNamingService) container; + } else if (container instanceof com.sun.star.container.XNameReplace) { + NR = (XNameReplace) container; + inst2 = tEnv.getObjRelation("XContainer.NewValue"); + inst = tEnv.getObjRelation("XContainer.ElementName"); + } else if (container instanceof com.sun.star.container.XNameContainer) { + NC = (XNameContainer) container; + } + } + + if (NC == null && CC == null && NV == null && NR == null) + throw new StatusException( + Status.failed("Neither object implements XNameContainer" + + " nor relation 'XContainer.Container' found.")) ; + + if (inst == null) + inst = tEnv.getObjRelation("INSTANCE"); + if (inst == null) { + log.println("No INSTANCE ObjRelation!!! "); + throw new StatusException(Status.failed("No INSTANCE ObjRelation!!!")) ; + } + if (inst2 == null) + inst2 = tEnv.getObjRelation("INSTANCE2"); + } + + /** + * Listener implementation which just set flags on appropriate + * events. + */ + public class MyListener implements XContainerListener { + public void elementInserted(ContainerEvent e) { + bElementInserted = true; + } + public void elementRemoved(ContainerEvent e) { + bElementRemoved = true; + } + public void elementReplaced(ContainerEvent e) { + bElementReplaced = true; + } + public void disposing (EventObject obj) {} + } + + MyListener listener = new MyListener(); + + /** + * Adds <code>MyListener</code> and performs all possible changes + * (insert, replace, remove) with container. The checks which + * events were called. <p> + * Has <b>OK</b> status if all methods of the listener were called. + */ + public void _addContainerListener() { + boolean bResult = true; + + oObj.addContainerListener(listener); + bResult &= performChanges(); + //we can't replace if the container is XControlContainer + if (NC != null) bResult &= bElementReplaced; + // we do not remove and insert if the listener is triggered by XNameReplace + if (NR == null) bResult &= bElementRemoved; + if (NR == null) bResult &= bElementInserted; + + if (!bResult) { + log.println("inserted was " + (bElementInserted ? "" : "NOT") + + " called."); + + if (NC != null) { + log.println("replaced was " + (bElementReplaced ? "" : "NOT") + + " called."); + } + log.println("removed was " + (bElementRemoved ? "" : "NOT") + + " called."); + } + + tRes.tested("addContainerListener()", bResult); + } + + /** + * Removes listener added before and performs all possible changes + * (insert, replace, remove) with container. The checks which + * events were called. <p> + * Has <b>OK</b> status if no methods of the listener were called. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> addContainerListener() </code> : to remove it now. </li> + * </ul> + */ + public void _removeContainerListener() { + requiredMethod("addContainerListener()") ; + + boolean bResult = true; + bElementReplaced = bElementRemoved = bElementInserted = false; + + oObj.removeContainerListener(listener); + bResult &= performChanges(); + bResult &= !bElementReplaced; + bResult &= !bElementRemoved; + bResult &= !bElementInserted; + + tRes.tested("removeContainerListener()", bResult); + } + + /** + * Inserts, replaces and finally removes object from container. + * Object is gotten from <code>'INSTANCE'</code> relation. If + * the relation <code>'INSTANCE2'</code> exists then the first + * instance is replaced with second. + */ + protected boolean performChanges() { + if (CC != null) return performChanges2(); + if (NV != null) return performChanges3(); + if (NR != null) return performChanges4(); + boolean bResult = true; + try { + String[] names = NC.getElementNames(); + log.println("Elements count = " + names.length); + NC.insertByName("XContainer_dummy", inst); + names = NC.getElementNames(); + log.println("Elements count = " + names.length); + if (inst2 == null) { + NC.replaceByName("XContainer_dummy", inst); + } else { + NC.replaceByName("XContainer_dummy", inst2); + } + NC.removeByName("XContainer_dummy"); + } catch (com.sun.star.lang.IllegalArgumentException ex) { + log.println("Exception occurred "); + ex.printStackTrace(log); + bResult = false; + } catch (com.sun.star.lang.WrappedTargetException ex) { + log.println("Exception occurred "); + ex.printStackTrace(log); + bResult = false; + } catch (com.sun.star.container.NoSuchElementException ex) { + log.println("Exception occurred "); + ex.printStackTrace(log); + bResult = false; + } catch (com.sun.star.container.ElementExistException ex) { + log.println("Exception occurred "); + ex.printStackTrace(log); + bResult = false; + } + + return bResult; + } + + /** + * In case no XNameContainer is available, but a XControlContainer + * instead. + * the XControl instance is inserted + * Method returns true if the count of Controls is changed afterwards + */ + protected boolean performChanges2() { + int precount = CC.getControls().length; + CC.addControl("NewControl",(XControl) inst); + waitForEventIdle(); + int count = CC.getControls().length; + CC.removeControl(CC.getControl("NewControl")); + waitForEventIdle(); + return count>precount; + } + + /** + * In case no XNameContainer is available, but a XNamingService + * instead. + * the instance is registered and revoked again + * Method return true if getRegisteredObject() works after + * registering and doesn't after revoke + */ + protected boolean performChanges3() { + boolean res = true; + Object reg = null; + + try { + reg = NV.getRegisteredObject("MyFactory"); + NV.revokeObject("MyFactory"); + } catch (Exception e) { + + } + + try { + NV.registerObject("MyFactory", inst); + reg = NV.getRegisteredObject("MyFactory"); + res &= (reg != null); + } catch (Exception e) { + e.printStackTrace(log); + log.println("registerObject failed"); + res &= false; + } + + try { + NV.revokeObject("MyFactory"); + reg = NV.getRegisteredObject("MyFactory"); + log.println("revokeObject failed"); + res &= false; + } catch (Exception e) { + res &= true; + } + + return res; + } + + /** + * In case no XNameContainer is available, but a XNamingReplace + * instead. + */ + protected boolean performChanges4() { + boolean res = true; + Object newValue = inst2; + Object originalValue = null; + String name = null; + + try { + name = (String)inst; + } + catch(java.lang.ClassCastException e) { + log.write("Expected String as object relations 'XContainer.ElementName'."); + e.printStackTrace(log); + return false; + } + + try { + originalValue = NR.getByName(name); + NR.replaceByName(name, newValue); + } catch (Exception e) { + e.printStackTrace(log); + res = false; + } + + try { + NR.replaceByName(name, originalValue); + } catch (Exception e) { + e.printStackTrace(log); + res = false; + } + + return res; + } +} + + diff --git a/qadevOOo/tests/java/ifc/container/_XContainerQuery.java b/qadevOOo/tests/java/ifc/container/_XContainerQuery.java new file mode 100644 index 000000000..68cacca00 --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XContainerQuery.java @@ -0,0 +1,154 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + +import com.sun.star.beans.NamedValue; +import com.sun.star.container.XContainerQuery; +import com.sun.star.container.XEnumeration; + + +/** +* Testing <code>com.sun.star.container.XContainerQuery</code> +* interface methods : +* <ul> +* <li><code> createSubSetEnumerationByProperties()</code></li> +* <li><code> createSubSetEnumerationByQuery()</code></li> +* </ul> +* This test needs the following object relations : +* <ul> +* <li> <code>'XContainerQuery.createSubSetEnumerationByProperties'</code> : +* <code>NameValue[]</code> which is a valid argument for +* <code>createSubSetEnumerationByProperties()</code>.</li> +* <li> <code>'XContainerQuery.createSubSetEnumerationByQuery'</code> : <b>(optional)</b> +* Normally <code>createSubSetEnumerationByProperties()</code> covers all +* possible queries. But for special cases, i.e. sorted output, the function +* <code>createSubSetEnumerationByQuery()</code> was made. The special cases was not +* implemented by default in the implementation object. So this function could be +* marked as <code>optional</code></li> +* <ul> <p> +* <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.container.XContainerQuery +*/ +public class _XContainerQuery extends MultiMethodTest { + + public XContainerQuery oObj = null; + private NamedValue[] m_querySequenze = null; + private String[] m_queryStrings = null; + + + /** + * Retrieves object relations + * @throws StatusException If one of relations not found. + */ + @Override + public void before() throws StatusException { + + m_querySequenze = (NamedValue[]) tEnv.getObjRelation( + "XContainerQuery.createSubSetEnumerationByProperties"); + if (m_querySequenze == null) { + throw new StatusException( + Status.failed("Could not get object relation " + + "'XContainerQuery.createSubSetEnumerationByProperties'")) ; + } + + m_queryStrings = (String[]) tEnv.getObjRelation( + "XContainerQuery.createSubSetEnumerationByQuery"); + if (m_queryStrings == null) { + log.println("Could not get object relation " + + "'XContainerQuery.createSubSetEnumerationByQuery'"); + } + } + + + /** + * If object relation is available, the function was called with relation + * as parameter. The returned <code>XEnumeration</code> must not be null and + * elements of it must be valid. + * If object relation is not available, the result is always <code>true</code> + */ + public void _createSubSetEnumerationByQuery() { + + boolean bResult = true; + if ( m_queryStrings == null ) { + log.println("This object does not have an implementation for this function"); + // This is not a bug, because it's a feature for future purposes + } else { + for (int i = 0; i < m_queryStrings.length; i++){ + String queryString = m_queryStrings[i]; + XEnumeration subSet = oObj.createSubSetEnumerationByQuery( queryString ); + + bResult &= subSet.hasMoreElements(); + + while (subSet.hasMoreElements()) { + try{ + subSet.nextElement(); + + } catch (com.sun.star.container.NoSuchElementException e){ + log.println("Exception occurred "); + e.printStackTrace(log); + bResult = false; + } catch (com.sun.star.lang.WrappedTargetException e){ + log.println("Exception occurred "); + e.printStackTrace(log); + bResult = false; + } + } + } + } + + tRes.tested("createSubSetEnumerationByQuery()", bResult); + } + + /** + * The function was called with object relation + * as parameter. The returned <code>XEnumeration</code> must not be null and + * elements of it must be valid. + * + */ + public void _createSubSetEnumerationByProperties() { + + boolean bResult = true; + + XEnumeration subSet = oObj.createSubSetEnumerationByProperties( m_querySequenze ); + + bResult = subSet.hasMoreElements(); + + while (subSet.hasMoreElements()) { + try{ + subSet.nextElement(); + + } catch (com.sun.star.container.NoSuchElementException e){ + log.println("Exception occurred "); + e.printStackTrace(log); + bResult = false; + } catch (com.sun.star.lang.WrappedTargetException e){ + log.println("Exception occurred "); + e.printStackTrace(log); + bResult = false; + } + } + + tRes.tested("createSubSetEnumerationByProperties()", bResult); + } +} diff --git a/qadevOOo/tests/java/ifc/container/_XContentEnumerationAccess.java b/qadevOOo/tests/java/ifc/container/_XContentEnumerationAccess.java new file mode 100644 index 000000000..24488025e --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XContentEnumerationAccess.java @@ -0,0 +1,86 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import lib.MultiMethodTest; + +import com.sun.star.container.XContentEnumerationAccess; +import com.sun.star.container.XEnumeration; + +/** +* Testing <code>com.sun.star.container.XContentEnumerationAccess</code> +* interface methods : +* <ul> +* <li><code> createContentEnumeration()</code></li> +* <li><code> getAvailableServiceNames()</code></li> +* </ul> <p> +* @see com.sun.star.container.XContentEnumerationAccess +*/ +public class _XContentEnumerationAccess extends MultiMethodTest{ + public XContentEnumerationAccess oObj = null; + String[] serviceNames = null; + + /** + * Retrieves service names and stores them. <p> + * Has <b> OK </b> status if not <code>null</code> + * value returned. + */ + public void _getAvailableServiceNames(){ + boolean bResult = true; + try { + serviceNames = oObj.getAvailableServiceNames(); + bResult = serviceNames != null ; + } catch (Exception e) { + log.println("Exception occurred. " + e); + bResult = false; + } + tRes.tested("getAvailableServiceNames()", bResult); + } + + /** + * If at least one service available then an enumeration for + * it created. <p> + * Has <b> OK </b> status if no services available or enumeration + * created for available service is not <code>null</code>. + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code>getAvailableServiceNames()</code> : + * to have at least one service name for enumeration to create for.</li> + * </ul> + */ + public void _createContentEnumeration(){ + requiredMethod("getAvailableServiceNames()"); + + if (serviceNames.length == 0) { + log.println("No service name available") ; + tRes.tested("createContentEnumeration()", true) ; + return ; + } + + boolean bResult = true; + + log.println( "creating Enumeration" ); + XEnumeration oEnum = oObj.createContentEnumeration(serviceNames[0]); + bResult &= oEnum != null; + + tRes.tested( "createContentEnumeration()", bResult); + } +} + + diff --git a/qadevOOo/tests/java/ifc/container/_XElementAccess.java b/qadevOOo/tests/java/ifc/container/_XElementAccess.java new file mode 100644 index 000000000..25dee4a09 --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XElementAccess.java @@ -0,0 +1,60 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import lib.MultiMethodTest; + +import com.sun.star.container.XElementAccess; + +/** + * Testing <code>com.sun.star.container.XElementAccess</code> + * interface methods : + * <ul> + * <li><code> getElementType()</code></li> + * <li><code> hasElements()</code></li> + * </ul> <p> + * + * @see com.sun.star.container.XElementAccess + */ +public class _XElementAccess extends MultiMethodTest { + public XElementAccess oObj = null; + + /** + * Test calls the method and checks return value. <p> + * Has <b> OK </b> status if the method returns <code>true</code>, + * only in the case the container is not empty.<p> + */ + public void _hasElements(){ + // Testing hasElements() method + tRes.tested( "hasElements()", oObj.hasElements() ); + } // end hasElements + + /** + * Test calls the method and checks return value. <p> + * Has <b> OK </b> status if the method returns not null value.<p> + */ + public void _getElementType(){ + // Testing getElementType() method + com.sun.star.uno.Type type = oObj.getElementType(); + tRes.tested( "getElementType()", type != null ); + } // end ElementType + +} /// finished class _XElementAccess + + diff --git a/qadevOOo/tests/java/ifc/container/_XEnumeration.java b/qadevOOo/tests/java/ifc/container/_XEnumeration.java new file mode 100644 index 000000000..4cddb309e --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XEnumeration.java @@ -0,0 +1,115 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import lib.MultiMethodTest; + +import com.sun.star.container.NoSuchElementException; +import com.sun.star.container.XEnumeration; +import com.sun.star.lang.WrappedTargetException; + +/** +* Testing <code>com.sun.star.container.XEnumeration</code> +* interface methods : +* <ul> +* <li><code> hasMoreElements()</code></li> +* <li><code> nextElement()</code></li> +* </ul> +* Test is multithread compliant. <p> +* @see com.sun.star.container.XEnumeration +*/ +public class _XEnumeration extends MultiMethodTest { + + public XEnumeration oObj = null; + + /** + * Retrieves relation and sets oObj to a separate enumeration + * created. Retrieves all elements from enumeration.<p> + * Has <b> OK </b> status if all elements successfully retrieved + * and exceptions occurred. + */ + public void _hasMoreElements() { + boolean result = true; + + log.println("get all elements"); + int counter = 0; + int tmpCounter = 0; + while ( oObj.hasMoreElements() ) { + try { + oObj.nextElement(); + counter ++; + if (counter - tmpCounter > 10000) { + log.println(counter+ " Elements"); + tmpCounter = counter; + } + } catch (WrappedTargetException e) { + log.println("hasMoreElements() : " + e); + result = false; + break; + } catch (NoSuchElementException e) { + log.println("hasMoreElements() : " + e); + result = false; + break; + } + } + Object expCount = tEnv.getObjRelation("ExpectedCount"); + if (expCount != null) { + int ec = ((Integer) expCount).intValue(); + boolean locResult = counter == ec; + if (!locResult) { + log.println("Not all Elements are returned: "); + log.println("\tExpected: "+ ec); + log.println("\tFound: "+counter); + } + result &= locResult; + } + tRes.tested("hasMoreElements()", result); + } // end hasMoreElements + + /** + * Calls the method (on starting this method there is no more elements + * in the enumeration. <p> + * Has <b> OK </b> status if only <code>NoSuchElementException</code> + * exception rises. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> hasMoreElements() </code> : it retrieves all elements </li> + * </ul> + */ + public void _nextElement(){ + requiredMethod("hasMoreElements()"); + boolean result = true; + log.println("additional call must throw NoSuchElementException"); + + try { + oObj.nextElement(); + log.println("nextElement: no exception!"); + result = false; + } catch (WrappedTargetException e) { + log.println("nextElement: wrong exception!"); + result = false; + } catch (NoSuchElementException e) { + log.println("nextElement: correct exception"); + } + + tRes.tested("nextElement()", result); + } // end NextElement + +} //end XEnumeration + diff --git a/qadevOOo/tests/java/ifc/container/_XEnumerationAccess.java b/qadevOOo/tests/java/ifc/container/_XEnumerationAccess.java new file mode 100644 index 000000000..df79c9a53 --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XEnumerationAccess.java @@ -0,0 +1,47 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import lib.MultiMethodTest; + +import com.sun.star.container.XEnumeration; +import com.sun.star.container.XEnumerationAccess; + + +/** +* Testing <code>com.sun.star.container.XEnumerationAccess</code> +* interface methods. <p> +* Test is multithread compliant. <p> +*/ +public class _XEnumerationAccess extends MultiMethodTest{ + public XEnumerationAccess oObj = null; + + /** + * Test calls the method and checks return value. <p> + * Has <b> OK </b> status if the method returns not null value. <p> + */ + public void _createEnumeration(){ + log.println( "creating Enumeration" ); + XEnumeration oEnum = oObj.createEnumeration(); + tRes.tested( "createEnumeration()", oEnum != null ); + } // end createEnumeration() +} // finish class _XEnumerationAccess + + + diff --git a/qadevOOo/tests/java/ifc/container/_XHierarchicalName.java b/qadevOOo/tests/java/ifc/container/_XHierarchicalName.java new file mode 100644 index 000000000..83897bc43 --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XHierarchicalName.java @@ -0,0 +1,71 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package ifc.container; + +import com.sun.star.container.XHierarchicalName; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + + +public class _XHierarchicalName extends MultiMethodTest { + public XHierarchicalName oObj; + + public void _composeHierarchicalName() { + String expName = (String) tEnv.getObjRelation("HierachicalName"); + String element = (String) tEnv.getObjRelation("ElementName"); + boolean res = false; + + try { + String hn = oObj.composeHierarchicalName(element); + res = hn.startsWith(expName); + + if (!res) { + log.println("Getting : " + hn + + " but expected it to start with " + expName); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Exception " + e.getMessage()); + } catch (com.sun.star.lang.NoSupportException e) { + log.println("Exception " + e.getMessage()); + } + + tRes.tested("composeHierarchicalName()", res); + } + + public void _getHierarchicalName() { + String hName = oObj.getHierarchicalName(); + String expName = (String) tEnv.getObjRelation("HierachicalName"); + boolean res = true; +System.out.println("### "+hName); + if (expName != null) { + res = hName.startsWith(expName); + + if (!res) { + log.println("Expected the name to start with " + expName); + log.println("got " + hName); + } + } else { + throw new StatusException(Status.failed( + "ObjectRelation 'HierachicalName' missing")); + } + + tRes.tested("getHierarchicalName()", res); + } +}
\ No newline at end of file diff --git a/qadevOOo/tests/java/ifc/container/_XHierarchicalNameAccess.java b/qadevOOo/tests/java/ifc/container/_XHierarchicalNameAccess.java new file mode 100644 index 000000000..b128f199d --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XHierarchicalNameAccess.java @@ -0,0 +1,83 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import lib.MultiMethodTest; + +import com.sun.star.container.NoSuchElementException; +import com.sun.star.container.XHierarchicalNameAccess; + +/** +* Testing <code>com.sun.star.container.XHierarchicalNameAccess</code> +* interface methods : +* <ul> +* <li><code> getByHierarchicalName()</code></li> +* <li><code> hasByHierarchicalName()</code></li> +* </ul> <p> +* This test needs the following object relations : +* <ul> +* <li> <code>'ElementName'</code> (of type <code>String</code>): +* name of the element which exists in the container. </li> +* <ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.container.XHierarchicalNameAccess +*/ +public class _XHierarchicalNameAccess extends MultiMethodTest{ + public XHierarchicalNameAccess oObj = null; + + /** + * Calls the method with existing and nonexistent + * element names. <p> + * Has <b>OK</b> status if for existing name <code>true</code> + * is returned and for nonexistent - <code>false</code>. + */ + public void _hasByHierarchicalName(){ + String name = (String) tEnv.getObjRelation("ElementName") ; + boolean res = oObj.hasByHierarchicalName(name) ; + name +="ItMakesThisNameNonExistantForSure"; + boolean res2 = oObj.hasByHierarchicalName(name); + res &= !res2; + tRes.tested("hasByHierarchicalName()", res) ; + } // end _hasByHierarchicalName() + + /** + * Tries to retrieve an element with existing name. <p> + * Has <b>OK</b> status if non null object is returned. + */ + public void _getByHierarchicalName(){ + String name = (String) tEnv.getObjRelation("ElementName") ; + Object res ; + + try { + res = oObj.getByHierarchicalName(name) ; + + } catch (NoSuchElementException e) { + log.println("Element with name '" + name + + "' doesn't exist in this container") ; + res = null ; + } + + tRes.tested("getByHierarchicalName()", res != null) ; + + } // end _getByHierarchicalName() + +} // finish class _XHierarchicalNameAccess + + + diff --git a/qadevOOo/tests/java/ifc/container/_XIndexAccess.java b/qadevOOo/tests/java/ifc/container/_XIndexAccess.java new file mode 100644 index 000000000..6b1908428 --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XIndexAccess.java @@ -0,0 +1,144 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import lib.MultiMethodTest; + +import com.sun.star.container.XIndexAccess; +import com.sun.star.lang.IndexOutOfBoundsException; +import com.sun.star.lang.WrappedTargetException; + +/** +* Testing <code>com.sun.star.container.XIndexAccess</code> +* interface methods : +* <ul> +* <li><code> getCount()</code></li> +* <li><code> getByIndex()</code></li> +* </ul> <p> +* Test seems to work properly in multithreaded environment. +* @see com.sun.star.container.XIndexAccess +*/ +public class _XIndexAccess extends MultiMethodTest { + + public XIndexAccess oObj = null; + + /** + * Number of elements in the container. + */ + public int count = 0; + + /** + * Get number of element in the container. <p> + * Has <b> OK </b> status if method returns number lager than -1. + */ + public void _getCount() { + boolean result = true; + log.println("getting the number of the elements"); + // hope we haven't a count lower than zero ;-) + count = -1; + count = oObj.getCount(); + result = (count != -1); + tRes.tested("getCount()", result); + } //end getCount() + + /** + * This method tests the IndexAccess from the first element, + * the middle element and the last element. Finally it test + * Exceptions which throws by a not available index. <p> + * Has <b> OK </b> status if first, middle and last elements + * successfully returned and has non null value; and if on + * invalid index parameter <code>IndexOutOfBoundsException</code> + * is thrown.<p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> getCount() </code> : to have number of elements + * in container. </li> + * </ul> + */ + public void _getByIndex() { + requiredMethod("getCount()"); + // get count from holder + + waitForEventIdle(); + + boolean result = true; + log.println("Testing getByIndex()"); + + if (count > 0) { + // Check the first element + log.println("Check the first element"); + result &= checkGetByIndex(0); + + // Check the middle element + log.println("Check the middle element"); + result &= checkGetByIndex(count /2); + + // Check the last element + log.println("Check the last element"); + result &= checkGetByIndex(count -1); + + // Testing getByIndex with wrong params. + log.println("Testing getByIndex with wrong params."); + try { + log.println("getByIndex(" + count + ")"); + oObj.getByIndex(count); + log.println("no exception thrown - FAILED"); + result = false; + } catch (IndexOutOfBoundsException e) { + log.println("Expected exception caught! " + e + " OK"); + } catch (WrappedTargetException e) { + log.println("Wrong exception! " + e + " FAILED"); + result = false; + } + } + + tRes.tested("getByIndex()", result); + + } // end getByIndex + + private boolean checkGetByIndex(int index){ + Object o = null; + boolean result = true; + try { + log.println("getByIndex(" + index + ")"); + o = oObj.getByIndex(index); + + if ( tEnv.getObjRelation("XIndexAccess.getByIndex.mustBeNull") != null){ + result = (o == null); + if (result) log.println("OK"); else log.println("FAILED -> not null"); + } else { + result = (o != null); + if (result) log.println("OK"); else log.println("FAILED -> null"); + } + + } catch (WrappedTargetException e) { + log.println("Exception! " + e); + result = false; + } catch (IndexOutOfBoundsException e) { + log.println("Exception! " + e); + result = false; + } + + return result; + } + +} // end XIndexAccess + + + diff --git a/qadevOOo/tests/java/ifc/container/_XIndexContainer.java b/qadevOOo/tests/java/ifc/container/_XIndexContainer.java new file mode 100644 index 000000000..9b3a23f97 --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XIndexContainer.java @@ -0,0 +1,201 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import lib.MultiMethodTest; + +import com.sun.star.container.XIndexContainer; +import com.sun.star.lang.IndexOutOfBoundsException; + +/** +* Testing <code>com.sun.star.container.XIndexContainer</code> +* interface methods : +* <ul> +* <li><code> insertByIndex()</code></li> +* <li><code> removeByIndex()</code></li> +* </ul> <p> +* +* This test needs the following object relations : +* <ul> +* <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> : N relations +* which represents objects to be inserted. See below +* for more information.</li> +* <li> <code>'XIndexContainerINDEX'</code> : For internal test +* usage. Contains current thread number. </li> +* <li> Test environment variable <code>'THRCNT'</code> : number +* of interface threads running concurrently. </li> +* <ul> <p> +* XIndexContainer needs n ObjectRelations "INSTANCEn" , where n=1, ..., +* THRCNT.<p> +* When this interface tested by different threads, it must use different +* instances to insert/remove - one for each thread. +* <p> +* That's why we use objRelation "XIndexContainerINDEX" to store the number of +* last taken instance. If there is no such relation, it initialize with 1. +* <p> +* This ObjectRelations should be necessary to create an Object, +* which is insertable by insterByIndex() +* INSTANCEn are n Objectrelations so that every thread can insert its own +* object. n depends on the variable THRCNT which and comes from API.INI +* <p> +* Why that: +* If you insert the same Object by insertByIndex() several times you +* don't insert the Object several times. The first insertByIndex() inserts +* the Object to the Container but all other insertByIndex() changes +* the Index in the Container because it's the same Object. <p> +* Test is multithread compliant. <p> +* @see com.sun.star.container.XIndexContainer +*/ + +public class _XIndexContainer extends MultiMethodTest { + public XIndexContainer oObj = null; + + int Index = 0; + + /** + * First tries to insert proper object. Second tries to insert + * null value. For each test thread different objects are inserted + * on different indexes. For example for the first started test index + * is 0 and object is get from relation 'INSTANCE1', and so on. <p> + * Has <b>OK</b> status if in the first case <code>getByIndex</code> + * method returns non null value and in the second <code> + * IndexOutOfBoundsException</code> was thrown. + */ + public void _insertByIndex() { + boolean result = true; + + log.println("get ObjRelation(\"XIndexContainerINDEX\")"); + String sIndex = (String)tEnv.getObjRelation("XIndexContainerINDEX"); + if (sIndex == null) { + log.println("No XIndexContainerINDEX - so set it to 1."); + tEnv.addObjRelation("XIndexContainerINDEX", Integer.toString(1)); + Index = 1; + } else { + Index = Integer.parseInt(sIndex); + Index++; + tEnv.addObjRelation("XIndexContainerINDEX", + Integer.toString(Index)); + } + + + log.println("get ObjRelation(\"INSTANCE" + Index +"\")"); + Object oInstance = tEnv.getObjRelation("INSTANCE"+ Index); + if (oInstance == null) { + log.println("ObjRelation(\"INSTANCE" + Index +"\") Object n.a."); + } + + log.println("testing insertByIndex(\"" + Index + "\")..."); + try { + oObj.insertByIndex(Index, oInstance); + result &= oObj.getByIndex(Index) != null ; + log.println("insertByIndex(\""+Index+"\")...OK"); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + log.println("insertByIndex(\""+Index+"\"): " + e + " FLASE"); + result = false; + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("insertByIndex(\""+Index+"\"): " + e + " FLASE"); + result = false; + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("insertByIndex(\""+Index+"\"): " + e + " FLASE"); + result = false; + } + + log.println("inserting a wrong Object occurs Exceptions ..."); + try { + Object dummy = null; + oObj.insertByIndex(0, dummy); + log.println("No Exception: -> FALSE"); + result = false; + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Dummy-Exception: " + e + " -> OK"); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + log.println("!!! Wrong Exception: " + e + " -> FAILED"); + result = false; + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("!!! Wrong Exception: " + e + " -> FAILED"); + result = false; + } + + tRes.tested("insertByIndex()", result); + } + + /** + * Removes the element inserted by <code>insertByIndex</code> method test. + * The number of elements is checked before and after removing. + * Then tries to remove an element with invalid index and checks exceptions. + * <p> + * Has <b>OK</b> status if after removing number of elements decreases by + * one and <code>IndexOutOfBoundsException</code> is thrown on invalid index + * removing. + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> insertByIndex </code> : to have an object which can be + * removed.</li> + * </ul> + */ + public void _removeByIndex() { + requiredMethod("insertByIndex()"); + boolean result = true; + + log.println("testing removeByIndex() ..."); + + try { + log.println("remove " +Index); + int cnt1 = -1 , cnt2 = -1 ; + synchronized (oObj) { + cnt1 = oObj.getCount() ; + oObj.removeByIndex(Index); + cnt2 = oObj.getCount() ; + } + log.println("Count before removing : " + cnt1 + + ", and after : " + cnt2) ; + + result &= cnt1 == cnt2 + 1 ; + + log.println("1. removeByIndex(\""+Index+"\") ...OK"); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + result = false; + log.println("1. removeByIndex:(\""+Index+"\") " + + e + " - FAILED"); + } catch (com.sun.star.lang.WrappedTargetException e) { + result = false; + log.println("1. removeByIndex:(\""+Index+"\") " + + e + " - FAILED"); + } + + log.println("removing a non existent object to get an exception"); + try { + oObj.removeByIndex(100); + result = false; + log.println("2. removeByIndex(): Exception expected! - FAILED"); + } catch (IndexOutOfBoundsException e) { + log.println("2. removeByIndex(): Expected exception - OK"); + result &= true; + } catch (com.sun.star.lang.WrappedTargetException e) { + result = false; + log.println("2. removeByIndex(): Unexpected exception! - " + + e + " - FAILED"); + } + + tRes.tested("removeByIndex()", result); + } +} + + + diff --git a/qadevOOo/tests/java/ifc/container/_XIndexReplace.java b/qadevOOo/tests/java/ifc/container/_XIndexReplace.java new file mode 100644 index 000000000..f97dfb0d9 --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XIndexReplace.java @@ -0,0 +1,200 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import lib.MultiMethodTest; +import util.ValueComparer; + +import com.sun.star.container.XIndexReplace; +import com.sun.star.container.XNameContainer; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.IndexOutOfBoundsException; +import com.sun.star.uno.UnoRuntime; + + +/** +* Testing <code>com.sun.star.container.XIndexReplace</code> +* interface methods : +* <ul> +* <li><code> replaceByIndex()</code></li> +* </ul> +* This test needs the following object relations : +* <ul> +* <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> : N relations +* which represents objects to be replaced with. See below +* for more information.</li> +* <li> <code>'XIndexReplaceINDEX'</code> : For internal test +* usage. Contains current thread number. </li> +* <li> Test environment variable <code>'THRCNT'</code> : number +* of interface threads running concurrently. </li> +* <ul> <p> +* XIndexReplace needs n ObjectRelations "INSTANCEn" , where n = 1, ..., THRCNT. +* <p> +* When this interface tested by different threads, it must use different +* instances to replace - one for each thread.<p> +* That's why we use objRelation "XIndexReplaceINDEX" to store the number of +* last taken instance. If there is no such relation, it initialize with 1. +* <p> +* This ObjectRelations should be necessary to create an Object, +* which is can be replaced by index +* INSTANCEn are n Objectrelations so that every thread can insert its own +* object. n depends on the variable THRCNT which and comes from API.INI +* <p> +* Why that: +* If you insert the same Object by replaceByIndex() several times you +* don't insert the Object several times. The first replaceByIndex() inserts +* the Object to the Container but all other replaceByIndex() changes +* the Index in the Container because it's the same Object. <p> +* Test is multithread compliant. <p> +* @see com.sun.star.container.XIndexReplace +*/ + +public class _XIndexReplace extends MultiMethodTest { + public XIndexReplace oObj = null; + + /** + * Primarily tries to replace elements in a proper way : + * replaces the first, middle and the last element then + * checks if elements were properly replaced. + * Then wrong parameters are passed : invalid index and + * null value for replacing, and test checks for proper + * exceptions to be thrown. <p> + * In different threads it replaces elements with different + * objects. + * Has <b>OK</b> status if in the first (correct) case + * elements were successfully replaced (i.e. values got + * after replacing must be equal to those replaced with), + * and in the second case proper exceptions were thrown. + */ + public void _replaceByIndex() { + boolean result = true; + Object old = null; + Object oInstance = null; + int Index = 0; + + //get for every thread its own Object to insert it + log.println("get ObjRelation(\"XIndexReplaceINDEX\")"); + String sIndex = (String)tEnv.getObjRelation("XIndexReplaceINDEX"); + if (sIndex == null) { + log.println("No XIndexReplaceINDEX - so set it to 1."); + tEnv.addObjRelation("XIndexReplaceINDEX", Integer.toString(1)); + Index = 1; + } else { + Index = Integer.parseInt(sIndex); + Index++; + tEnv.addObjRelation("XIndexReplaceINDEX", Integer.toString(Index)); + } + + + log.println("get ObjRelation(\"INSTANCE" + Index +"\")"); + oInstance = tEnv.getObjRelation("INSTANCE"+ Index); + if (oInstance == null) { + log.println("ObjRelation(\"INSTANCE" + Index +"\") Object n.a."); + } + + log.println("testing replaceByIndex(0)..."); + + try { + + log.println("Getting old object"); + old = oObj.getByIndex(0); + oObj.replaceByIndex(0, oInstance); + result = !(oObj.getByIndex(0)).equals(old); + result = ! ValueComparer.equalValue(oObj,old); + + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + e.printStackTrace(log) ; + result = false; + } catch (com.sun.star.lang.IllegalArgumentException e) { + e.printStackTrace(log) ; + result = false; + } catch (com.sun.star.lang.WrappedTargetException e) { + e.printStackTrace(log) ; + result = false; + } + + + log.println("replace with a wrong Object occurs Exceptions ..."); + try { + oObj.replaceByIndex(999, oInstance); + result = false; + log.println("1. replaceByIndex(): Exception expected! - FAILED"); + + + XNameContainer xNC = UnoRuntime.queryInterface(XNameContainer.class, oObj) ; + String[] names = xNC.getElementNames() ; + log.println("Element names :") ; + for (int i = 0; i<names.length; i++) { + log.println(" '" + names[i] + "'") ; + } + } catch (IndexOutOfBoundsException e) { + log.println("1. replaceByIndex(): Expected exception - OK"); + result &= true; + } catch (com.sun.star.lang.IllegalArgumentException e) { + result = false; + log.println("1. replaceByIndex(): Unexpected exception! - " + + e + " - FAILED"); + } catch (com.sun.star.lang.WrappedTargetException e) { + result = false; + log.println("1. replaceByIndex(): Unexpected exception! - " + + e + " - FAILED"); + } + + log.println("replace with a wrong Object occurs Exceptions ..."); + try { + oObj.replaceByIndex(0, null); + result = false; + log.println("2. replaceByIndex(): Exception expected! - FAILED"); + + + XNameContainer xNC = UnoRuntime.queryInterface(XNameContainer.class, oObj) ; + String[] names = xNC.getElementNames() ; + log.println("Element names :") ; + for (int i = 0; i<names.length; i++) { + log.println(" '" + names[i] + "'") ; + } + } catch (IllegalArgumentException e) { + log.println("2. replaceByIndex(): Expected exception - OK"); + result &= true; + } catch (com.sun.star.lang.WrappedTargetException e) { + result = false; + log.println("2. replaceByIndex(): Unexpected exception! - " + + e + " - FAILED"); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + result = false; + log.println("2. replaceByIndex(): Unexpected exception! - " + + e + " - FAILED"); + } + + log.println("replace with the old object"); + try { + oObj.replaceByIndex(0, old); + } catch (IllegalArgumentException e) { + e.printStackTrace(log) ; + } catch (com.sun.star.lang.WrappedTargetException e) { + e.printStackTrace(log) ; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + e.printStackTrace(log) ; + } + + tRes.tested("replaceByIndex()", result); + } +} + + diff --git a/qadevOOo/tests/java/ifc/container/_XNameAccess.java b/qadevOOo/tests/java/ifc/container/_XNameAccess.java new file mode 100644 index 000000000..765fb8fcd --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XNameAccess.java @@ -0,0 +1,149 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import lib.MultiMethodTest; + +import com.sun.star.container.NoSuchElementException; +import com.sun.star.container.XNameAccess; + +/** +* Testing <code>com.sun.star.container.XNameAccess</code> interface methods. <p> +* Test is <b> NOT </b> multithread compliant. <p> +*/ +public class _XNameAccess extends MultiMethodTest { + public XNameAccess oObj = null; + public String[] Names = null; + + /** + * Test calls the method and checks return value and that + * no exceptions were thrown. <p> + * Has <b> OK </b> status if the method successfully returns + * not null value and no exceptions were thrown. <p> + */ + public void _getElementNames() { + boolean result = true; + log.println("getting elements names"); + Names = oObj.getElementNames(); + + result = (Names != null); + tRes.tested("getElementNames()", result); + } // end getElementNames() + + /** + * First test calls the method with existing element name, + * then with non existing. <p> + * Has <b> OK </b> status if in the first case the method returns + * true and in the second - false. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> getElementNames </code> : to retrieve at least one + * element name. </li> + * </ul> + */ + public void _hasByName() { + requiredMethod("getElementNames()"); + log.println("testing hasByName() ..."); + + boolean result = true; + boolean loc_result = true; + + String name = null; + + if (Names.length != 0) { + name = Names[0]; + log.println("testing hasByName() with valid name '" + name + "'"); + loc_result = oObj.hasByName(name); + log.println("hasByName with valid names: " + loc_result); + result &= loc_result; + } + + name = "non_existent_name__1234"; + log.println("testing hasByName() with invalid name"); + try { + loc_result = !oObj.hasByName(name); + } catch ( Exception nsee) { + log.println("Expected exception was thrown"); + } + log.println("hasByName with invalid names: " + loc_result); + result &= loc_result; + + tRes.tested("hasByName()", result); + } // end hasByName() + + + /** + * First test calls the method with existing element name, + * then with non existing. <p> + * Has <b> OK </b> status if in the first case the method returns + * not null value and no exceptions were thrown, + * and in the second case <code>NoSuchElementException</code> was + * thrown. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> getElementNames </code> : to retrieve at least one + * element name. </li> + * </ul> + */ + public void _getByName() { + log.println("require getElementNames() ..."); + requiredMethod("getElementNames()"); + log.println("require getElementNames() ...OK"); + log.println("testing getByName() ..."); + + boolean result = true; + boolean loc_result = true; + + String name = null; + + if (Names.length != 0) { + name = Names[0]; + log.println("testing with valid name '" + name + "'"); + try { + loc_result = (null != oObj.getByName(name)); + } catch (Exception e) { + log.println("Exception! - FAILED"); + log.println(e.toString()); + loc_result = false; + } + log.println("getByName with valid name: " + loc_result); + result &= loc_result; + } + + log.println("testing with non-existent name"); + name = "non_existent_name__1234"; + try { + loc_result = (null != oObj.getByName(name)); + loc_result = false; + log.println("getByName: Exception expected - FAILED"); + } catch (NoSuchElementException e) { + log.println("getByName: Expected exception - OK"); + loc_result = true; + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("getByName: Wrong exception - " + e + " - FAILED"); + loc_result = false; + } + + result &= loc_result; + tRes.tested("getByName()", result); + } // end getByName() +} /// finished class _XNameAccess + + + diff --git a/qadevOOo/tests/java/ifc/container/_XNameContainer.java b/qadevOOo/tests/java/ifc/container/_XNameContainer.java new file mode 100644 index 000000000..45a1b2c92 --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XNameContainer.java @@ -0,0 +1,245 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import com.sun.star.container.NoSuchElementException; +import com.sun.star.container.XNameContainer; +import lib.MultiMethodTest; +import lib.StatusException; + +/** +* Testing <code>com.sun.star.container.XNameContainer</code> +* interface methods : +* <ul> +* <li><code> insertByName()</code></li> +* <li><code> removeByName()</code></li> +* </ul> +* This test needs the following object relations : +* <ul> +* <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> : N relations +* which represents objects to be inserted. See below +* for more information.</li> +* <li> <code>'XNameContainerINDEX'</code> : For internal test +* usage. Contains current thread number. </li> +* <li> <code>'XNameContainer.AllowDuplicateNames'</code> <b>optional</b>: +* if this relation exists then container elements can have duplicate +* names. </li> +* <li> Test environment variable <code>'THRCNT'</code> : number +* of interface threads running concurrently. </li> +* <ul> <p> +* XNameContainer needs n ObjectRelations "INSTANCEn" , where n=1, ..., THRCNT. +* +* When this interface tested by different threads, it must use different +* instances to insert/remove - one for each thread. +* +* That's why we use objRelation "XNameContainerINDEX" to store the number of +* last taken instance. If there is no such relation, it initialize with 1. +* +* If you insert the same Object by insertByName() several times you +* don't insert the Object several times. The first insertByName() inserts +* the Object to the Container but all other insertByName() changes +* the Name in the Container because it's the same Object. +* @see com.sun.star.container.XNameContainer +*/ + +public class _XNameContainer extends MultiMethodTest { + public XNameContainer oObj = null; + String Name = "XNameContainer"; + + /** + * First inserts object by name (different objects for different threads) + * and checks if it exists. Second, if duplicate names are not allowed + * test tries to insert element with the same name and checks for + * proper exception. Third, tries to add <code>null</code> element and + * checks for proper exception. <p> + * Has <b>OK</b> status if in the first case element added exists in + * the container, in the second case <code>ElementExistException</code> + * is thrown, and in the third case <code>IllegalArgumentException</code> + * is thrown. + */ + public void _insertByName() { + boolean result = true; + int Index = 0; + + //get for every thread its own Object to insert it + log.println("get ObjRelation(\"XNameContainerINDEX\")"); + String sIndex = null ; + synchronized (tEnv) { + sIndex = (String)tEnv.getObjRelation("XNameContainerINDEX"); + if (sIndex == null) { + log.println("No XNameContainerINDEX - so set it to 1."); + tEnv.addObjRelation("XNameContainerINDEX",Integer.toString(1)); + Index = 1; + } else { + Index = Integer.parseInt(sIndex); + Index++; + tEnv.addObjRelation("XNameContainerINDEX", + Integer.toString(Index)); + } + } + Name += Index ; + + log.println("get ObjRelation(\"INSTANCE" + Index +"\")"); + Object oInstance = tEnv.getObjRelation("INSTANCE"+ Index); + log.println("ObjRelation(\"INSTANCE" + Index +"\") Object n.a."); + + log.println("testing insertByName(\""+Name+"\")..."); + try { + String[] names = oObj.getElementNames() ; + log.println("Element names :") ; + for (int i = 0; i<names.length; i++) { + log.println(" '" + names[i] + "'") ; + } + + oObj.insertByName(Name, oInstance); + + names = oObj.getElementNames() ; + log.println("Element names :") ; + for (int i = 0; i<names.length; i++) { + log.println(" " + names[i]) ; + } + + result &= oObj.hasByName(Name) ; + log.println("insertByName(\""+Name+"\")...OK"); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("insertByName(\""+Name+"\"): " + e + " FALSE"); + result = false; + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("insertByName(\""+Name+"\"): " + e + " FALSE"); + result = false; + } catch (com.sun.star.container.ElementExistException e) { + log.println("insertByName(\""+Name+"\"): " + e + " FALSE"); + result = false; + } + + // if duplicate names is not allowed test for valid exception + if (tEnv.getObjRelation("XNameContainer.AllowDuplicateNames")==null) { + Object secondInstance = tEnv.getObjRelation("SecondInstance"); + if (secondInstance != null) { + oInstance = secondInstance; + } + log.println("Trying to add element with the same name ...") ; + try { + oObj.insertByName(Name, oInstance); + result = false ; + log.println("!!! No exception were thrown !!!"); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("!!! Wrong exception : " + e + " FALSE"); + result = false; + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("!!! Wrong exception : " + e + " FALSE"); + result = false; + } catch (com.sun.star.container.ElementExistException e) { + log.println("Right exception : " + e + " OK"); + } + } + + log.println("inserting a wrong Object occurs Exceptions ..."); + try { + Object dummy = null; + oObj.insertByName("Dummy", dummy); + log.println("No Exception: -> FALSE"); + result = false; + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Dummy-Exception: " + e + " -> OK"); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("!!! This exception not expected: " +e+ " -> FAILED"); + result = false; + } catch (com.sun.star.container.ElementExistException e) { + log.println("!!! This exception not expected: " +e+ " -> FAILED"); + result = false; + } + + tRes.tested("insertByName()", result); + + } // end insertByName() + + /** + * Test removes element inserted before and checks if element + * still exists in the container. Second test tries to remove + * element with non-existing name and checks for proper exception. <p> + * Has <b> OK </b> status if in the first case element doesn't + * exist anymore (or duplicate names are allowed), and in the + * second case <code>NoSuchElementException</code> is thrown. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> insertByName() </code> : to remove the element inserted + * in this test. </li> + * </ul> + */ + public void _removeByName() { + try { + requiredMethod("insertByName()"); + } catch (StatusException e) { + // removing the name anywhere + try { + oObj.removeByName(Name); + } catch (com.sun.star.container.NoSuchElementException e1) { + } catch (com.sun.star.lang.WrappedTargetException e1) { + } + } + + boolean result = true; + + log.println("testing removeByName() ..."); + + try { + log.println("remove " + Name); + String[] names = oObj.getElementNames() ; + log.println("Element names :") ; + for (int i = 0; i<names.length; i++) { + log.println(" " + names[i]) ; + } + oObj.removeByName(Name); + boolean loc_res = !oObj.hasByName(Name) || tEnv.getObjRelation + ("XNameContainer.AllowDuplicateNames") != null ; + result &= loc_res ; + if (loc_res) + log.println("1. removeByName(\""+Name+"\") ...OK"); + else + log.println("1. !!! Container still has element with name " + + Name) ; + } catch (com.sun.star.lang.WrappedTargetException e) { + result = false; + log.println("1. removeByName:(\""+Name+"\") " + e + " - FAILED"); + } catch (com.sun.star.container.NoSuchElementException e) { + result = false; + log.println("1. removeByName:(\""+Name+"\") " + e + " - FAILED"); + } + + log.println("removing a non existent object to get an exception"); + try { + oObj.removeByName(Name+ " dummy"); + result = false; + log.println("2. removeByName(): Exception expected! - FAILED"); + } catch (NoSuchElementException e) { + log.println("2. removeByName(): Expected exception - OK"); + result &= true; + } catch (com.sun.star.lang.WrappedTargetException e) { + result = false; + log.println("2. removeByName(): Unexpected exception! - " + + e + " - FAILED"); + } + + tRes.tested("removeByName()", result); + } // end removeByName() +} //XNameContainer + + + diff --git a/qadevOOo/tests/java/ifc/container/_XNameReplace.java b/qadevOOo/tests/java/ifc/container/_XNameReplace.java new file mode 100644 index 000000000..d0ca70971 --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XNameReplace.java @@ -0,0 +1,216 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import com.sun.star.sheet.XCellRangeAddressable; +import lib.MultiMethodTest; +import util.ValueComparer; + +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XNameReplace; +import com.sun.star.uno.UnoRuntime; +/** +* Testing <code>com.sun.star.container.XNameReplace</code> +* interface methods : +* <ul> +* <li><code> replaceByName()</code></li> +* </ul> +* This test needs the following object relations : +* <ul> +* <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> : N relations +* which represents objects to be replaced with. See below +* for more information.</li> +* <li> <code>'NAMEREPLACE'</code> <b>optional</b>: <code>String</code> +* relation which represents element name to be replaced. +* Some Objects can't replace the first that comes along, i.e. +* SwXStyleFamily. It has some pool styles which can't be replaced. +* So the test need a special object to replace it by name. </li> +* <li> <code>'XNameReplaceINDEX'</code> : For internal test +* usage. Contains current thread number. </li> +* <li> Test environment variable <code>'THRCNT'</code> : number +* of interface threads running concurrently. </li> +* <ul> <p> +* XNameReplace needs n ObjectRelations "INSTANCEn" , where n = 1, ..., THRCNT. +* <p> +* When this interface tested by different threads, it must use different instances +* to replace - one for each thread. +* <p> +* That's why we use objRelation "XNameReplaceINDEX" to store the number of last +* taken instance. If there is no such relation, it initialize with 1. +* <p> +* In one of the last steps the replaced object will be compared with the old +* object. For that it is necessary that every thread replace its own object. +* INSTANCEn are n Objectrelations so that every thread can insert its own +* object. n depends on the variable THRCNT which and comes from API.INI +* Some Object-Container can't replace the first that comes belong. So in +* NAMEREPLACE you can determine a container object, which is replaceable. <p> +* +* Test is <b> NOT </b> multithread compliant. <p> +* After test completion object environment has to be recreated. +* @see com.sun.star.container.XNameReplace +*/ +public class _XNameReplace extends MultiMethodTest { + + public XNameReplace oObj = null; + + /** + * First test retrieves instance to be replaced with for each interface thread. + * Then list of element names is retrieved, the first of them will + * be replaced. In special case when <code>'NAMEREPLACE'</code> relation + * exists, element with the specified name is replaced. + * Test replaces element and checks values of element with the + * specified name before and after replacement. <p> + * Has <b>OK</b> status if values before and after replacement are + * different. + */ + public void _replaceByName(){ + boolean result = true; + String[] oNames = null; + + int Index = 0; + + //get for every thread its own Object to insert it + log.println("get ObjRelation(\"XNameReplaceINDEX\")"); + String sIndex = (String)tEnv.getObjRelation("XNameReplaceINDEX"); + System.out.println("Index: "+sIndex); + if (sIndex == null) { + log.println("No XNameReplaceINDEX - so set it to 1."); + tEnv.addObjRelation("XNameReplaceINDEX", Integer.toString(1)); + Index = 1; + } else { + Index = Integer.parseInt(sIndex); + Index++; + tEnv.addObjRelation("XNameReplaceINDEX", Integer.toString(Index)); + } + + log.println("get ObjRelation(\"INSTANCE" + Index +"\")"); + Object oInstance = tEnv.getObjRelation("INSTANCE"+ Index); + if (oInstance == null) { + log.println("ObjRelation(\"INSTANCE" + Index +"\") Object n.a."); + } + + log.println("getting the existing object's name"); + XNameAccess oNameAccess = UnoRuntime.queryInterface( + XNameAccess.class, oObj); + oNames = oNameAccess.getElementNames(); + /* Some Objects can't replace the first that comes along, i.e. + SwXStyleFamily. It has some pool styles which can't be replaced. + So the test need a special object to replace it by name. + */ + log.println("get ObjRelation(\"NAMEREPLACE\")"); + Object oNameReplace = tEnv.getObjRelation("NAMEREPLACE"); + if (oNameReplace != null) { + oNames[0] = oNameReplace.toString(); + } + + log.println("replaceByName()"); + try { + boolean ok; + log.println("get current object '" + oNames[0] + "'"); + Object old = oObj.getByName(oNames[0]) ; + log.println("replace object '" + oNames[0] + "' with another instance"); + oObj.replaceByName(oNames[0],oInstance); + Object newEl = oObj.getByName(oNames[0]) ; + + if (tEnv.getTestCase().getObjectName().equals("ScCellRangesObj")) { + ok = compareRanges(old, newEl); + } else { + ok = ! ValueComparer.equalValue(old, newEl); + } + result &= ok; + log.println("result of replace: " + ok); + log.println("replace back the old object"); + oObj.replaceByName(oNames[0],old); + Object origEl = oObj.getByName(oNames[0]) ; + + if (tEnv.getTestCase().getObjectName().equals("ScCellRangesObj")) { + ok = ! compareRanges(old, origEl); + } else { + ok = ValueComparer.equalValue(old, origEl); + } + + result &= ok; + log.println("result of replace back: " + ok); + } catch (com.sun.star.lang.IllegalArgumentException e ) { + result = false; + e.printStackTrace(log) ; + } catch (com.sun.star.container.NoSuchElementException e ) { + result = false; + e.printStackTrace(log) ; + } catch (com.sun.star.lang.WrappedTargetException e ) { + result = false; + e.printStackTrace(log) ; + } + + tRes.tested("replaceByName()", result); + + } // end replaceByName() + + /** + * Forces object environment recreation. + */ + @Override + public void after() { + disposeEnvironment() ; + } + + // method returns false if the ranges are equal and true otherwise + + private boolean compareRanges(Object old, Object newEl) { + XCellRangeAddressable xCRA = UnoRuntime.queryInterface(XCellRangeAddressable.class,old); + + XCellRangeAddressable xCRA2 = UnoRuntime.queryInterface(XCellRangeAddressable.class,newEl); + + int orgStartCol = xCRA.getRangeAddress().StartColumn; + int orgEndCol = xCRA.getRangeAddress().EndColumn; + int orgStartRow = xCRA.getRangeAddress().StartRow; + int orgEndRow = xCRA.getRangeAddress().EndRow; + + int newStartCol = xCRA2.getRangeAddress().StartColumn; + int newEndCol = xCRA2.getRangeAddress().EndColumn; + int newStartRow = xCRA2.getRangeAddress().StartRow; + int newEndRow = xCRA2.getRangeAddress().EndRow; + + boolean ret = true; + + if (orgStartCol == newStartCol) { + log.println("\t StartColumn is the same"); + ret = false; + } + + if (orgEndCol == newEndCol) { + log.println("\t EndColumn is the same"); + ret = false; + } + if (orgStartRow == newStartRow) { + log.println("\t StartRow is the same"); + ret = false; + } + + if (orgEndRow == newEndRow) { + log.println("\t EndRow is the same"); + ret = false; + } + + return ret; + } + +} + + diff --git a/qadevOOo/tests/java/ifc/container/_XNamed.java b/qadevOOo/tests/java/ifc/container/_XNamed.java new file mode 100644 index 000000000..054306f40 --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XNamed.java @@ -0,0 +1,156 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package ifc.container; + +import com.sun.star.container.XNamed; + +import lib.MultiMethodTest; + +import util.utils; + + +/** +* Testing <code>com.sun.star.container.XNamed</code> +* interface methods : +* <ul> +* <li><code> getName()</code></li> +* <li><code> setName()</code></li> +* </ul> +* This test need the following object relations : +* <ul> +* <li> <code>'setName'</code> : of <code>Boolean</code> +* type. If it exists then <code>setName</code> method +* isn't to be tested and result of this test will be +* equal to relation value.</li> +* <ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.container.XNamed +*/ +public class _XNamed extends MultiMethodTest { + public XNamed oObj = null; // oObj filled by MultiMethodTest + + /** + * Test calls the method and checks return value and that + * no exceptions were thrown. <p> + * Has <b> OK </b> status if the method returns non null value + * and no exceptions were thrown. <p> + */ + public void _getName() { + // write to log what we try next + log.println("test for getName()"); + + boolean result = true; + boolean loc_result = true; + String name = null; + + loc_result = ((name = oObj.getName()) != null); + log.println("getting the name \"" + name + "\""); + + if (loc_result) { + log.println("... getName() - OK"); + } else { + log.println("... getName() - FAILED"); + } + + result &= loc_result; + tRes.tested("getName()", result); + } + + /** + * Sets a new name for object and checks if it was properly + * set. Special cases for the following objects : + * <ul> + * <li><code>ScSheetLinkObj</code> : name must be in form of URL.</li> + * <li><code>ScDDELinkObj</code> : name must contain link to cell in + * some external Sheet.</li> + * </ul> + * Has <b> OK </b> status if new name was successfully set, or if + * object environment contains relation <code>'setName'</code> with + * value <code>true</code>. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> getName() </code> : to be sure the method works</li> + * </ul> + */ + public void _setName() { + String Oname = tEnv.getTestCase().getObjectName(); + String nsn = (String) tEnv.getObjRelation("NoSetName"); + + if (nsn != null) { + Oname = nsn; + } + + if ((Oname.indexOf("Exporter") > 0) || (nsn != null)) { + log.println("With " + Oname + " setName() doesn't work"); + log.println("see idl-file for further information"); + tRes.tested("setName()", true); + + return; + } + + requiredMethod("getName()"); + log.println("testing setName() ... "); + + String oldName = oObj.getName(); + String NewName = (oldName == null) ? "XNamed" : oldName + "X"; + + String testobjname = tEnv.getTestCase().getObjectName(); + + if (testobjname.equals("ScSheetLinkObj")) { + // special case, here name is equals to links URL. + NewName = "file:///c:/somename/from/XNamed"; + } else if (testobjname.equals("ScDDELinkObj")) { + String fileName = utils.getFullTestDocName("ScDDELinksObj.ods"); + NewName = "soffice|" + fileName + "!Sheet1.A2"; + } else if (testobjname.equals("SwXAutoTextGroup")) { + //This avoids a GPF + NewName = "XNamed*1"; + } + + boolean result = true; + boolean loc_result = true; + Boolean sName = (Boolean) tEnv.getObjRelation("setName"); + + if (sName == null) { + log.println("set the name of object to \"" + NewName + "\""); + oObj.setName(NewName); + log.println("check that container has element with this name"); + + String name = oObj.getName(); + log.println("getting the name \"" + name + "\""); + loc_result = name.equals(NewName); + + if (loc_result) { + log.println("... setName() - OK"); + } else { + log.println("... setName() - FAILED"); + } + + result &= loc_result; + oObj.setName(oldName); + } else { + log.println("The names for the object '" + testobjname + + "' are fixed."); + log.println("It is not possible to rename."); + log.println("So 'setName()' is always OK"); + result = sName.booleanValue(); + } + + tRes.tested("setName()", result); + } +} diff --git a/qadevOOo/tests/java/ifc/container/_XSet.java b/qadevOOo/tests/java/ifc/container/_XSet.java new file mode 100644 index 000000000..743a894f5 --- /dev/null +++ b/qadevOOo/tests/java/ifc/container/_XSet.java @@ -0,0 +1,141 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.container; + +import lib.MultiMethodTest; + +import com.sun.star.container.XSet; +import com.sun.star.lang.XMultiServiceFactory; + +/** +* Testing <code>com.sun.star.container.XSet</code> +* interface methods : +* <ul> +* <li><code> has()</code></li> +* <li><code> insert()</code></li> +* <li><code> remove()</code></li> +* </ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.container.XSet +*/ +public class _XSet extends MultiMethodTest { + + public static XSet oObj = null; + + private Object element = null ; + private boolean hasResult = true ; + + /** + * Inserts the element stored and removed before. <p> + * Has <b> OK </b> status if <code>has()</code> method returns + * <code>true</code>. + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> remove() </code> : element from set is stored and + * removed </li> + * </ul> + */ + public void _insert() { + boolean res = true ; + try { + XMultiServiceFactory xMSF = tParam.getMSF(); + element = xMSF.createInstance( + "com.sun.star.reflection.TypeDescriptionProvider"); + + + oObj.insert(element) ; + + if (!oObj.has(element)) { + res = false ; + log.println("After adding element method has()" + + " returned false") ; + hasResult = false ; + } + } catch (com.sun.star.container.ElementExistException e) { + e.printStackTrace(log) ; + res = false ; + } catch (com.sun.star.lang.IllegalArgumentException e) { + e.printStackTrace(log) ; + res = false ; + } + catch(com.sun.star.uno.Exception e) { + e.printStackTrace(log); + res = false; + } + + tRes.tested("insert()", res) ; + } + + /** + * Through <code>XEnumeration</code> interface an element from the set + * is retrieved. Then this element removed.<p> + * Has <b> OK </b> status if after removing <code>has()</code> method + * returns false. + */ + public void _remove() { + requiredMethod("insert()"); + boolean res = true ; + + try { + + // get an element to be removed/inserted + + oObj.remove(element) ; + + if (oObj.has(element)) { + res = false ; + log.println("After removing element method has()" + + " returned true") ; + hasResult = false ; + } + + + + } catch (com.sun.star.container.NoSuchElementException e) { + e.printStackTrace(log) ; + res = false ; + } catch (com.sun.star.lang.IllegalArgumentException e) { + e.printStackTrace(log) ; + res = false ; + } + + tRes.tested("remove()", res) ; + } + + /** + * Does nothing. Testing performed in previous methods.<p> + * Has <b> OK </b> status if after <code>remove()</code> call + * methods returned <code>false</code>, and after <code>remove()</code> + * call methods returned <code>true</code>. + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> insert() </code> : here the method is checked </li> + * <li> <code> remove() </code> : here the method is checked </li> + * </ul> + */ + public void _has() { + + requiredMethod("insert()") ; + requiredMethod("remove()") ; + + tRes.tested("has()", hasResult) ; + } + +} // finished class _XSet + |