diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /qadevOOo/tests/java/ifc/document | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream.tar.xz libreoffice-upstream.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
17 files changed, 1488 insertions, 0 deletions
diff --git a/qadevOOo/tests/java/ifc/document/_ExportFilter.java b/qadevOOo/tests/java/ifc/document/_ExportFilter.java new file mode 100644 index 000000000..7fcbdb711 --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_ExportFilter.java @@ -0,0 +1,42 @@ +/* + * 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.document; + +import lib.MultiPropertyTest; + +/** +* Testing <code>com.sun.star.document.ExportFilter</code> +* service properties : +* <ul> +* <li><code> Type</code></li> +* <li><code> UIName</code></li> +* <li><code> DocumentService</code></li> +* <li><code> FilterService</code></li> +* <li><code> Flags</code></li> +* <li><code> UserData</code></li> +* <li><code> FileFormatVersion</code></li> +* <li><code> TemplateName</code></li> +* </ul> <p> +* Properties testing is automated by <code>lib.MultiPropertyTest</code>. +* @see com.sun.star.document.ExportFilter +*/ +public class _ExportFilter extends MultiPropertyTest { + +} + diff --git a/qadevOOo/tests/java/ifc/document/_ImportFilter.java b/qadevOOo/tests/java/ifc/document/_ImportFilter.java new file mode 100644 index 000000000..aef27e02d --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_ImportFilter.java @@ -0,0 +1,43 @@ +/* + * 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.document; + +/** +* Testing <code>com.sun.star.document.ImportFilter</code> +* service properties : +* <ul> +* <li><code> Type</code></li> +* <li><code> UIName</code></li> +* <li><code> DocumentService</code></li> +* <li><code> FilterService</code></li> +* <li><code> Flags</code></li> +* <li><code> UserData</code></li> +* <li><code> FileFormatVersion</code></li> +* <li><code> TemplateName</code></li> +* </ul> <p> +* Properties testing is automated by <code>lib.MultiPropertyTest</code>. +* @see com.sun.star.document.ImportFilter +*/ +import lib.MultiPropertyTest; + +public class _ImportFilter extends MultiPropertyTest { + + +} + diff --git a/qadevOOo/tests/java/ifc/document/_LinkTarget.java b/qadevOOo/tests/java/ifc/document/_LinkTarget.java new file mode 100644 index 000000000..f39c5d694 --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_LinkTarget.java @@ -0,0 +1,66 @@ +/* + * 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.document; + +import lib.MultiPropertyTest; + +/** +* Testing <code>com.sun.star.document.LinkTarget</code> +* service properties : +* <ul> +* <li><code> LinkDisplayName </code></li> +* </ul> <p> +* Properties testing is automated by <code>lib.MultiPropertyTest</code>. +* @see com.sun.star.document.LinkTarget +*/ +public class _LinkTarget extends MultiPropertyTest { + +/* + public XPropertySet oObj = null; // oObj filled by MultiMethodTest + + public void _LinkDisplayName() { + // check if Service is available + XServiceInfo xInfo = (XServiceInfo) + UnoRuntime.queryInterface(XServiceInfo.class, oObj); + String [] sa = xInfo.getSupportedServiceNames(); + + for (int i = 0; i < sa.length; i++) { + System.out.println(sa[i]); + } + + if ( ! xInfo.supportsService("com.sun.star.document.LinkTarget")) { + log.println("Service not available !!!!!!!!!!!!!"); + tRes.tested("Supported", false); + } + //the only property is read only + try { + String LDN = (String) oObj.getPropertyValue("LinkDisplayName"); + tRes.tested("LinkDisplayName",LDN!=null); + } + catch (Exception ex) { + log.println("Exception occurred during LinkDisplayName"); + ex.printStackTrace(log); + tRes.tested("LinkDisplayName",false); + } + + }// EOF LinkDisplayName +*/ + +} + diff --git a/qadevOOo/tests/java/ifc/document/_OfficeDocument.java b/qadevOOo/tests/java/ifc/document/_OfficeDocument.java new file mode 100644 index 000000000..7b1c2abde --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_OfficeDocument.java @@ -0,0 +1,36 @@ +/* + * 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.document; + +import lib.MultiPropertyTest; + +/** +* Testing <code>com.sun.star.document.OfficeDocument</code> +* service properties : +* <ul> +* <li><code> AutomaticControlFocus</code></li> +* <li><code> ApplyFormDesignMode</code></li> +* </ul> <p> +* Properties testing is automated by <code>lib.MultiPropertyTest</code>. +* @see com.sun.star.document.OfficeDocument +*/ +public class _OfficeDocument extends MultiPropertyTest { + +} + diff --git a/qadevOOo/tests/java/ifc/document/_Settings.java b/qadevOOo/tests/java/ifc/document/_Settings.java new file mode 100644 index 000000000..a0b0f87b6 --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_Settings.java @@ -0,0 +1,160 @@ +/* + * 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.document; + +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.i18n.XForbiddenCharacters; +import com.sun.star.uno.UnoRuntime; +import java.lang.reflect.Method; + +import lib.MultiPropertyTest; +import lib.Status; +import lib.StatusException; + + +/* + * Generic test for all properties contained in this service + */ +public class _Settings extends MultiPropertyTest { + + /** + * This property accepts only values in a range of 1-3 + * @see com.sun.star.document.PrinterIndependentLayout + */ + public void _PrinterIndependentLayout() { + try{ + Short oldVal = (Short) oObj.getPropertyValue("PrinterIndependentLayout"); + Short newVal = oldVal.intValue() == 1 ? Short.valueOf("3") : Short.valueOf("1"); + + + testProperty("PrinterIndependentLayout", oldVal, newVal); + + } catch (com.sun.star.beans.UnknownPropertyException e) { + throw new StatusException(e, Status.failed("the property 'PrinterIndependentLayout' is unknown.")); + } catch (com.sun.star.lang.WrappedTargetException e) { + throw new StatusException(e, Status.failed("the property 'PrinterIndependentLayout' could not be tested.")); + } + } + + public void _PrinterName() { + Object[] oServices = null; + Exception ex = null; + + try { + Class<?> cPrinterJob = Class.forName("java.awt.print.PrinterJob"); + Method lookupMethod = cPrinterJob.getDeclaredMethod("lookupPrintServices", new Class[0]); + Object retValue = lookupMethod.invoke(cPrinterJob, new Object[0]); + oServices = (Object[])retValue; + } + catch(java.lang.ClassNotFoundException e) { + ex = e; + } + catch(java.lang.NoSuchMethodException e) { + ex = e; + } + catch(java.lang.IllegalAccessException e) { + ex = e; + } + catch(java.lang.reflect.InvocationTargetException e) { + ex = e; + } + + if (ex != null) { + // get Java version: + String javaVersion = System.getProperty("java.version"); + throw new StatusException(Status.failed( + "Cannot execute test with current Java version (Java 1.4 required) " + + javaVersion + ": " + ex.getMessage())); + } + + if (oServices.length > 1) { + testProperty("PrinterName", getPrinterNameWithReflection(oServices[0]), + getPrinterNameWithReflection(oServices[1])); + } else { + log.println( + "checking this property needs at least two printers to be installed on your system"); + throw new StatusException(Status.failed( + "only one printer installed so I can't change it")); + } + } + + public void _ForbiddenCharacters() { + boolean res = true; + + try { + //check if it is read only as specified + res &= isReadOnly("ForbiddenCharacters"); + + if (!isReadOnly("ForbiddenCharacters")) { + log.println( + "The Property 'ForbiddenCharacters' isn't readOnly as specified"); + } + + //check if the property has the right type + Object pValue = oObj.getPropertyValue("ForbiddenCharacters"); + XForbiddenCharacters fc = UnoRuntime.queryInterface( + XForbiddenCharacters.class, + pValue); + res &= (fc != null); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println( + "Exception while checking property 'ForbiddenCharacters' " + + e.getMessage()); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println( + "Exception while checking property 'ForbiddenCharacters' " + + e.getMessage()); + } + + tRes.tested("ForbiddenCharacters", res); + } + + protected boolean isReadOnly(String PropertyName) { + boolean res = false; + Property[] props = oObj.getPropertySetInfo().getProperties(); + + for (int i = 0; i < props.length; i++) { + if (props[i].Name.equals(PropertyName)) { + res = ((props[i].Attributes & PropertyAttribute.READONLY) != 0); + } + } + + return res; + } + + private String getPrinterNameWithReflection(Object pService) { + String pName = null; + try { + Class<?> cPrintService = Class.forName("javax.print.PrintService"); + Method getNameMethod = cPrintService.getDeclaredMethod("getName", new Class[0]); + Object retValue = getNameMethod.invoke(pService, new Object[0]); + pName = (String)retValue; + } + // ignore all exceptions: we already ran into one of these if Java is too old + catch(java.lang.ClassNotFoundException e) { + } + catch(java.lang.NoSuchMethodException e) { + } + catch(java.lang.IllegalAccessException e) { + } + catch(java.lang.reflect.InvocationTargetException e) { + } + return pName; + } +} diff --git a/qadevOOo/tests/java/ifc/document/_XActionLockable.java b/qadevOOo/tests/java/ifc/document/_XActionLockable.java new file mode 100644 index 000000000..8276eb62a --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_XActionLockable.java @@ -0,0 +1,100 @@ +/* + * 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.document; + +import lib.MultiMethodTest; + +import com.sun.star.document.XActionLockable; + +/** +* Testing <code>com.sun.star.document.XActionLockable</code> +* interface methods : +* <ul> +* <li><code> isActionLocked()</code></li> +* <li><code> addActionLock()</code></li> +* <li><code> removeActionLock()</code></li> +* <li><code> setActionLocks()</code></li> +* <li><code> resetActionLocks()</code></li> +* </ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.document.XActionLockable +*/ +public class _XActionLockable extends MultiMethodTest { + public XActionLockable oObj = null; + + /** + * Method addActionLock called first and then + * checked value returned by isActionLocked().<p> + * Has <b> OK </b> status if no runtime exceptions occurred + * and returned value is true. + */ + public void _isActionLocked() { + //determines if at least one lock exists + oObj.addActionLock(); + boolean result = oObj.isActionLocked(); + tRes.tested("isActionLocked()", result); + } + + /** + * Just calls the method. <p> + * Has <b> OK </b> status if no runtime exceptions occurred + */ + public void _addActionLock() { + requiredMethod("resetActionLocks()"); + oObj.addActionLock(); + tRes.tested("addActionLock()", true); + } + + /** + * Calls the method and check value returned by isActionLocked(). <p> + * Has <b> OK </b> status if no runtime exceptions occurred + * and returned value is false. + */ + public void _removeActionLock() { + requiredMethod("addActionLock()"); + oObj.removeActionLock(); + boolean result = ! oObj.isActionLocked(); + tRes.tested("removeActionLock()", result); + } + + /** + * Calls the method with specific value. <p> + * Has <b> OK </b> status if no runtime exceptions occurred + */ + public void _setActionLocks() { + oObj.setActionLocks( nLock ); + tRes.tested("setActionLocks()", true); + } + + static final short nLock = 8; + + /** + * Calls the method and checks returned value.<p> + * Has <b> OK </b> status if the component is not currently + * locked and returned value is the same as locks number + * set by <code>setActionLocks</code> method test. + */ + public void _resetActionLocks() { + requiredMethod("setActionLocks()"); + short nLocksBeforeReset = oObj.resetActionLocks(); + boolean result = !oObj.isActionLocked() && nLocksBeforeReset == nLock; + tRes.tested("resetActionLocks()", result); + } +}// finish class _XActionLockable + diff --git a/qadevOOo/tests/java/ifc/document/_XDocumentInsertable.java b/qadevOOo/tests/java/ifc/document/_XDocumentInsertable.java new file mode 100644 index 000000000..c3417118e --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_XDocumentInsertable.java @@ -0,0 +1,190 @@ +/* + * 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.document; + +import com.sun.star.io.IOException; +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; +import util.utils; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.document.XDocumentInsertable; +import com.sun.star.text.XTextRange; +import com.sun.star.uno.UnoRuntime; + + +/** +* Testing <code>com.sun.star.document.XDocumentInsertable</code> +* interface methods : +* <ul> +* <li><code> insertDocumentFromURL()</code></li> +* </ul> <p> +* This test needs the following object relations : +* <ul> +* <li> <code>'XDocumentInsertable.Checker'</code> +* (of type <code>_XDocumentInsertable.InsertChecker</code>) +* <b> optional </b> : +* relation for checking if document was inserted properly and +* for obtaining document file name. For details see the class +* description. If the relation doesn't exist default document +* name is used, and <code>XTextRange</code> interface of +* component is used for checking.</li> +* <ul> <p> +* The following predefined files needed to complete the test: +* <ul> +* <li> <code>XDocumentInsertable.sxw</code> : StarWriter document +* which content started with 'XDocumentInsertable test.' string. +* The file is needed if no other file name specified by relation. +* </li> +* <ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.document.XDocumentInsertable +*/ +public class _XDocumentInsertable extends MultiMethodTest { + + public XDocumentInsertable oObj = null; + protected XTextRange range = null ; + protected static final String defaultFileName = "XDocumentInsertable.sxw" ; + protected InsertChecker checker = null ; + protected String fileName = defaultFileName ; + + /** + * Abstract class for relation passing. It must check if + * document was inserted successfully and can specify its + * own document name to be inserted. + */ + public static abstract class InsertChecker { + /** + * Must be overridden to check if document was + * successfully inserted. + * @return <code>true</code> if document was inserted. + */ + public abstract boolean isInserted() ; + /** + * Can be overridden to specify different than default + * document name. This document must be situated in + * the test document directory, and its name must + * be specified relational to this directory. By + * default 'XDocumentInsertable.swx' file name returned. + * @return File name of the document to be inserted. + */ + public String getFileNameToInsert() { + return defaultFileName ; + } + } + + /** + * Retrieves object relation. If the relation is not found + * then the object tested is tried to query <code>XTextRange</code> + * interface for testing. If the relation is found then document name + * for testing is retrieved, else the default one is used. + * + * @throws StatusException If neither relation found nor + * <code>XTextRange</code> interface is queried. + */ + @Override + public void before() { + checker = (InsertChecker) + tEnv.getObjRelation("XDocumentInsertable.Checker") ; + + if (checker == null) { + log.println("Relation not found, trying to query for "+ + "XTextRange ...") ; + range = UnoRuntime.queryInterface (XTextRange.class, oObj) ; + if (range == null) { + log.println("XTextRange isn't supported by the component."); + throw new StatusException(Status.failed + ("XTextRange isn't supported and relation not found")) ; + } + } else { + fileName = checker.getFileNameToInsert(); + } + } + + /** + * Tries to insert document from URL specified by relation or + * from default URL. If no relation was passed, text range is + * checked for existence of loaded document content. In case + * if relation was found, then its <code>isInserted</code> + * method is used to check insertion.<p> + * A Second test uses an invalid URL and checks for correct exceptions. + * + * Has <b> OK </b> status if at first insertion was completed successfully + * and no exceptions were thrown and as second an expected exception was thrown. <p> + */ + public void _insertDocumentFromURL() { + boolean result = true ; + + try { + PropertyValue [] szEmptyArgs = new PropertyValue [0]; + String docURL = utils.getFullTestURL(fileName) ; + log.println("Inserting document from URL '" + docURL + "'"); + oObj.insertDocumentFromURL(docURL, szEmptyArgs); + + if (checker == null) { + log.println("Checker is not specified, testing through "+ + "XTextRange ...") ; + String text = range.getString() ; + log.println("Document text :\n" + text); + log.println("---"); + result &= ( text.indexOf("XDocumentInsertable test.") >= 0 ); + } else { + result &= checker.isInserted(); + } + + } catch (com.sun.star.lang.IllegalArgumentException ex) { + log.println("Exception occurred while testing "+ + "insertDocumentFromURL()"); + ex.printStackTrace(log); + result = false ; + } catch (com.sun.star.io.IOException ex) { + log.println("Exception occurred while testing "+ + "insertDocumentFromURL()"); + ex.printStackTrace(log); + result = false ; + } + + if (result) { + try { + PropertyValue [] szEmptyArgs = new PropertyValue [0]; + String docURL = "file:///c:/ThisIsAnInvalidURL"; + log.println("Inserting document from URL '" + docURL + "'"); + oObj.insertDocumentFromURL(docURL, szEmptyArgs); + + result=false; + + } catch (IOException ex) { + log.println("expected exception was thrown -> ok"); + } catch (com.sun.star.lang.IllegalArgumentException ex) { + log.println("expected exception was thrown -> ok"); + } + } + + tRes.tested("insertDocumentFromURL()", result); + } + + /** + * Forces environment recreation. + */ + @Override + protected void after() { + disposeEnvironment(); + } +} // finish class _XDocumentInsertable diff --git a/qadevOOo/tests/java/ifc/document/_XEmbeddedObjectSupplier.java b/qadevOOo/tests/java/ifc/document/_XEmbeddedObjectSupplier.java new file mode 100644 index 000000000..63aa6f4bf --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_XEmbeddedObjectSupplier.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.document; + +import lib.MultiMethodTest; + +import com.sun.star.document.XEmbeddedObjectSupplier; + +/** +* Testing <code>com.sun.star.document.XEmbeddedObjectSupplier</code> +* interface methods : +* <ul> +* <li><code> getEmbeddedObject()</code></li> +* </ul> <p> +* Test is multithread compliant. <p> +* @see com.sun.star.document.XEmbeddedObjectSupplier +*/ +public class _XEmbeddedObjectSupplier extends MultiMethodTest { + + public XEmbeddedObjectSupplier oObj = null; + + /** + * Just calls the method. <p> + * Has <b> OK </b> status if not <code>null</code> value returned. + */ + public void _getEmbeddedObject() { + tRes.tested("getEmbeddedObject()", + oObj.getEmbeddedObject() != null); + } +} // finish class _XEmbeddedObjectSupplier + diff --git a/qadevOOo/tests/java/ifc/document/_XEventBroadcaster.java b/qadevOOo/tests/java/ifc/document/_XEventBroadcaster.java new file mode 100644 index 000000000..cc30c7ebb --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_XEventBroadcaster.java @@ -0,0 +1,74 @@ +/* + * 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.document; + +import lib.MultiMethodTest; + +import com.sun.star.document.XEventBroadcaster; +import com.sun.star.document.XEventListener; +import com.sun.star.frame.XController; +import com.sun.star.frame.XModel; +import com.sun.star.uno.UnoRuntime; + +public class _XEventBroadcaster extends MultiMethodTest { + + public XEventBroadcaster oObj; + protected boolean listenerCalled = false; + private XEventListener listener = null; + + public class MyEventListener implements XEventListener { + + public void disposing(com.sun.star.lang.EventObject eventObject) { + } + + public void notifyEvent(com.sun.star.document.EventObject eventObject) { + System.out.println("EventObject "+eventObject.EventName); + listenerCalled = true; + } + + } + + private void switchFocus() { + XModel docModel = UnoRuntime.queryInterface( + XModel.class,tEnv.getTestObject()); + docModel.getCurrentController().getFrame().getContainerWindow().setFocus(); + waitForEventIdle(); + XController xc = UnoRuntime.queryInterface(XController.class,tEnv.getObjRelation("CONT2")); + xc.getFrame().getContainerWindow().setFocus(); + } + + public void _addEventListener() { + listener = new MyEventListener(); + listenerCalled = false; + oObj.addEventListener(listener); + switchFocus(); + waitForEventIdle(); + tRes.tested("addEventListener()",listenerCalled); + } + + public void _removeEventListener() { + requiredMethod("addEventListener()"); + listenerCalled = false; + oObj.removeEventListener(listener); + switchFocus(); + waitForEventIdle(); + tRes.tested("removeEventListener()",!listenerCalled); + } + +} diff --git a/qadevOOo/tests/java/ifc/document/_XEventsSupplier.java b/qadevOOo/tests/java/ifc/document/_XEventsSupplier.java new file mode 100644 index 000000000..ee41f37c4 --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_XEventsSupplier.java @@ -0,0 +1,51 @@ +/* + * 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.document; + +import lib.MultiMethodTest; + +import com.sun.star.container.XNameReplace; +import com.sun.star.document.XEventsSupplier; + +/** +* Testing <code>com.sun.star.document.XEventsSupplier</code> +* interface methods : +* <ul> +* <li><code> getEvents()</code></li> +* </ul> <p> +* Test is multithread compliant. <p> +* @see com.sun.star.document.XEventsSupplier +*/ +public class _XEventsSupplier extends MultiMethodTest { + + public XEventsSupplier oObj = null; + + /** + * Just calls the method. <p> + * Has <b> OK </b> status if not <code>null</code> value returned. + */ + public void _getEvents() { + + XNameReplace xNR = oObj.getEvents(); + xNR.getElementNames(); + tRes.tested("getEvents()", true); + } + +} // finish class _XEventSupplier + diff --git a/qadevOOo/tests/java/ifc/document/_XExporter.java b/qadevOOo/tests/java/ifc/document/_XExporter.java new file mode 100644 index 000000000..067f8b5d5 --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_XExporter.java @@ -0,0 +1,82 @@ +/* + * 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.document; + + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + +import com.sun.star.document.XExporter; +import com.sun.star.lang.XComponent; + +/** +* Testing <code>com.sun.star.document.XExporter</code> +* interface methods : +* <ul> +* <li><code> setSourceDocument()</code></li> +* </ul> <p> +* This test needs the following object relations : +* <ul> +* <li> <code>'SourceDocument'</code> (of type <code>XComponent</code>): +* the source document to be passed to the method. </li> +* <ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.document.XExporter +*/ +public class _XExporter extends MultiMethodTest { + + public XExporter oObj = null; + public XComponent source = null ; + + /** + * Retrieves object relations. + * @throws StatusException If one of relations not found. + */ + @Override + public void before() { + source = (XComponent) tEnv.getObjRelation("SourceDocument") ; + + if (source == null) throw new StatusException(Status.failed + ("Relation not found")) ; + } + + /** + * Just calls the method. <p> + * Has <b> OK </b> status if no runtime exceptions occurred. + * Usually this interface is supported both with <code>XFilter</code> + * where source document setting is checked. + */ + public void _setSourceDocument() { + boolean result = true ; + + try { + oObj.setSourceDocument(source); + } + catch (com.sun.star.lang.IllegalArgumentException ex) { + log.println("Exception while checking :"); + ex.printStackTrace(log); + result = false; + } + + tRes.tested("setSourceDocument()", result) ; + } +} + + diff --git a/qadevOOo/tests/java/ifc/document/_XFilter.java b/qadevOOo/tests/java/ifc/document/_XFilter.java new file mode 100644 index 000000000..8ea1326bc --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_XFilter.java @@ -0,0 +1,177 @@ +/* + * 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.document; + + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.document.XExporter; +import com.sun.star.document.XFilter; +import com.sun.star.lang.XComponent; +import com.sun.star.uno.UnoRuntime; + +/** +* Testing <code>com.sun.star.document.XFilter</code> +* interface methods : +* <ul> +* <li><code> filter()</code></li> +* <li><code> cancel()</code></li> +* </ul> <p> +* This test needs the following object relations : +* <ul> +* <li> <code>'MediaDescriptor'</code> (of type <code>PropertyValue[]</code>): +* the property set described in +* <code>com.sun.star.document.MediaDescriptor</code> +* </li> +* <li> <code>'XFilter.Checker'</code> <b>(optional)</b> (of type +* <code>ifc.document._XFilter.FilterChecker</code>) : implementation +* of interface must allow checking that document was exported successfully. +* If the relation doesn't exist then by default successful filtering +* assumed. +* </li> +* <ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.document.XFilter +*/ +public class _XFilter extends MultiMethodTest { + + public interface FilterChecker { + boolean checkFilter() ; + } + + public XFilter oObj = null; + protected PropertyValue[] mDesc = null ; + protected FilterChecker checker = null ; + protected XComponent sourceDoc = null; + protected boolean dummy = false; + + /** + * Retrieves object relations. + * @throws StatusException If one of relations not found.<br> + * In case of Importers only a dummy implementation exists + * therefore the methods of this interface will be skipped + * in this case + */ + @Override + public void before() { + String name = tEnv.getTestCase().getObjectName(); + if (name.indexOf("Importer")>0) { + log.println(name+" contains only a dummy implementation"); + log.println("therefore all methods are skipped"); + dummy = true; + } + mDesc = (PropertyValue[]) tEnv.getObjRelation("MediaDescriptor") ; + checker = (FilterChecker) tEnv.getObjRelation("XFilter.Checker") ; + if (mDesc == null && !dummy) throw new StatusException( + Status.failed("Relation not found.")) ; + sourceDoc = (XComponent)tEnv.getObjRelation("SourceDocument"); + try { + if (sourceDoc != null) { + XExporter xEx = UnoRuntime.queryInterface( + XExporter.class,oObj); + xEx.setSourceDocument(sourceDoc); + } + } + catch (com.sun.star.lang.IllegalArgumentException e) {} + } + + @Override + public void after() { + if (dummy) { + throw new StatusException(Status.skipped(true)); + } + } + + /** + * Just calls the method. <p> + * Has <b> OK </b> status if no runtime exceptions occurred + */ + public void _filter() { + if (dummy) { + tRes.tested("filter()", true); + return; + } + boolean result = true ; + result = oObj.filter(mDesc) ; + + if (checker == null) { + log.println("!!! Warning : can't check filter as no relation found"); + } else { + result &= checker.checkFilter() ; + } + + tRes.tested("filter()", result) ; + } + + /** + * Just calls the method. <p> + * Has <b> OK </b> status if no runtime exceptions occurred + */ + public void _cancel() { + if (dummy) { + tRes.tested("cancel()",true); + return; + } + requiredMethod("filter()"); + if (tEnv.getObjRelation("NoFilter.cancel()") != null) { + System.out.println("Cancel not tested."); + log.println("Method 'cancel()' is not working and therefore "+ + "not tested.\nResult is set to SKIPPED.OK"); + tRes.tested("cancel()", Status.skipped(true)); + return; + } + + boolean result = false ; + FilterThread newFilter = new FilterThread(oObj); + newFilter.mdesc = mDesc; + newFilter.start(); + oObj.cancel(); + while (newFilter.isAlive()) { + } + result = !newFilter.filterRes; + tRes.tested("cancel()", result) ; + } + + /** + * Calls <code>filter()</code> method in a separate thread. + * Necessary to check if the cancel method works + */ + protected static class FilterThread extends Thread { + + public boolean filterRes = true; + private final XFilter Filter; + public PropertyValue[] mdesc = null; + + public FilterThread(XFilter Filter) { + this.Filter = Filter ; + } + + @Override + public void run() { + filterRes = Filter.filter(mdesc); + } + } + +} + + + diff --git a/qadevOOo/tests/java/ifc/document/_XImporter.java b/qadevOOo/tests/java/ifc/document/_XImporter.java new file mode 100644 index 000000000..087494e65 --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_XImporter.java @@ -0,0 +1,68 @@ +/* + * 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.document; + +import lib.MultiMethodTest; + +import com.sun.star.document.XImporter; +import com.sun.star.lang.XComponent; + +/** +* Testing <code>com.sun.star.document.XImporter</code> +* interface methods : +* <ul> +* <li><code> setTargetDocument()</code></li> +* </ul> <p> +* This test needs the following object relations : +* <ul> +* <li> <code>'TargetDocument'</code> (of type <code>XComponent</code>): +* the target document to be passed to the method. </li> +* <ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.document.XImporter +*/ +public class _XImporter extends MultiMethodTest { + + public XImporter oObj = null; + + /** + * Retrieves relation and sets target document. <p> + * Has <b> OK </b> status if no runtime exceptions occurred, + * really this method tested when the whole import result + * checked. + */ + public void _setTargetDocument() { + boolean res = true; + try { + XComponent the_doc = (XComponent) + tEnv.getObjRelation("TargetDocument"); + oObj.setTargetDocument(the_doc); + } + catch (com.sun.star.lang.IllegalArgumentException ex) { + log.println("Exception while checking 'setTargetDocument'"); + ex.printStackTrace(log); + res = false; + } + + tRes.tested("setTargetDocument()",res); + + } + +} // finish class _XImporter + diff --git a/qadevOOo/tests/java/ifc/document/_XLinkTargetSupplier.java b/qadevOOo/tests/java/ifc/document/_XLinkTargetSupplier.java new file mode 100644 index 000000000..1cc5b3299 --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_XLinkTargetSupplier.java @@ -0,0 +1,48 @@ +/* + * 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.document; + +import lib.MultiMethodTest; + +import com.sun.star.container.XNameAccess; +import com.sun.star.document.XLinkTargetSupplier; + +/** +* Testing <code>com.sun.star.document.XLinkTargetSupplier</code> +* interface methods : +* <ul> +* <li><code> getLinks()</code></li> +* </ul> <p> +* @see com.sun.star.document.XLinkTargetSupplier +*/ +public class _XLinkTargetSupplier extends MultiMethodTest { + + public XLinkTargetSupplier oObj = null; + + /** + * Just calls the method. <p> + * Has <b> OK </b> status if not <code>null</code> value returned. + */ + public void _getLinks() { + XNameAccess links = oObj.getLinks(); + links.getElementNames(); + tRes.tested("getLinks()", true); + } + +} diff --git a/qadevOOo/tests/java/ifc/document/_XMimeTypeInfo.java b/qadevOOo/tests/java/ifc/document/_XMimeTypeInfo.java new file mode 100644 index 000000000..81b39942b --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_XMimeTypeInfo.java @@ -0,0 +1,80 @@ +/* + * 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.document; + + +import lib.MultiMethodTest; + +import com.sun.star.document.XMimeTypeInfo; + +/** + * Testing <code>com.sun.star.document.XMimeTypeInfo</code> + * interface methods : + * <ul> + * <li><code> supportsMimeType()</code></li> + * <li><code> getSupportedMimeTypeNames()</code></li> + * </ul> <p> + * + * @see com.sun.star.document.XMimeTypeInfo + */ +public class _XMimeTypeInfo extends MultiMethodTest { + + public XMimeTypeInfo oObj = null; + public String[] smi = null; + + /** + * Gets supported types and stores them. <p> + * Has <b> OK </b> status if at least one type exists. + */ + public void _getSupportedMimeTypeNames() { + smi = oObj.getSupportedMimeTypeNames(); + tRes.tested("getSupportedMimeTypeNames()", smi.length>0) ; + } + + /** + * Calls the method for one supported type retrieved by + * <code>getSupportedMimeTypeNames</code> method and for + * bad type. <p> + * + * Has <b> OK </b> status if <code>true</code> returned for + * supported type and <code>false</code> for bad type. + * + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> getSupportedMimeTypeNames </code> : to have a list of + * supported types. </li> + * </ul> + */ + public void _supportsMimeType() { + requiredMethod("getSupportedMimeTypeNames()"); + boolean pos = false; + pos = oObj.supportsMimeType(smi[0]); + if (!pos) { + log.println("Method returns false for existing MimeType"); + } + boolean neg = true; + neg = oObj.supportsMimeType("NoRealMimeType"); + if (neg) { + log.println("Method returns true for non existing MimeType"); + } + tRes.tested("supportsMimeType()", (pos && !neg)) ; + } +} + + diff --git a/qadevOOo/tests/java/ifc/document/_XTypeDetection.java b/qadevOOo/tests/java/ifc/document/_XTypeDetection.java new file mode 100644 index 000000000..8aa1f5cdb --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_XTypeDetection.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.document; + +import lib.MultiMethodTest; +import util.utils; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.document.XTypeDetection; + +/** + * Testing <code>com.sun.star.document.XTypeDetection</code> + * interface methods : + * <ul> + * <li><code> queryTypeByURL()</code></li> + * <li><code> queryTypeByDescriptor()</code></li> + * </ul> <p> + * + * The following predefined files needed to complete the test: + * <ul> + * <li> <code>XTypeDetection.sxw</code> : <b>Calc</b> + * document which extension is <b>sxw</b>. </li> + * <ul> <p> + * + * @see com.sun.star.document.XTypeDetection + */ +public class _XTypeDetection extends MultiMethodTest { + public XTypeDetection oObj = null; + + private String docURL = null; + private String bookmarkURL = null; + + /** + * Get the document URL. + */ + @Override + public void before() { + docURL = utils.getFullTestURL("XTypeDetection.sxw"); + bookmarkURL = (String) tEnv.getObjRelation("XTypeDetection.bookmarkDoc"); + } + + /** + * Tries to detect type by writer document URL. <p> + * + * Has <b> OK </b> status if type returned contains + * 'writer' as substring. + */ + public void _queryTypeByURL() { + + boolean result = true ; + String type = oObj.queryTypeByURL(docURL) ; + result &= type.indexOf("writer") > -1; + + tRes.tested("queryTypeByURL()", result) ; + } + + /** + * Tries to detect type of the document using <i>flat</i> + * and <i>deep</i> detection. For flat detection a writer type + * must be returned (file has writer extension), but deep + * detection must return calc type (document has calc contents)<p> + * + * Has <b> OK </b> status if for the first case type contains + * 'writer' string and for the second 'calc' string. + */ + public void _queryTypeByDescriptor() { + boolean result = true ; + boolean ok = true; + log.println("test document with wrong extension"); + log.println("the document '" + docURL + "' is not what it seems to be ;-)"); + PropertyValue[][] mediaDescr = new PropertyValue[1][1]; + mediaDescr[0][0] = new PropertyValue(); + mediaDescr[0][0].Name = "URL"; + mediaDescr[0][0].Value = docURL; + + String type = oObj.queryTypeByDescriptor(mediaDescr, false); + ok = type.indexOf("writer") > -1; + result &= ok; + log.println("flat detection should detect a writer and has detected '"+ type +"': " + ok); + + type = oObj.queryTypeByDescriptor(mediaDescr, true); + ok = type.indexOf("calc") > -1; + result &= ok; + log.println("deep detection should detect a calc and has detected '"+ type +"': " + ok); + + log.println("test document with bookmark: " + bookmarkURL); + mediaDescr = new PropertyValue[1][1]; + mediaDescr[0][0] = new PropertyValue(); + mediaDescr[0][0].Name = "URL"; + mediaDescr[0][0].Value = bookmarkURL; + type = oObj.queryTypeByDescriptor(mediaDescr, true); + ok = type.indexOf("writer") > -1; + result &= ok; + log.println("deep detection should detect a writer and has detected '"+ type +"': " + ok); + + tRes.tested("queryTypeByDescriptor()", result) ; + } +} + diff --git a/qadevOOo/tests/java/ifc/document/_XViewDataSupplier.java b/qadevOOo/tests/java/ifc/document/_XViewDataSupplier.java new file mode 100644 index 000000000..81a92e7c3 --- /dev/null +++ b/qadevOOo/tests/java/ifc/document/_XViewDataSupplier.java @@ -0,0 +1,109 @@ +/* + * 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.document; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.container.XIndexAccess; +import com.sun.star.container.XIndexContainer; +import com.sun.star.document.XViewDataSupplier; +import com.sun.star.uno.UnoRuntime; +import lib.MultiMethodTest; +import lib.Status; + +/** + * Check the XViewDataSupplier interface. + * Test idea: take the property values from the index access, change one + * property value, put this into the index access and write it back. + * Get the property value again and check that the change made it. + */ +public class _XViewDataSupplier extends MultiMethodTest { + public XViewDataSupplier oObj = null; + XIndexAccess xAccess = null; + PropertyValue[] newProps = null; + PropertyValue[] oldProps = null; + String myview = "myview1"; + + public void _getViewData() { + xAccess = oObj.getViewData(); + if (xAccess != null) { + setViewID(xAccess, myview); + } + tRes.tested("getViewData()", true); + } + + public void _setViewData() { + if (xAccess == null) { + log.println("No view data to change available"); + tRes.tested("setViewData()", Status.skipped(true)); + } + else { + // 2do: provide an own implementation of the XIndexAccess to set. + // this will work without "setViewData()", it just checks that a + // setViewData can be done. + oObj.setViewData(xAccess); + XIndexAccess xAccess2 = oObj.getViewData(); + String newView = getViewID(xAccess2); + tRes.tested("setViewData()", newView != null && newView.equals(myview)); + } + } + + private void setViewID(XIndexAccess xAccess, String value) { + XIndexContainer xIndexContainer = UnoRuntime.queryInterface(XIndexContainer.class, xAccess); + int count = xAccess.getCount(); + try { + if (count > 0) { + oldProps = (PropertyValue[])xAccess.getByIndex(0); + newProps = new PropertyValue[oldProps.length]; + for (int j=0; j<oldProps.length; j++) { + newProps[j] = new PropertyValue(); + newProps[j].Name = oldProps[j].Name; + newProps[j].Handle = oldProps[j].Handle; + newProps[j].State = oldProps[j].State; + if (oldProps[j].Name.equals("ViewId")) { + newProps[j].Value = value; + } + + } + xIndexContainer.insertByIndex(0, newProps); + } + } + catch(Exception e) { + e.printStackTrace(log); + } + } + + private String getViewID(XIndexAccess xAccess) { + String retValue = null; + int count = xAccess.getCount(); + try { + if (count > 0) { + oldProps = (PropertyValue[])xAccess.getByIndex(0); + for (int j=0; j<oldProps.length; j++) { + if (oldProps[j].Name.equals("ViewId")) { + retValue = (String)newProps[j].Value; + } + + } + } + } + catch(Exception e) { + e.printStackTrace(log); + } + return retValue; + } +} |