modules/graphics/src/test/java/test/javafx/scene/ImageCursor_getCurrentFrame_Test.java

Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.scene;
  27 
  28 import static javafx.scene.image.TestImages.TEST_ERROR_IMAGE;
  29 import static org.junit.Assert.assertEquals;
  30 import static org.junit.Assert.assertNotSame;
  31 import static org.junit.Assert.assertSame;
  32 import javafx.scene.image.Image;
  33 import javafx.scene.image.TestImages;
  34 
  35 import org.junit.Test;
  36 
  37 import com.sun.javafx.pgstub.StubToolkit;
  38 import com.sun.javafx.tk.Toolkit;



  39 
  40 public final class ImageCursor_getCurrentFrame_Test {
  41     private final StubToolkit toolkit;
  42 
  43     public ImageCursor_getCurrentFrame_Test() {
  44         toolkit = (StubToolkit) Toolkit.getToolkit();
  45     }
  46 
  47     @Test
  48     public void specialCasesTest() {
  49         final Object defaultCursorFrame =
  50                 Cursor.DEFAULT.getCurrentFrame();
  51 
  52         assertEquals(defaultCursorFrame,
  53                      new ImageCursor(null).getCurrentFrame());
  54 
  55         assertEquals(defaultCursorFrame,
  56                      new ImageCursor(TEST_ERROR_IMAGE).getCurrentFrame());
  57     }
  58 
  59     @Test
  60     public void animatedCursorTest() {
  61         // reset time
  62         toolkit.setAnimationTime(0);
  63         final Image animatedImage =
  64                 TestImages.createAnimatedTestImage(
  65                         300, 400,        // width, height
  66                         0,               // loop count
  67                         2000, 1000, 3000 // frame delays
  68                 );
  69         final ImageCursor animatedImageCursor = new ImageCursor(animatedImage);
  70 
  71         Object lastCursorFrame;
  72         Object currCursorFrame;
  73 
  74         animatedImageCursor.activate();
  75 
  76         lastCursorFrame = animatedImageCursor.getCurrentFrame();
  77 
  78         toolkit.setAnimationTime(1000);
  79         currCursorFrame = animatedImageCursor.getCurrentFrame();
  80         assertSame(lastCursorFrame, currCursorFrame);
  81         
  82         lastCursorFrame = currCursorFrame;
  83 
  84         toolkit.setAnimationTime(2500);
  85         currCursorFrame = animatedImageCursor.getCurrentFrame();
  86         assertNotSame(lastCursorFrame, currCursorFrame);
  87         
  88         lastCursorFrame = currCursorFrame;
  89 
  90         toolkit.setAnimationTime(4500);
  91         currCursorFrame = animatedImageCursor.getCurrentFrame();
  92         assertNotSame(lastCursorFrame, currCursorFrame);
  93 
  94         lastCursorFrame = currCursorFrame;
  95 
  96         toolkit.setAnimationTime(7000);
  97         currCursorFrame = animatedImageCursor.getCurrentFrame();
  98         assertNotSame(lastCursorFrame, currCursorFrame);
  99 
 100         animatedImageCursor.deactivate();
 101 
 102         TestImages.disposeAnimatedImage(animatedImage);
 103     }
 104 
 105     @Test
 106     public void animatedCursorCachingTest() {
 107         // reset time
 108         toolkit.setAnimationTime(0);
 109         final Image animatedImage =
 110                 TestImages.createAnimatedTestImage(
 111                         300, 400,        // width, height
 112                         0,               // loop count
 113                         2000, 1000, 3000 // frame delays
 114                 );
 115         final ImageCursor animatedImageCursor = new ImageCursor(animatedImage);
 116 
 117         animatedImageCursor.activate();
 118 
 119         toolkit.setAnimationTime(1000);
 120         final Object time1000CursorFrame =
 121                 animatedImageCursor.getCurrentFrame();
 122 
 123         toolkit.setAnimationTime(2500);
 124         final Object time2500CursorFrame =
 125                 animatedImageCursor.getCurrentFrame();
 126 
 127         toolkit.setAnimationTime(4500);
 128         final Object time4500CursorFrame =
 129                 animatedImageCursor.getCurrentFrame();
 130 
 131         toolkit.setAnimationTime(6000 + 1000);
 132         assertSame(time1000CursorFrame,
 133                    animatedImageCursor.getCurrentFrame());
 134 
 135         toolkit.setAnimationTime(6000 + 2500);
 136         assertSame(time2500CursorFrame,
 137                    animatedImageCursor.getCurrentFrame());
 138 
 139         toolkit.setAnimationTime(6000 + 4500);
 140         assertSame(time4500CursorFrame,
 141                    animatedImageCursor.getCurrentFrame());
 142 
 143         animatedImageCursor.deactivate();
 144 
 145         TestImages.disposeAnimatedImage(animatedImage);
 146     }
 147 }


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.javafx.scene;
  27 
  28 import static test.javafx.scene.image.TestImages.TEST_ERROR_IMAGE;
  29 import static org.junit.Assert.assertEquals;
  30 import static org.junit.Assert.assertNotSame;
  31 import static org.junit.Assert.assertSame;
  32 import javafx.scene.image.Image;
  33 import test.javafx.scene.image.TestImages;
  34 
  35 import org.junit.Test;
  36 
  37 import test.com.sun.javafx.pgstub.StubToolkit;
  38 import com.sun.javafx.tk.Toolkit;
  39 import javafx.scene.Cursor;
  40 import javafx.scene.CursorShim;
  41 import javafx.scene.ImageCursor;
  42 
  43 public final class ImageCursor_getCurrentFrame_Test {
  44     private final StubToolkit toolkit;
  45 
  46     public ImageCursor_getCurrentFrame_Test() {
  47         toolkit = (StubToolkit) Toolkit.getToolkit();
  48     }
  49 
  50     @Test
  51     public void specialCasesTest() {
  52         final Object defaultCursorFrame =
  53                 CursorShim.getCurrentFrame(Cursor.DEFAULT);
  54 
  55         assertEquals(defaultCursorFrame,
  56                 CursorShim.getCurrentFrame(new ImageCursor(null)));
  57 
  58         assertEquals(defaultCursorFrame,
  59                 CursorShim.getCurrentFrame(new ImageCursor(TEST_ERROR_IMAGE)));
  60     }
  61 
  62     @Test
  63     public void animatedCursorTest() {
  64         // reset time
  65         toolkit.setAnimationTime(0);
  66         final Image animatedImage =
  67                 TestImages.createAnimatedTestImage(
  68                         300, 400,        // width, height
  69                         0,               // loop count
  70                         2000, 1000, 3000 // frame delays
  71                 );
  72         final ImageCursor animatedImageCursor = new ImageCursor(animatedImage);
  73 
  74         Object lastCursorFrame;
  75         Object currCursorFrame;
  76 
  77         CursorShim.activate(animatedImageCursor);
  78 
  79         lastCursorFrame = CursorShim.getCurrentFrame(animatedImageCursor);
  80 
  81         toolkit.setAnimationTime(1000);
  82         currCursorFrame = CursorShim.getCurrentFrame(animatedImageCursor);
  83         assertSame(lastCursorFrame, currCursorFrame);
  84         
  85         lastCursorFrame = currCursorFrame;
  86 
  87         toolkit.setAnimationTime(2500);
  88         currCursorFrame = CursorShim.getCurrentFrame(animatedImageCursor);
  89         assertNotSame(lastCursorFrame, currCursorFrame);
  90         
  91         lastCursorFrame = currCursorFrame;
  92 
  93         toolkit.setAnimationTime(4500);
  94         currCursorFrame = CursorShim.getCurrentFrame(animatedImageCursor);
  95         assertNotSame(lastCursorFrame, currCursorFrame);
  96 
  97         lastCursorFrame = currCursorFrame;
  98 
  99         toolkit.setAnimationTime(7000);
 100         currCursorFrame = CursorShim.getCurrentFrame(animatedImageCursor);
 101         assertNotSame(lastCursorFrame, currCursorFrame);
 102 
 103         CursorShim.deactivate(animatedImageCursor);
 104 
 105         TestImages.disposeAnimatedImage(animatedImage);
 106     }
 107 
 108     @Test
 109     public void animatedCursorCachingTest() {
 110         // reset time
 111         toolkit.setAnimationTime(0);
 112         final Image animatedImage =
 113                 TestImages.createAnimatedTestImage(
 114                         300, 400,        // width, height
 115                         0,               // loop count
 116                         2000, 1000, 3000 // frame delays
 117                 );
 118         final ImageCursor animatedImageCursor = new ImageCursor(animatedImage);
 119 
 120         CursorShim.activate(animatedImageCursor);
 121 
 122         toolkit.setAnimationTime(1000);
 123         final Object time1000CursorFrame =
 124                 CursorShim.getCurrentFrame(animatedImageCursor);
 125 
 126         toolkit.setAnimationTime(2500);
 127         final Object time2500CursorFrame =
 128                 CursorShim.getCurrentFrame(animatedImageCursor);
 129 
 130         toolkit.setAnimationTime(4500);
 131         final Object time4500CursorFrame =
 132                 CursorShim.getCurrentFrame(animatedImageCursor);
 133 
 134         toolkit.setAnimationTime(6000 + 1000);
 135         assertSame(time1000CursorFrame,
 136                    CursorShim.getCurrentFrame(animatedImageCursor));
 137 
 138         toolkit.setAnimationTime(6000 + 2500);
 139         assertSame(time2500CursorFrame,
 140                    CursorShim.getCurrentFrame(animatedImageCursor));
 141 
 142         toolkit.setAnimationTime(6000 + 4500);
 143         assertSame(time4500CursorFrame,
 144                    CursorShim.getCurrentFrame(animatedImageCursor));
 145 
 146         CursorShim.deactivate(animatedImageCursor);
 147 
 148         TestImages.disposeAnimatedImage(animatedImage);
 149     }
 150 }