2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc
.datatransfer
.clipboard
;
21 import lib
.MultiMethodTest
;
22 import lib
.StatusException
;
24 import com
.sun
.star
.datatransfer
.DataFlavor
;
25 import com
.sun
.star
.datatransfer
.XTransferable
;
26 import com
.sun
.star
.datatransfer
.clipboard
.XClipboard
;
27 import com
.sun
.star
.datatransfer
.clipboard
.XClipboardOwner
;
30 * Testing <code>com.sun.star.datatransfer.clipboard.XClipboard</code>
33 * <li><code> getContents()</code></li>
34 * <li><code> setContents()</code></li>
35 * <li><code> getName()</code></li>
37 * Test is <b> NOT </b> multithread compliant. <p>
38 * @see com.sun.star.datatransfer.clipboard.XClipboard
40 public class _XClipboard
extends MultiMethodTest
{
42 public XClipboard oObj
;
44 MyTransferable myTransferable1
;
45 MyTransferable myTransferable2
;
50 * <code>XClipboardOwner</code> interface implementation which
51 * stores parameters passed to <code>lostOwnership</code> method.
53 class MyOwner
implements XClipboardOwner
{
55 XTransferable contents
;
57 public void lostOwnership(XClipboard board
, XTransferable contents
) {
59 this.contents
= contents
;
65 * Simpliest <code>XTransferable</code> interface implementation.
67 class MyTransferable
implements XTransferable
{
68 public Object
getTransferData(DataFlavor dataFlavor
) {
72 public com
.sun
.star
.datatransfer
.DataFlavor
[] getTransferDataFlavors() {
73 return new DataFlavor
[0];
76 public boolean isDataFlavorSupported(DataFlavor dataFlavor
) {
83 * Initially sets the content of the clipboard.
86 public void before() {
87 oObj
.setContents(myTransferable1
= new MyTransferable(),
88 myOwner
= new MyOwner());
92 * Gets the name of the clipboard. <p>
93 * Has <b>OK</b> status if not <code>null</code> value returned.
95 public void _getName() {
96 String name
= oObj
.getName();
97 tRes
.tested("getName()", name
!= null);
101 * Gets the contents of the clipboard. <p>
102 * Has <b>OK</b> status if the content obtained is equal to content
103 * set in <code>before</code> method.
105 public void _getContents() {
106 tRes
.tested("getContents()", oObj
.getContents() == myTransferable1
);
110 * Sets new contents for the clipboard. Then checks if it was set,
111 * and if <code>lostOwnership()</code> notification of the prevoius
112 * contents was called with appropriate parameters.<p>
113 * Has <b> OK </b> status if <code>getContents</code> returns the same
114 * object which is set, and notification was received.
115 * The following method tests are to be completed successfully before :
117 * <li> <code> getContents() </code> : for right testing order </li>
120 public void _setContents() {
121 requiredMethod("getContents()");
122 myTransferable2
= new MyTransferable();
124 oObj
.setContents(myTransferable2
, new MyOwner());
126 log
.println("sleeping for 1 second");
130 } catch (InterruptedException e
) {
131 log
.println("interrupted");
132 e
.printStackTrace(log
);
133 throw new StatusException("Operation interrupted", e
);
136 tRes
.tested("setContents()", oObj
.getContents() == myTransferable2
);