1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc
.datatransfer
.clipboard
;
30 import lib
.MultiMethodTest
;
31 import lib
.StatusException
;
33 import com
.sun
.star
.datatransfer
.DataFlavor
;
34 import com
.sun
.star
.datatransfer
.XTransferable
;
35 import com
.sun
.star
.datatransfer
.clipboard
.XClipboard
;
36 import com
.sun
.star
.datatransfer
.clipboard
.XClipboardOwner
;
39 * Testing <code>com.sun.star.datatransfer.clipboard.XClipboard</code>
42 * <li><code> getContents()</code></li>
43 * <li><code> setContents()</code></li>
44 * <li><code> getName()</code></li>
46 * Test is <b> NOT </b> multithread compilant. <p>
47 * @see com.sun.star.datatransfer.clipboard.XClipboard
49 public class _XClipboard
extends MultiMethodTest
{
51 public XClipboard oObj
;
53 MyTransferable myTransferable1
;
54 MyTransferable myTransferable2
;
59 * <code>XClipboardOwner</code> interface implementation which
60 * stores parameters passed to <code>lostOwnership</code> method.
62 class MyOwner
implements XClipboardOwner
{
64 XTransferable contents
;
66 public void lostOwnership(XClipboard board
, XTransferable contents
) {
68 this.contents
= contents
;
74 * Simpliest <code>XTransferable</code> interface implementation.
76 class MyTransferable
implements XTransferable
{
77 public Object
getTransferData(DataFlavor dataFlavor
) {
81 public com
.sun
.star
.datatransfer
.DataFlavor
[] getTransferDataFlavors() {
82 return new DataFlavor
[0];
85 public boolean isDataFlavorSupported(DataFlavor dataFlavor
) {
92 * Initially sets the content of the clipboard.
94 public void before() {
95 oObj
.setContents(myTransferable1
= new MyTransferable(),
96 myOwner
= new MyOwner());
100 * Gets the name of the clipboard. <p>
101 * Has <b>OK</b> status if not <code>null</code> value returned.
103 public void _getName() {
104 String name
= oObj
.getName();
105 tRes
.tested("getName()", name
!= null);
109 * Gets the contents of the clipboard. <p>
110 * Has <b>OK</b> status if the content obtained is equal to content
111 * set in <code>before</code> method.
113 public void _getContents() {
114 tRes
.tested("getContents()", oObj
.getContents() == myTransferable1
);
118 * Sets new contents for the clipboard. Then checks if it was set,
119 * and if <code>lostOwnerShip()</code> notification of the prevoius
120 * contents was called with appropriate parameters.<p>
121 * Has <b> OK </b> status if <code>getContents</code> returns the same
122 * object which is set, and notification was received.
123 * The following method tests are to be completed successfully before :
125 * <li> <code> getContents() </code> : for right testing order </li>
128 public void _setContents() {
129 requiredMethod("getContents()");
130 myTransferable2
= new MyTransferable();
132 oObj
.setContents(myTransferable2
, new MyOwner());
134 log
.println("sleeping for 1 second");
138 } catch (InterruptedException e
) {
139 log
.println("interrupted");
140 e
.printStackTrace(log
);
141 throw new StatusException("Operation interrupted", e
);
144 tRes
.tested("setContents()", oObj
.getContents() == myTransferable2
);