Skip to content

Commit 52b1171

Browse files
committed
Cleaned up test code
1 parent 30dd950 commit 52b1171

File tree

5 files changed

+69
-161
lines changed

5 files changed

+69
-161
lines changed

scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,14 @@ abstract class AbstractGraphicsScreenshotTest extends AbstractTest {
1212

1313
@Override
1414
public boolean runTest() throws Exception {
15-
final Form[] holder = new Form[1];
16-
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
17-
Form form = new Form("Graphics", new BorderLayout());
18-
form.add(BorderLayout.CENTER, createContent());
19-
holder[0] = form;
20-
form.show();
21-
});
22-
23-
Cn1ssDeviceRunnerHelper.waitForMillis(1200);
24-
25-
final boolean[] result = new boolean[1];
26-
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
27-
if (holder[0] != null) {
28-
holder[0].revalidate();
29-
holder[0].repaint();
15+
Form form = new Form("Graphics", new BorderLayout()) {
16+
@Override
17+
protected void onShowCompleted() {
18+
Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(screenshotName());
3019
}
31-
result[0] = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(screenshotName());
32-
});
33-
return result[0];
20+
}
21+
form.add(BorderLayout.CENTER, createContent());
22+
form.show();
23+
return true;
3424
}
3525
}

scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,23 @@
99
public class BrowserComponentScreenshotTest extends AbstractTest {
1010
@Override
1111
public boolean runTest() throws Exception {
12-
final boolean[] supported = new boolean[1];
13-
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> supported[0] = BrowserComponent.isNativeBrowserSupported());
14-
if (!supported[0]) {
15-
TestUtils.log("BrowserComponent native support unavailable; skipping screenshot test");
12+
if (!BrowserComponent.isNativeBrowserSupported()) {
1613
return true;
1714
}
18-
19-
final boolean[] loadFinished = new boolean[1];
20-
final Form[] formHolder = new Form[1];
21-
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
22-
Form form = new Form("Browser Test", new BorderLayout());
23-
BrowserComponent browser = new BrowserComponent();
24-
browser.addWebEventListener(BrowserComponent.onLoad, evt -> loadFinished[0] = true);
25-
browser.setPage(buildHtml(), null);
26-
form.add(BorderLayout.CENTER, browser);
27-
formHolder[0] = form;
28-
form.show();
29-
});
30-
31-
for (int elapsed = 0; elapsed < 15000 && !loadFinished[0]; elapsed += 200) {
32-
TestUtils.waitFor(200);
33-
}
34-
if (!loadFinished[0]) {
35-
TestUtils.log("BrowserComponent content did not finish loading in time");
36-
return false;
37-
}
38-
39-
Cn1ssDeviceRunnerHelper.waitForMillis(3000);
40-
41-
final boolean[] result = new boolean[1];
42-
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
43-
Form current = formHolder[0];
44-
if (current != null) {
45-
current.revalidate();
46-
current.repaint();
15+
Form form = new Form("Browser Test", new BorderLayout()) {
16+
@Override
17+
protected void onShowCompleted() {
18+
TestUtils.waitFor(100);
19+
Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("BrowserComponent");
4720
}
48-
result[0] = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("BrowserComponent");
49-
});
50-
return result[0];
21+
};
22+
BrowserComponent browser = new BrowserComponent();
23+
browser.addWebEventListener(BrowserComponent.onLoad, evt -> loadFinished[0] = true);
24+
browser.setPage(buildHtml(), null);
25+
form.add(BorderLayout.CENTER, browser);
26+
form.show();
27+
TestUtils.waitFor(250);
28+
return true;
5129
}
5230

5331
private static String buildHtml() {

scripts/device-runner-app/tests/GraphicsPipelineScreenshotTest.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,15 @@
1111
public class GraphicsPipelineScreenshotTest extends AbstractTest {
1212
@Override
1313
public boolean runTest() throws Exception {
14-
final Form[] formHolder = new Form[1];
15-
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
16-
Form form = new Form("Graphics Pipeline", new BorderLayout());
17-
form.add(BorderLayout.CENTER, new GraphicsShowcase());
18-
formHolder[0] = form;
19-
form.show();
20-
});
21-
22-
Cn1ssDeviceRunnerHelper.waitForMillis(1200);
23-
24-
final boolean[] result = new boolean[1];
25-
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
26-
if (formHolder[0] != null) {
27-
formHolder[0].revalidate();
28-
formHolder[0].repaint();
14+
Form form = new Form("Graphics Pipeline", new BorderLayout()) {
15+
@Override
16+
protected void onShowCompleted() {
17+
Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("GraphicsPipeline");
2918
}
30-
result[0] = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("GraphicsPipeline");
31-
});
32-
return result[0];
19+
};
20+
form.add(BorderLayout.CENTER, new GraphicsShowcase());
21+
form.show();
22+
return true;
3323
}
3424

