Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / datatransfer / clipboard / _XClipboard.java
blob1dc3cba5dcce8cb0ca4046cf967af417b95a3687
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XClipboard.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.datatransfer.clipboard;
33 import lib.MultiMethodTest;
34 import lib.StatusException;
36 import com.sun.star.datatransfer.DataFlavor;
37 import com.sun.star.datatransfer.XTransferable;
38 import com.sun.star.datatransfer.clipboard.XClipboard;
39 import com.sun.star.datatransfer.clipboard.XClipboardOwner;
41 /**
42 * Testing <code>com.sun.star.datatransfer.clipboard.XClipboard</code>
43 * interface methods :
44 * <ul>
45 * <li><code> getContents()</code></li>
46 * <li><code> setContents()</code></li>
47 * <li><code> getName()</code></li>
48 * </ul> <p>
49 * Test is <b> NOT </b> multithread compilant. <p>
50 * @see com.sun.star.datatransfer.clipboard.XClipboard
52 public class _XClipboard extends MultiMethodTest {
54 public XClipboard oObj;
56 MyTransferable myTransferable1;
57 MyTransferable myTransferable2;
59 MyOwner myOwner;
61 /**
62 * <code>XClipboardOwner</code> interface implementation which
63 * stores parameters passed to <code>lostOwnership</code> method.
65 class MyOwner implements XClipboardOwner {
66 XClipboard board;
67 XTransferable contents;
69 public void lostOwnership(XClipboard board, XTransferable contents) {
70 this.board = board;
71 this.contents = contents;
76 /**
77 * Simpliest <code>XTransferable</code> interface implementation.
79 class MyTransferable implements XTransferable {
80 public Object getTransferData(DataFlavor dataFlavor) {
81 return "";
84 public com.sun.star.datatransfer.DataFlavor[] getTransferDataFlavors() {
85 return new DataFlavor[0];
88 public boolean isDataFlavorSupported(DataFlavor dataFlavor) {
89 return false;
94 /**
95 * Initially sets the content of the clipboard.
97 public void before() {
98 oObj.setContents(myTransferable1 = new MyTransferable(),
99 myOwner = new MyOwner());
103 * Gets the name of the clipboard. <p>
104 * Has <b>OK</b> status if not <code>null</code> value returned.
106 public void _getName() {
107 String name = oObj.getName();
108 tRes.tested("getName()", name != null);
112 * Gets the contents of the clipboard. <p>
113 * Has <b>OK</b> status if the content obtained is equal to content
114 * set in <code>before</code> method.
116 public void _getContents() {
117 tRes.tested("getContents()", oObj.getContents() == myTransferable1);
121 * Sets new contents for the clipboard. Then checks if it was set,
122 * and if <code>lostOwnerShip()</code> notification of the prevoius
123 * contents was called with appropriate parameters.<p>
124 * Has <b> OK </b> status if <code>getContents</code> returns the same
125 * object which is set, and notification was received.
126 * The following method tests are to be completed successfully before :
127 * <ul>
128 * <li> <code> getContents() </code> : for right testing order </li>
129 * </ul>
131 public void _setContents() {
132 requiredMethod("getContents()");
133 myTransferable2 = new MyTransferable();
135 oObj.setContents(myTransferable2, new MyOwner());
137 log.println("sleeping for 1 second");
139 try {
140 Thread.sleep(1000);
141 } catch (InterruptedException e) {
142 log.println("interrupted");
143 e.printStackTrace(log);
144 throw new StatusException("Operation interrupted", e);
147 tRes.tested("setContents()", oObj.getContents() == myTransferable2);