1 /*
2 * Copyright (c) 2012, 2016, 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. 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 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 package test.robot.javafx.scene.layout;
26
27 import javafx.scene.Group;
28 import javafx.scene.Scene;
29 import javafx.scene.paint.Color;
30 import javafx.scene.paint.Paint;
31 import javafx.stage.Stage;
32 import java.util.ArrayList;
33 import java.util.LinkedList;
34 import java.util.List;
35 import java.util.concurrent.atomic.AtomicReference;
36 import javafx.scene.layout.Background;
37 import javafx.scene.layout.BackgroundFill;
38 import javafx.scene.layout.Border;
39 import javafx.scene.layout.CornerRadii;
40 import javafx.scene.layout.Region;
41 import test.robot.testharness.VisualTestBase;
42
43 /**
44 */
45 public abstract class RegionUITestBase extends VisualTestBase {
46 static final int WIDTH = 400;
47 static final int HEIGHT = 300;
48 static final int REGION_TOP = 50;
49 static final int REGION_LEFT = 50;
50 static final int REGION_RIGHT = 350;
51 static final int REGION_BOTTOM = 250;
52 static final int REGION_WIDTH = 300;
53 static final int REGION_HEIGHT = 200;
54 static final Color SCENE_FILL = Color.WHITE;
62 public void doSetup() {
63 super.doSetup();
64 runAndWait(() -> {
65 stage = getStage();
66 region = new Region();
67 region.setPrefSize(REGION_WIDTH, REGION_HEIGHT);
68 region.relocate(REGION_LEFT, REGION_TOP);
69 scene = new Scene(root = new Group(region), WIDTH, HEIGHT);
70 scene.setFill(SCENE_FILL);
71 stage.setScene(scene);
72 stage.show();
73 });
74 }
75
76 protected void setStyle(final String style) {
77 runAndWait(() -> region.setStyle(style));
78 waitFirstFrame();
79 }
80
81 static final double TOLERANCE = 0.07;
82
83 protected void assertColorEquals(Color expected, int x, int y, double tolerance) {
84 Color actual = getColorThreadSafe(x, y);
85 try {
86 assertColorEquals(expected, actual, tolerance);
87 } catch (AssertionError error) {
88 throw new AssertionError(error.getMessage() + " at position x=" + x + ", y=" + y);
89 }
90 }
91
92 protected void assertColorDoesNotEqual(Color notExpected, int x, int y, double tolerance) {
93 Color actual = getColorThreadSafe(x, y);
94 assertColorDoesNotEqual(notExpected, actual, tolerance);
95 }
96
97 private Color getColorThreadSafe(int x, int y) {
98 AtomicReference<Color> color = new AtomicReference<>();
99 runAndWait(() -> color.set(getColor(scene, x, y)));
100 return color.get();
101 }
|
1 /*
2 * Copyright (c) 2012, 2018, 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. 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 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 package test.robot.javafx.scene.layout;
26
27 import javafx.scene.Group;
28 import javafx.scene.Scene;
29 import javafx.scene.paint.Color;
30 import javafx.scene.paint.Paint;
31 import javafx.stage.Stage;
32 import javafx.stage.Window;
33 import java.util.ArrayList;
34 import java.util.LinkedList;
35 import java.util.List;
36 import java.util.concurrent.atomic.AtomicBoolean;
37 import java.util.concurrent.atomic.AtomicReference;
38 import javafx.scene.layout.Background;
39 import javafx.scene.layout.BackgroundFill;
40 import javafx.scene.layout.Border;
41 import javafx.scene.layout.CornerRadii;
42 import javafx.scene.layout.Region;
43 import test.robot.testharness.VisualTestBase;
44
45 /**
46 */
47 public abstract class RegionUITestBase extends VisualTestBase {
48 static final int WIDTH = 400;
49 static final int HEIGHT = 300;
50 static final int REGION_TOP = 50;
51 static final int REGION_LEFT = 50;
52 static final int REGION_RIGHT = 350;
53 static final int REGION_BOTTOM = 250;
54 static final int REGION_WIDTH = 300;
55 static final int REGION_HEIGHT = 200;
56 static final Color SCENE_FILL = Color.WHITE;
64 public void doSetup() {
65 super.doSetup();
66 runAndWait(() -> {
67 stage = getStage();
68 region = new Region();
69 region.setPrefSize(REGION_WIDTH, REGION_HEIGHT);
70 region.relocate(REGION_LEFT, REGION_TOP);
71 scene = new Scene(root = new Group(region), WIDTH, HEIGHT);
72 scene.setFill(SCENE_FILL);
73 stage.setScene(scene);
74 stage.show();
75 });
76 }
77
78 protected void setStyle(final String style) {
79 runAndWait(() -> region.setStyle(style));
80 waitFirstFrame();
81 }
82
83 static final double TOLERANCE = 0.07;
84
85 protected boolean checkIntegralUIScale() {
86 AtomicBoolean integralUIScale = new AtomicBoolean(false);
87 runAndWait(() -> {
88 Window window = scene.getWindow();
89 double outScaleX = window.getOutputScaleX();
90 double outScaleY = window.getOutputScaleY();
91
92 if (outScaleX == Math.rint(outScaleX)
93 && outScaleY == Math.rint(outScaleY)) {
94 integralUIScale.set(true);
95 }
96 });
97 return integralUIScale.get();
98 }
99
100 protected void assertColorEquals(Color expected, int x, int y, double tolerance) {
101 Color actual = getColorThreadSafe(x, y);
102 try {
103 assertColorEquals(expected, actual, tolerance);
104 } catch (AssertionError error) {
105 throw new AssertionError(error.getMessage() + " at position x=" + x + ", y=" + y);
106 }
107 }
108
109 protected void assertColorDoesNotEqual(Color notExpected, int x, int y, double tolerance) {
110 Color actual = getColorThreadSafe(x, y);
111 assertColorDoesNotEqual(notExpected, actual, tolerance);
112 }
113
114 private Color getColorThreadSafe(int x, int y) {
115 AtomicReference<Color> color = new AtomicReference<>();
116 runAndWait(() -> color.set(getColor(scene, x, y)));
117 return color.get();
118 }
|