1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.datatransfer.clipboard;
25 
26 import lib.MultiMethodTest;
27 import lib.StatusException;
28 
29 import com.sun.star.datatransfer.DataFlavor;
30 import com.sun.star.datatransfer.XTransferable;
31 import com.sun.star.datatransfer.clipboard.XClipboard;
32 import com.sun.star.datatransfer.clipboard.XClipboardOwner;
33 
34 /**
35 * Testing <code>com.sun.star.datatransfer.clipboard.XClipboard</code>
36 * interface methods :
37 * <ul>
38 *  <li><code> getContents()</code></li>
39 *  <li><code> setContents()</code></li>
40 *  <li><code> getName()</code></li>
41 * </ul> <p>
42 * Test is <b> NOT </b> multithread compilant. <p>
43 * @see com.sun.star.datatransfer.clipboard.XClipboard
44 */
45 public class _XClipboard extends MultiMethodTest {
46 
47     public XClipboard oObj;
48 
49     MyTransferable myTransferable1;
50     MyTransferable myTransferable2;
51 
52     MyOwner myOwner;
53 
54     /**
55      * <code>XClipboardOwner</code> interface implementation which
56      * stores parameters passed to <code>lostOwnership</code> method.
57      */
58     class MyOwner implements XClipboardOwner {
59         XClipboard board;
60         XTransferable contents;
61 
lostOwnership(XClipboard board, XTransferable contents)62         public void lostOwnership(XClipboard board, XTransferable contents) {
63             this.board = board;
64             this.contents = contents;
65         }
66 
67     }
68 
69     /**
70      * Simpliest <code>XTransferable</code> interface implementation.
71      */
72     class MyTransferable implements XTransferable {
getTransferData(DataFlavor dataFlavor)73         public Object getTransferData(DataFlavor dataFlavor) {
74             return "";
75         }
76 
getTransferDataFlavors()77         public com.sun.star.datatransfer.DataFlavor[] getTransferDataFlavors() {
78             return new DataFlavor[0];
79         }
80 
isDataFlavorSupported(DataFlavor dataFlavor)81         public boolean isDataFlavorSupported(DataFlavor dataFlavor) {
82             return false;
83         }
84 
85     }
86 
87     /**
88      * Initially sets the content of the clipboard.
89      */
before()90     public void before() {
91         oObj.setContents(myTransferable1 = new MyTransferable(),
92                 myOwner = new MyOwner());
93     }
94 
95     /**
96      * Gets the name of the clipboard. <p>
97      * Has <b>OK</b> status if not <code>null</code> value returned.
98      */
_getName()99     public void _getName() {
100         String name = oObj.getName();
101         tRes.tested("getName()", name != null);
102     }
103 
104     /**
105      * Gets the contents of the clipboard. <p>
106      * Has <b>OK</b> status if the content obtained is equal to content
107      * set in <code>before</code> method.
108      */
_getContents()109     public void _getContents() {
110         tRes.tested("getContents()", oObj.getContents() == myTransferable1);
111     }
112 
113     /**
114     * Sets new contents for the clipboard. Then checks if it was set,
115     * and if <code>lostOwnerShip()</code> notification of the prevoius
116     * contents was called with appropriate parameters.<p>
117     * Has <b> OK </b> status if <code>getContents</code> returns the same
118     * object which is set, and notification was received.
119     * The following method tests are to be completed successfully before :
120     * <ul>
121     *  <li> <code> getContents() </code> : for right testing order </li>
122     * </ul>
123     */
_setContents()124     public void _setContents() {
125         requiredMethod("getContents()");
126         myTransferable2 = new MyTransferable();
127 
128         oObj.setContents(myTransferable2, new MyOwner());
129 
130         log.println("sleeping for 1 second");
131 
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);
138         }
139 
140         tRes.tested("setContents()", oObj.getContents() == myTransferable2);
141     }
142 }
143