Skip to content

Commit 1b2f022

Browse files
author
Andy Goryachev
committed
8347359: RichTextArea API Tests
Reviewed-by: kcr
1 parent 1a12966 commit 1b2f022

File tree

10 files changed

+1428
-59
lines changed

10 files changed

+1428
-59
lines changed

modules/javafx.graphics/src/test/java/test/com/sun/javafx/pgstub/StubToolkit.java

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,12 +23,43 @@
2323
* questions.
2424
*/
2525

26-
/*
27-
* StubToolkit.java
28-
*/
29-
3026
package test.com.sun.javafx.pgstub;
3127

28+
import java.io.File;
29+
import java.io.InputStream;
30+
import java.util.Arrays;
31+
import java.util.HashMap;
32+
import java.util.HashSet;
33+
import java.util.List;
34+
import java.util.Map;
35+
import java.util.Optional;
36+
import java.util.Set;
37+
import java.util.concurrent.Future;
38+
import javafx.application.ConditionalFeature;
39+
import javafx.geometry.Dimension2D;
40+
import javafx.scene.image.Image;
41+
import javafx.scene.input.DataFormat;
42+
import javafx.scene.input.DragEvent;
43+
import javafx.scene.input.Dragboard;
44+
import javafx.scene.input.InputMethodRequests;
45+
import javafx.scene.input.KeyCode;
46+
import javafx.scene.input.KeyEvent;
47+
import javafx.scene.input.TransferMode;
48+
import javafx.scene.paint.Color;
49+
import javafx.scene.paint.ImagePattern;
50+
import javafx.scene.paint.LinearGradient;
51+
import javafx.scene.paint.RadialGradient;
52+
import javafx.scene.shape.FillRule;
53+
import javafx.scene.shape.PathElement;
54+
import javafx.scene.shape.SVGPath;
55+
import javafx.scene.shape.StrokeLineCap;
56+
import javafx.scene.shape.StrokeLineJoin;
57+
import javafx.scene.shape.StrokeType;
58+
import javafx.stage.FileChooser.ExtensionFilter;
59+
import javafx.stage.Modality;
60+
import javafx.stage.StageStyle;
61+
import javafx.stage.Window;
62+
import javafx.util.Pair;
3263
import com.sun.glass.ui.CommonDialogs.FileChooserResult;
3364
import com.sun.glass.ui.GlassRobot;
3465
import com.sun.javafx.application.PlatformImpl;
@@ -42,31 +73,26 @@
4273
import com.sun.javafx.runtime.async.AsyncOperationListener;
4374
import com.sun.javafx.scene.SceneHelper;
4475
import com.sun.javafx.scene.text.TextLayoutFactory;
45-
import com.sun.javafx.tk.*;
76+
import com.sun.javafx.tk.FileChooserType;
77+
import com.sun.javafx.tk.FontLoader;
78+
import com.sun.javafx.tk.ImageLoader;
79+
import com.sun.javafx.tk.PlatformImage;
80+
import com.sun.javafx.tk.RenderJob;
81+
import com.sun.javafx.tk.ScreenConfigurationAccessor;
82+
import com.sun.javafx.tk.TKClipboard;
83+
import com.sun.javafx.tk.TKDragGestureListener;
84+
import com.sun.javafx.tk.TKDragSourceListener;
85+
import com.sun.javafx.tk.TKDropTargetListener;
86+
import com.sun.javafx.tk.TKScene;
87+
import com.sun.javafx.tk.TKScreenConfigurationListener;
88+
import com.sun.javafx.tk.TKStage;
89+
import com.sun.javafx.tk.TKSystemMenu;
90+
import com.sun.javafx.tk.Toolkit;
4691
import com.sun.prism.BasicStroke;
4792
import com.sun.scenario.DelayedRunnable;
4893
import com.sun.scenario.animation.AbstractPrimaryTimer;
4994
import com.sun.scenario.effect.FilterContext;
5095
import com.sun.scenario.effect.Filterable;
51-
import javafx.application.ConditionalFeature;
52-
import javafx.geometry.Dimension2D;
53-
import javafx.scene.image.Image;
54-
import javafx.scene.input.*;
55-
import javafx.scene.paint.Color;
56-
import javafx.scene.paint.ImagePattern;
57-
import javafx.scene.paint.LinearGradient;
58-
import javafx.scene.paint.RadialGradient;
59-
import javafx.scene.shape.*;
60-
import javafx.stage.FileChooser.ExtensionFilter;
61-
import javafx.stage.Modality;
62-
import javafx.stage.StageStyle;
63-
import javafx.stage.Window;
64-
import javafx.util.Pair;
65-
66-
import java.io.File;
67-
import java.io.InputStream;
68-
import java.util.*;
69-
import java.util.concurrent.Future;
7096

