Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / datatransfer / clipboard / _XClipboard.java
blobd486472f76e107e5ad9ed05cbeb2f89fe1d464a4
1 /*
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;
29 /**
30 * Testing <code>com.sun.star.datatransfer.clipboard.XClipboard</code>
31 * interface methods :
32 * <ul>
33 * <li><code> getContents()</code></li>
34 * <li><code> setContents()</code></li>
35 * <li><code> getName()</code></li>
36 * </ul> <p>
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;
47 MyOwner myOwner;
49 /**
50 * <code>XClipboardOwner</code> interface implementation which
51 * stores parameters passed to <code>lostOwnership</code> method.
53 class MyOwner implements XClipboardOwner {
54 XClipboard board;
55 XTransferable contents;
57 public void lostOwnership(XClipboard board, XTransferable contents) {
58 this.board = board;
59 this.contents = contents;
64 /**
65 * Simpliest <code>XTransferable</code> interface implementation.
67 class MyTransferable implements XTransferable {
68 public Object getTransferData(DataFlavor dataFlavor) {
69 return "";
72 public com.sun.star.datatransfer.DataFlavor[] getTransferDataFlavors() {
73 return new DataFlavor[0];
76 public boolean isDataFlavorSupported(DataFlavor dataFlavor) {
77 return false;
82 /**
83 * Initially sets the content of the clipboard.
85 @Override
86 public void before() {
87 oObj.setContents(myTransferable1 = new MyTransferable(),
88 myOwner = new MyOwner());
91 /**
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 :
116 * <ul>
117 * <li> <code> getContents() </code> : for right testing order </li>
118 * </ul>
120 public void _setContents() {
121 requiredMethod("getContents()");
122 myTransferable2 = new MyTransferable();
124 oObj.setContents(myTransferable2, new MyOwner());
126 log.println("sleeping for 1 second");
128 try {
129 Thread.sleep(1000);
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);