File: addImpl.java

package info (click to toggle)
mauve 20080616-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 26,856 kB
  • ctags: 21,952
  • sloc: java: 234,107; sh: 2,834; xml: 208; makefile: 59
file content (245 lines) | stat: -rw-r--r-- 6,268 bytes parent folder | download | duplicates (2)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// Tags: JDK1.5
// Uses: DisabledEventQueue

// Copyright (C) 2005 Roman Kennke <kennke@aicas.com>

// 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
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.java.awt.Container;

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

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Label;
import java.awt.LayoutManager;
import java.awt.Panel;
import java.awt.Toolkit;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;

/**
 * This checks tests if the addImpl method notfies container listeners when
 * a container is not showing and if the notification is sent over the event
 * queue or delivered directly. The test shows that the event is also sent when
 * the container is not showing and that the event is delivered directly.
 *
 * @author Roman Kennke (kennke@aicas.com)
 */
public class addImpl implements Testlet
{

  /**
   * A container listener for test.
   *
   * @author Roman Kennke (kennke@aicas.com)
   */
  class TestContainerListener implements ContainerListener
  {

    /**
     * Receives notification when a component was added to the container.
     *
     * @param event the container event
     */
    public void componentAdded(ContainerEvent event)
    {
      componentAddedCalled = true;
    }

    /**
     * Receives notification when a component was removed from the container.
     *
     * @param event the container event
     */
    public void componentRemoved(ContainerEvent event)
    {
      // TODO Auto-generated method stub
      
    }
    
  }

  /**
   * True when the componentAdded method in the container listener was called.
   */
  boolean componentAddedCalled;

  /**
   * Starts the test run.
   *
   * @param harness the test harness to use
   */
  public void test(TestHarness harness)
  {
    test1(harness);
    test2(harness);
  }
  
  public void test1(TestHarness harness)
  {
    // We disable the event queue so we can check if this event is delivered
    // via the event queue or not.
    Toolkit.getDefaultToolkit().getSystemEventQueue().push(new DisabledEventQueue());

    final TestHarness transfer = harness;
    Container c = new Container()
    {
      TestHarness harness = transfer;
            
      public void repaint(long tm, int x, int y, int w, int h)
      {
        harness.fail("repaint has been called.");
      }
    };
    c.addContainerListener(new TestContainerListener());
    // Pre-condition check.
    harness.check(c.isShowing(), false);
    componentAddedCalled = false;
    
    Component a = new Component()
    {
      TestHarness harness = transfer;

      public void repaint(long tm, int x, int y, int w, int h)
      {
        harness.fail("repaint has been called.");
      }
    };
    
    Component b = new Component()
    {
      TestHarness harness = transfer;

      public void repaint(long tm, int x, int y, int w, int h)
      {
        harness.fail("repaint has been called.");
      }
    };
    
    c.add(a);
    harness.check(componentAddedCalled, true);
    
    // check that LayoutManager.addLayoutComponent() is called
    // with non-null name.
    Container two = new Container()
    {
      TestHarness harness = transfer;
            
      public void repaint(long tm, int x, int y, int w, int h)
      {
        harness.fail("repaint has been called.");
      }
    };
    
    two.setLayout(new LayoutManager()
    {
      TestHarness harness = transfer;

      Dimension size = new Dimension();

      public void removeLayoutComponent(Component comp)
      {
      }

      public java.awt.Dimension preferredLayoutSize(Container cont)
      {
        return size;
      }

      public Dimension minimumLayoutSize(Container cont)
      {
        return size;
      }

      public void layoutContainer(Container container)
      {
      }

      public void addLayoutComponent(String name, Component comp)
      {
        boolean pass = (name != null);
        harness.check(pass, true);
      }
    });
    harness.check(two.isShowing(), false);
    componentAddedCalled = false;
    two.addContainerListener(new TestContainerListener());
    two.add(b);
    harness.check(componentAddedCalled, true);
  }
  
  public void test2(TestHarness harness)
  {
    final TestHarness transfer = harness;
    Frame f = new Frame()
    {
      TestHarness harness = transfer;

      public void repaint(long tm, int x, int y, int w, int h)
      {
        harness.fail("repaint has been called.");
      }
    };
    
    Panel a = new Panel()
    {
      TestHarness harness = transfer;
            
      public void repaint(long tm, int x, int y, int w, int h)
      {
        harness.fail("repaint has been called.");
      }
    };
    
    Label l = new Label("!!!!!")
    {
      TestHarness harness = transfer;

      public void repaint(long tm, int x, int y, int w, int h)
      {
        harness.fail("repaint has been called.");
      }
    };
    
    Container c = new Container()
    {
      TestHarness harness = transfer;

      public void repaint(long tm, int x, int y, int w, int h)
      {
        harness.fail("repaint has been called.");
      }
    };
    
    a.add(c);
    a.add(l);
    c.setSize(100,100);
    f.add(a);
    f.pack();
    f.show();    
    harness.check(a.isShowing(), true);
    harness.check(c.isShowing(), true);
    harness.check(l.isShowing(), true);
    harness.check(f.isShowing(), true);
    harness.check(c.isLightweight(), true);
    harness.check(a.isLightweight(), false);
    harness.check(l.isLightweight(), false);
  }
}