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/frame | |
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 'qadevOOo/tests/java/ifc/frame')
27 files changed, 4306 insertions, 0 deletions
diff --git a/qadevOOo/tests/java/ifc/frame/_Desktop.java b/qadevOOo/tests/java/ifc/frame/_Desktop.java new file mode 100644 index 000000000..e43ed9850 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_Desktop.java @@ -0,0 +1,45 @@ +/* + * 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.frame; + +import lib.MultiPropertyTest; + +/** +* Testing <code>com.sun.star.frame.Desktop</code> +* service properties: +* <ul> +* <li><code> HasBeamer </code></li> +* <li><code> HasCommonTaskBar </code></li> +* <li><code> HasStylist </code></li> +* <li><code> HasExplorer </code></li> +* <li><code> HasFunctionBar </code></li> +* <li><code> HasMacroBar </code></li> +* <li><code> HasNavigator </code></li> +* <li><code> HasObjectBar </code></li> +* <li><code> HasOptionBar </code></li> +* <li><code> HasStatusBar </code></li> +* <li><code> HasToolBar </code></li> +* </ul> <p> +* Properties testing is automated by <code>lib.MultiPropertyTest</code>. +* @see com.sun.star.frame.Desktop +*/ +public class _Desktop extends MultiPropertyTest { + +} + diff --git a/qadevOOo/tests/java/ifc/frame/_Frame.java b/qadevOOo/tests/java/ifc/frame/_Frame.java new file mode 100644 index 000000000..e20c16817 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_Frame.java @@ -0,0 +1,26 @@ +/* + * 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.frame; + +import lib.MultiPropertyTest; + +public class _Frame extends MultiPropertyTest { + +} + diff --git a/qadevOOo/tests/java/ifc/frame/_FrameLoader.java b/qadevOOo/tests/java/ifc/frame/_FrameLoader.java new file mode 100644 index 000000000..91c57ae18 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_FrameLoader.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.frame; + +import lib.MultiPropertyTest; + +/** +* Testing <code>com.sun.star.frame.FrameLoader</code> +* service properties : +* <ul> +* <li><code> Types</code></li> +* <li><code> UIName</code></li> +* </ul> <p> +* Properties testing is automated by <code>lib.MultiPropertyTest</code>. +* @see com.sun.star.frame.FrameLoader +*/ +public class _FrameLoader extends MultiPropertyTest { + +} + diff --git a/qadevOOo/tests/java/ifc/frame/_SynchronousFrameLoader.java b/qadevOOo/tests/java/ifc/frame/_SynchronousFrameLoader.java new file mode 100644 index 000000000..182612019 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_SynchronousFrameLoader.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.frame; + +import lib.MultiPropertyTest; + +/** +* Testing <code>com.sun.star.frame.SynchronousFrameLoader</code> +* service properties : +* <ul> +* <li><code> Types</code></li> +* <li><code> UIName</code></li> +* </ul> <p> +* Properties testing is automated by <code>lib.MultiPropertyTest</code>. +* @see com.sun.star.frame.SynchronousFrameLoader +*/ +public class _SynchronousFrameLoader extends MultiPropertyTest { + +} + diff --git a/qadevOOo/tests/java/ifc/frame/_XComponentLoader.java b/qadevOOo/tests/java/ifc/frame/_XComponentLoader.java new file mode 100644 index 000000000..afda3657a --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XComponentLoader.java @@ -0,0 +1,139 @@ +/* + * 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.frame; + +import lib.MultiMethodTest; + +import com.sun.star.beans.PropertyState; +import com.sun.star.beans.PropertyValue; +import com.sun.star.frame.XComponentLoader; +import com.sun.star.lang.XComponent; + + +/** +* Testing <code>com.sun.star.frame.XComponentLoader</code> +* interface methods: +* <ul> +* <li><code> loadComponentFromURL() </code></li> +* </ul><p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.frame.XComponentLoader +*/ +public class _XComponentLoader extends MultiMethodTest { + public XComponentLoader oObj = null; // oObj filled by MultiMethodTest + + /** + * Method which tests the objects ability to load a + * component from URL. All available components are loaded by turns. <p> + * Has <b> OK </b> status if the method successfully returns + * and no exceptions were thrown. <p> + * @see XComponent + */ + public void _loadComponentFromURL() throws Exception { + boolean result = true; + + log.println("testing loadComponentFromURL() ... "); + try { + PropertyValue [] szEmptyArgs = new PropertyValue [0]; + String frameName = "_blank"; + XComponent oDoc = null; + + log.println("load writer doc that contains links"); + PropertyValue [] szArgs = new PropertyValue [1]; + PropertyValue Arg = new PropertyValue(); + Arg.Name = "UpdateDocMode"; + Arg.Value = Short.valueOf(com.sun.star.document.UpdateDocMode.NO_UPDATE); + szArgs[0]=Arg; + String url = util.utils.getFullTestURL("Writer_link.sxw"); + log.println("try to load '" + url + "'"); + oDoc = oObj.loadComponentFromURL( + url, frameName, 0, szArgs); + + waitForEventIdle(); + + oDoc.dispose(); + + url = util.utils.getFullTestURL("Calc_Link.sxc"); + log.println("try to load '" + url + "'"); + oDoc = oObj.loadComponentFromURL( + url, frameName, 0, szArgs); + + waitForEventIdle(); + + oDoc.dispose(); + + + + log.println("load a blank impress doc"); + Arg.Name = "OpenFlags"; + Arg.Value = "S"; + Arg.Handle = -1; + Arg.State = PropertyState.DEFAULT_VALUE; + szArgs[0]=Arg; + oDoc = oObj.loadComponentFromURL( + "private:factory/simpress", frameName, 0, szArgs ); + + log.println("disposing impress doc"); + oDoc.dispose(); + + log.println("load a blank writer doc"); + oDoc = oObj.loadComponentFromURL( + "private:factory/swriter", frameName, 0, szEmptyArgs ); + + log.println("disposing writer doc"); + oDoc.dispose(); + + log.println("load a blank calc doc"); + oDoc = oObj.loadComponentFromURL( + "private:factory/scalc", frameName, 0, szEmptyArgs ); + + log.println("disposing calc doc"); + oDoc.dispose(); + + log.println("load a blank draw doc"); + oDoc = oObj.loadComponentFromURL( + "private:factory/sdraw", frameName, 0, szEmptyArgs ); + + log.println("disposing draw doc"); + oDoc.dispose(); + + log.println("load a blank math doc"); + oDoc = oObj.loadComponentFromURL( + "private:factory/smath", frameName, 0, szEmptyArgs ); + + log.println("disposing math doc"); + oDoc.dispose(); + + } + catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Exception occurred while loading"); + e.printStackTrace(log); + result=false; + } + catch (com.sun.star.io.IOException e) { + log.println("Exception occurred while loading"); + e.printStackTrace(log); + result=false; + } + + tRes.tested("loadComponentFromURL()", result); + } + +} + diff --git a/qadevOOo/tests/java/ifc/frame/_XController.java b/qadevOOo/tests/java/ifc/frame/_XController.java new file mode 100644 index 000000000..48ecad772 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XController.java @@ -0,0 +1,218 @@ +/* + * 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.frame; + +import lib.MultiMethodTest; + +import com.sun.star.frame.XController; +import com.sun.star.frame.XFrame; +import com.sun.star.frame.XModel; +import com.sun.star.util.XModifiable; + + +/** +* Testing <code>com.sun.star.frame.XController</code> +* interface methods: +* <ul> +* <li><code> getFrame() </code></li> +* <li><code> attachFrame() </code></li> +* <li><code> getModel() </code></li> +* <li><code> attachModel() </code></li> +* <li><code> getViewData() </code></li> +* <li><code> restoreViewData() </code></li> +* <li><code> suspend() </code></li> +* </ul><p> +* This test needs the following object relations : +* <ul> +* <li> <code>'Frame'</code> (of type <code>XFrame</code>): +* any other frame, used for tests</li> +* <li> <code>'FirstModel'</code> (of type <code>XModel</code>): +* model of a controller tested</li> +* <li> <code>'SecondModel'</code> (of type <code>XModel</code>): +* other model, used for tests </li> +* <li> <code>'HasViewData'</code> (of type <code>Boolean</code>): +* (optional relation) if it exists, so controller has no view data</li> +* <li> <code>'SecondController'</code> (of type <code>XController</code>): +* other controller, used for tests </li> +* </ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.frame.XController +*/ +public class _XController extends MultiMethodTest { + public XController oObj = null; + public XModel firstModel = null; + public XModel secondModel = null; + public XFrame frame = null; + public Object ViewData = null; + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method returns object, that's equal to + * previously obtained object relation 'Frame'. + * The following method tests are to be completed successfully before: + * <ul> + * <li> <code> attachFrame() </code> : attaches frame obtained object + * relation 'Frame' </li> + * </ul> + */ + public void _getFrame() { + requiredMethod("attachFrame()"); + XFrame getting = oObj.getFrame(); + boolean eq = getting.equals(frame); + if ( !eq ) { + log.println("Getting: " + getting.toString()); + log.println("Expected: " + frame.toString()); + } + tRes.tested("getFrame()", eq); + } + + /** + * After obtaining a corresponding object relation test calls the method. + * Has <b> OK </b> status if no exceptions were thrown. <p> + */ + public void _attachFrame() { + frame = (XFrame) tEnv.getObjRelation("Frame"); + oObj.attachFrame(frame); + tRes.tested("attachFrame()", true); + } + + /** + * At first object relation 'FirstModel' is gotten. Then test calls the + * method. <p> + * Has <b> OK </b> status if string representation of an object, returned by + * the method is equal to string representation of corresponding object + * relation. + */ + public void _getModel() { + firstModel = (XModel) tEnv.getObjRelation("FirstModel"); + XModel getting = oObj.getModel(); + String out1 = ""; + String out2 = ""; + if ( (firstModel == null) ) out1="none"; + else out1 = firstModel.toString(); + if ( (getting == null) ) out2="none"; else out2 = getting.toString(); + boolean eq = out1.equals(out2); + if ( !eq ) { + log.println("Getting: " + out2); + log.println("Expected: " + out1); + } + tRes.tested("getModel()", eq); + } + + /** + * At first, we obtain an object relation 'SecondModel'. Then test calls + * the method and check result. <p> + * Has <b> OK </b> status if method returns true and attached model is + * equal to a model 'SecondModel' obtained before. + * <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> getModel() </code> : returns model (XModel) of the + * XController object</li> + * </ul> + */ + public void _attachModel() { + boolean result = false; + + requiredMethod("getModel()"); + secondModel = (XModel) tEnv.getObjRelation("SecondModel"); + XModel gotBefore = oObj.getModel(); + boolean attached = oObj.attachModel(secondModel); + XModel gotAfter = oObj.getModel(); + if ( attached ) { + if ( ! gotBefore.equals(gotAfter) ) { + if ( gotAfter.equals(secondModel) ) { + result = true; + } else { + log.println("Attached and gotten models are not equal"); + log.println("Getting: " + gotAfter.toString()); + log.println("Expected: " + secondModel.toString()); + } + } else { + log.println("method did not change model"); + } + } else { + result=true; + log.println("attachModel() returns false"); + log.println("as expected, see #82938"); + } + tRes.tested("attachModel()", result); + boolean bResult = oObj.attachModel(firstModel); + log.println("attachModel() --> " + bResult); + } + + /** + * At first gotten object relation 'HasViewData' is checked. Then if + * 'HasViewData' is null, test calls the method. <p> + * Has <b> OK </b> status if obtained object relation is not null, or if + * the method does not return null. + */ + public void _getViewData() { + if (tEnv.getObjRelation("HasViewData") != null) { + log.println("This Object has no View Data"); + tRes.tested("getViewData()", true); + return; + } + ViewData = oObj.getViewData(); + tRes.tested( "getViewData()", ViewData != null ); + } + + /** + * If obtained object relation 'HasViewData' is null, test calls the method. + * <p>Has <b> OK </b> status if obtained object relation is not null, or + * if no exceptions were thrown while method call.<p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> getViewData() </code> : gets view data of an object. </li> + * </ul> + */ + public void _restoreViewData() { + requiredMethod("getViewData()"); + if (tEnv.getObjRelation("HasViewData") != null) { + log.println("This Object has no View Data"); + tRes.tested("restoreViewData()", true); + return; + } + oObj.restoreViewData(ViewData); + tRes.tested( "restoreViewData()", true ); + } + + /** + * Has <b> OK </b> status if the method returns true.<p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> restoreViewData() </code> : restores view status of an + * object </li> + * </ul> + */ + public void _suspend() { + requiredMethod("restoreViewData()"); + XModifiable modify = (XModifiable) tEnv.getObjRelation("Modifiable"); + if (modify != null) { + try { + modify.setModified(false); + } catch (com.sun.star.beans.PropertyVetoException pve) { + log.println("PropertyVetoException, couldn't change Modify flag"); + } + } + tRes.tested( "suspend()", oObj.suspend(true) ); + } + +} + diff --git a/qadevOOo/tests/java/ifc/frame/_XDesktop.java b/qadevOOo/tests/java/ifc/frame/_XDesktop.java new file mode 100644 index 000000000..ac1457197 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XDesktop.java @@ -0,0 +1,120 @@ +/* + * 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.frame; + +import lib.MultiMethodTest; + +import com.sun.star.container.NoSuchElementException; +import com.sun.star.container.XEnumeration; +import com.sun.star.container.XEnumerationAccess; +import com.sun.star.frame.XDesktop; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.Type; +import com.sun.star.uno.XInterface; + +/** +* Testing <code>com.sun.star.frame.XDesktop</code> +* interface methods: +* <ul> +* <li><code> getComponents() </code></li> +* <li><code> terminate() </code></li> +* <li><code> addTerminateListener() </code></li> +* <li><code> removeTerminateListener() </code></li> +* <li><code> getCurrentComponent() </code></li> +* <li><code> getCurrentFrame() </code></li> +* </ul><p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.frame.XDesktop +*/ +public class _XDesktop extends MultiMethodTest { + public XDesktop oObj = null; // oObj filled by MultiMethodTest + + /** + * Test calls the method. Then elements enumeration is created and tested.<p> + * Has <b> OK </b> status if no exceptions were thrown. + */ + public void _getComponents() { + XEnumerationAccess xComps = oObj.getComponents(); + XEnumeration xEnum = xComps.createEnumeration(); + boolean result = false; + + try { + while (xEnum.hasMoreElements()) { + try { + AnyConverter.toObject( + new Type(XInterface.class), xEnum.nextElement()); + } catch (com.sun.star.lang.IllegalArgumentException iae) { + log.println("Can't convert any"); + } + } + result = true; + } catch (WrappedTargetException e) { + log.println("Couldn't get a component : " + e.getMessage()); + e.printStackTrace(); + } catch (NoSuchElementException e) { + log.println("Couldn't get a component : " + e.getMessage()); + e.printStackTrace(); + } + tRes.tested("getComponents()", result); + } + + /** + * Cannot test the method because it requires + * terminating StarOffice. Will add real test later. + */ + public void _terminate() { + tRes.tested("terminate()", true); + } + + /** + * Cannot test the method because of terminate(). + * Will add real test later. + */ + public void _addTerminateListener() { + tRes.tested("addTerminateListener()", true); + } + + /** + * Cannot test the method because of terminate(). + * Will add real test later. + */ + public void _removeTerminateListener() { + tRes.tested("removeTerminateListener()", true); + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method does not return null. + */ + public void _getCurrentComponent() { + tRes.tested("getCurrentComponent()", + oObj.getCurrentComponent() != null); + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method does not return null. + */ + public void _getCurrentFrame() { + tRes.tested("getCurrentFrame()", oObj.getCurrentFrame() != null); + } + +} + diff --git a/qadevOOo/tests/java/ifc/frame/_XDispatch.java b/qadevOOo/tests/java/ifc/frame/_XDispatch.java new file mode 100644 index 000000000..3cc536f7a --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XDispatch.java @@ -0,0 +1,221 @@ +/* + * 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.frame; + + +import com.sun.star.beans.PropertyValue; +import com.sun.star.frame.XDispatch; +import com.sun.star.util.URL; +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; +import com.sun.star.frame.XNotifyingDispatch; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.frame.DispatchResultEvent; + +/** +* Testing <code>com.sun.star.frame.XDispatch</code> +* interface methods : +* <ul> +* <li><code> dispatch()</code></li> +* <li><code> addStatusListener()</code></li> +* <li><code> removeStatusListener()</code></li> +* </ul> <p> +* This test needs the following object relations : +* <ul> +* <li> <code>'XDispatch.URL'</code> (of type <code>com.sun.star.util.URL +* </code>): URL for passing to <code>dispatch()</code> method. </li> +* <ul> <p> +* @see com.sun.star.frame.XDispatch +* @see com.sun.star.frame.XNotifyingDispatch +* @see ifc.frame._XDispatch +* @see ifc.frame._XNotifyingDispatch +*/ + +public class _XDispatch extends MultiMethodTest { + + public XDispatch oObj = null; + + /** + * Listener implementation which sets flags on appropriate method calls + */ + protected static class TestStatusListener implements + com.sun.star.frame.XStatusListener { + public boolean statusChangedCalled = false ; + private final java.io.PrintWriter log; + + public TestStatusListener(java.io.PrintWriter log) { + this.log = log ; + } + + public void disposing(com.sun.star.lang.EventObject e) { + log.println(" disposing was called.") ; + } + + public void statusChanged(com.sun.star.frame.FeatureStateEvent e) { + statusChangedCalled = true ; + log.println(" statusChanged was called.") ; + log.println(" FeatureURL = '" + e.FeatureURL + "'"); + log.println(" FeatureDescriptor = '" + e.FeatureDescriptor + "'"); + log.println(" IsEnabled = " + e.IsEnabled); + log.println(" Requery = " + e.Requery); + log.println(" State = '" + e.State.toString() + "'"); + } + + } + + /** + * Listener implementation which sets flags on appropriate method calls + */ + protected static class TestNotificationListener implements + com.sun.star.frame.XDispatchResultListener { + public boolean finishedDispatch = false ; + private final java.io.PrintWriter log; + + public TestNotificationListener(java.io.PrintWriter log) { + this.log = log ; + } + + public void disposing(com.sun.star.lang.EventObject e) { + log.println(" disposing was called.") ; + } + + public void dispatchFinished( DispatchResultEvent e) { + finishedDispatch = true ; + log.println(" dispatchFinished was called.") ; + } + + } + + TestStatusListener listener = null ; + TestNotificationListener notificationListener = null; + URL url = null ; + + /** + * Not all implementations could call the + * <code>com.sun.star.frame.XStatusListener</code>. For this purposes the + * <code>com.sun.star.frame.XDispatchWithNotification</code> was designed. + * If <code>com.sun.star.frame.XStatusListener</code> was not called and + * <code>com.sun.star.frame.XStatusListener</code> is present, it was used + * to check listeners. + */ + private boolean checkXDispatchWithNotification() + { + XNotifyingDispatch xND = UnoRuntime.queryInterface(XNotifyingDispatch.class, oObj); + if ( xND != null) { + log.println(" XNotifyingDispatch found:"); + PropertyValue[] arguments = (PropertyValue[]) + tEnv.getObjRelation("XNotifyingDispatchArgument"); + + notificationListener = new TestNotificationListener(log) ; + xND.dispatchWithNotification(url, arguments, notificationListener); + + waitForEventIdle(); + + log.println(" Listener called: "+ notificationListener.finishedDispatch); + + return notificationListener.finishedDispatch; + } else { + return false; + } + + } + /** + * Retrieves object relations and creates new listeners. + * @throws StatusException If one of relations not found. + */ + @Override + public void before() { + listener = new TestStatusListener(log) ; + url = (URL) tEnv.getObjRelation("XDispatch.URL") ; + + if (url == null) throw new StatusException + (Status.failed("Relation not found.")) ; + } + + /** + * Calls the method using URL from relation. <p> + * Has <b> OK </b> status if one listener (not removed) is called, and + * another (removed) is not. + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code>addStatusListener</code> : + * to check that the listener is called + * </li> + * </ul> + */ + public void _dispatch() { + requiredMethod("addStatusListener()") ; + + boolean result = true ; + + oObj.dispatch(url, new PropertyValue[0]) ; + + waitForEventIdle(); + + log.println("Listener called: "+ listener.statusChangedCalled); + + result = listener.statusChangedCalled; + + if (!result) { + result = checkXDispatchWithNotification(); + } + + tRes.tested("dispatch()", result) ; + } + + /** + * Adds two listeners. <p> + * Has <b> OK </b> status if no runtime exceptions occurred. + */ + public void _addStatusListener() { + + boolean result = true ; + oObj.addStatusListener(listener, url) ; + + tRes.tested("addStatusListener()", result) ; + } + + /** + * Removes the listener added before. <p> + * Has <b> OK </b> status if the dispatch call doesn't call the listener. + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> dispatch() </code> : to have a listener to remove + * </li> + * </ul> + */ + public void _removeStatusListener() { + requiredMethod("dispatch()") ; + listener.statusChangedCalled = false; + boolean result = true ; + oObj.removeStatusListener(listener, url) ; + + oObj.dispatch(url, new PropertyValue[0]) ; + + waitForEventIdle(); + + System.out.println("Listener called: "+ listener.statusChangedCalled); + + result = ! listener.statusChangedCalled; + + tRes.tested("removeStatusListener()", result) ; + } +} + diff --git a/qadevOOo/tests/java/ifc/frame/_XDispatchProvider.java b/qadevOOo/tests/java/ifc/frame/_XDispatchProvider.java new file mode 100644 index 000000000..3cc7c1718 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XDispatchProvider.java @@ -0,0 +1,155 @@ +/* + * 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.frame; + +import lib.MultiMethodTest; +import util.utils; + +import com.sun.star.frame.DispatchDescriptor; +import com.sun.star.frame.FrameSearchFlag; +import com.sun.star.frame.XDispatch; +import com.sun.star.frame.XDispatchProvider; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.util.URL; +import com.sun.star.util.XURLTransformer; + +/** +* Testing <code>com.sun.star.frame.XDispatchProvider</code> +* interface methods: +* <ul> +* <li><code> queryDispatch() </code></li> +* <li><code> queryDispatches() </code></li> +* </ul><p> +* This test needs the following object relations : +* <ul> +* <li> <code>'XDispatchProvider.URL'</code> (of type <code>String</code>): +* used to obtain unparsed url of DispatchProvider </li> +* </ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.frame.XDispatchProvider +*/ +public class _XDispatchProvider extends MultiMethodTest { + public static XDispatchProvider oObj = null; + private String dispatchUrl = null ; + + /** + * Retrieves object relation. + */ + @Override + public void before() { + dispatchUrl = (String) tEnv.getObjRelation("XDispatchProvider.URL") ; + if (dispatchUrl == null) { + dispatchUrl = utils.getFullTestDocName("index.html"); + } + log.println("Using URL: '" + dispatchUrl + "'"); + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method does not return null. + */ + public void _queryDispatch() { + URL url = new URL(); + String frameName = "_top"; + + url.Complete = dispatchUrl; + try { + XURLTransformer xParser=UnoRuntime.queryInterface(XURLTransformer.class, + tParam.getMSF().createInstance + ("com.sun.star.util.URLTransformer")); + // Because it's an in/out parameter we must use an array of + // URL objects. + URL[] aParseURL = new URL[1]; + aParseURL[0] = new URL(); + aParseURL[0].Complete = dispatchUrl; + xParser.parseStrict(aParseURL); + url = aParseURL[0]; + } catch (com.sun.star.uno.Exception e) { + log.println("Couldn't parse URL"); + } + XDispatch xDispatch = oObj.queryDispatch(url, + frameName, FrameSearchFlag.ALL); + tRes.tested("queryDispatch()", xDispatch != null); + } + + /** + * Before test calls the method, DispatchDescriptor sequence is defined.<p> + * Has <b> OK </b> status if the method does not return null, returned + * sequence length is equal to a number of DispatchDescriptors + * and returned sequence consists of non-null elements. + */ + public void _queryDispatches() { + String name1 = "_self"; + String name2 = "_top"; + URL url1 = new URL(); + URL url2 = new URL(); + + url1.Complete = dispatchUrl; + url2.Complete = dispatchUrl; + try { + log.println("Parsing URL"); + XURLTransformer xParser = UnoRuntime.queryInterface(XURLTransformer.class, + tParam.getMSF().createInstance + ("com.sun.star.util.URLTransformer")); + // Because it's an in/out parameter we must use an array of + // URL objects. + URL[] aParseURL = new URL[1]; + aParseURL[0] = new URL(); + aParseURL[0].Complete = dispatchUrl; + xParser.parseStrict(aParseURL); + url1 = aParseURL[0]; + url2 = aParseURL[0]; + } catch (com.sun.star.uno.Exception e) { + log.println("Couldn't parse URL"); + } + DispatchDescriptor descs[] = new DispatchDescriptor[] { + new DispatchDescriptor(url1, name1, FrameSearchFlag.ALL), + new DispatchDescriptor(url2, name2, FrameSearchFlag.ALL) + }; + XDispatch[] xDispatches = oObj.queryDispatches(descs); + + if (xDispatches == null) { + log.println("queryDispatches() returned null"); + tRes.tested("queryDispatches()", false); + return; + } + + if (xDispatches.length != descs.length) { + log.println("queryDispatches() returned " + + xDispatches.length + + " amount of XDispatch instead of " + + descs.length); + tRes.tested("queryDispatches()", false); + return; + } + + for (int i = 0; i < xDispatches.length; i++) { + if (xDispatches[i] == null) { + log.println("queryDispatches() result contains" + + " null object"); + tRes.tested("queryDispatches()", false); + return; + } + } + + tRes.tested("queryDispatches()", true); + } + +} + diff --git a/qadevOOo/tests/java/ifc/frame/_XDispatchProviderInterception.java b/qadevOOo/tests/java/ifc/frame/_XDispatchProviderInterception.java new file mode 100644 index 000000000..ada2a936c --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XDispatchProviderInterception.java @@ -0,0 +1,134 @@ +/* + * 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.frame; + +import java.io.PrintWriter; + +import lib.MultiMethodTest; + +import com.sun.star.frame.DispatchDescriptor; +import com.sun.star.frame.XDispatch; +import com.sun.star.frame.XDispatchProvider; +import com.sun.star.frame.XDispatchProviderInterception; +import com.sun.star.frame.XDispatchProviderInterceptor; +import com.sun.star.util.URL; + +/** +* Testing <code>com.sun.star.frame.XDispatchProviderInterception</code> +* interface methods : +* <ul> +* <li><code> registerDispatchProviderInterceptor()</code></li> +* <li><code> releaseDispatchProviderInterceptor()</code></li> +* </ul> <p> +* @see com.sun.star.frame.XDispatchProviderInterception +*/ +public class _XDispatchProviderInterception extends MultiMethodTest { + + public XDispatchProviderInterception oObj = null; + + /** + * Implementation of <code>XDispatchProviderInterceptor</code> interface + * which writes info about method calls to log, stores master and + * slave interceptors, and redirect all dispatch queries to the master + * provider. + */ + public static class TestInterceptor implements XDispatchProviderInterceptor { + private final PrintWriter log; + public XDispatchProvider master = null, slave = null ; + + public TestInterceptor(PrintWriter log) { + this.log = log ; + } + + public XDispatchProvider getSlaveDispatchProvider() { + log.println("getSlaveDispatchProvider() called.") ; + return slave; + } + public XDispatchProvider getMasterDispatchProvider() { + log.println("getMasterDispatchProvider() called.") ; + return master; + } + public void setSlaveDispatchProvider(XDispatchProvider prov) { + log.println("setSlaveDispatchProvider(" + prov + ") called.") ; + slave = prov ; + } + public void setMasterDispatchProvider(XDispatchProvider prov) { + log.println("setMasterDispatchProvider(" + prov + ") called.") ; + master = prov ; + } + + public XDispatch queryDispatch(URL url, String frame, int flags) { + log.println("my queryDispatch('" + url.Complete + "', '" + + frame + "', " + flags + ") called.") ; + return slave.queryDispatch(url, frame, flags) ; + } + public XDispatch[] queryDispatches(DispatchDescriptor[] desc) { + log.println("my queryDispatches() called.") ; + return slave.queryDispatches(desc) ; + } + } + + + TestInterceptor interceptor = null ; + /** + * Creates new interceptor implementation. + */ + @Override + public void before() { + interceptor = new TestInterceptor(log) ; + } + + /** + * Registers new interceptor implementation. <p> + * Has <b> OK </b> status if during registering interceptor's + * <code>setMasterDispatchProvider</code> method with non null + * parameter was called. <p> + */ + public void _registerDispatchProviderInterceptor() { + + boolean result = true ; + oObj.registerDispatchProviderInterceptor(interceptor) ; + + result = interceptor.master != null ; + + tRes.tested("registerDispatchProviderInterceptor()", result) ; + } + + /** + * Releases interceptor. <p> + * Has <b> OK </b> status if during method call interceptor's + * <code>setMasterDispatchProvider</code> method with <code>null</code> + * parameter was called. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> registerDispatchProviderInterceptor </code> </li> + * </ul> + */ + public void _releaseDispatchProviderInterceptor() { + requiredMethod("registerDispatchProviderInterceptor()") ; + + boolean result = true ; + oObj.releaseDispatchProviderInterceptor(interceptor) ; + + result = interceptor.master == null ; + + tRes.tested("releaseDispatchProviderInterceptor()", result) ; + } +} + diff --git a/qadevOOo/tests/java/ifc/frame/_XDispatchRecorder.java b/qadevOOo/tests/java/ifc/frame/_XDispatchRecorder.java new file mode 100644 index 000000000..b48d11ff8 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XDispatchRecorder.java @@ -0,0 +1,208 @@ +/* + * 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.frame; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; +import util.utils; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.frame.XDispatch; +import com.sun.star.frame.XDispatchProvider; +import com.sun.star.frame.XDispatchRecorder; +import com.sun.star.frame.XFrame; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.util.URL; + +/** +* Testing <code>com.sun.star.frame.XDispatchRecorder</code> +* interface methods: +* <ul> +* <li><code> startRecording() </code></li> +* <li><code> recordDispatch() </code></li> +* <li><code> recordDispatchAsComment() </code></li> +* <li><code> endRecording() </code></li> +* <li><code> getRecordedMacro() </code></li> +* </ul><p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.frame.XDispatchRecorder +*/ +public class _XDispatchRecorder extends MultiMethodTest { + public static XDispatchRecorder oObj = null; + + XFrame xFrame = null; + URL dispURL = null; + PropertyValue[] dispArgs = new PropertyValue[0]; + + @Override + protected void before() { + xFrame = (XFrame) tEnv.getObjRelation("XDispatchRecorder.Frame"); + + if (xFrame == null) { + throw new StatusException(Status.failed("Relation not found")); + } + } + + public void _startRecording() { + + oObj.startRecording(xFrame); + oObj.endRecording(); + tRes.tested("startRecording()", true); + } + + public void _getRecordedMacro() throws Exception { + + clearBuffer(); + + oObj.startRecording(xFrame); + + log.println("dispatch calls via API must be recorded"); + dispURL = utils.parseURL(tParam.getMSF(), ".uno:InsertText"); + + PropertyValue prop = new PropertyValue(); + prop.Name = "Text"; + prop.Value = "XDispatchRecorder.endRecording()"; + dispArgs = new PropertyValue[] {prop}; + + log.println("Dispatching event for frame ..."); + XDispatchProvider xDispProv = UnoRuntime.queryInterface(XDispatchProvider.class, xFrame); + XDispatch xDisp = xDispProv.queryDispatch(dispURL, "", 0); + xDisp.dispatch(dispURL, dispArgs); + + waitForEventIdle(); + + log.println("Getting macro ... :"); + String macro = oObj.getRecordedMacro(); + log.println(macro); + + log.println("Ending record ..."); + oObj.endRecording(); + + boolean res = macro != null + && macro.indexOf(dispURL.Complete) > -1; + if (!res) log.println("Dispatch URL '" + dispURL.Complete + + "' was NOT found in macro - FAILED"); + + tRes.tested("getRecordedMacro()", res); + } + + public void _endRecording() { + + oObj.startRecording(xFrame); + oObj.endRecording(); + String macro = oObj.getRecordedMacro(); + boolean res = true; + if (macro.length() != 0){ + log.println("'endRecording()' was called but macro buffer is not cleared: FALSE"); + log.println(macro); + res = false; + } + + tRes.tested("endRecording()", res); + } + + public void _recordDispatch() { + clearBuffer(); + + oObj.startRecording(xFrame); + + // positive test + dispURL = utils.parseURL(tParam.getMSF(), ".uno:InsertText"); + + PropertyValue prop = new PropertyValue(); + prop.Name = "Text"; + prop.Value = "XDispatchRecorder.recordDispatch()"; + dispArgs = new PropertyValue[] {prop}; + + log.println("Recording dispatch ..."); + oObj.recordDispatch(dispURL, dispArgs); + + log.println("Getting macro ... :"); + String macro = oObj.getRecordedMacro(); + log.println(macro); + + oObj.endRecording(); + + boolean res = macro != null + && macro.indexOf(dispURL.Complete) > -1 + && macro.indexOf((String)dispArgs[0].Value) > -1; + if (!res) log.println("Dispatch URL '" + dispURL.Complete + + "' or its argument '" + dispArgs[0].Value + + "' was not found in macro returned - FAILED"); + + tRes.tested("recordDispatch()", res); + } + + public void _recordDispatchAsComment() { + clearBuffer(); + + oObj.startRecording(xFrame); + + dispURL = utils.parseURL(tParam.getMSF(), ".uno:InsertText"); + + PropertyValue prop = new PropertyValue(); + prop.Name = "Text"; + prop.Value = "XDispatchRecorder.recordDispatchAsComment()"; + dispArgs = new PropertyValue[] {prop}; + + log.println("Recording dispatch ..."); + oObj.recordDispatchAsComment(dispURL, dispArgs); + + log.println("Getting macro ... :"); + String macro = oObj.getRecordedMacro(); + log.println(macro); + + oObj.endRecording(); + + boolean res = macro != null + && macro.indexOf(dispURL.Complete) > -1 + && macro.indexOf((String)dispArgs[0].Value) > -1; + if (!res) log.println("Dispatch URL '" + dispURL.Complete + + "' or its argument '" + dispArgs[0].Value + + "' was not found in macro returned - FAILED"); + + log.println("Checking if macro is commented ..."); + int idx = macro.indexOf((String)dispArgs[0].Value); + int lineStartIdx = macro.lastIndexOf("\n", idx); + String lineStart = macro.substring(lineStartIdx + 1, idx).toLowerCase(); + log.println("Line start is '" + lineStart + "'"); + + if (lineStart.startsWith("'") || lineStart.startsWith("rem")) { + log.println("Line is commented : OK"); + } else { + log.println("Line is not commented : FAILED"); + res =false; + } + + tRes.tested("recordDispatchAsComment()", res); + } + + + private void clearBuffer() { + oObj.startRecording(xFrame); + oObj.endRecording(); + String macro = oObj.getRecordedMacro(); + if (macro.length() != 0){ + log.println("ERROR: 'endRecording()' was called but macro buffer is not cleared!"); + log.println(macro); + } + } + +} diff --git a/qadevOOo/tests/java/ifc/frame/_XDispatchRecorderSupplier.java b/qadevOOo/tests/java/ifc/frame/_XDispatchRecorderSupplier.java new file mode 100644 index 000000000..00e8f6ba4 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XDispatchRecorderSupplier.java @@ -0,0 +1,224 @@ +/* + * 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.frame; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.frame.XDesktop; +import com.sun.star.frame.XDispatch; +import com.sun.star.frame.XDispatchProvider; +import com.sun.star.frame.XDispatchRecorder; +import com.sun.star.frame.XModel; +import com.sun.star.frame.XDispatchRecorderSupplier; +import com.sun.star.frame.XFrame; +import com.sun.star.lang.XComponent; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.util.URL; +import lib.MultiMethodTest; +import lib.StatusException; +import util.SOfficeFactory; +import util.utils; + +/** +* Testing <code>com.sun.star.frame.XDispatchRecorderSupplier</code> +* interface methods: +* <ul> +* <li><code> setDispatchRecorder() </code></li> +* <li><code> getDispatchRecorder() </code></li> +* <li><code> dispatchAndRecord() </code></li> +* </ul><p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.frame.XDispatchRecorderSupplier +*/ +public class _XDispatchRecorderSupplier extends MultiMethodTest { + public static XDispatchRecorderSupplier oObj = null; + + XComponent xTextDoc = null; + XDispatchRecorder recorder = null; + + /** + * Simple <code>XDispatchRecorder</code> implementation + * which method <code>getRecordedMacro</code> returns a fixed + * string. + */ + private static class MyRecorder implements XDispatchRecorder { + public void startRecording(XFrame p0) {} + public void recordDispatch(URL p0, PropertyValue[] p1) {} + public void recordDispatchAsComment(URL p0, PropertyValue[] p1) {} + public void endRecording(){} + public String getRecordedMacro() { + return "MyRecorder implementation"; + } + } + + /** + * Creates a new document which supplies a frame. + * Also a <code>com.sun.star.frame.Desktop</code> + * service created for obtaining document's frame. + */ + @Override + protected void before() throws Exception { + SOfficeFactory SOF = SOfficeFactory.getFactory(tParam.getMSF()); + + log.println( "creating a text document" ); + xTextDoc = SOF.createTextDoc(null); + + Object inst = tParam.getMSF().createInstance + ("com.sun.star.frame.Desktop"); + UnoRuntime.queryInterface(XDesktop.class, inst); + } + + /** + * Creates an instance of <code>MyRecorder</code> and set if, + * then get the current recorder. Second case is setting + * recorder to null. Finally restores the old macro recorder. <p> + * + * Has <b>OK</b> status if in the first case custom recorder + * was successfully returned, and in second case current + * recorder is null. + */ + public void _setDispatchRecorder() { + requiredMethod("getDispatchRecorder()"); + + boolean res = true, + locRes = true; + log.print("Setting custom macro recorder ..."); + oObj.setDispatchRecorder(new MyRecorder()); + XDispatchRecorder rec = oObj.getDispatchRecorder(); + + locRes = rec != null && + "MyRecorder implementation".equals(rec.getRecordedMacro()); + if (locRes) log.println("OK"); + else log.println("FAILED"); + res &= locRes; + + log.print("Setting null dispatch recorder ..."); + oObj.setDispatchRecorder(null); + locRes = oObj.getDispatchRecorder() == null; + if (locRes) log.println("OK"); + else log.println("FAILED"); + res &= locRes; + + log.println("Setting old macro recorder ..."); + oObj.setDispatchRecorder(recorder); + + tRes.tested("setDispatchRecorder()", res); + } + + /** + * Just gets the current recorder and stores it. + * + * Has <b>OK</b> status. + */ + public void _getDispatchRecorder() { + recorder = oObj.getDispatchRecorder(); + tRes.tested("getDispatchRecorder()", true); + } + + /** + * First sets the current dispatch recorder to new + * <code>DispatchRecorder</code> instance if the current one + * is null. The a <code>Dispatch</code> instance is created + * which inserts some text into text document. + * A number of cases is checked : + * <ul> + * <li> A valid call : here the recorded macro must contain + * inserted string and URL </li> + * <li> Call with invalid URL : the macro recorded must not + * contain this URL </li> + * <li> Call with null dispatcher : checking for GPF </li> + * <li> Call with the current recorder set to null : + * checking for GPF </li> + * </ul> + * + * Has <b>OK</b> status if all cases are OK. + */ + public void _dispatchAndRecord() throws Exception { + requiredMethod("getDispatchRecorder()"); + + boolean res = true; + if (recorder == null) { + try { + Object inst = tParam.getMSF().createInstance + ("com.sun.star.comp.framework.DispatchRecorder"); + recorder = UnoRuntime.queryInterface + (XDispatchRecorder.class, inst); + oObj.setDispatchRecorder(recorder); + } catch (com.sun.star.uno.Exception e) { + throw new StatusException("Couldn't create recorder", e); + } + } + + waitForEventIdle(); + + XModel model = UnoRuntime.queryInterface(XModel.class, xTextDoc); + XFrame fr = model.getCurrentController().getFrame(); + + XDispatchProvider xDispProv = UnoRuntime.queryInterface(XDispatchProvider.class, fr); + + URL dispURL = utils.parseURL(tParam.getMSF(), ".uno:InsertText"); + + XDispatch xDisp = xDispProv.queryDispatch(dispURL,"",0); + + PropertyValue[] args = new PropertyValue[1]; + args[0] = new PropertyValue(); + args[0].Name = "Text"; + args[0].Value = "XDispatchRecorderSupplier"; + + log.print("Dispatching and recording ..."); + oObj.dispatchAndRecord(dispURL, args, xDisp); + + String macro = recorder.getRecordedMacro(); + boolean locRes = macro != null && + macro.indexOf("XDispatchRecorderSupplier")>-1 && + macro.indexOf(".uno:InsertText")>-1; + if (locRes) log.println("OK"); + else log.println("FAILED"); + res &= locRes; + log.println("Recorder macro :\n" + macro); + + log.print("Trying to set dispatch with null Dispatcher ..."); + try { + oObj.dispatchAndRecord(dispURL, args, null); + log.println("OK"); + } catch (java.lang.Exception e){ + log.println("Exception is OK: " + e); + } + + log.print("Trying to set dispatch recorder to null and record ..."); + oObj.setDispatchRecorder(null); + try { + oObj.dispatchAndRecord(dispURL, args, xDisp); + log.println("OK"); + } catch (java.lang.Exception e){ + log.println("Exception is OK: " + e); + } + + oObj.setDispatchRecorder(recorder); + + tRes.tested("dispatchAndRecord()", res); + } + + /** + * Disposes the document created in <code>before()</code> + */ + @Override + protected void after() { + xTextDoc.dispose(); + } +}
\ No newline at end of file diff --git a/qadevOOo/tests/java/ifc/frame/_XDocumentTemplates.java b/qadevOOo/tests/java/ifc/frame/_XDocumentTemplates.java new file mode 100644 index 000000000..0a7f7f8bb --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XDocumentTemplates.java @@ -0,0 +1,267 @@ +/* + * 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.frame; + +import lib.MultiMethodTest; +import util.utils; + +import com.sun.star.beans.Property; +import com.sun.star.frame.XDocumentTemplates; +import com.sun.star.frame.XStorable; +import com.sun.star.sdbc.XResultSet; +import com.sun.star.sdbc.XRow; +import com.sun.star.ucb.Command; +import com.sun.star.ucb.OpenCommandArgument2; +import com.sun.star.ucb.XCommandProcessor; +import com.sun.star.ucb.XContent; +import com.sun.star.ucb.XContentAccess; +import com.sun.star.ucb.XDynamicResultSet; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +/** +* Testing <code>com.sun.star.frame.XDesktop</code> +* interface methods: +* <ul> +* <li><code> getContent() </code></li> +* <li><code> storeTemplate() </code></li> +* <li><code> addTemplate() </code></li> +* <li><code> removeTemplate() </code></li> +* <li><code> renameTemplate() </code></li> +* <li><code> addGroup() </code></li> +* <li><code> removeGroup() </code></li> +* <li><code> renameGroup() </code></li> +* <li><code> update() </code></li> +* </ul><p> +*/ +public class _XDocumentTemplates extends MultiMethodTest { + public XDocumentTemplates oObj = null; // oObj filled by MultiMethodTest + protected XContent content = null; + /** + * Test calls the method and prints contents list to log.<p> + * Has <b> OK </b> status if the XContent isn't empty. + */ + public void _getContent() { + content = oObj.getContent(); + log.println("Content list:" + getContentList(content)); + tRes.tested("getContent()", content != null); + } + + /** + * Test calls the method and checks that new group was added. <p> + * Has <b> OK </b> status if method returns true and new group was added. + */ + public void _addGroup() { + requiredMethod("getContent()"); + if (getSubContent(content, "XDocumentTemplatesTemp") != null ) { + oObj.removeGroup("XDocumentTemplatesTemp"); + } + if (getSubContent(content, "XDocumentTemplates") != null ) { + oObj.removeGroup("XDocumentTemplates"); + } + boolean res = oObj.addGroup("XDocumentTemplatesTemp"); + log.println("Method returned: " + res); + res &= getSubContent(content, "XDocumentTemplatesTemp") != null; + tRes.tested("addGroup()", res); + } + + XContent groupContent = null; + /** + * Test calls the method and checks that content has no group with old name + * and that content has group with new name. <p> + * Has <b> OK </b> status if method returns true, content has no group with + * old name and content has group with new name.<p> + */ + public void _renameGroup() { + requiredMethod("addGroup()"); + boolean res = oObj.renameGroup("XDocumentTemplatesTemp", + "XDocumentTemplates"); + log.println("Method returned: " + res); + groupContent = getSubContent(content, "XDocumentTemplates"); + res &= getSubContent(content, "XDocumentTemplatesTemp") == null; + res &= groupContent != null; + tRes.tested("renameGroup()", res); + } + + /** + * Test calls the method and checks that group content has new template. <p> + * Has <b> OK </b> status if method returns true and group content has new + * template.<p> + */ + public void _addTemplate() { + requiredMethod("renameGroup()"); + String testDoc = utils.getFullTestURL("report.stw"); + log.println("Adding template from " + testDoc); + boolean res = oObj.addTemplate("XDocumentTemplates", + "ANewTemplateTemp",testDoc); + log.println("Method returned: " + res); + res &= getSubContent(groupContent, "ANewTemplateTemp") != null; + tRes.tested("addTemplate()", res); + } + + /** + * Test calls the method and checks that group content has no template with + * old name and that group content has template with new name. <p> + * Has <b> OK </b> status if method returns true, group content has no + * template with old name and group content has template with new name.<p> + */ + public void _renameTemplate() { + requiredMethod("addTemplate()"); + boolean res = oObj.renameTemplate("XDocumentTemplates", + "ANewTemplateTemp", + "ANewTemplate"); + log.println("Method returned: " + res); + res &= getSubContent(groupContent, "ANewTemplateTemp") == null; + res &= getSubContent(groupContent, "ANewTemplate") != null; + + tRes.tested("renameTemplate()", res); + } + + /** + * Test calls the method and checks that group content has new template. <p> + * Has <b> OK </b> status if method returns true and new template was created.<p> + */ + public void _storeTemplate() { + requiredMethod("renameGroup()"); + XStorable store = (XStorable) tEnv.getObjRelation("Store"); + boolean res = oObj.storeTemplate("XDocumentTemplates", + "NewStoreTemplate", + store); + log.println("Method returned: " + res); + res &= getSubContent(groupContent, "NewStoreTemplate") != null; + tRes.tested("storeTemplate()", res); + } + + /** + * Test calls the method and checks that group content has no deleted template. <p> + * Has <b> OK </b> status if method returns true and group content has no + * deleted template.<p> + */ + public void _removeTemplate() { + requiredMethod("renameTemplate()"); + boolean res = oObj.removeTemplate("XDocumentTemplates", "ANewTemplate"); + log.println("Method returned: " + res); + res &= getSubContent(groupContent, "ANewTemplate") == null; + tRes.tested("removeTemplate()", res); + } + + /** + * Test calls the method and checks that content has no deleted group. <p> + * Has <b> OK </b> status if method returns true and content has no deleted + * group.<p> + */ + public void _removeGroup() { + requiredMethod("renameGroup()"); + executeMethod("renameTemplate()"); + boolean res = oObj.removeGroup("XDocumentTemplates"); + log.println("Method returned: " + res); + res &= getSubContent(content, "XDocumentTemplates") == null; + tRes.tested("removeGroup()", res); + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if no exception occurs.<p> + */ + public void _update() { + oObj.update(); + tRes.tested("update()",true); + } + + /** + * Returns the string representation of content passed as parameter. + */ + protected String getContentList(XContent content) { + StringBuilder ret = new StringBuilder(); + XResultSet statRes = getStatResultSet(content); + if (statRes != null) { + try { + statRes.first(); + XRow row = UnoRuntime.queryInterface(XRow.class, statRes); + while(! statRes.isAfterLast()) { + ret.append("\n ").append(row.getString(1)); + statRes.next(); + } + } catch (com.sun.star.sdbc.SQLException e) { + log.println("Exception occurred:" + e); + } + } + return ret.toString(); + } + + protected XResultSet getStatResultSet(XContent content) { + XResultSet statResSet = null; + try { + statResSet = getDynaResultSet(content).getStaticResultSet(); + } catch(com.sun.star.ucb.ListenerAlreadySetException e) { + log.println("Exception occurred:" + e); + } + return statResSet; + } + + protected XDynamicResultSet getDynaResultSet(XContent content) { + Command command = new Command(); + OpenCommandArgument2 comArg = new OpenCommandArgument2(); + Property[] comProps = new Property[1]; + comArg.Mode = com.sun.star.ucb.OpenMode.ALL; + comProps[0] = new Property(); + comProps[0].Name = "Title"; + comArg.Properties = comProps; + + command.Name = "open"; + command.Handle = -1; + command.Argument = comArg; + + XCommandProcessor comProc = UnoRuntime.queryInterface(XCommandProcessor.class, content); + + XDynamicResultSet DynResSet = null; + try { + DynResSet = (XDynamicResultSet) AnyConverter.toObject( + new Type(XDynamicResultSet.class),comProc.execute(command, 0, null)); + } catch(com.sun.star.ucb.CommandAbortedException e) { + log.println("Couldn't execute command:" + e); + } catch(com.sun.star.uno.Exception e) { + log.println("Couldn't execute command:" + e); + } + + return DynResSet; + } + + protected XContent getSubContent(XContent content, String subName) { + XResultSet statRes = getStatResultSet(content); + XRow row = UnoRuntime.queryInterface(XRow.class, statRes); + XContentAccess contAcc = UnoRuntime.queryInterface(XContentAccess.class, statRes); + XContent subContent = null; + if (statRes != null) { + try { + statRes.first(); + while(!statRes.isAfterLast()) { + if ( subName.equals(row.getString(1)) ) { + subContent = contAcc.queryContent(); + } + statRes.next(); + } + } catch(com.sun.star.sdbc.SQLException e) { + log.println("Exception occurred:" + e); + } + } + return subContent; + } +} + diff --git a/qadevOOo/tests/java/ifc/frame/_XFrame.java b/qadevOOo/tests/java/ifc/frame/_XFrame.java new file mode 100644 index 000000000..9536cdb2b --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XFrame.java @@ -0,0 +1,571 @@ +/* + * 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.frame; + +import com.sun.star.awt.XWindow; +import com.sun.star.frame.FrameAction; +import com.sun.star.frame.FrameActionEvent; +import com.sun.star.frame.XController; +import com.sun.star.frame.XFrame; +import com.sun.star.frame.XFrameActionListener; +import com.sun.star.frame.XFramesSupplier; +import com.sun.star.lang.EventObject; +import java.io.PrintWriter; +import lib.MultiMethodTest; +import lib.TestEnvironment; + +/** +* Testing <code>com.sun.star.frame.XFrame</code> +* interface methods: +* <ul> +* <li><code> getName() </code></li> +* <li><code> setName() </code></li> +* <li><code> activate() </code></li> +* <li><code> deactivate() </code></li> +* <li><code> isActive() </code></li> +* <li><code> addFrameActionListener() </code></li> +* <li><code> removeFrameActionListener() </code></li> +* <li><code> getCreator() </code></li> +* <li><code> getComponentWindow() </code></li> +* <li><code> getContainerWindow() </code></li> +* <li><code> getController() </code></li> +* <li><code> isTop() </code></li> +* <li><code> findFrame() </code></li> +* <li><code> contextChanged() </code></li> +* <li><code> setCreator() </code></li> +* <li><code> setComponent() </code></li> +* <li><code> initialize() </code></li> +* </ul><p> +* This test needs the following object relations : +* <ul> +* <li> <code>'XFrame'</code> (of type <code>XFrame</code>) +* <b>optional</b>: any frame named 'XFrame'. +* Could be used by <code>findFrame</code> method to try +* to find other frame than itself.</li> +* +* <li> <code>'Desktop'</code> (of type <code>Object</code>): +* if exists, then desktop component is tested</li> +* </ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.frame.XFrame +*/ +public class _XFrame extends MultiMethodTest { + final FrameAction[] actionEvent = new FrameAction[1] ; + final boolean[] listenerCalled = new boolean[] {false} ; + final boolean[] activatedCalled = new boolean[] {false} ; + final boolean[] deactivatedCalled = new boolean[] {false} ; + final TestFrameActionListener listener = + new TestFrameActionListener() ; + public static XFrame oObj = null; + + /** + * Class used to test listeners. + */ + private class TestFrameActionListener + implements XFrameActionListener { + + public void frameAction(FrameActionEvent e) { + listenerCalled[0] = true ; + activatedCalled[0] |= e.Action == FrameAction.FRAME_ACTIVATED; + deactivatedCalled[0] |= e.Action == FrameAction.FRAME_DEACTIVATING; + actionEvent[0] = e.Action; + } + + public void disposing(EventObject e) {} + + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method does not return null. + */ + public void _getName() { + String name = oObj.getName() ; + if (name == null) + log.println("getName() returned null: FAILED") ; + + tRes.tested("getName()", name!=null) ; + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if set and gotten names are equal. + */ + public void _setName() { + String sName = "XFrame" ; + + oObj.setName(sName); + String gName = oObj.getName(); + boolean res = sName.equals(gName); + if (! res) + log.println("setName('" + sName + + "'), but getName() return '" + gName + "'") ; + tRes.tested("setName()", res); + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method successfully returns + * and no exceptions were thrown. + */ + public void _activate() { + oObj.activate() ; + tRes.tested("activate()", true) ; + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method successfully returns + * and no exceptions were thrown. + */ + public void _deactivate() { + oObj.deactivate() ; + oObj.activate() ; + tRes.tested("deactivate()", true) ; + } + + /** + * Test calls the method. Then frame is deactivated and method called + * again. <p> + * Has <b> OK </b> status if isDesktop() returns true or if the method + * always display real status of a frame during activation/deactivation. + */ + public void _isActive() { + boolean result = true; + + if (tEnv.getTestCase().getObjectName().equals("Desktop")) { + log.println("Desktop is always active"); + tRes.tested("isActive()", oObj.isActive()) ; + return; + } + + oObj.deactivate(); + result &= !oObj.isActive(); + if (oObj.isActive()) + log.println("after deactivate() method call, isActive() returned true"); + oObj.activate(); + result &= oObj.isActive(); + if (!oObj.isActive()) + log.println("after activate() method call, isActive() returned false") ; + boolean res = isDesktop(log,tEnv,"isActive()"); + if (res) result=res; + + tRes.tested("isActive()", result) ; + } + + /** + * Test calls the method. Then frame status (activated/deactivated) is + * changed, and the listener is checked.<p> + * Has <b> OK </b> status if isDesktop() method returns true, or if the + * listener was called and frame was activated. + */ + public void _addFrameActionListener() throws Exception { + boolean result = true ; + + oObj.addFrameActionListener(listener) ; + oObj.activate() ; + oObj.deactivate() ; + oObj.activate() ; + + if (tEnv.getTestCase().getObjectName().equals("Desktop")) { + log.println("No actions supported by Desktop"); + tRes.tested("addFrameActionListener()", true) ; + return; + } + + waitForEventIdle(); + + if (!listenerCalled[0]) { + log.println("listener was not called.") ; + result = false ; + } else { + if (!activatedCalled[0]) { + log.println("Listener was called, FRAME_ACTIVATED was not") ; + result = false ; + } + if (!deactivatedCalled[0]) { + log.println("Listener was called, FRAME_DEACTIVATING was not") ; + result = false ; + } + } + + boolean res = isDesktop(log, tEnv, "addFrameActionListener()"); + if (res) result=res; + + tRes.tested("addFrameActionListener()", result) ; + } + + /** + * Test calls the method. Then frame status (activated/deactivated) is + * changed, and the listener is checked.<p> + * Has <b> OK </b> status if isDesktop() method returns true, or if the + * method actually removes listener so it does not react on + * activate/deactivate events. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> addFrameActionListener() </code>: adds action listener + * to a frame </li> + * </ul> + */ + public void _removeFrameActionListener() { + boolean result = true; + + requiredMethod("addFrameActionListener()"); + listenerCalled[0] = false; + oObj.removeFrameActionListener(listener); + oObj.activate(); + oObj.deactivate(); + oObj.activate(); + if (tEnv.getTestCase().getObjectName().equals("Desktop")) { + log.println("No actions supported by Desktop"); + tRes.tested("removeFrameActionListener()", true) ; + return; + } + + if (listenerCalled[0]) + log.println("Listener wasn't removed, and was called"); + boolean res = isDesktop(log, tEnv, "removeFrameActionListener()"); + if (res) result=res; else result = (!listenerCalled[0]); + + tRes.tested("removeFrameActionListener()", result); + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if isDesktop() method returns true or if the method + * does not return null. + */ + public void _getCreator() { + boolean result = true; + + if (tEnv.getTestCase().getObjectName().equals("Desktop")) { + log.println("Desktop has no creator"); + tRes.tested("getCreator()", true) ; + return; + } + + XFramesSupplier creator = oObj.getCreator() ; + if (creator == null) + log.println("getCreator() returns null") ; + boolean res = isDesktop(log,tEnv,"getCreator()"); + if (res) result=res; else result = (creator != null); + tRes.tested("getCreator()", result) ; + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if isDesktop() method returns true or if the method + * does not return null. + */ + public void _getComponentWindow() { + boolean result = true; + + XWindow win = oObj.getComponentWindow() ; + + if (tEnv.getTestCase().getObjectName().equals("Desktop")) { + log.println("Desktop has no component window"); + tRes.tested("getComponentWindow()", true) ; + return; + } + + if (win == null) + log.println("getComponentWindow() returns null") ; + boolean res = isDesktop(log,tEnv,"getComponentWindow()"); + if (res) result=res; else result = (win != null); + tRes.tested("getComponentWindow()", result) ; + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if isDesktop() method returns true or if the method + * does not return null. + */ + public void _getContainerWindow() { + boolean result = true; + + if (tEnv.getTestCase().getObjectName().equals("Desktop")) { + log.println("Desktop has no container window"); + tRes.tested("getContainerWindow()", true) ; + return; + } + + XWindow win = oObj.getContainerWindow() ; + if (win == null) + log.println("getContainerWindow() returns null") ; + boolean res = isDesktop(log,tEnv,"getContainerWindow()"); + if (res) result=res; else result = (win != null); + tRes.tested("getContainerWindow()", result) ; + } + + /** + * Test calls the method. Then returned controller is checked. <p> + * Has <b> OK </b> status if isDesktop() method returns true or + * if the method returns non-null controller, having frame that's equal to + * a (XFrame) oObj. + */ + public void _getController() { + boolean result = true; + XController ctrl = oObj.getController(); + + if (tEnv.getTestCase().getObjectName().equals("Desktop")) { + log.println("Desktop has no controller"); + tRes.tested("getController()", true) ; + return; + } + + if (ctrl == null) { + log.println("getController() returns null"); + result = false; + } else { + XFrame frm = ctrl.getFrame(); + if (!oObj.equals(frm)) { + log.println("Frame returned by controller not " + + "equals to frame testing"); + result = false; + } + } + boolean res = isDesktop(log, tEnv, "getController()"); + if (res) result=res; + tRes.tested("getController()", result) ; + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method successfully returns + * and no exceptions were thrown. + */ + public void _isTop() { + log.println("isTop() = " + oObj.isTop()); + tRes.tested("isTop()", true) ; + } + + /** + * After obtaining an object relation 'XFrame', test tries to find a frame + * named 'XFrame'. <p> + * Has <b> OK </b> status if the method returns non-null object that's equal + * to previously obtained object relation. + */ + public void _findFrame() { + boolean result = true ; + + XFrame aFrame = (XFrame) tEnv.getObjRelation("XFrame"); + + if (aFrame != null) { + log.println("Trying to find a frame with name 'XFrame' ..."); + XFrame frame = oObj.findFrame("XFrame", + com.sun.star.frame.FrameSearchFlag.GLOBAL) ; + if (frame == null) { + log.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") returns null") ; + result = false ; + } else if ( !aFrame.equals(frame) ) { + log.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") " + + " returns frame which is not equal to passed in relation") ; + result = false ; + } + } + + log.println("Trying to find a frame with name '_self' ..."); + XFrame frame = oObj.findFrame("_self", + com.sun.star.frame.FrameSearchFlag.AUTO) ; + if (frame == null) { + log.println("findFrame(\"_self\") returns null") ; + result = false ; + } else if ( !oObj.equals(frame) ) { + log.println("findFrame(\"_self\") " + + " returns frame which is not equal to tested") ; + result = false ; + } + + tRes.tested("findFrame()", result) ; + } + + /** + * At first new listener is added, then test calls the method and result + * is checked. <p> + * Has <b> OK </b> status if isDesktop() method returns true or if the + * listener was called and proper event past to listener. + */ + public void _contextChanged() { + boolean result = true; + TestFrameActionListener listener = new TestFrameActionListener(); + + if (tEnv.getTestCase().getObjectName().equals("Desktop")) { + log.println("Desktop can't change context"); + tRes.tested("contextChanged()", true) ; + return; + } + + listenerCalled[0] = false; + oObj.addFrameActionListener(listener); + try { + oObj.contextChanged(); + if ( !listenerCalled[0] ) { + log.println("listener was not called on contextChanged() call.") ; + result = false; + } else if (actionEvent[0] != FrameAction.CONTEXT_CHANGED) { + log.println("listener was called, but Action != CONTEXT_CHANGED") ; + result = false; + } + } finally { + oObj.removeFrameActionListener(listener); + } + + boolean res = isDesktop(log, tEnv, "contextChanged()"); + if (res) result = res; + tRes.tested("contextChanged()", result); + } + + + /** + * Test calls the method. Remembered old creator is restored at the end. <p> + * Has <b> OK </b> status if the method successfully set new value to (XFrame) + * oObj object. + */ + public void _setCreator() { + if (tEnv.getTestCase().getObjectName().equals("Desktop")) { + log.println("Desktop has no creator"); + tRes.tested("setCreator()", true) ; + return; + } + + XFramesSupplier oldCreator = oObj.getCreator() ; + oObj.setCreator(null) ; + tRes.tested("setCreator()", oObj.getCreator() == null) ; + oObj.setCreator(oldCreator) ; + } + + /** + * Test calls the method, then result is checked.<p> + * Has <b> OK </b> status if method returns true, and values, set by the + * method are nulls, or if method returns false, and values are not changed. + * This method destroy the object. Therefore all other methods have to be + * executed before : + * <ul> + * <li> <code> getName() </code> + * <li> <code> setName() </code> + * <li> <code> activate() </code> + * <li> <code> deactivate() </code> + * <li> <code> isActive() </code> + * <li> <code> addFrameActionListener() </code> + * <li> <code> getComponentWindow() </code> + * <li> <code> getContainerWindow() </code> + * <li> <code> getController() </code> + * <li> <code> isTop() </code> + * <li> <code> findFrame() </code> + * <li> <code> contextChanged() </code> + * <li> <code> setCreator() </code> + * object</li> + * </ul> + */ + public void _setComponent() { + // setComponent() destr + requiredMethod("getName()") ; + requiredMethod("setName()") ; + requiredMethod("activate()") ; + requiredMethod("deactivate()") ; + requiredMethod("isActive()") ; + requiredMethod("addFrameActionListener()") ; + requiredMethod("getComponentWindow()") ; + requiredMethod("getContainerWindow()") ; + requiredMethod("getController()") ; + requiredMethod("isTop()") ; + requiredMethod("findFrame()") ; + requiredMethod("contextChanged()") ; + requiredMethod("setCreator()") ; + + boolean result = true; + + XWindow oldWindow = oObj.getComponentWindow(); + XController oldController = oObj.getController(); + boolean rs = oObj.setComponent(null, null); + if (rs) { // component must be changed + result &= oObj.getComponentWindow() == null; + result &= oObj.getController() == null; + if (!result) + log.println("setComponent() returns true, but component is " + + "not changed."); + } else { // frame is not allowed to change component + result &= oObj.getComponentWindow() == oldWindow ; + result &= oObj.getController() == oldController ; + if (!result) + log.println("setComponent() returns false, but component is" + + "changed."); + } + tRes.tested("setComponent()", result); + + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method successfully returns. + * In case a frame should initialised twice, a + * <CODE>com.sun.star.uno.RuntimeException</CODE> was thrown. This is ok. But since + * a com.sun.star.uno.RuntimeException could thrown in any state the message of + * the exception must contain a defined string. In this case the test get an + * <CODE>OK</CODE> status. + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> setComponent() </code> : sets window and controller to the + * object</li> + * </ul> + */ + public void _initialize() { + requiredMethod("setComponent()") ; + XWindow win = oObj.getContainerWindow() ; + boolean bOK = true; + try { + oObj.initialize(win) ; + } catch (com.sun.star.uno.RuntimeException e){ + String message="Frame::initialized() is called more than once, which is not useful nor allowed."; + if (e.toString().indexOf(message) != -1){ + log.println(e.toString()); + log.println("methods throws exception, but it's OK"); + }else{ + log.println(e.toString()); + bOK=false; + } + + } + tRes.tested("initialize()", bOK) ; + } + + /** + * Checks does relation 'Desktop' exist. Returns true if exist. + */ + public static boolean isDesktop(PrintWriter log, + TestEnvironment env, String method) { + Object isD = env.getObjRelation("Desktop"); + if (isD != null) { + log.println("The Desktop doesn't support the method " + method); + log.println("It will always return true"); + return true; + } + else { + return false; + } + } + + /** + * Forces environment recreation. + */ + @Override + public void after() { + disposeEnvironment(); + } +} diff --git a/qadevOOo/tests/java/ifc/frame/_XFrameActionListener.java b/qadevOOo/tests/java/ifc/frame/_XFrameActionListener.java new file mode 100644 index 000000000..d225e86f7 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XFrameActionListener.java @@ -0,0 +1,35 @@ +/* + * 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.frame; + +import com.sun.star.frame.FrameActionEvent; +import com.sun.star.frame.XFrameActionListener; +import lib.MultiMethodTest; + +public class _XFrameActionListener extends MultiMethodTest { + + public XFrameActionListener oObj = null; + + + public void _frameAction() { + FrameActionEvent event = new FrameActionEvent(); + oObj.frameAction(event); + tRes.tested("frameAction()", true); + } +} diff --git a/qadevOOo/tests/java/ifc/frame/_XFrameLoader.java b/qadevOOo/tests/java/ifc/frame/_XFrameLoader.java new file mode 100644 index 000000000..987605480 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XFrameLoader.java @@ -0,0 +1,192 @@ +/* + * 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.frame; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; +import util.SOfficeFactory; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.frame.XDesktop; +import com.sun.star.frame.XFrame; +import com.sun.star.frame.XFrameLoader; +import com.sun.star.frame.XLoadEventListener; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.XComponent; +import com.sun.star.uno.UnoRuntime; + + +/** +* Testing <code>com.sun.star.frame.XFrameLoader</code> +* interface methods : +* <ul> +* <li><code> load()</code></li> +* <li><code> cancel()</code></li> +* </ul> <p> +* This test needs the following object relations : +* <ul> +* <li> <code>'FrameLoader.URL'</code> (of type <code>String</code>): +* a url or component to be loaded </li> +* <li> <code>'FrameLoader.Frame'</code> <b>(optional)</b> +* (of type <code>com.sun.star.frame.XFrame</code>): +* a target frame where component to be loaded. If this +* relation is omitted then a text document created and its +* frame is used. </li> +* <li> <code>'FrameLoader.args'</code> <b>(optional)</b> +* (of type <code>Object[]</code>): +* necessary arguments for loading a component. If omitted +* then zero length array is passed as parameter</li> +* <ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.frame.XFrameLoader +*/ +public class _XFrameLoader extends MultiMethodTest { + + public XFrameLoader oObj = null; // oObj filled by MultiMethodTest + private String url = null ; + private XFrame frame = null ; + private PropertyValue[] args = new PropertyValue[0] ; + + /** + * Implementation of load listener which registers all its calls. + */ + protected static class TestListener implements XLoadEventListener { + public boolean finished = false ; + public boolean cancelled = false ; + + public void loadFinished(XFrameLoader l) { + finished = true ; + } + public void loadCancelled(XFrameLoader l) { + cancelled = true ; + } + public void disposing(EventObject e) {} + } + + TestListener listener = new TestListener() ; + XComponent frameSup = null ; + + /** + * Retrieves all relations. If optional ones are not found + * creates their default values. <p> + * @throws StatusException If one of required relations not found. + */ + @Override + public void before() { + url = (String) tEnv.getObjRelation("FrameLoader.URL") ; + frame = (XFrame) tEnv.getObjRelation("FrameLoader.Frame") ; + + if (frame == null) { + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() ); + + try { + log.println( "creating a textdocument" ); + frameSup = SOF.createTextDoc( null ); + + Object oDsk = tParam.getMSF() + .createInstance("com.sun.star.frame.Desktop") ; + XDesktop dsk = UnoRuntime.queryInterface(XDesktop.class, oDsk) ; + + util.utils.shortWait(); + frame = dsk.getCurrentFrame() ; + } catch ( com.sun.star.uno.Exception e ) { + // Some exception occurs.FAILED + e.printStackTrace( log ); + throw new StatusException( "Couldn't create a frame.", e ); + } + } + + Object args = tEnv.getObjRelation("FrameLoader.args") ; + if (args != null) this.args = (PropertyValue[]) args ; + + if (url == null /*|| frame == null*/) { + throw new StatusException + (Status.failed("Some relations not found")) ; + } + } + + private boolean loaded = false ; + + /** + * First <code>cancel</code> method test is called. + * If in that test loading process was interrupted by + * <code>cancel</code> call then <code>load</code> test + * executes. It loads a component, waits some moment to + * listener have a chance to be called and then checks + * if the load listener was called.<p> + * Has <b>OK</b> status if <code>cancel</code> method test + * didn't interrupt loading and it was successful, or + * if in this method it loads successful and listener's + * <code>finished</code> method was called. + * The following method tests are to be executed before: + * <ul> + * <li> <code> cancel() </code> </li> + * </ul> + */ + public void _load() throws Exception { + executeMethod("cancel()") ; + + if (!loaded) { + oObj.load(frame, url, args, listener) ; + + waitForEventIdle(); + + loaded = listener.finished ; + } + + tRes.tested("load()", loaded) ; + } + + /** + * Starts to load a component and then immediately tries to + * cancel the process. <p> + * Has <b>OK</b> status if the process was cancelled or + * finished (appropriate listener methods were called). + */ + public void _cancel() throws Exception { + boolean result = true ; + + oObj.load(frame, url, args, listener) ; + oObj.cancel() ; + + waitForEventIdle(); + + if (listener.cancelled) { + log.println("Loading was canceled.") ; + } + if (listener.finished) { + log.println("Loading was finished.") ; + loaded = true ; + } + if (!listener.cancelled && !listener.finished) { + log.println("Loading was not canceled and not finished") ; + result = false ; + } + + tRes.tested("cancel()", result) ; + } + + @Override + public void after() { + if (frameSup != null) frameSup.dispose() ; + frame.dispose(); + } +} + diff --git a/qadevOOo/tests/java/ifc/frame/_XFramesSupplier.java b/qadevOOo/tests/java/ifc/frame/_XFramesSupplier.java new file mode 100644 index 000000000..a54718b70 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XFramesSupplier.java @@ -0,0 +1,204 @@ +/* + * 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.frame; + +import lib.MultiMethodTest; + +import com.sun.star.container.XIndexAccess; +import com.sun.star.frame.XFrame; +import com.sun.star.frame.XFramesSupplier; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.Type; + +/** +* Testing <code>com.sun.star.frame.XFramesSupplier</code> +* interface methods: +* <ul> +* <li><code> getActiveFrame() </code></li> +* <li><code> getFrames() </code></li> +* <li><code> setActiveFrame() </code></li> +* </ul><p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.frame.XFramesSupplier +*/ +public class _XFramesSupplier extends MultiMethodTest { + public static XFramesSupplier oObj = null; + protected XIndexAccess frames = null ; + protected XFrame active = null ; + protected int activeIdx = -1 ; + + /** + * Test calls the method, then result is checked. Also active frame index + * is saved in activeIdx variable.<p> + * + * Has <b> OK </b> status if the method does not return null and the object + * contains returned frame. Or if no frames available and the method + * returns null.<p> + * + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> getFrames() </code> : obtains frames from the object </li> + * </ul> + */ + public void _getActiveFrame() { + boolean result = true ; + + requiredMethod("getFrames()") ; + active = oObj.getActiveFrame() ; + if (active == null) { + // if no child frames then no active frame could be + result = oObj.getFrames().getCount() == 0; + log.println("getActiveFrame() returned null") ; + } + else { + boolean hasActiveFrame = false ; + for (int i = 0; i < frames.getCount(); i++) { + XFrame fr = null ; + try { + try { + fr = (XFrame) AnyConverter.toObject( + new Type(XFrame.class),frames.getByIndex(i)); + } catch (com.sun.star.lang.IllegalArgumentException iae) { + log.println("Can't convert any"); + } + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception occurred while calling getByIndex() method :") ; + e.printStackTrace(log) ; + return; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + log.println("Exception occurred while calling getByIndex() method :") ; + e.printStackTrace(log) ; + return; + } + if (active.equals(fr)) { + hasActiveFrame = true ; + activeIdx = i ; + } + } + if (!hasActiveFrame) { + log.println("getActiveFrame() isn't contained " + + "in getFrames() collection") ; + result = false ; + } + } + + tRes.tested("getActiveFrame()", result) ; + } + + /** + * Test calls the method, then result is checked. <p> + * Has <b> OK </b> status if the method does not return null, + * number of returned frames is not zero and each of them is not null too. + */ + public void _getFrames() { + boolean result = true ; + int cnt = 0; + + frames = oObj.getFrames() ; + if (frames != null) { + cnt = frames.getCount() ; + log.println("There are " + cnt + " frames.") ; + } else { + log.println("getFrames() returned null !!!") ; + result = false ; + } + for (int i = 0; i < cnt; i++) { + try { + if (frames.getByIndex(i) == null) { + log.println("Frame(" + i + ") == null") ; + result = false ; + } + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception occurred while calling getByIndex() method :") ; + e.printStackTrace(log) ; + return; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + log.println("Exception occurred while calling getByIndex() method :") ; + e.printStackTrace(log) ; + return; + } + } + + tRes.tested("getFrames()", result) ; + } + + /** + * After selecting frame to be activated, test calls the method. <p> + * + * Has <b> OK </b> status if set and gotten active frames are equal.<p> + * + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> getActiveFrame() </code> : gets active frame </li> + * </ul> + */ + public void _setActiveFrame() { + XFrame sFrame = null ; + + requiredMethod("getActiveFrame()") ; + if (frames.getCount() > 1) { + try { + if (activeIdx != 0) + try { + sFrame = (XFrame) AnyConverter.toObject( + new Type(XFrame.class),frames.getByIndex(0)); + } catch (com.sun.star.lang.IllegalArgumentException iae) { + log.println("Can't convert any"); + } + else + try { + sFrame = (XFrame) AnyConverter.toObject( + new Type(XFrame.class),frames.getByIndex(1)); + } catch (com.sun.star.lang.IllegalArgumentException iae) { + log.println("Can't convert any"); + } + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception occurred while calling getByIndex() method :") ; + e.printStackTrace(log) ; + return; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + log.println("Exception occurred while calling getByIndex() method :") ; + e.printStackTrace(log) ; + return; + } + } else if (frames.getCount() > 0) { + sFrame = active ; + } + + oObj.setActiveFrame(sFrame) ; + XFrame gFrame = oObj.getActiveFrame() ; + + boolean result; + if (gFrame == null && sFrame == null) + result = true; + else if (gFrame != null && sFrame != null) + result = sFrame.equals(gFrame); + else + result = false; + + if (!result) { + log.println("Active frame set is not equal frame get: FAILED"); + result = false ; + } + + tRes.tested("setActiveFrame()", result) ; + } + +} // finished class _XFramesSupplier + diff --git a/qadevOOo/tests/java/ifc/frame/_XLayoutManager.java b/qadevOOo/tests/java/ifc/frame/_XLayoutManager.java new file mode 100644 index 000000000..7f2a40c6b --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XLayoutManager.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.frame; + +import com.sun.star.awt.Point; +import com.sun.star.frame.XFrame; +import com.sun.star.frame.XLayoutManager; +import com.sun.star.awt.Rectangle; +import com.sun.star.awt.Size; +import com.sun.star.ui.DockingArea; +import com.sun.star.ui.XUIElement; +import lib.MultiMethodTest; +import util.utils; + +public class _XLayoutManager extends MultiMethodTest { + public XLayoutManager oObj = null; + + private XFrame xFrame = null; + private static final String sElementName = "private:resource/menubar/myMenu"; + + @Override + public void before() { + xFrame = (XFrame)tEnv.getObjRelation("XLayoutManager.Frame"); + } + + public void _attachFrame() { + oObj.attachFrame(xFrame); + tRes.tested("attachFrame()", true); + } + + public void _createElement() { + requiredMethod("attachFrame()"); + oObj.createElement(sElementName); + tRes.tested("createElement()", true); + } + + public void _destroyElement() { + requiredMethod("getElement()"); + requiredMethod("getElements()"); + oObj.destroyElement(sElementName); + tRes.tested("destroyElement()", true); + } + + public void _doLayout() { + oObj.doLayout(); + tRes.tested("doLayout()", true); + } + + public void _dockWindow() { + requiredMethod("createElement()"); + Point p = new Point(); + p.X = 0; + p.Y = 0; + oObj.dockWindow(sElementName, DockingArea.DOCKINGAREA_TOP, p); + tRes.tested("dockWindow()", true); + } + + public void _floatWindow() { + requiredMethod("createElement()"); + oObj.floatWindow(sElementName); + tRes.tested("floatWindow()", true); + } + + public void _getCurrentDockingArea() { + requiredMethod("attachFrame()"); + Rectangle rect = oObj.getCurrentDockingArea(); + tRes.tested("getCurrentDockingArea()", rect != null); + } + + public void _getElement() { + requiredMethod("createElement()"); + oObj.getElement(sElementName); + tRes.tested("getElement()", true); + } + + public void _getElementPos() { + Point p = oObj.getElementPos(sElementName); + tRes.tested("getElementPos()", p != null); + } + + public void _getElementSize() { + Size s = oObj.getElementSize(sElementName); + tRes.tested("getElementSize()", s != null); + } + + public void _getElements() { + requiredMethod("createElement()"); + XUIElement[] xElements = oObj.getElements(); + for (int i=0; i<xElements.length; i++) { + Object o = xElements[i].getRealInterface(); + log.println("Element " + i + ": " + o.toString() + " " + utils.getImplName(o)); + } + tRes.tested("getElements()", true); + } + + public void _hideElement() { + oObj.hideElement(sElementName); + tRes.tested("hideElement()", true); + } + + public void _isElementDocked() { + oObj.isElementDocked(sElementName); + tRes.tested("isElementDocked()", true); + } + + public void _isElementFloating() { + oObj.isElementFloating(sElementName); + tRes.tested("isElementFloating()", true); + } + + public void _isElementVisible() { + oObj.isElementVisible(sElementName); + tRes.tested("isElementVisible()", true); + } + + public void _lock() { + oObj.lock(); + tRes.tested("lock()", true); + } + + public void _reset() { + oObj.reset(); + tRes.tested("reset()", true); + } + + public void _setDockingAreaAcceptor() { + oObj.setDockingAreaAcceptor(null); + tRes.tested("setDockingAreaAcceptor()", true); + } + + public void _setElementPos() { + requiredMethod("createElement()"); + Point p = new Point(); + p.X = 0; + p.Y = 150; + oObj.setElementPos(sElementName, p); + tRes.tested("setElementPos()", true); + } + + public void _setElementPosSize() { + requiredMethod("createElement()"); + Point p = new Point(); + p.X = 150; + p.Y = 0; + Size size = new Size(); + size.Height = 50; + size.Width = 80; + oObj.setElementPosSize(sElementName, p, size); + tRes.tested("setElementPosSize()", true); + } + + public void _setElementSize() { + requiredMethod("createElement()"); + Size size = new Size(); + size.Height = 80; + size.Width = 50; + oObj.setElementSize(sElementName, size); + tRes.tested("setElementSize()", true); + } + + public void _showElement() { + requiredMethod("createElement()"); + oObj.showElement(sElementName); + tRes.tested("showElement()", true); + + } + + public void _unlock() { + requiredMethod("lock()"); + oObj.unlock(); + tRes.tested("unlock()", true); + } + +} diff --git a/qadevOOo/tests/java/ifc/frame/_XModel.java b/qadevOOo/tests/java/ifc/frame/_XModel.java new file mode 100644 index 000000000..320570b5f --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XModel.java @@ -0,0 +1,249 @@ +/* + * 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.frame; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.frame.XController; +import com.sun.star.frame.XModel; +import com.sun.star.view.XSelectionSupplier; + +import lib.MultiMethodTest; + + +/** +* Testing <code>com.sun.star.frame.XModel</code> +* interface methods: +* <ul> +* <li><code> attachResource() </code></li> +* <li><code> connectController() </code></li> +* <li><code> disconnectController() </code></li> +* <li><code> getArgs() </code></li> +* <li><code> getCurrentController() </code></li> +* <li><code> getCurrentSelection() </code></li> +* <li><code> getURL() </code></li> +* <li><code> hasControllersLocked() </code></li> +* <li><code> lockControllers() </code></li> +* <li><code> setCurrentController() </code></li> +* <li><code> unlockControllers() </code></li> +* </ul><p> +* This test needs the following object relations : +* <ul> +* <li> <code>'CONT2'</code> (of type <code>XController</code>): +* a controller used as an argument for several test methods </li> +* <li> <code>'TOSELECT'</code> (of type <code>Object</code>): +* something, we want to select from document </li> +* <li> <code>'SELSUPP'</code> (of type <code>XSelectionSupplier</code>): +* supplier, we use to select something in a document </li> +* </ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.frame.XModel +*/ +public class _XModel extends MultiMethodTest { + public XModel oObj = null; + boolean result = true; + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method returns true. + */ + public void _attachResource() { + log.println("opening DataSourceBrowser"); + + PropertyValue[] noArgs = new PropertyValue[0]; + result = oObj.attachResource(".component:DB/DataSourceBrowser", noArgs); + tRes.tested("attachResource()", result); + } + + /** + * After obtaining object relation 'CONT2' and storing old controller, + * test calls the method, then result is checked.<p> + * Has <b> OK </b> status if controller, gotten after method call is not + * equal to a previous controller. + */ + public void _connectController() { + XController cont2 = (XController) tEnv.getObjRelation("CONT2"); + XController old = oObj.getCurrentController(); + result = false; + + if (cont2 == null) { + log.println("No controller no show"); + } else { + oObj.connectController(cont2); + + String oldFrame = old.getFrame().getName(); + String newFrame = cont2.getFrame().getName(); + result = (!oldFrame.equals(newFrame)); + } + + tRes.tested("connectController()", result); + } + + /** + * After obtaining object relation 'CONT2', test calls the method, + * then result is checked.<p> + * Has <b> OK </b> status if controller, gotten after method call is not + * equal to a controller we use as an argument to method. + */ + public void _disconnectController() { + XController cont2 = (XController) tEnv.getObjRelation("CONT2"); + result = false; + + if (cont2 == null) { + log.println("No controller no show"); + } else { + oObj.disconnectController(cont2); + result = (oObj.getCurrentController() != cont2); + } + + tRes.tested("disconnectController()", result); + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method does not return null. + */ + public void _getArgs() { + tRes.tested("getArgs()", oObj.getArgs() != null); + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method does not return null. + */ + public void _getCurrentController() { + XController ctrl = oObj.getCurrentController(); + tRes.tested("getCurrentController()", ctrl != null); + } + + /** + * After obtaining object relations 'SELSUPP' and 'TOSELECT', test prepares + * selection and calls the method. <p> + * Has <b> OK </b> status if the method does not return null. + */ + public void _getCurrentSelection() { + XSelectionSupplier selsupp = (XSelectionSupplier) tEnv.getObjRelation( + "SELSUPP"); + Object toSelect = tEnv.getObjRelation("TOSELECT"); + result = false; + + if (selsupp == null) { + log.println("No Selection Supplier no show"); + } else { + try { + selsupp.select(toSelect); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Exception occurred while select:"); + e.printStackTrace(log); + + return; + } + + Object sel = oObj.getCurrentSelection(); + result = (sel != null); + } + + tRes.tested("getCurrentSelection()", result); + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method does not return null. + */ + public void _getURL() { + String url = oObj.getURL(); + log.println("The url: " + url); + tRes.tested("getURL()", url != null); + } + + /** + * if controller is not locked, test calls the method. <p> + * Has <b> OK </b> status if the method returns true. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> lockControllers() </code> : locks controllers </li> + * </ul> + */ + public void _hasControllersLocked() { + requiredMethod("lockControllers()"); + tRes.tested("hasControllersLocked()", oObj.hasControllersLocked()); + } + + /** + * Test calls the method, then result is checked.<p> + * Has <b> OK </b> status if method locks controllers. + */ + public void _lockControllers() { + oObj.lockControllers(); + result = oObj.hasControllersLocked(); + tRes.tested("lockControllers()", result); + } + + /** + * After obtaining object relation 'CONT2' and storing old controller, + * controller cont2 is connected, then this controller is + * setting as current. + * Sets the old controller as current. + * <p>Has <b> OK </b> status if set and gotten controllers are not equal. + */ + public void _setCurrentController() { + XController cont2 = (XController) tEnv.getObjRelation("CONT2"); + XController old = oObj.getCurrentController(); + result = false; + + if (cont2 == null) { + log.println("No controller no show"); + } else { + oObj.connectController(cont2); + + try { + oObj.setCurrentController(cont2); + } catch (com.sun.star.container.NoSuchElementException e) { + log.print("Cannot set current controller:"); + e.printStackTrace(log); + } + + result = (oObj.getCurrentController() != old); + + try { + oObj.setCurrentController(old); + } catch (com.sun.star.container.NoSuchElementException e) { + log.print("Cannot set current controller:"); + e.printStackTrace(log); + } + } + + tRes.tested("setCurrentController()", result); + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if method unlocks controllers. + * <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> hasControllersLocked() </code> : checks if controllers are + * locked </li> + * </ul> + */ + public void _unlockControllers() { + requiredMethod("hasControllersLocked()"); + oObj.unlockControllers(); + result = !oObj.hasControllersLocked(); + tRes.tested("unlockControllers()", result); + } +} diff --git a/qadevOOo/tests/java/ifc/frame/_XModuleManager.java b/qadevOOo/tests/java/ifc/frame/_XModuleManager.java new file mode 100644 index 000000000..d870589c3 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XModuleManager.java @@ -0,0 +1,153 @@ +/* + * 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.frame; + +import com.sun.star.beans.PropertyValue; + +import com.sun.star.frame.XModuleManager; +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.frame.UnknownModuleException; + + +/** +* Testing <code>com.sun.star.frame.XModuleManager</code> +* interface methods: +* <ul> +* <li><code> identify() </code></li> +* </ul><p> +* This test needs the following object relations : +* <ul> +* <li> <code>'XModuleManager.XFrame'</code> (of type <code>PropertyValue[]</code>): +* PropertyValue[n].Value : a XFrame +* PropertyValue[n].Name : the expected return value of <code>identify()</code></li> +* <li> <code>'XModuleManager.XController'</code> (of type <code>PropertyValue[]</code>): +* PropertyValue[n].Value : a XController +* PropertyValue[n].Name : the expected return value of <code>identify()</code></li> +* <li> <code>'XModuleManager.XModel'</code> (of type <code>PropertyValue[]</code>): +* PropertyValue[n].Value : a XFrame +* PropertyValue[n].Name : the expected return value of <code>identify()</code></li> +* </ul> <p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.frame.XModuleManager +*/ +public class _XModuleManager extends MultiMethodTest { + /** Test calls the method. <p> + * The object relations <CODE>XModuleManager.XFrame</CODE>, + * <CODE>XModuleManager.XController</CODE> and <CODE>XModuleManager.XModel</CODE> + * are sequences of <CODE>PropertyValue</CODE>. The value of a PropertyValue + * contains a <CODE>XFrame</CODE>, <CODE>XController</CODE> or a + * <CODE>XModel</CODE>. The name of the PropertyValue contains the expected return + * value of method <CODE>indetify()</CODE> if the method was called with + * corresponding value.<p> + * As enhancement the method <CODE>identify()</CODE> was called with invalid + * parameter. In this case the thrown exceptions were caught. + */ + public XModuleManager oObj = null; + /** + * Test calls the method. <p> + * Has <b> OK </b> status if the method returns expected values, that's equal to + * previously obtained object relation 'Frame'. + * The following method tests are to be completed successfully before: + * <ul> + * <li> <code> attachFrame() </code> : attaches frame obtained object + * relation 'Frame' </li> + * </ul> + */ + + private PropertyValue[] xFrameSeq = null; + private PropertyValue[] xControllerSeq = null; + private PropertyValue[] xModelSeq = null; + /** Retrieves object relations. */ + + @Override + public void before() { + + xFrameSeq = (PropertyValue[]) tEnv.getObjRelation("XModuleManager.XFrame") ; + + if (xFrameSeq == null) throw new StatusException + (Status.failed("Relation 'xFrameSeq' not found.")) ; + + + xControllerSeq = (PropertyValue[]) tEnv.getObjRelation("XModuleManager.XController") ; + + if (xControllerSeq == null) throw new StatusException + (Status.failed("Relation 'xControllerSeq' not found.")) ; + + + xModelSeq = (PropertyValue[]) tEnv.getObjRelation("XModuleManager.XModel") ; + + if (xModelSeq == null) throw new StatusException + (Status.failed("Relation 'xModelSeq' not found.")) ; + } + + /* The method <CODE>identify()</CODE> was used for every entry in sequence of + * object relations. + */ + public void _identify() { + boolean ok = true; + log.println("testing frame sequence..."); + ok &= testSequence(xFrameSeq); + log.println("testing controller sequence..."); + ok &= testSequence(xControllerSeq); + log.println("testing model sequence..."); + ok &= testSequence(xModelSeq); + tRes.tested("identify()", ok); + + log.println("testing invalid objects..."); + try{ + oObj.identify(oObj); + } catch (IllegalArgumentException e){ + log.println("expected exception."); + } catch (UnknownModuleException e){ + log.println("expected exception."); + } + } + + private boolean testSequence(PropertyValue[] sequence){ + boolean ok = true; + for (int i = 0 ; i < sequence.length; i++){ + try{ + log.println("testing '" + sequence[i].Name + "'"); + if (!oObj.identify(sequence[i].Value).equals( + sequence[i].Name)) { + log.println("failure: returned value: '" + + oObj.identify(sequence[i].Value) + + "' ,expected value: '" + sequence[i].Name + "'"); + ok = false; + } + } catch (IllegalArgumentException e){ + log.println("Could not get value of sequence '" + + sequence[i].Name + "'"); + return false; + + } catch (UnknownModuleException e){ + log.println("Could not indetify value of sequence '" + + sequence[i].Name + "'"); + return false; + } + } + return ok; + } + +} + diff --git a/qadevOOo/tests/java/ifc/frame/_XNotifyingDispatch.java b/qadevOOo/tests/java/ifc/frame/_XNotifyingDispatch.java new file mode 100644 index 000000000..b214364f0 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XNotifyingDispatch.java @@ -0,0 +1,118 @@ +/* + * 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.frame; + + +import com.sun.star.beans.PropertyValue; +import com.sun.star.util.URL; +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; +import com.sun.star.frame.XNotifyingDispatch; +import com.sun.star.frame.DispatchResultEvent; + +/** +* Testing <code>com.sun.star.frame.XNotifyingDispatch</code> +* interface methods : +* <ul> +* <li><code> dispatchWithNotification()</code></li> +* </ul> <p> +* This test needs the following object relations : +* <ul> +* <li> <code>'XDispatch.URL'</code> (of type <code>com.sun.star.util.URL +* </code>): URL for passing to <code>dispatch()</code> method. </li> +* <li> <code>[OPTIONAL] 'XNotifyingDispatchArgument'</code> +* (of type sequence<code>com::sun::star::beans::PropertyValue +* </code>): arguments for <code>dispatchWithNotification()</code> method. </li> +* <ul> <p> +* @see com.sun.star.frame.XDispatch +* @see com.sun.star.frame.XNotifyingDispatch +* @see ifc.frame._XDispatch +*/ +public class _XNotifyingDispatch extends MultiMethodTest { + + public XNotifyingDispatch oObj = null; + + + /** + * Listener implementation which sets flags on appropriate method calls + */ + protected static class TestNotificationListener implements + com.sun.star.frame.XDispatchResultListener { + public boolean finishedDispatch = false ; + private final java.io.PrintWriter log; + + public TestNotificationListener(java.io.PrintWriter log) { + this.log = log ; + } + + public void disposing(com.sun.star.lang.EventObject e) { + log.println(" disposing was called.") ; + } + + public void dispatchFinished( DispatchResultEvent e) { + finishedDispatch = true ; + log.println(" dispatchFinished was called.") ; + } + + } + + TestNotificationListener notificationListener = null; + PropertyValue[] arguments = null; + URL url = null ; + + /** + * Retrieves object relations and creates new listeners. + * @throws StatusException If one of relations not found. + */ + @Override + public void before() { + notificationListener = new TestNotificationListener(log) ; + url = (URL) tEnv.getObjRelation("XDispatch.URL") ; + + if (url == null) throw new StatusException + (Status.failed("Relation not found.")) ; + + arguments = (PropertyValue[]) + tEnv.getObjRelation("XNotifyingDispatchArgument"); + } + + /** + * Calls the method using URL and arguments from relation. <p> + * Has <b> OK </b> status if listener is called. + * The following method tests are to be completed successfully before : + */ + public void _dispatchWithNotification() { + + boolean result = true ; + + oObj.dispatchWithNotification(url, arguments, notificationListener); + + waitForEventIdle(); + + log.println("Listener called: "+ notificationListener.finishedDispatch); + + result = notificationListener.finishedDispatch; + + + tRes.tested("dispatchWithNotification()", result) ; + } + +} + diff --git a/qadevOOo/tests/java/ifc/frame/_XPopupMenuController.java b/qadevOOo/tests/java/ifc/frame/_XPopupMenuController.java new file mode 100644 index 000000000..8a6d0e397 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XPopupMenuController.java @@ -0,0 +1,218 @@ +/* + * 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.frame; + +import com.sun.star.graphic.XGraphic; +import com.sun.star.awt.XPopupMenu; +import com.sun.star.awt.KeyEvent; +import com.sun.star.frame.XPopupMenuController; +import lib.MultiMethodTest; + +public class _XPopupMenuController extends MultiMethodTest { + public XPopupMenuController oObj = null; + + @Override + public void before() { + + } + + public void _setPopupMenu() { + XPopupMenu xMenu = new PopupMenuImpl(); + oObj.setPopupMenu(xMenu); + tRes.tested("setPopupMenu()", true); + } + + public void _updatePopupMenu() { + oObj.updatePopupMenu(); + tRes.tested("updatePopupMenu()", true); + } + + private static class PopupMenuImpl implements XPopupMenu { + + public void addMenuListener(com.sun.star.awt.XMenuListener xMenuListener) { + System.out.println("addMenuListener called."); + } + + public void checkItem(short param, boolean param1) { + System.out.println("checkItemListener called."); + } + + public void enableItem(short param, boolean param1) { + System.out.println("enableItem called."); + } + + public short execute(com.sun.star.awt.XWindowPeer xWindowPeer, com.sun.star.awt.Rectangle pos, short param) { + System.out.println("execute called."); + return 0; + } + + public short getDefaultItem() { + System.out.println("getDefaultItem called."); + return 0; + } + + public short getItemCount() { + System.out.println("getItemCount called."); + return 0; + } + + public short getItemId(short param) { + System.out.println("getItemId called."); + return 0; + } + + public short getItemPos(short param) { + System.out.println("getItemPos called."); + return 0; + } + + public String getItemText(short param) { + System.out.println("getItemText called."); + return "Hi."; + } + + public com.sun.star.awt.XPopupMenu getPopupMenu(short param) { + System.out.println("getPopupMenu called."); + return this; + } + + public void insertItem(short param, String str, short param2, short param3) { + System.out.println("insertItem called."); + } + + public void insertSeparator(short param) { + System.out.println("insertSeparator called."); + } + + public boolean isItemChecked(short param) { + System.out.println("isItemChecked called."); + return false; + } + + public boolean isItemEnabled(short param) { + System.out.println("isItemEnabled called."); + return false; + } + + public void removeItem(short param, short param1) { + System.out.println("removeItem called."); + } + + public void removeMenuListener(com.sun.star.awt.XMenuListener xMenuListener) { + System.out.println("removeMenuListener called."); + } + + public void setDefaultItem(short param) { + System.out.println("setDefaultItem called."); + } + + public void setItemText(short param, String str) { + System.out.println("setItemText called."); + } + + public void setPopupMenu(short param, com.sun.star.awt.XPopupMenu xPopupMenu) { + System.out.println("setPopupMenu called."); + } + + public XGraphic getItemImage(short param ) { + System.out.println("getItemImage called."); + return null; + } + + public void setItemImage(short param, XGraphic param1, boolean param2 ) { + System.out.println("setItemImage called."); + } + + public KeyEvent getAcceleratorKeyEvent(short param ) { + System.out.println("getAcceleratorKeyEvent called."); + return new KeyEvent(); + } + + public void setAcceleratorKeyEvent(short param, KeyEvent param1 ) { + System.out.println("setAcceleratorKeyEvent called."); + } + + public void endExecute() { + System.out.println("endExecute called."); + } + + public boolean isInExecute() { + System.out.println("isInExecute called."); + return false; + } + + public boolean isPopupMenu() { + System.out.println("isPopupMenu called."); + return true; + } + + public String getTipHelpText(short param ) { + System.out.println("getTipHelpText called."); + return null; + } + + public void setTipHelpText(short param, String param1 ) { + System.out.println("setTipHelpText called."); + } + + public String getHelpText(short param ) { + System.out.println("getHelpText called."); + return null; + } + + public void setHelpText(short param, String param1 ) { + System.out.println("setHelpText called."); + } + + public String getHelpCommand(short param ) { + System.out.println("getHelpCommand called."); + return null; + } + + public void setHelpCommand(short param, String param1 ) { + System.out.println("setHelpCommand called."); + } + + public String getCommand(short param ) { + System.out.println("getCommand called."); + return null; + } + + public void setCommand(short param, String param1 ) { + System.out.println("setCommand called."); + } + + public void enableAutoMnemonics(boolean param ) { + System.out.println("enableAutoMnemonics called."); + } + + public void hideDisabledEntries(boolean param ) { + System.out.println("hideDisabledEntries called."); + } + + public com.sun.star.awt.MenuItemType getItemType(short param ) { + System.out.println("getItemType called."); + return com.sun.star.awt.MenuItemType.DONTKNOW; + } + + public void clear() { + System.out.println("clear called."); + } + } +} diff --git a/qadevOOo/tests/java/ifc/frame/_XStatusListener.java b/qadevOOo/tests/java/ifc/frame/_XStatusListener.java new file mode 100644 index 000000000..393c0a205 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XStatusListener.java @@ -0,0 +1,40 @@ +/* + * 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.frame; + +import com.sun.star.frame.FeatureStateEvent; +import com.sun.star.frame.XStatusListener; +import lib.MultiMethodTest; + +public class _XStatusListener extends MultiMethodTest { + public XStatusListener oObj = null; + + + @Override + public void before() { + + } + + public void _statusChanged() { + FeatureStateEvent event = new FeatureStateEvent(); + oObj.statusChanged(event); + tRes.tested("statusChanged()", true); + } + +} diff --git a/qadevOOo/tests/java/ifc/frame/_XStorable.java b/qadevOOo/tests/java/ifc/frame/_XStorable.java new file mode 100644 index 000000000..c61a43802 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XStorable.java @@ -0,0 +1,218 @@ +/* + * 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.frame; + +import lib.MultiMethodTest; +import util.utils; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.frame.XStorable; +import com.sun.star.io.IOException; + +/** +* Testing <code>com.sun.star.frame.XStorable</code> +* interface methods: +* <ul> +* <li><code> getLocation() </code></li> +* <li><code> hasLocation() </code></li> +* <li><code> isReadonly() </code></li> +* <li><code> storeAsURL() </code></li> +* <li><code> storeToURL() </code></li> +* <li><code> store() </code></li> +* </ul><p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.frame.XStorable +*/ +public class _XStorable extends MultiMethodTest { + public XStorable oObj = null; // oObj filled by MultiMethodTest + String storeUrl; + boolean stored; + + /** + * Test calls the method. <p> + * Has <b> OK </b> status in three cases: + * <ol> + * <li>An object has location stored in. Then if method does not return + * null, it has <b> OK </b> status</li> + * <li>An object has no location stored in. Then method storeAsURL() is + * called, and if url is not null and equals to a url where component + * was stored, method has <b> OK </b> status</li> + * <li>An object has no location stored in. Then method storeAsURL() is + * called, and if url is null and method returns null too, method + * has <b> OK </b> status </li> + * </ol><p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> storeAsURL() </code> : stores the object's persistent data + * to a URL and lets the object become the representation of this new + * URL</li> + * </ul> + */ + public void _getLocation() { + if (oObj.hasLocation()) { + // if it has location it should know it + tRes.tested("getLocation()", oObj.getLocation() != null); + } else { + // else try to obtain location + requiredMethod("storeAsURL()"); + if (storeUrl != null) { + // if stored successfully - check location + log.println(oObj.getLocation() + "--" + storeUrl); + tRes.tested("getLocation()", + storeUrl.equals(oObj.getLocation())); + } else { + // if not - it should not have a location + tRes.tested("getLocation()", oObj.getLocation() == null); + } + } + } + + /** + * Test calls the method, then result is checked. <p> + * Has <b> OK </b> status if stored url is not null and method does not + * return null or if stored url is null and the method returns null.<p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> storeAsURL() </code>: stores the object's persistent data + * to a URL and lets the object become the representation of this new + * URL</li> + * </ul> + */ + public void _hasLocation() { + requiredMethod("storeAsURL()"); + if (storeUrl != null) { + // if stored successfully - it should have a location + tRes.tested("hasLocation()", oObj.hasLocation()); + } else { + // if not - it should not + tRes.tested("hasLocation()", !oObj.hasLocation()); + } + } + + /** + * Test calls the method. <p> + * Has <b> OK </b> status if value, returned by the method is not equal to + * 'stored' variable. ( If it's readonly it should not have been stored. ) + * <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> store() </code> : stores data to the URL from which it + * was loaded </li> + * </ul> + */ + public void _isReadonly() { + requiredMethod("store()"); + tRes.tested("isReadonly()", oObj.isReadonly() != stored); + } + + /** + * Object is stored into temporary directory. <p> + * Has <b> OK </b> status if the method successfully returns + * and no exceptions were thrown. + */ + public void _storeAsURL() { + // getting a url to store + String url = utils.getOfficeTemp( + tParam.getMSF()); + + if (url != null) { + url += "xstorable.store.as.test"; + log.println("store as '" + url + "'"); + try { + oObj.storeAsURL(url, new PropertyValue[0]); + storeUrl = url; + tRes.tested("storeAsURL()", true); + } catch (IOException e) { + log.println("Couldn't store as "+url+" : "+e.getMessage()); + e.printStackTrace(log); + storeUrl = null; + tRes.tested("storeAsURL()", false); + } + } else { + log.println("a url to store is not found"); + } + } + + /** + * Object is stored into temporary directory. <p> + * Has <b> OK </b> status if the method successfully returns + * and no exceptions were thrown. + */ + public void _storeToURL() { + // getting a url to store + String url = utils.getOfficeTemp( + tParam.getMSF()); + + if (url != null) { + url += "xstorable.store.as.test"; + log.println("store to '" + url + "'"); + try { + oObj.storeToURL(url, new PropertyValue[0]); + tRes.tested("storeToURL()", true); + } catch (IOException e) { + log.println("Couldn't store to "+url+" : "+e.getMessage()); + e.printStackTrace(log); + tRes.tested("storeToURL()", false); + } + } else { + log.println("a url to store is not found"); + } + } + + /** + * Test calls the method. Then result is checked.<p> + * Has <b> OK </b> status if: + * <ol> + * <li>component was stored, object is not readonly and has location</li> + * <li>exception occurred because of component is readonly + * and wasn't stored</li> + * </ol> + */ + public void _store() { + IOException ioE = null; + + try { + oObj.store(); + stored = true; + } catch (IOException e) { + stored = false; + ioE = e; + } + if (oObj.hasLocation() && !oObj.isReadonly()) { + tRes.tested("store()", stored); + if (!stored) { + log.println("Couldn't store : " + ioE.getMessage()); + ioE.printStackTrace(log); + } + } else { + tRes.tested("store()", !stored); + if (stored) { + if (!oObj.hasLocation()) { + log.println("Shouldn't store successfully" + + " a document without location"); + } else { + log.println("Shouldn't store successfully" + + " a read-only document"); + } + } + } + } + +}// finished class _XStorable + diff --git a/qadevOOo/tests/java/ifc/frame/_XSynchronousFrameLoader.java b/qadevOOo/tests/java/ifc/frame/_XSynchronousFrameLoader.java new file mode 100644 index 000000000..b56d9d89d --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XSynchronousFrameLoader.java @@ -0,0 +1,172 @@ +/* + * 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.frame; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; +import util.SOfficeFactory; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.frame.XDesktop; +import com.sun.star.frame.XFrame; +import com.sun.star.frame.XSynchronousFrameLoader; +import com.sun.star.lang.XComponent; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.util.URL; +import com.sun.star.util.XURLTransformer; + +/** + * Testing <code>com.sun.star.frame.XSynchronousFrameLoader</code> + * interface methods : + * <ul> + * <li><code> load()</code></li> + * <li><code> cancel()</code></li> + * </ul> <p> + * This test needs the following object relations : + * <ul> + * <li> <code>'FrameLoader.URL'</code> (of type <code>String</code>): + * a url of component to be loaded </li> + * <li> <code>'FrameLoader.Frame'</code> <b>(optional)</b> + * (of type <code>com.sun.star.frame.XFrame</code>): + * a target frame where component to be loaded. If this + * relation is omitted then a text document created and its + * frame is used. </li> + * <ul> <p> + * + * @see com.sun.star.frame.XSynchronousFrameLoader + */ +public class _XSynchronousFrameLoader extends MultiMethodTest { + + public XSynchronousFrameLoader oObj = null; // oObj filled by MultiMethodTest + private XFrame frame = null ; + private XComponent frameSup = null ; + private PropertyValue[] descr = null; + + /** + * Retrieves all relations. If optional relation + * <code>FrameLoader.Frame</code> not found + * creates a new document and obtains its frame for loading. <p> + * + * Also <code>MediaDescriptor</code> is created using + * URL from <code>FrameLoader.URL</code> relation. + * + * @throws StatusException If one of required relations not found. + */ + @Override + public void before() { + String url = (String) tEnv.getObjRelation("FrameLoader.URL") ; + frame = (XFrame) tEnv.getObjRelation("FrameLoader.Frame") ; + + if (url == null) { + throw new StatusException(Status.failed("Some relations not found")) ; + } + + SOfficeFactory SOF = SOfficeFactory.getFactory( + tParam.getMSF() ); + + XURLTransformer xURLTrans = null; + + // if frame is not contained in relations the writer frame will be used. + if (frame == null) { + try { + log.println( "creating a textdocument" ); + frameSup = SOF.createTextDoc( null ); + + Object oDsk = tParam.getMSF().createInstance + ("com.sun.star.frame.Desktop") ; + XDesktop dsk = UnoRuntime.queryInterface + (XDesktop.class, oDsk) ; + frame = dsk.getCurrentFrame() ; + + Object o = tParam.getMSF().createInstance + ("com.sun.star.util.URLTransformer") ; + xURLTrans = UnoRuntime.queryInterface + (XURLTransformer.class, o) ; + + } catch ( com.sun.star.uno.Exception e ) { + // Some exception occurs.FAILED + e.printStackTrace( log ); + throw new StatusException( "Couldn't create a document.", e ); + } + } + + URL[] urlS = new URL[1]; + urlS[0] = new URL(); + urlS[0].Complete = url; + if (xURLTrans == null) + throw new IllegalStateException("xURLTrans unexpected null"); + boolean res = xURLTrans.parseStrict(urlS); + log.println("Parsing URL '" + url + "': " + res); + descr = new PropertyValue[1] ; + descr[0] = new PropertyValue(); + descr[0].Name = "URL" ; + descr[0].Value = urlS[0] ; + } + + + /** + * Tries to load component to a frame. <p> + * Has <b> OK </b> status if <code>true</code> is returned. + */ + public void _load() { + boolean result = oObj.load(descr, frame) ; + + tRes.tested("load()", result) ; + } + + /** + * Tries to load component to a frame in separate thread to + * avoid blocking of the current thread and immediately + * cancels loading. <p> + * + * Has <b> OK </b> status if <code>flase</code> is returned, + * i.e. loading was not completed. + */ + public void _cancel() { + requiredMethod("load()") ; + + final boolean[] result = new boolean[1] ; + + (new Thread() { + @Override + public void run() { + result[0] = oObj.load(descr, frame); + } + }).start(); + + oObj.cancel() ; + + waitForEventIdle(); + + tRes.tested("cancel()", !result[0]) ; + } + + /** + * Disposes document if it was created for frame supplying. + */ + @Override + protected void after() { + if (frameSup != null) { + frameSup.dispose(); + } + } +} + + diff --git a/qadevOOo/tests/java/ifc/frame/_XTasksSupplier.java b/qadevOOo/tests/java/ifc/frame/_XTasksSupplier.java new file mode 100644 index 000000000..9409cf36c --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XTasksSupplier.java @@ -0,0 +1,62 @@ +/* + * 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.frame; + +import lib.MultiMethodTest; + +import com.sun.star.frame.XTasksSupplier; + + +/** +* Testing <code>com.sun.star.frame.XTasksSupplier</code> +* interface methods: +* <ul> +* <li><code> getActiveTask() </code></li> +* <li><code> getTasks() </code></li> +* </ul><p> +* Test is <b> NOT </b> multithread compliant. <p> +* @see com.sun.star.frame.XTasksSupplier +*/ +public class _XTasksSupplier extends MultiMethodTest { + public static XTasksSupplier oObj = null; + + /** + * DEPRECATED. <p> + * Has <b> OK </b> status . + */ + public void _getActiveTask() { + log.println("DEPRECATED"); + + tRes.tested("getActiveTask()", true) ; + } // finished _getTasks() + + /** + * DEPRECATED. <p> + * Has <b> OK </b> status. + */ + @Deprecated + public void _getTasks() { + log.println("DEPRECATED"); + + tRes.tested("getTasks()", true); + + } // finished _removeResetListener() + +} // finished class _XTaskSupplier + diff --git a/qadevOOo/tests/java/ifc/frame/_XUIControllerRegistration.java b/qadevOOo/tests/java/ifc/frame/_XUIControllerRegistration.java new file mode 100644 index 000000000..e42b9be24 --- /dev/null +++ b/qadevOOo/tests/java/ifc/frame/_XUIControllerRegistration.java @@ -0,0 +1,55 @@ +/* + * 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.frame; + +import com.sun.star.frame.XUIControllerRegistration; +import lib.MultiMethodTest; + +public class _XUIControllerRegistration extends MultiMethodTest { + public XUIControllerRegistration oObj = null; + private String aRegisteredController = null; + private static final String aController = ".uno:MySecondController"; + + @Override + public void before() { + aRegisteredController = (String)tEnv.getObjRelation("XUIControllerRegistration.RegisteredController"); + } + + + public void _registerController() { + oObj.registerController(aController, "", "com.sun.star.comp.framework.FooterMenuController"); + oObj.registerController(aRegisteredController, "", "com.sun.star.comp.framework.HeaderMenuController"); + tRes.tested("registerController()", true); + } + + public void _deregisterController() { + requiredMethod("registerController()"); + oObj.deregisterController(aController, ""); + tRes.tested("deregisterController()", true); + } + + public void _hasController() { + requiredMethod("registerController()"); + requiredMethod("deregisterController()"); + boolean res = oObj.hasController(aRegisteredController, ""); + res &= !oObj.hasController(aController, ""); + tRes.tested("hasController()", res); + } + +} |