1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 package ifc.datatransfer.clipboard;
29 
30 import lib.MultiMethodTest;
31 import lib.StatusException;
32 
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;
37 
38 /**
39 * Testing <code>com.sun.star.datatransfer.clipboard.XClipboard</code>
40 * interface methods :
41 * <ul>
42 *  <li><code> getContents()</code></li>
43 *  <li><code> setContents()</code></li>
44 *  <li><code> getName()</code></li>
45 * </ul> <p>
46 * Test is <b> NOT </b> multithread compilant. <p>
47 * @see com.sun.star.datatransfer.clipboard.XClipboard
48 */
49 public class _XClipboard extends MultiMethodTest {
50 
51     public XClipboard oObj;
52 
53     MyTransferable myTransferable1;
54     MyTransferable myTransferable2;
55 
56     MyOwner myOwner;
57 
58     /**
59      * <code>XClipboardOwner</code> interface implementation which
60      * stores parameters passed to <code>lostOwnership</code> method.
61      */
62     class MyOwner implements XClipboardOwner {
63         XClipboard board;
64         XTransferable contents;
65 
66         public void lostOwnership(XClipboard board, XTransferable contents) {
67             this.board = board;
68             this.contents = contents;
69         }
70 
71     }
72 
73     /**
74      * Simpliest <code>XTransferable</code> interface implementation.
75      */
76     class MyTransferable implements XTransferable {
77         public Object getTransferData(DataFlavor dataFlavor) {
78             return "";
79         }
80 
81         public com.sun.star.datatransfer.DataFlavor[] getTransferDataFlavors() {
82             return new DataFlavor[0];
83         }
84 
85         public boolean isDataFlavorSupported(DataFlavor dataFlavor) {
86             return false;
87         }
88 
89     }
90 
91     /**
92      * Initially sets the content of the clipboard.
93      */
94     public void before() {
95         oObj.setContents(myTransferable1 = new MyTransferable(),
96                 myOwner = new MyOwner());
97     }
98 
99     /**
100      * Gets the name of the clipboard. <p>
101      * Has <b>OK</b> status if not <code>null</code> value returned.
102      */
103     public void _getName() {
104         String name = oObj.getName();
105         tRes.tested("getName()", name != null);
106     }
107 
108     /**
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.
112      */
113     public void _getContents() {
114         tRes.tested("getContents()", oObj.getContents() == myTransferable1);
115     }
116 
117     /**
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 :
124     * <ul>
125     *  <li> <code> getContents() </code> : for right testing order </li>
126     * </ul>
127     */
128     public void _setContents() {
129         requiredMethod("getContents()");
130         myTransferable2 = new MyTransferable();
131 
132         oObj.setContents(myTransferable2, new MyOwner());
133 
134         log.println("sleeping for 1 second");
135 
136         try {
137             Thread.sleep(1000);
138         } catch (InterruptedException e) {
139             log.println("interrupted");
140             e.printStackTrace(log);
141             throw new StatusException("Operation interrupted", e);
142         }
143 
144         tRes.tested("setContents()", oObj.getContents() == myTransferable2);
145     }
146 }
147