Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / datatransfer / clipboard / _XClipboardNotifier.java
blob77a9a2d99284ea7a77d23f31b973155edf780231
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.ClipboardEvent;
36 import com.sun.star.datatransfer.clipboard.XClipboard;
37 import com.sun.star.datatransfer.clipboard.XClipboardListener;
38 import com.sun.star.datatransfer.clipboard.XClipboardNotifier;
39 import com.sun.star.datatransfer.clipboard.XClipboardOwner;
40 import com.sun.star.lang.EventObject;
41 import com.sun.star.uno.Type;
42 import com.sun.star.uno.UnoRuntime;
44 /**
45 * Testing <code>com.sun.star.datatransfer.clipboard.XClipboardNotifier</code>
46 * interface methods :
47 * <ul>
48 * <li><code> addClipboardListener()</code></li>
49 * <li><code> removeClipboardListener()</code></li>
50 * </ul> <p>
51 * The object <b>must also implement</b> <code>XClipboard</code>
52 * interface. <p>
53 * Test is <b> NOT </b> multithread compilant. <p>
54 * @see com.sun.star.datatransfer.clipboard.XClipboardNotifier
55 * @see com.sun.star.datatransfer.clipboard.XClipboard
57 public class _XClipboardNotifier extends MultiMethodTest {
59 public XClipboardNotifier oObj;
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;
75 /**
76 * Simpliest <code>XTransferable</code> interface implementation
77 * which supports "text/htmp" data type.
79 class MyTransferable implements XTransferable {
80 DataFlavor[] supportedFlavors;
82 public MyTransferable() {
83 supportedFlavors = new DataFlavor[] {
84 new DataFlavor("text/plain", "Plain text", new Type(String.class))
88 public Object getTransferData(DataFlavor dataFlavor) {
89 return "";
92 public DataFlavor[] getTransferDataFlavors() {
93 return supportedFlavors;
96 public boolean isDataFlavorSupported(DataFlavor dataFlavor) {
97 return supportedFlavors[0].MimeType.equals(dataFlavor.MimeType);
102 * Implementation of listener which registers its method calls.
104 class MyClipboardListener implements XClipboardListener {
105 boolean called = false;
107 public void changedContents(ClipboardEvent evt) {
108 called = true;
111 public void disposing(EventObject wvt) {
112 log.println("");
116 MyClipboardListener myListener;
119 * Adds a listener and put a new contents into clipboard. <p>
120 * Has <b> OK </b> status if the listener was called on contents changing.
122 public void _addClipboardListener() {
123 oObj.addClipboardListener(myListener = new MyClipboardListener());
125 XClipboard board = (XClipboard)UnoRuntime.queryInterface(
126 XClipboard.class, tEnv.getTestObject());
128 board.setContents(new MyTransferable(), new MyOwner());
130 log.println("sleeping for 1 second");
132 try {
133 Thread.sleep(1000);
134 } catch (InterruptedException e) {
135 log.println("interrupted");
136 e.printStackTrace(log);
137 throw new StatusException("Operation interrupted", e);
140 tRes.tested("addClipboardListener()", myListener.called);
144 * Removes the listener and put a new contents into clipboard. <p>
145 * Has <b> OK </b> status if the listener was not called on contents
146 * changing.
147 * The following method tests are to be completed successfully before :
148 * <ul>
149 * <li> <code>addClipboardListener()</code> </li>
150 * </ul>
152 public void _removeClipboardListener() {
153 try {
154 requiredMethod("addClipboardListener()");
155 myListener.called = false;
156 } finally {
157 oObj.removeClipboardListener(myListener);
160 XClipboard board = (XClipboard)UnoRuntime.queryInterface(
161 XClipboard.class, oObj);
163 board.setContents(new MyTransferable(), new MyOwner());
165 try {
166 Thread.sleep(1000);
167 } catch (InterruptedException e) {
168 log.println("interrupted");
169 e.printStackTrace(log);
170 throw new StatusException("Operation interrupted", e);
173 tRes.tested("removeClipboardListener()", !myListener.called);