1 /*
   2  * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.awt.*;
  25 
  26 /*
  27  * @test
  28  * @summary Testcase to check if there is any memory leak when components are
  29  *          added and then removed from an embedded AWT Frame in an SWT shell.
  30  * @author Girish R (girish.ramachandran@sun.com), AWT-SQE
  31  * @library ../../../lib/testlibrary
  32  * @build ExtendedRobot
  33  * @run shell TaskXEmbedMemory.sh
  34  */
  35 
  36 public class TaskXEmbedMemory extends Task<GUIXEmbedMemory> {
  37 
  38     public static void main (String[] args) throws Exception {
  39         new TaskXEmbedMemory(new GUIXEmbedMemory(), new ExtendedRobot()).runTask();
  40         System.exit(0);
  41     }
  42 
  43     public TaskXEmbedMemory(GUIXEmbedMemory gui, ExtendedRobot robot) {
  44          super(gui, robot);
  45     }
  46 
  47     /**
  48      * Simple test. All components and remove them. Check if there's memory leak.
  49      * Took the test from Frame test.
  50      */
  51     public void task() throws Exception {
  52         robot.glide(100, 100, 200, 110);
  53         robot.waitForIdle();
  54         robot.click();
  55 
  56         Panel panel;
  57         Button button;
  58         Canvas canvas;
  59         Checkbox checkbox;
  60         Choice choice;
  61         Container container;
  62         Label label;
  63         List list;
  64         Scrollbar scrollbar;
  65         TextArea textarea;
  66         TextField textfield;
  67         panel = new Panel();
  68 
  69         container = new Container();
  70         container.setLayout(new FlowLayout());
  71 
  72         button = new Button("Button");
  73         canvas = new Canvas();
  74         checkbox = new Checkbox("CheckBox");
  75         choice = new Choice();
  76         choice.add("Choice 1");
  77         choice.add("Choice 2");
  78         choice.add("Choice 3");
  79         choice.add("Choice 4");
  80 
  81         label = new Label("Label");
  82         list = new List(2);
  83         list.add("list 1");
  84         list.add("list 2");
  85         list.add("list 3");
  86         scrollbar = new Scrollbar();
  87 
  88         textarea = new TextArea("TextArea", 3, 10);
  89         textfield = new TextField("TextField");
  90 
  91         container.add(button);
  92         container.add(canvas);
  93         container.add(checkbox);
  94         container.add(choice);
  95         container.add(label);
  96         container.add(list);
  97         container.add(scrollbar);
  98         container.add(textarea);
  99         container.add(textfield);
 100 
 101         panel.add(container);
 102         gui.frame.add(panel);
 103         robot.waitForIdle(1000);
 104 
 105         gui.frame.removeAll();
 106         robot.waitForIdle(1000);
 107 
 108         gui.destroyProcess();
 109         gui.dispose();
 110     }
 111 }
 112