1 /*
2 * Copyright (c) 2010, 2015, 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 *
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
37 import javafx.beans.property.ObjectProperty;
38 import javafx.beans.property.SimpleDoubleProperty;
39 import javafx.beans.property.SimpleObjectProperty;
40 import javafx.beans.value.ChangeListener;
41 import javafx.beans.value.ObservableValue;
42 import javafx.beans.value.WritableValue;
43 import javafx.scene.Group;
44 import javafx.scene.Node;
45 import javafx.scene.shape.Rectangle;
46 import com.sun.javafx.scene.control.Logging;
47 import javafx.css.Styleable;
48 import javafx.css.StyleableProperty;
49 import javafx.scene.control.ContextMenu;
50 import javafx.scene.control.Control;
51 import javafx.scene.control.ControlShim;
52 import javafx.scene.control.Skin;
53 import javafx.scene.control.Tooltip;
54 import org.junit.Before;
55 import org.junit.Ignore;
56 import org.junit.Test;
57 import sun.util.logging.PlatformLogger;
58 import sun.util.logging.PlatformLogger.Level;
59
60 import static org.junit.Assert.*;
61
62 /**
63 * Things every Control needs to test:
64 * - Properties
65 * - Set the value, see that it changes
66 * - Set an illegal value, see that it is rejected
67 * - Bind to some other value, see that when the binding fires, the property is updated (vague)
68 * - CSS
69 * - Change state, watch the pseudo class state change
70 * - Default style-class has what you expect
71 * - (2nd order) impl_cssSettable returns true for thing in their default state
72 * - (2nd order) impl_cssSettable returns false for things manually specified
73 * - (3rd order) impl_cssKeys includes all the public properties
74 * - Methods
75 * - For all methods, calling the method mutates the state appropriately
76 */
77 public class ControlTest {
78 private static final double MIN_WIDTH = 35;
89
90 private Level originalLogLevel = null;
91
92 @Before public void setUp() {
93 c = new ControlStub();
94 s = new SkinStub<ControlStub>(c);
95 skinNode = new ResizableRectangle();
96 skinNode.resize(20, 20);
97 skinNode.minWidth = MIN_WIDTH;
98 skinNode.minHeight = MIN_HEIGHT;
99 skinNode.maxWidth = MAX_WIDTH;
100 skinNode.maxHeight = MAX_HEIGHT;
101 skinNode.prefWidth = PREF_WIDTH;
102 skinNode.prefHeight = PREF_HEIGHT;
103 skinNode.baselineOffset = BASELINE_OFFSET;
104 s.setNode(skinNode);
105 }
106
107 private void disableLogging() {
108 final PlatformLogger logger = Logging.getControlsLogger();
109 originalLogLevel = logger.level();
110 logger.setLevel(Level.OFF);
111 }
112
113 private void enableLogging() {
114 final PlatformLogger logger = Logging.getControlsLogger();
115 // logger.setLevel(originalLogLevel);
116 logger.setLevel(Level.FINE);
117 }
118
119 @Test public void focusTraversableIsTrueByDefault() {
120 assertTrue(c.isFocusTraversable());
121 }
122
123 @Test public void resizableIsTrueByDefault() {
124 assertTrue(c.isResizable());
125 }
126
127 @Test public void modifyingTheControlWidthUpdatesTheLayoutBounds() {
128 c.resize(173, c.getHeight());
129 assertEquals(173, c.getLayoutBounds().getWidth(), 0);
130 }
131
132 @Test public void modifyingTheControlWidthLeadsToRequestLayout() {
133 // Make sure the Control has it's needsLayout flag cleared
134 c.layout();
135 assertTrue(!c.isNeedsLayout());
136 // Run the test
|
1 /*
2 * Copyright (c) 2010, 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 *
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
37 import javafx.beans.property.ObjectProperty;
38 import javafx.beans.property.SimpleDoubleProperty;
39 import javafx.beans.property.SimpleObjectProperty;
40 import javafx.beans.value.ChangeListener;
41 import javafx.beans.value.ObservableValue;
42 import javafx.beans.value.WritableValue;
43 import javafx.scene.Group;
44 import javafx.scene.Node;
45 import javafx.scene.shape.Rectangle;
46 import com.sun.javafx.scene.control.Logging;
47 import javafx.css.Styleable;
48 import javafx.css.StyleableProperty;
49 import javafx.scene.control.ContextMenu;
50 import javafx.scene.control.Control;
51 import javafx.scene.control.ControlShim;
52 import javafx.scene.control.Skin;
53 import javafx.scene.control.Tooltip;
54 import org.junit.Before;
55 import org.junit.Ignore;
56 import org.junit.Test;
57 import com.sun.javafx.logging.PlatformLogger;
58 import com.sun.javafx.logging.PlatformLogger.Level;
59
60 import static org.junit.Assert.*;
61
62 /**
63 * Things every Control needs to test:
64 * - Properties
65 * - Set the value, see that it changes
66 * - Set an illegal value, see that it is rejected
67 * - Bind to some other value, see that when the binding fires, the property is updated (vague)
68 * - CSS
69 * - Change state, watch the pseudo class state change
70 * - Default style-class has what you expect
71 * - (2nd order) impl_cssSettable returns true for thing in their default state
72 * - (2nd order) impl_cssSettable returns false for things manually specified
73 * - (3rd order) impl_cssKeys includes all the public properties
74 * - Methods
75 * - For all methods, calling the method mutates the state appropriately
76 */
77 public class ControlTest {
78 private static final double MIN_WIDTH = 35;
89
90 private Level originalLogLevel = null;
91
92 @Before public void setUp() {
93 c = new ControlStub();
94 s = new SkinStub<ControlStub>(c);
95 skinNode = new ResizableRectangle();
96 skinNode.resize(20, 20);
97 skinNode.minWidth = MIN_WIDTH;
98 skinNode.minHeight = MIN_HEIGHT;
99 skinNode.maxWidth = MAX_WIDTH;
100 skinNode.maxHeight = MAX_HEIGHT;
101 skinNode.prefWidth = PREF_WIDTH;
102 skinNode.prefHeight = PREF_HEIGHT;
103 skinNode.baselineOffset = BASELINE_OFFSET;
104 s.setNode(skinNode);
105 }
106
107 private void disableLogging() {
108 final PlatformLogger logger = Logging.getControlsLogger();
109 logger.disableLogging();
110 }
111
112 private void enableLogging() {
113 final PlatformLogger logger = Logging.getControlsLogger();
114 logger.enableLogging();
115 }
116
117 @Test public void focusTraversableIsTrueByDefault() {
118 assertTrue(c.isFocusTraversable());
119 }
120
121 @Test public void resizableIsTrueByDefault() {
122 assertTrue(c.isResizable());
123 }
124
125 @Test public void modifyingTheControlWidthUpdatesTheLayoutBounds() {
126 c.resize(173, c.getHeight());
127 assertEquals(173, c.getLayoutBounds().getWidth(), 0);
128 }
129
130 @Test public void modifyingTheControlWidthLeadsToRequestLayout() {
131 // Make sure the Control has it's needsLayout flag cleared
132 c.layout();
133 assertTrue(!c.isNeedsLayout());
134 // Run the test
|