7197
/**
7298
* A Toolkit implementation for use with Testing.
@@ -379,11 +405,11 @@ public void clearPulseRequested() {
379405
return map.keySet();
380406
}
381407

382-
@Override public boolean putContent(Pair<DataFormat, Object>... content) {
383-
boolean good;
408+
@Override
409+
public boolean putContent(Pair<DataFormat, Object>... content) {
410+
map.clear();
384411
for (Pair<DataFormat,Object> pair : content) {
385-
good = map.put(pair.getKey(), pair.getValue()) == pair.getValue();
386-
if (!good) return false;
412+
map.put(pair.getKey(), pair.getValue());
387413
}
388414
return true;
389415
}

modules/jfx.incubator.richtext/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<classpathentry kind="src" path="/graphics">
4343
<attributes>
4444
<attribute name="module" value="true"/>
45+
<attribute name="add-exports" value="javafx.graphics/com.sun.javafx.tk=jfx.incubator.richtext"/>
4546
</attributes>
4647
</classpathentry>
4748
<classpathentry kind="src" path="/controls">

modules/jfx.incubator.richtext/src/test/java/test/jfx/incubator/scene/control/richtext/CodeAreaTest.java

Lines changed: 109 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,129 @@
2626
package test.jfx.incubator.scene.control.richtext;
2727

2828
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertSame;
30+
import static org.junit.jupiter.api.Assertions.assertThrows;
31+
import static org.junit.jupiter.api.Assertions.assertTrue;
32+
import java.util.List;
33+
import javafx.css.CssMetaData;
34+
import javafx.css.Styleable;
35+
import javafx.scene.Scene;
36+
import javafx.scene.text.Font;
2937
import org.junit.jupiter.api.AfterEach;
30-
import org.junit.jupiter.api.Assertions;
3138
import org.junit.jupiter.api.BeforeEach;
3239
import org.junit.jupiter.api.Test;
3340
import jfx.incubator.scene.control.richtext.CodeArea;
41+
import jfx.incubator.scene.control.richtext.RichTextArea;
3442
import jfx.incubator.scene.control.richtext.model.CodeTextModel;
3543
import jfx.incubator.scene.control.richtext.model.RichTextModel;
3644
import jfx.incubator.scene.control.richtext.skin.CodeAreaSkin;
45+
import test.jfx.incubator.scene.util.TUtil;
3746

3847
/**
39-
* Tests CodeArea.
48+
* Tests the CodeArea control.
4049
*/
4150
public class CodeAreaTest {
4251
private CodeArea control;
4352

4453
@BeforeEach
4554
public void beforeEach() {
46-
setUncaughtExceptionHandler();
55+
TUtil.setUncaughtExceptionHandler();
4756
control = new CodeArea();
4857
control.setSkin(new CodeAreaSkin(control));
4958
}
5059

5160
@AfterEach
5261
public void afterEach() {
53-
removeUncaughtExceptionHandler();
62+
TUtil.removeUncaughtExceptionHandler();
5463
}
5564

56-
private void setUncaughtExceptionHandler() {
57-
Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> {
58-
if (throwable instanceof RuntimeException) {
59-
throw (RuntimeException)throwable;
60-
} else {
61-
Thread.currentThread().getThreadGroup().uncaughtException(thread, throwable);
62-
}
65+
// constructors
66+
67+
@Test
68+
public void defaultModelIsCodeTextModel() {
69+
assertTrue(control.getModel() instanceof CodeTextModel);
70+
}
71+
72+
@Test
73+
public void nullModelInConstructor() {
74+
control = new CodeArea(null);
75+
assertTrue(control.getModel() == null);
76+
77+
control = new CodeArea(null);
78+
CodeTextModel m = new CodeTextModel() { };
79+
control.setModel(m);
80+
assertSame(m, control.getModel());
81+
}
82+
83+
// properties
84+
85+
@Test
86+
public void propertiesSettersAndGetters() {
87+
TUtil.testProperty(control.fontProperty(), control::getFont, control::setFont, new Font("Bogus", 22));
88+
TUtil.testBooleanProperty(control.lineNumbersEnabledProperty(), control::isLineNumbersEnabled, control::setLineNumbersEnabled);
89+
TUtil.testProperty(control.lineSpacingProperty(), control::getLineSpacing, (n) -> control.setLineSpacing(n.doubleValue()), 10.0, 22.0);
90+
TUtil.testProperty(control.tabSizeProperty(), control::getTabSize, (n) -> control.setTabSize(n.intValue()), 1, 2);
91+
}
92+
93+
// default values
94+
95+
@Test
96+
public void defaultPropertyValues() {
97+
TUtil.checkDefaultValue(control.fontProperty(), control::getFont, (f) -> {
98+
Font expected = new Font("Monospace", -1);
99+
assertEquals(f.getFamily(), expected.getFamily());
100+
assertEquals(f.getSize(), expected.getSize());
101+
return true;
63102
});
103+
TUtil.testDefaultValue(control.lineNumbersEnabledProperty(), control::isLineNumbersEnabled, false);
104+
TUtil.testDefaultValue(control.lineSpacingProperty(), control::getLineSpacing, 0.0);
105+
TUtil.testDefaultValue(control.tabSizeProperty(), control::getTabSize, 8);
64106
}
65107

66-
private void removeUncaughtExceptionHandler() {
67-
Thread.currentThread().setUncaughtExceptionHandler(null);
108+
// css
109+
110+
@Test
111+
public void testFontCSS() {
112+
Scene s = new Scene(control);
113+
control.setStyle("-fx-font: 24 Amble");
114+
control.applyCss();
115+
assertEquals(Font.font("Amble", 24), control.getFont());
116+
}
117+
118+
@Test
119+
public void testLineSpacingCSS() {
120+
Scene s = new Scene(control);
121+
control.setStyle("-fx-line-spacing: 5.55");
122+
control.applyCss();
123+
assertEquals(5.55, control.getLineSpacing());
124+
}
125+
126+
@Test
127+
public void testTabSizeCSS() {
128+
Scene s = new Scene(control);
129+
control.setStyle("-fx-tab-size: 17");
130+
control.applyCss();
131+
assertEquals(17, control.getTabSize());
132+
}
133+
134+
// property binding
135+
136+
@Test
137+
public void testPropertyBinding() {
138+
TUtil.testBinding(control.fontProperty(), control::getFont, new Font("Bogus", 22));
139+
TUtil.testBinding(control.lineNumbersEnabledProperty(), control::isLineNumbersEnabled);
140+
TUtil.testBinding(control.lineSpacingProperty(), control::getLineSpacing, 10.0, 22.0);
141+
TUtil.testBinding(control.tabSizeProperty(), control::getTabSize, 1, 2, 5, 17);
142+
}
143+
144+
// functional API tests
145+
146+
@Test
147+
public void getControlCssMetaData() {
148+
List<CssMetaData<? extends Styleable, ?>> md = control.getControlCssMetaData();
149+
// CodeArea:395
150+
int styleablesCount = 3;
151+
assertEquals(md.size(), RichTextArea.getClassCssMetaData().size() + styleablesCount);
68152
}
69153

70154
@Test
@@ -92,30 +176,26 @@ public void getText() {
92176

93177
/** can set a null and non-null CodeTextModel */
94178
@Test
95-
public void nullModel() {
96-
CodeArea t = new CodeArea();
97-
t.setModel(null);
98-
t.setModel(new CodeTextModel());
99-
179+
public void modelNull() {
180+
control.setModel(null);
181+
control.setModel(new CodeTextModel());
100182
}
101183

102184
/** disallows setting model other than CodeTextModel */
103185
@Test
104-
public void wrongModel() {
105-
CodeArea t = new CodeArea();
106-
Assertions.assertThrows(IllegalArgumentException.class, () -> {
107-
t.setModel(new RichTextModel());
186+
public void modelWrong() {
187+
var m = control.getModel();
188+
assertThrows(IllegalArgumentException.class, () -> {
189+
control.setModel(new RichTextModel());
108190
});
109-
Assertions.assertTrue(t.getModel() instanceof CodeTextModel);
191+
assertTrue(control.getModel() == m);
110192
}
111193

112194
/** acceptable custom model */
113195
@Test
114-
public void acceptableModel() {
115-
class M extends CodeTextModel { }
116-
M custom = new M();
117-
CodeArea t = new CodeArea();
118-
t.setModel(custom);
119-
Assertions.assertTrue(t.getModel() instanceof M);
196+
public void modelAcceptable() {
197+
CustomCodeTextModel m = new CustomCodeTextModel();
198+
control.setModel(m);
199+
assertTrue(control.getModel() == m);
120200
}
121201
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2025, 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
23+
* questions.
24+
*/
25+
26+
package test.jfx.incubator.scene.control.richtext;
27+
28+
import jfx.incubator.scene.control.richtext.model.CodeTextModel;
29+
30+
public class CustomCodeTextModel extends CodeTextModel {
31+
public CustomCodeTextModel() {
32+
}
33+
}

0 commit comments

Comments
 (0)