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.effect;
27
28 import static org.junit.Assert.assertEquals;
29
30 import java.lang.reflect.Method;
31
32 import javafx.beans.property.IntegerProperty;
33 import javafx.beans.property.SimpleIntegerProperty;
34
35 import org.junit.Before;
36 import org.junit.Test;
37
38 public class FloatMapTest extends EffectsTestBase {
39 private FloatMap floatMap;
40 private DisplacementMap displacementMap;
41
42 @Before
43 public void setUp() {
44 floatMap = new FloatMap();
45 displacementMap = new DisplacementMap();
46 displacementMap.setMapData(floatMap);
47 setupTest(displacementMap);
48 }
49
50 @Test
51 public void testSetWidth() {
52 // try setting correct value
53 floatMap.setWidth(2);
54 assertEquals(2, floatMap.getWidth());
55 pulse();
56 assertEquals(2, ((com.sun.scenario.effect.FloatMap) floatMap.getImpl()).getWidth());
57 }
58
59 @Test
60 public void testDefaultWidth() {
61 // default value should be 1
62 assertEquals(1, floatMap.getWidth());
63 assertEquals(1, floatMap.widthProperty().get());
64 pulse();
65 assertEquals(1, ((com.sun.scenario.effect.FloatMap) floatMap.getImpl()).getWidth());
66 }
67
68 @Test
69 public void testMinWidth() {
70 // 1 should be ok
71 floatMap.setWidth(1);
72 // try setting value smaller than minimal
73 floatMap.setWidth(0);
74 assertEquals(0, floatMap.getWidth());
75 pulse();
76 assertEquals(1, ((com.sun.scenario.effect.FloatMap) floatMap.getImpl()).getWidth());
77 }
78
79 @Test
80 public void testMaxWidth() {
81 // 4096 should be ok
82 floatMap.setWidth(4096);
83 // try setting value greater than maximal
84 floatMap.setWidth(4097);
85 assertEquals(4097, floatMap.getWidth());
86 pulse();
87 assertEquals(4096, ((com.sun.scenario.effect.FloatMap) floatMap.getImpl()).getWidth());
88 }
89
90 @Test
91 public void testSetHeight() {
92 // try setting correct value
93 floatMap.setHeight(5);
94 assertEquals(5, floatMap.getHeight());
95 pulse();
96 assertEquals(5, ((com.sun.scenario.effect.FloatMap) floatMap.getImpl()).getHeight());
97 }
98
99 @Test
100 public void testDefaultHeight() {
101 // default value should be 1
102 assertEquals(1, floatMap.getHeight());
103 assertEquals(1, floatMap.heightProperty().get());
104 pulse();
105 assertEquals(1, ((com.sun.scenario.effect.FloatMap) floatMap.getImpl()).getHeight());
106 }
107
108 @Test
109 public void testMinHeight() {
110 // 1 should be ok
111 floatMap.setHeight(1);
112 // try setting value smaller than minimal
113 floatMap.setHeight(0);
114 assertEquals(0, floatMap.getHeight());
115 pulse();
116 assertEquals(1, ((com.sun.scenario.effect.FloatMap) floatMap.getImpl()).getHeight());
117 }
118
119 @Test
120 public void testMaxHeight() {
121 // 4096 should be ok
122 floatMap.setHeight(4096);
123 // try setting value greater than maximal
124 floatMap.setHeight(4097);
125 assertEquals(4097, floatMap.getHeight());
126 pulse();
127 assertEquals(4096, ((com.sun.scenario.effect.FloatMap) floatMap.getImpl()).getHeight());
128 }
129
130 @Test
131 public void testSetSamples3() {
132 floatMap.setSamples(0, 0, 0.5f);
133 pulse();
134 com.sun.scenario.effect.FloatMap fm = floatMap.getImpl();
135 float[] data = fm.getData();
136 assertEquals(0.5f, data[0], 1e-100);
137 assertEquals(0.0f, data[1], 1e-100);
138 assertEquals(0.0f, data[2], 1e-100);
139 assertEquals(0.0f, data[3], 1e-100);
140 }
141
142 @Test
143 public void testSetSamples4() {
144 floatMap.setSamples(0, 0, 0.5f, 0.4f);
145 pulse();
146 com.sun.scenario.effect.FloatMap fm = floatMap.getImpl();
147 float[] data = fm.getData();
148 assertEquals(0.5f, data[0], 1e-100);
149 assertEquals(0.4f, data[1], 1e-100);
150 assertEquals(0.0f, data[2], 1e-100);
151 assertEquals(0.0f, data[3], 1e-100);
152 }
153
154 @Test
155 public void testSetSamples5() {
156 floatMap.setSamples(0, 0, 0.5f, 0.4f, 0.3f);
157 pulse();
158 com.sun.scenario.effect.FloatMap fm = floatMap.getImpl();
159 float[] data = fm.getData();
160 assertEquals(0.5f, data[0], 1e-100);
161 assertEquals(0.4f, data[1], 1e-100);
162 assertEquals(0.3f, data[2], 1e-100);
163 assertEquals(0.0f, data[3], 1e-100);
164 }
165
166 @Test
167 public void testSetSamples6() {
168 floatMap.setSamples(0, 0, 0.5f, 0.4f, 0.3f, 0.2f);
169 pulse();
170 com.sun.scenario.effect.FloatMap fm = floatMap.getImpl();
171 float[] data = fm.getData();
172 assertEquals(0.5f, data[0], 1e-100);
173 assertEquals(0.4f, data[1], 1e-100);
174 assertEquals(0.3f, data[2], 1e-100);
175 assertEquals(0.2f, data[3], 1e-100);
176 }
177
178 @Test
179 public void testSetSample() {
180 floatMap.setSample(0, 0, 0, 0.5f);
181 floatMap.setSample(0, 0, 1, 0.4f);
182 floatMap.setSample(0, 0, 2, 0.3f);
183 floatMap.setSample(0, 0, 3, 0.2f);
184 pulse();
185 com.sun.scenario.effect.FloatMap fm = floatMap.getImpl();
186 float[] data = fm.getData();
187 assertEquals(0.5f, data[0], 1e-100);
188 assertEquals(0.4f, data[1], 1e-100);
189 assertEquals(0.3f, data[2], 1e-100);
190 assertEquals(0.2f, data[3], 1e-100);
191 }
192
193 @Test
194 public void testHeightSynced() throws Exception {
195 checkIntPropertySynced(
196 "javafx.scene.effect.FloatMap", "height",
197 "com.sun.scenario.effect.FloatMap", "height", 10);
198 }
199
200 @Test
201 public void testWidthSynced() throws Exception {
202 checkIntPropertySynced(
203 "javafx.scene.effect.FloatMap", "width",
204 "com.sun.scenario.effect.FloatMap", "width", 10);
205 }
212 String propertyName,
213 String pgEffectName,
214 String pgPropertyName,
215 int expected)
216 throws Exception {
217 final Class effectClass = Class.forName(effectName);
218 final Class pgEffectClass = Class.forName(pgEffectName);
219
220 final StringBuilder pgPropertyNameBuilder = new StringBuilder(pgPropertyName);
221 pgPropertyNameBuilder.setCharAt(0, Character.toUpperCase(pgPropertyName.charAt(0)));
222 final String pgGetterName = new StringBuilder("get").append(pgPropertyNameBuilder).toString();
223 final Method pgGetter = pgEffectClass.getMethod(pgGetterName);
224
225 IntegerProperty v = new SimpleIntegerProperty();
226 Method m = effectClass.getMethod(propertyName + "Property", new Class[] {});
227 ((IntegerProperty)m.invoke(floatMap)).bind(v);
228
229 pulse(); // make sure that the dirty flag is cleaned before testing of binding
230 v.set(expected);
231 pulse();
232 assertEquals(expected, ((Number)pgGetter.invoke(floatMap.getImpl())).intValue());
233 }
234
235 @Test
236 public void testCreateWithParams() {
237 floatMap = new FloatMap(2, 3);
238 displacementMap = new DisplacementMap();
239 displacementMap.setMapData(floatMap);
240 setupTest(displacementMap);
241 assertEquals(2, floatMap.getWidth(), 1e-100);
242 assertEquals(3, floatMap.getHeight(), 1e-100);
243 pulse();
244 assertEquals(2, ((com.sun.scenario.effect.FloatMap) floatMap.getImpl()).getWidth());
245 assertEquals(3, ((com.sun.scenario.effect.FloatMap) floatMap.getImpl()).getHeight());
246 }
247
248 @Test
249 public void testCreateWithDefaultParams() {
250 floatMap = new FloatMap(1, 1);
251 displacementMap = new DisplacementMap();
252 displacementMap.setMapData(floatMap);
253 setupTest(displacementMap);
254 assertEquals(1, floatMap.getWidth(), 1e-100);
255 assertEquals(1, floatMap.getHeight(), 1e-100);
256 pulse();
257 assertEquals(1, ((com.sun.scenario.effect.FloatMap) floatMap.getImpl()).getWidth());
258 assertEquals(1, ((com.sun.scenario.effect.FloatMap) floatMap.getImpl()).getHeight());
259 }
260
261 }
|
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.effect;
27
28 import test.javafx.scene.effect.EffectsTestBase;
29 import static org.junit.Assert.assertEquals;
30
31 import java.lang.reflect.Method;
32
33 import javafx.beans.property.IntegerProperty;
34 import javafx.beans.property.SimpleIntegerProperty;
35 import javafx.scene.effect.DisplacementMap;
36 import javafx.scene.effect.FloatMap;
37 import javafx.scene.effect.FloatMapShim;
38
39 import org.junit.Before;
40 import org.junit.Test;
41
42 public class FloatMapTest extends EffectsTestBase {
43 private FloatMap floatMap;
44 private DisplacementMap displacementMap;
45
46 @Before
47 public void setUp() {
48 floatMap = new FloatMap();
49 displacementMap = new DisplacementMap();
50 displacementMap.setMapData(floatMap);
51 setupTest(displacementMap);
52 }
53
54 @Test
55 public void testSetWidth() {
56 // try setting correct value
57 floatMap.setWidth(2);
58 assertEquals(2, floatMap.getWidth());
59 pulse();
60 assertEquals(2, ((com.sun.scenario.effect.FloatMap)
61 FloatMapShim.getImpl(floatMap)).getWidth());
62 }
63
64 @Test
65 public void testDefaultWidth() {
66 // default value should be 1
67 assertEquals(1, floatMap.getWidth());
68 assertEquals(1, floatMap.widthProperty().get());
69 pulse();
70 assertEquals(1, ((com.sun.scenario.effect.FloatMap)
71 FloatMapShim.getImpl(floatMap)).getWidth());
72 }
73
74 @Test
75 public void testMinWidth() {
76 // 1 should be ok
77 floatMap.setWidth(1);
78 // try setting value smaller than minimal
79 floatMap.setWidth(0);
80 assertEquals(0, floatMap.getWidth());
81 pulse();
82 assertEquals(1, ((com.sun.scenario.effect.FloatMap)
83 FloatMapShim.getImpl(floatMap)).getWidth());
84 }
85
86 @Test
87 public void testMaxWidth() {
88 // 4096 should be ok
89 floatMap.setWidth(4096);
90 // try setting value greater than maximal
91 floatMap.setWidth(4097);
92 assertEquals(4097, floatMap.getWidth());
93 pulse();
94 assertEquals(4096, ((com.sun.scenario.effect.FloatMap)
95 FloatMapShim.getImpl(floatMap)).getWidth());
96 }
97
98 @Test
99 public void testSetHeight() {
100 // try setting correct value
101 floatMap.setHeight(5);
102 assertEquals(5, floatMap.getHeight());
103 pulse();
104 assertEquals(5, ((com.sun.scenario.effect.FloatMap)
105 FloatMapShim.getImpl(floatMap)).getHeight());
106 }
107
108 @Test
109 public void testDefaultHeight() {
110 // default value should be 1
111 assertEquals(1, floatMap.getHeight());
112 assertEquals(1, floatMap.heightProperty().get());
113 pulse();
114 assertEquals(1, ((com.sun.scenario.effect.FloatMap)
115 FloatMapShim.getImpl(floatMap)).getHeight());
116 }
117
118 @Test
119 public void testMinHeight() {
120 // 1 should be ok
121 floatMap.setHeight(1);
122 // try setting value smaller than minimal
123 floatMap.setHeight(0);
124 assertEquals(0, floatMap.getHeight());
125 pulse();
126 assertEquals(1, ((com.sun.scenario.effect.FloatMap)
127 FloatMapShim.getImpl(floatMap)).getHeight());
128 }
129
130 @Test
131 public void testMaxHeight() {
132 // 4096 should be ok
133 floatMap.setHeight(4096);
134 // try setting value greater than maximal
135 floatMap.setHeight(4097);
136 assertEquals(4097, floatMap.getHeight());
137 pulse();
138 assertEquals(4096, ((com.sun.scenario.effect.FloatMap)
139 FloatMapShim.getImpl(floatMap)).getHeight());
140 }
141
142 @Test
143 public void testSetSamples3() {
144 floatMap.setSamples(0, 0, 0.5f);
145 pulse();
146 com.sun.scenario.effect.FloatMap fm = FloatMapShim.getImpl(floatMap);
147 float[] data = fm.getData();
148 assertEquals(0.5f, data[0], 1e-100);
149 assertEquals(0.0f, data[1], 1e-100);
150 assertEquals(0.0f, data[2], 1e-100);
151 assertEquals(0.0f, data[3], 1e-100);
152 }
153
154 @Test
155 public void testSetSamples4() {
156 floatMap.setSamples(0, 0, 0.5f, 0.4f);
157 pulse();
158 com.sun.scenario.effect.FloatMap fm = FloatMapShim.getImpl(floatMap);
159 float[] data = fm.getData();
160 assertEquals(0.5f, data[0], 1e-100);
161 assertEquals(0.4f, data[1], 1e-100);
162 assertEquals(0.0f, data[2], 1e-100);
163 assertEquals(0.0f, data[3], 1e-100);
164 }
165
166 @Test
167 public void testSetSamples5() {
168 floatMap.setSamples(0, 0, 0.5f, 0.4f, 0.3f);
169 pulse();
170 com.sun.scenario.effect.FloatMap fm = FloatMapShim.getImpl(floatMap);
171 float[] data = fm.getData();
172 assertEquals(0.5f, data[0], 1e-100);
173 assertEquals(0.4f, data[1], 1e-100);
174 assertEquals(0.3f, data[2], 1e-100);
175 assertEquals(0.0f, data[3], 1e-100);
176 }
177
178 @Test
179 public void testSetSamples6() {
180 floatMap.setSamples(0, 0, 0.5f, 0.4f, 0.3f, 0.2f);
181 pulse();
182 com.sun.scenario.effect.FloatMap fm = FloatMapShim.getImpl(floatMap);
183 float[] data = fm.getData();
184 assertEquals(0.5f, data[0], 1e-100);
185 assertEquals(0.4f, data[1], 1e-100);
186 assertEquals(0.3f, data[2], 1e-100);
187 assertEquals(0.2f, data[3], 1e-100);
188 }
189
190 @Test
191 public void testSetSample() {
192 floatMap.setSample(0, 0, 0, 0.5f);
193 floatMap.setSample(0, 0, 1, 0.4f);
194 floatMap.setSample(0, 0, 2, 0.3f);
195 floatMap.setSample(0, 0, 3, 0.2f);
196 pulse();
197 com.sun.scenario.effect.FloatMap fm = FloatMapShim.getImpl(floatMap);
198 float[] data = fm.getData();
199 assertEquals(0.5f, data[0], 1e-100);
200 assertEquals(0.4f, data[1], 1e-100);
201 assertEquals(0.3f, data[2], 1e-100);
202 assertEquals(0.2f, data[3], 1e-100);
203 }
204
205 @Test
206 public void testHeightSynced() throws Exception {
207 checkIntPropertySynced(
208 "javafx.scene.effect.FloatMap", "height",
209 "com.sun.scenario.effect.FloatMap", "height", 10);
210 }
211
212 @Test
213 public void testWidthSynced() throws Exception {
214 checkIntPropertySynced(
215 "javafx.scene.effect.FloatMap", "width",
216 "com.sun.scenario.effect.FloatMap", "width", 10);
217 }
224 String propertyName,
225 String pgEffectName,
226 String pgPropertyName,
227 int expected)
228 throws Exception {
229 final Class effectClass = Class.forName(effectName);
230 final Class pgEffectClass = Class.forName(pgEffectName);
231
232 final StringBuilder pgPropertyNameBuilder = new StringBuilder(pgPropertyName);
233 pgPropertyNameBuilder.setCharAt(0, Character.toUpperCase(pgPropertyName.charAt(0)));
234 final String pgGetterName = new StringBuilder("get").append(pgPropertyNameBuilder).toString();
235 final Method pgGetter = pgEffectClass.getMethod(pgGetterName);
236
237 IntegerProperty v = new SimpleIntegerProperty();
238 Method m = effectClass.getMethod(propertyName + "Property", new Class[] {});
239 ((IntegerProperty)m.invoke(floatMap)).bind(v);
240
241 pulse(); // make sure that the dirty flag is cleaned before testing of binding
242 v.set(expected);
243 pulse();
244 assertEquals(expected, ((Number)pgGetter.invoke(
245 FloatMapShim.getImpl(floatMap))).intValue());
246 }
247
248 @Test
249 public void testCreateWithParams() {
250 floatMap = new FloatMap(2, 3);
251 displacementMap = new DisplacementMap();
252 displacementMap.setMapData(floatMap);
253 setupTest(displacementMap);
254 assertEquals(2, floatMap.getWidth(), 1e-100);
255 assertEquals(3, floatMap.getHeight(), 1e-100);
256 pulse();
257 assertEquals(2, ((com.sun.scenario.effect.FloatMap)
258 FloatMapShim.getImpl(floatMap)).getWidth());
259 assertEquals(3, ((com.sun.scenario.effect.FloatMap)
260 FloatMapShim.getImpl(floatMap)).getHeight());
261 }
262
263 @Test
264 public void testCreateWithDefaultParams() {
265 floatMap = new FloatMap(1, 1);
266 displacementMap = new DisplacementMap();
267 displacementMap.setMapData(floatMap);
268 setupTest(displacementMap);
269 assertEquals(1, floatMap.getWidth(), 1e-100);
270 assertEquals(1, floatMap.getHeight(), 1e-100);
271 pulse();
272 assertEquals(1, ((com.sun.scenario.effect.FloatMap)
273 FloatMapShim.getImpl(floatMap)).getWidth());
274 assertEquals(1, ((com.sun.scenario.effect.FloatMap)
275 FloatMapShim.getImpl(floatMap)).getHeight());
276 }
277
278 }
|