3525
private static final class GraphicsShowcase extends Component {

scripts/device-runner-app/tests/MainScreenScreenshotTest.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,32 @@
1010
public class MainScreenScreenshotTest extends AbstractTest {
1111
@Override
1212
public boolean runTest() throws Exception {
13-
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
14-
Form form = new Form("Main Screen", new BorderLayout());
13+
Form form = new Form("Main Screen", new BorderLayout()) {
14+
@Override
15+
protected void onShowCompleted() {
16+
Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("MainActivity");
17+
}
18+
};
1519

16-
Container content = new Container(BoxLayout.y());
17-
content.getAllStyles().setBgColor(0x1f2937);
18-
content.getAllStyles().setBgTransparency(255);
19-
content.getAllStyles().setPadding(6, 6, 6, 6);
20-
content.getAllStyles().setFgColor(0xf9fafb);
20+
Container content = new Container(BoxLayout.y());
21+
content.getAllStyles().setBgColor(0x1f2937);
22+
content.getAllStyles().setBgTransparency(255);
23+
content.getAllStyles().setPadding(6, 6, 6, 6);
24+
content.getAllStyles().setFgColor(0xf9fafb);
2125

22-
Label heading = new Label("Hello Codename One");
23-
heading.getAllStyles().setFgColor(0x38bdf8);
24-
heading.getAllStyles().setMargin(0, 4, 0, 0);
26+
Label heading = new Label("Hello Codename One");
27+
heading.getAllStyles().setFgColor(0x38bdf8);
28+
heading.getAllStyles().setMargin(0, 4, 0, 0);
2529

26-
Label body = new Label("Instrumentation main activity preview");
27-
body.getAllStyles().setFgColor(0xf9fafb);
30+
Label body = new Label("Instrumentation main activity preview");
31+
body.getAllStyles().setFgColor(0xf9fafb);
2832

29-
content.add(heading);
30-
content.add(body);
33+
content.add(heading);
34+
content.add(body);
3135

32-
form.add(BorderLayout.CENTER, content);
33-
form.show();
34-
});
36+
form.add(BorderLayout.CENTER, content);
37+
form.show();
3538

36-
Cn1ssDeviceRunnerHelper.waitForMillis(500);
37-
38-
final boolean[] result = new boolean[1];
39-
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> result[0] = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("MainActivity"));
40-
return result[0];
39+
return true;
4140
}
4241
}

scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java

Lines changed: 18 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -22,81 +22,32 @@ public class MediaPlaybackScreenshotTest extends AbstractTest {
2222

2323
@Override
2424
public boolean runTest() throws Exception {
25-
final Label statusLabel = new Label("Preparing media sample…");
26-
final Form[] formHolder = new Form[1];
27-
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
28-
Form form = new Form("Media Playback", new BorderLayout());
29-
Container content = new Container(BoxLayout.y());
30-
content.getAllStyles().setPadding(6, 6, 6, 6);
31-
content.add(new Label("Media playback regression"));
32-
content.add(new Label("Verifies createMedia() against filesystem URI"));
33-
content.add(statusLabel);
34-
form.add(BorderLayout.CENTER, content);
35-
formHolder[0] = form;
36-
form.show();
37-
});
38-
25+
Form form = new Form("Media Playback", new BorderLayout());
3926
String tonePath = writeToneWav();
27+
final Label statusLabel = new Label("Preparing media sample…");
4028
if (tonePath == null) {
41-
updateStatus(statusLabel, formHolder[0], "Failed to generate tone file");
42-
return false;
43-
}
44-
45-
final String mediaPath = tonePath;
46-
final Media[] mediaHolder = new Media[1];
47-
final boolean[] playbackFailed = new boolean[1];
48-
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
49-
try {
50-
Media media = MediaManager.createMedia(mediaPath, false);
51-
if (media == null) {
52-
updateStatus(statusLabel, formHolder[0], "Media creation returned null");
53-
playbackFailed[0] = true;
54-
return;
55-
}
56-
media.setTime(0);
57-
media.play();
58-
statusLabel.setText("Starting playback…");
59-
formHolder[0].revalidate();
60-
mediaHolder[0] = media;
61-
} catch (IOException ex) {
62-
TestUtils.log("Unable to create media: " + ex.getMessage());
63-
updateStatus(statusLabel, formHolder[0], "Unable to create media");
64-
playbackFailed[0] = true;
29+
updateStatus(statusLabel, form, "Failed to generate tone file");
30+
} else {
31+
Media media = MediaManager.createMedia(mediaPath, false);
32+
if (media == null) {
33+
updateStatus(statusLabel, form, "Media creation returned null");
6534
}
66-
});
67-
68-
if (playbackFailed[0]) {
69-
cleanupMedia(mediaHolder[0]);
70-
FileSystemStorage.getInstance().delete(mediaPath);
71-
return false;
35+
media.setTime(0);
36+
media.play();
37+
statusLabel.setText("Starting playback…");
7238
}
39+
Container content = new Container(BoxLayout.y());
40+
content.getAllStyles().setPadding(6, 6, 6, 6);
41+
content.add(new Label("Media playback regression"));
42+
content.add(new Label("Verifies createMedia() against filesystem URI"));
43+
content.add(statusLabel);
44+
form.add(BorderLayout.CENTER, content);
7345

74-
final boolean[] playbackStarted = new boolean[1];
75-
for (int elapsed = 0; elapsed < 5000 && !playbackStarted[0]; elapsed += 200) {
76-
Cn1ssDeviceRunnerHelper.waitForMillis(200);
77-
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
78-
if (mediaHolder[0] != null && mediaHolder[0].isPlaying()) {
79-
playbackStarted[0] = true;
80-
}
81-
});
82-
}
83-
84-
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
85-
if (playbackStarted[0]) {
86-
statusLabel.setText("Media playback started successfully");
87-
} else {
88-
statusLabel.setText("Media playback did not start");
89-
}
90-
formHolder[0].revalidate();
91-
});
46+
form.show();
9247

9348
Cn1ssDeviceRunnerHelper.waitForMillis(800);
9449
boolean screenshotSuccess = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("MediaPlayback");
95-
96-
cleanupMedia(mediaHolder[0]);
97-
FileSystemStorage.getInstance().delete(mediaPath);
98-
99-
return playbackStarted[0] && screenshotSuccess;
50+
return screenshotSuccess;
10051
}
10152

10253
private static void updateStatus(Label label, Form form, String message) {

0 commit comments

Comments
 (0)