1 /*
   2  * Copyright (c) 2011, 2013, 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 /**
  25  @test
  26  @summary Verify that getLocationOnScreen and getLocation return the value that was passed to setLocation
  27  @summary com.apple.junit.java.awt.Frame
  28  @library ../../regtesthelpers
  29  @build VisibilityValidator
  30  @run junit GetLocation
  31  */
  32 
  33 // classes necessary for this test
  34 import test.java.awt.regtesthelpers.VisibilityValidator;
  35 import java.awt.*;
  36 
  37 public class GetLocation {
  38     // Note that these are all chosen to be valid points for most Mac
  39     // windows. A more rigorous test would use
  40     //       GraphicsEnvironment.getLocalGraphicsEnvironment()
  41     // and make sure these points were valid
  42 
  43     static Point[] set_loc = {
  44         new Point(  25, 110 ),
  45         new Point(  22, 145 ),
  46         new Point(  25, 112 ),
  47         new Point(  21, 141 ),
  48         new Point(  25, 120 ),
  49         new Point(  27, 100 ),
  50         new Point(  25, 110 ),
  51         new Point(  28,  54 ),
  52         new Point(  25, 110 ),
  53         new Point(  20,  34 ),
  54         new Point(  23, 110 ),
  55         new Point(  22,  24 ),
  56         new Point(  25,  59 ),
  57         new Point( 112,  61 ),
  58         new Point(  25, 110 ),
  59         new Point(  27, 114 )
  60     };
  61 
  62     static Point[]  get_loc = new Point[set_loc.length];
  63 
  64     static int ITERATIONS = 10;
  65 
  66     public static void main( String[] args ) throws Exception{
  67         Frame windowf = new Frame();
  68         try {
  69             windowf.setSize(100, 100);
  70 
  71             VisibilityValidator.setVisibleAndConfirm(windowf);
  72 
  73             // getLocationOnScreen test
  74             for (int iter=0; iter<ITERATIONS; iter++) {
  75                 for (int i = 0; i < set_loc.length; i++) {
  76                     windowf.setLocation( set_loc[i] );
  77                     get_loc[i] = windowf.getLocationOnScreen();
  78 
  79                     if ((get_loc[i].getX() != set_loc[i].getX()) || (get_loc[i].getY() != set_loc[i].getY())) {
  80                         throw new RuntimeException("Unexpected getLocationOnScreen() problem: set_loc = " + set_loc[i] + "; get_loc = " + get_loc[i]);
  81                     }
  82                 }
  83             }
  84 
  85             // getLocation test
  86             for (int iter=0; iter<ITERATIONS; iter++) {
  87                 for (int i = 0; i < set_loc.length; i++) {
  88                     windowf.setLocation( set_loc[i] );
  89                     get_loc[i] = windowf.getLocation();
  90 
  91                     if ((get_loc[i].getX() != set_loc[i].getX()) || (get_loc[i].getY() != set_loc[i].getY())) {
  92                         throw new RuntimeException("Unexpected getLocation() problem: set_loc = " + set_loc[i] +"; get_loc = " + get_loc[i]);
  93                     }
  94                 }
  95             }
  96         }
  97         finally {
  98             windowf.setVisible(false);
  99             windowf.dispose();
 100         }
 101     }
 102 }