aboutsummaryrefslogtreecommitdiff
path: root/gnu/testlet/java/awt/datatransfer/Clipboard/clipboard.java
blob: 97643efed380ea2312675e37fe755d4ae77fb93e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Tags: JDK1.1

// Copyright (C) 2005 Mark J. Wielaard <mark@klomp.org>

// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version. 

// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING.  If not, write to
// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301 USA.

package gnu.testlet.java.awt.datatransfer.Clipboard;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.awt.datatransfer.*;

public class clipboard
  extends Clipboard
  implements Testlet, Transferable, ClipboardOwner
{

  public clipboard()
  {
    super("mauve");
  }

  private clipboard(String name)
  {
    super(name);
  }

  public void test(TestHarness harness)      
  {
    harness.check(this.getName(), "mauve");
    harness.check(this.contents, null);
    harness.check(this.getContents(null), this.contents);
    harness.check(this.owner, null);

    // Claim ownership of the clipboard.
    this.setContents(this, this);
    harness.check(this.contents, this);
    harness.check(this.getContents(null), this.contents);
    harness.check(this.owner, this);
    harness.check(lostOwnerCalled, false);

    // Make someone else the owner.
    clipboard cp2 = new clipboard("dummy2");
    this.setContents(cp2, cp2);
    harness.check(lostOwnerCalled, true);
    harness.check(this.contents, cp2);
    harness.check(this.getContents(null), this.contents);
    harness.check(this.owner, cp2);
    harness.check(lostOwnerClipboard, this);
    harness.check(lostOwnerTransferable, this);
  
    // Set owner/content back to this.
    lostOwnerCalled = false;
    this.setContents(this, this);
    harness.check(lostOwnerCalled, false);
    harness.check(this.contents, this);
    harness.check(this.getContents(null), this.contents);
    harness.check(this.owner, this);

    // Keep outself as owner, but change the content.
    this.setContents(cp2, this);
    harness.check(lostOwnerCalled, false);
    harness.check(this.contents, cp2);
    harness.check(this.getContents(null), this.contents);
    harness.check(this.owner, this);
  }

  // Transferable 
  public DataFlavor[] getTransferDataFlavors()
  {
    return new DataFlavor[0];
  }

  public boolean isDataFlavorSupported(DataFlavor flavor)
  {
    return false;
  }

  public Object getTransferData(DataFlavor flavor)
  {
    return null;
  }

  // ClipboardOwner
  private boolean lostOwnerCalled = false;
  private Clipboard lostOwnerClipboard = null;
  private Transferable lostOwnerTransferable = null;
  public void lostOwnership(Clipboard clipboard, Transferable contents)
  {
    lostOwnerCalled = true;
    lostOwnerClipboard = clipboard;
    lostOwnerTransferable = contents;
  }

  // For debug readability
  public String toString()
  {
    return "[name=" + getName() + "]";
  }
}