public inbox for mauve-patches@sourceware.org
 help / color / mirror / Atom feed
* FYI: New Container test
@ 2005-11-02 15:18 Roman Kennke
  0 siblings, 0 replies; 2+ messages in thread
From: Roman Kennke @ 2005-11-02 15:18 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 447 bytes --]

I added a new test for Container.addImpl. This shows that events are sent
to ContainerListeners even when the Container is not showing, and that
these events are delivered directly (and not via the EventQueue).

2005-11-02  Roman Kennke  <kennke@aicas.com>

        * gnu/testlet/java/awt/Container/addImpl.java: New test.
        * gnu/testlet/java/awt/Container/DisabledEventQueue: Auxiliary
        class for the above test.

/Roman

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: addImpl.java --]
[-- Type: text/x-java; name="addImpl.java", Size: 2869 bytes --]

// 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 java.awt.Component;
import java.awt.Container;
import java.awt.Toolkit;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;

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

/**
 * 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)
  {
    // 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());

    Container c = new Container();
    c.addContainerListener(new TestContainerListener());
    // Pre-condition check.
    harness.check(c.isShowing(), false);
    componentAddedCalled = false;
    c.add(new Component(){});
    harness.check(componentAddedCalled, true);
  }

}

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: DisabledEventQueue.java --]
[-- Type: text/x-java; name="DisabledEventQueue.java", Size: 1375 bytes --]

// Tags: not-a-test

// 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 java.awt.AWTEvent;
import java.awt.EventQueue;

/**
 * A special EventQueue used for testing purposes. It completely disables
 * dispatching of events, so the behaviour of the RepaintManager can be
 * examined more closely.
 *
 * @author Roman Kennke (kennke@aicas.com)
 */
public class DisabledEventQueue extends EventQueue
{
  /**
   * Overridden to do nothing.
   */
  protected void dispatchEvent(AWTEvent ev)
  {
    // Do nothing.
  }

  /**
   * Overridden to do nothing.
   */
  public void postEvent(AWTEvent ev)
  {
    // Do nothing.
  }
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* FYI: New Container test
@ 2006-07-07 12:10 Roman Kennke
  0 siblings, 0 replies; 2+ messages in thread
From: Roman Kennke @ 2006-07-07 12:10 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 194 bytes --]

This new test backs up a change that I made in Classpath recently.

2006-07-07  Roman Kennke  <kennke@aicas.com>

        * gnu/testlet/java/awt/Container/setLayout.java: New file.  



/Roman


[-- Attachment #2: setLayout.java --]
[-- Type: text/x-java, Size: 2294 bytes --]

/* setLayout.java -- Checks how setLayout is supposed to work
   Copyright (C) 2006 Roman Kennke (kennke@aicas.com)
This file is part of Mauve.

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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

*/

// Tags: JDK1.1

package gnu.testlet.java.awt.Container;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Frame;

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

public class setLayout implements Testlet
{

  private boolean invalidated;

  private class TestContainer extends Container
  {
    public void invalidate()
    {
      super.invalidate();
      invalidated = true;
    }
  }

  public void test(TestHarness harness)
  {
    testInvalidate(harness);
  }

  private void testInvalidate(TestHarness h)
  {
    h.checkPoint("invalidate");
    TestContainer c = new TestContainer();

    // Test not showing.
    // Valid components get invalidated.
    c.validate();
    h.check(! c.isValid());
    invalidated = false;
    c.setLayout(new FlowLayout());
    h.check(! invalidated);

    // Invalid components don't get invalidated.
    h.check(!c.isValid());
    invalidated = false;
    c.setLayout(new FlowLayout());
    h.check(! invalidated);

    // Test showing.
    Frame f = new Frame();
    f.add(c);
    f.setSize(100, 100);
    f.setVisible(true);

    h.check(c.isShowing());
    // Valid components get invalidated.
    c.validate();
    h.check(c.isValid());
    invalidated = false;
    c.setLayout(new FlowLayout());
    h.check(invalidated);

    // Invalid components don't get invalidated.
    h.check(!c.isValid());
    invalidated = false;
    c.setLayout(new FlowLayout());
    h.check(! invalidated);

  }
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-07-07 12:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-02 15:18 FYI: New Container test Roman Kennke
2006-07-07 12:10 Roman Kennke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).