1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XClipboard.java,v $
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
;
42 * Testing <code>com.sun.star.datatransfer.clipboard.XClipboard</code>
45 * <li><code> getContents()</code></li>
46 * <li><code> setContents()</code></li>
47 * <li><code> getName()</code></li>
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
;
62 * <code>XClipboardOwner</code> interface implementation which
63 * stores parameters passed to <code>lostOwnership</code> method.
65 class MyOwner
implements XClipboardOwner
{
67 XTransferable contents
;
69 public void lostOwnership(XClipboard board
, XTransferable contents
) {
71 this.contents
= contents
;
77 * Simpliest <code>XTransferable</code> interface implementation.
79 class MyTransferable
implements XTransferable
{
80 public Object
getTransferData(DataFlavor dataFlavor
) {
84 public com
.sun
.star
.datatransfer
.DataFlavor
[] getTransferDataFlavors() {
85 return new DataFlavor
[0];
88 public boolean isDataFlavorSupported(DataFlavor dataFlavor
) {
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 :
128 * <li> <code> getContents() </code> : for right testing order </li>
131 public void _setContents() {
132 requiredMethod("getContents()");
133 myTransferable2
= new MyTransferable();
135 oObj
.setContents(myTransferable2
, new MyOwner());
137 log
.println("sleeping for 1 second");
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
);