1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.datatransfer.clipboard; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import lib.MultiMethodTest; 27cdf0e10cSrcweir import lib.StatusException; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.datatransfer.DataFlavor; 30cdf0e10cSrcweir import com.sun.star.datatransfer.XTransferable; 31cdf0e10cSrcweir import com.sun.star.datatransfer.clipboard.XClipboard; 32cdf0e10cSrcweir import com.sun.star.datatransfer.clipboard.XClipboardOwner; 33cdf0e10cSrcweir 34cdf0e10cSrcweir /** 35cdf0e10cSrcweir * Testing <code>com.sun.star.datatransfer.clipboard.XClipboard</code> 36cdf0e10cSrcweir * interface methods : 37cdf0e10cSrcweir * <ul> 38cdf0e10cSrcweir * <li><code> getContents()</code></li> 39cdf0e10cSrcweir * <li><code> setContents()</code></li> 40cdf0e10cSrcweir * <li><code> getName()</code></li> 41cdf0e10cSrcweir * </ul> <p> 42cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 43cdf0e10cSrcweir * @see com.sun.star.datatransfer.clipboard.XClipboard 44cdf0e10cSrcweir */ 45cdf0e10cSrcweir public class _XClipboard extends MultiMethodTest { 46cdf0e10cSrcweir 47cdf0e10cSrcweir public XClipboard oObj; 48cdf0e10cSrcweir 49cdf0e10cSrcweir MyTransferable myTransferable1; 50cdf0e10cSrcweir MyTransferable myTransferable2; 51cdf0e10cSrcweir 52cdf0e10cSrcweir MyOwner myOwner; 53cdf0e10cSrcweir 54cdf0e10cSrcweir /** 55cdf0e10cSrcweir * <code>XClipboardOwner</code> interface implementation which 56cdf0e10cSrcweir * stores parameters passed to <code>lostOwnership</code> method. 57cdf0e10cSrcweir */ 58cdf0e10cSrcweir class MyOwner implements XClipboardOwner { 59cdf0e10cSrcweir XClipboard board; 60cdf0e10cSrcweir XTransferable contents; 61cdf0e10cSrcweir lostOwnership(XClipboard board, XTransferable contents)62cdf0e10cSrcweir public void lostOwnership(XClipboard board, XTransferable contents) { 63cdf0e10cSrcweir this.board = board; 64cdf0e10cSrcweir this.contents = contents; 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir /** 70cdf0e10cSrcweir * Simpliest <code>XTransferable</code> interface implementation. 71cdf0e10cSrcweir */ 72cdf0e10cSrcweir class MyTransferable implements XTransferable { getTransferData(DataFlavor dataFlavor)73cdf0e10cSrcweir public Object getTransferData(DataFlavor dataFlavor) { 74cdf0e10cSrcweir return ""; 75cdf0e10cSrcweir } 76cdf0e10cSrcweir getTransferDataFlavors()77cdf0e10cSrcweir public com.sun.star.datatransfer.DataFlavor[] getTransferDataFlavors() { 78cdf0e10cSrcweir return new DataFlavor[0]; 79cdf0e10cSrcweir } 80cdf0e10cSrcweir isDataFlavorSupported(DataFlavor dataFlavor)81cdf0e10cSrcweir public boolean isDataFlavorSupported(DataFlavor dataFlavor) { 82cdf0e10cSrcweir return false; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir /** 88cdf0e10cSrcweir * Initially sets the content of the clipboard. 89cdf0e10cSrcweir */ before()90cdf0e10cSrcweir public void before() { 91cdf0e10cSrcweir oObj.setContents(myTransferable1 = new MyTransferable(), 92cdf0e10cSrcweir myOwner = new MyOwner()); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir /** 96cdf0e10cSrcweir * Gets the name of the clipboard. <p> 97cdf0e10cSrcweir * Has <b>OK</b> status if not <code>null</code> value returned. 98cdf0e10cSrcweir */ _getName()99cdf0e10cSrcweir public void _getName() { 100cdf0e10cSrcweir String name = oObj.getName(); 101cdf0e10cSrcweir tRes.tested("getName()", name != null); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir /** 105cdf0e10cSrcweir * Gets the contents of the clipboard. <p> 106cdf0e10cSrcweir * Has <b>OK</b> status if the content obtained is equal to content 107cdf0e10cSrcweir * set in <code>before</code> method. 108cdf0e10cSrcweir */ _getContents()109cdf0e10cSrcweir public void _getContents() { 110cdf0e10cSrcweir tRes.tested("getContents()", oObj.getContents() == myTransferable1); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir /** 114cdf0e10cSrcweir * Sets new contents for the clipboard. Then checks if it was set, 115cdf0e10cSrcweir * and if <code>lostOwnerShip()</code> notification of the prevoius 116cdf0e10cSrcweir * contents was called with appropriate parameters.<p> 117cdf0e10cSrcweir * Has <b> OK </b> status if <code>getContents</code> returns the same 118cdf0e10cSrcweir * object which is set, and notification was received. 119cdf0e10cSrcweir * The following method tests are to be completed successfully before : 120cdf0e10cSrcweir * <ul> 121cdf0e10cSrcweir * <li> <code> getContents() </code> : for right testing order </li> 122cdf0e10cSrcweir * </ul> 123cdf0e10cSrcweir */ _setContents()124cdf0e10cSrcweir public void _setContents() { 125cdf0e10cSrcweir requiredMethod("getContents()"); 126cdf0e10cSrcweir myTransferable2 = new MyTransferable(); 127cdf0e10cSrcweir 128cdf0e10cSrcweir oObj.setContents(myTransferable2, new MyOwner()); 129cdf0e10cSrcweir 130cdf0e10cSrcweir log.println("sleeping for 1 second"); 131cdf0e10cSrcweir 132cdf0e10cSrcweir try { 133cdf0e10cSrcweir Thread.sleep(1000); 134cdf0e10cSrcweir } catch (InterruptedException e) { 135cdf0e10cSrcweir log.println("interrupted"); 136cdf0e10cSrcweir e.printStackTrace(log); 137cdf0e10cSrcweir throw new StatusException("Operation interrupted", e); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir tRes.tested("setContents()", oObj.getContents() == myTransferable2); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir } 143