diff --git a/scripts/device-runner-app/main/HelloCodenameOne.java b/scripts/device-runner-app/main/HelloCodenameOne.java
index 92aec4afd7..6a85771ef8 100644
--- a/scripts/device-runner-app/main/HelloCodenameOne.java
+++ b/scripts/device-runner-app/main/HelloCodenameOne.java
@@ -10,13 +10,13 @@
import com.codename1.ui.Label;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.BoxLayout;
+import com.codename1.ui.CN;
import com.codenameone.examples.hellocodenameone.tests.Cn1ssDeviceRunner;
import com.codenameone.examples.hellocodenameone.tests.Cn1ssDeviceRunnerReporter;
public class HelloCodenameOne {
private Form current;
- private Form mainForm;
private static boolean deviceRunnerExecuted;
public void init(Object context) {
@@ -28,11 +28,13 @@ public void start() {
current.show();
return;
}
- if (!deviceRunnerExecuted) {
+ Form c = CN.getCurrentForm();
+ if (!deviceRunnerExecuted || c == null) {
deviceRunnerExecuted = true;
- new Cn1ssDeviceRunner().runSuite();
+ CN.callSerially(() -> new Cn1ssDeviceRunner().runSuite());
+ return;
}
- showMainForm();
+ c.show();
}
public void stop() {
@@ -42,59 +44,4 @@ public void stop() {
public void destroy() {
// Nothing to clean up for this sample
}
-
- private void showMainForm() {
- if (mainForm == null) {
- mainForm = new Form("Main Screen", new BorderLayout());
-
- Container content = new Container(BoxLayout.y());
- content.getAllStyles().setBgColor(0x1f2937);
- content.getAllStyles().setBgTransparency(255);
- content.getAllStyles().setPadding(6, 6, 6, 6);
- content.getAllStyles().setFgColor(0xf9fafb);
-
- Label heading = new Label("Hello Codename One");
- heading.getAllStyles().setFgColor(0x38bdf8);
- heading.getAllStyles().setMargin(0, 4, 0, 0);
-
- Label body = new Label("Instrumentation main activity preview");
- body.getAllStyles().setFgColor(0xf9fafb);
-
- Button openBrowser = new Button("Open Browser Screen");
- openBrowser.addActionListener(evt -> showBrowserForm());
-
- content.add(heading);
- content.add(body);
- content.add(openBrowser);
-
- mainForm.add(BorderLayout.CENTER, content);
- }
- current = mainForm;
- mainForm.show();
- }
-
- private void showBrowserForm() {
- Form browserForm = new Form("Browser Screen", new BorderLayout());
-
- BrowserComponent browser = new BrowserComponent();
- browser.setPage(buildBrowserHtml(), null);
- browserForm.add(BorderLayout.CENTER, browser);
- browserForm.getToolbar().addMaterialCommandToLeftBar(
- "Back",
- FontImage.MATERIAL_ARROW_BACK,
- evt -> showMainForm()
- );
-
- current = browserForm;
- browserForm.show();
- }
-
- private String buildBrowserHtml() {
- return "
"
- + ""
- + "Codename One
"
- + "
BrowserComponent instrumentation test content.
";
- }
}
diff --git a/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java b/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java
index 5ad65130d6..597d378b09 100644
--- a/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java
+++ b/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java
@@ -1,35 +1,19 @@
package com.codenameone.examples.hellocodenameone.tests;
-import com.codename1.testing.AbstractTest;
import com.codename1.ui.Component;
import com.codename1.ui.Form;
import com.codename1.ui.layouts.BorderLayout;
-abstract class AbstractGraphicsScreenshotTest extends AbstractTest {
+abstract class AbstractGraphicsScreenshotTest extends BaseTest {
protected abstract Component createContent();
protected abstract String screenshotName();
@Override
public boolean runTest() throws Exception {
- final Form[] holder = new Form[1];
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
- Form form = new Form("Graphics", new BorderLayout());
- form.add(BorderLayout.CENTER, createContent());
- holder[0] = form;
- form.show();
- });
-
- Cn1ssDeviceRunnerHelper.waitForMillis(1200);
-
- final boolean[] result = new boolean[1];
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
- if (holder[0] != null) {
- holder[0].revalidate();
- holder[0].repaint();
- }
- result[0] = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(screenshotName());
- });
- return result[0];
+ Form form = createForm("Graphics", new BorderLayout(), screenshotName());
+ form.add(BorderLayout.CENTER, createContent());
+ form.show();
+ return waitForDone();
}
}
diff --git a/scripts/device-runner-app/tests/BaseTest.java b/scripts/device-runner-app/tests/BaseTest.java
new file mode 100644
index 0000000000..d8e4b76ca9
--- /dev/null
+++ b/scripts/device-runner-app/tests/BaseTest.java
@@ -0,0 +1,42 @@
+package com.codenameone.examples.hellocodenameone.tests;
+
+import com.codename1.testing.AbstractTest;
+import com.codename1.ui.Form;
+import com.codename1.ui.util.UITimer;
+import com.codename1.ui.layouts.Layout;
+import com.codename1.testing.TestUtils;
+
+public abstract class BaseTest extends AbstractTest {
+ private boolean done;
+
+ protected Form createForm(String title, Layout layout, final String imageName) {
+ return new Form(title, layout) {
+ @Override
+ protected void onShowCompleted() {
+ registerReadyCallback(this, () -> {
+ Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(imageName);
+ done = true;
+ });
+ }
+ };
+ }
+
+ protected void registerReadyCallback(Form parent, Runnable run) {
+ // Android misses some images when the time is lower
+ UITimer.timer(1500, false, parent, run);
+ }
+
+ protected boolean waitForDone() {
+ int timeout = 100;
+ while(!done) {
+ TestUtils.waitFor(20);
+ timeout--;
+ if(timeout == 0) {
+ return false;
+ }
+ }
+ // give the test a few additional milliseconds for the screenshot emission
+ TestUtils.waitFor(100);
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java b/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java
index 2038b40aec..01c4d722a9 100644
--- a/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java
+++ b/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java
@@ -4,50 +4,26 @@
import com.codename1.testing.TestUtils;
import com.codename1.ui.BrowserComponent;
import com.codename1.ui.Form;
+import com.codename1.ui.CN;
import com.codename1.ui.layouts.BorderLayout;
-public class BrowserComponentScreenshotTest extends AbstractTest {
+public class BrowserComponentScreenshotTest extends BaseTest {
+ private BrowserComponent browser;
@Override
public boolean runTest() throws Exception {
- final boolean[] supported = new boolean[1];
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> supported[0] = BrowserComponent.isNativeBrowserSupported());
- if (!supported[0]) {
- TestUtils.log("BrowserComponent native support unavailable; skipping screenshot test");
+ if (!BrowserComponent.isNativeBrowserSupported()) {
return true;
}
+ Form form = createForm("Browser Test", new BorderLayout(), "BrowserComponent");
+ browser = new BrowserComponent();
+ browser.setPage(buildHtml(), null);
+ form.add(BorderLayout.CENTER, browser);
+ form.show();
+ return waitForDone();
+ }
- final boolean[] loadFinished = new boolean[1];
- final Form[] formHolder = new Form[1];
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
- Form form = new Form("Browser Test", new BorderLayout());
- BrowserComponent browser = new BrowserComponent();
- browser.addWebEventListener(BrowserComponent.onLoad, evt -> loadFinished[0] = true);
- browser.setPage(buildHtml(), null);
- form.add(BorderLayout.CENTER, browser);
- formHolder[0] = form;
- form.show();
- });
-
- for (int elapsed = 0; elapsed < 15000 && !loadFinished[0]; elapsed += 200) {
- TestUtils.waitFor(200);
- }
- if (!loadFinished[0]) {
- TestUtils.log("BrowserComponent content did not finish loading in time");
- return false;
- }
-
- Cn1ssDeviceRunnerHelper.waitForMillis(3000);
-
- final boolean[] result = new boolean[1];
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
- Form current = formHolder[0];
- if (current != null) {
- current.revalidate();
- current.repaint();
- }
- result[0] = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("BrowserComponent");
- });
- return result[0];
+ protected void registerReadyCallback(Form parent, final Runnable run) {
+ browser.addWebEventListener(BrowserComponent.onLoad, evt -> CN.callSerially(run));
}
private static String buildHtml() {
diff --git a/scripts/device-runner-app/tests/Cn1ssDeviceRunner.java b/scripts/device-runner-app/tests/Cn1ssDeviceRunner.java
index 1de8bfe878..e68dcff811 100644
--- a/scripts/device-runner-app/tests/Cn1ssDeviceRunner.java
+++ b/scripts/device-runner-app/tests/Cn1ssDeviceRunner.java
@@ -4,26 +4,40 @@
import com.codename1.testing.TestReporting;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
+import com.codename1.testing.AbstractTest;
public final class Cn1ssDeviceRunner extends DeviceRunner {
- private static final String[] TEST_CLASSES = new String[] {
- MainScreenScreenshotTest.class.getName(),
- BrowserComponentScreenshotTest.class.getName(),
- MediaPlaybackScreenshotTest.class.getName(),
- GraphicsPipelineScreenshotTest.class.getName(),
- GraphicsShapesAndGradientsScreenshotTest.class.getName(),
- GraphicsStateAndTextScreenshotTest.class.getName(),
- GraphicsTransformationsScreenshotTest.class.getName(),
- GraphicsMethodsScreenshotTest.class.getName()
+ private static final AbstractTest[] TEST_CLASSES = new AbstractTest[] {
+ new MainScreenScreenshotTest(),
+ new GraphicsPipelineScreenshotTest(),
+ new GraphicsShapesAndGradientsScreenshotTest(),
+ new GraphicsStateAndTextScreenshotTest(),
+ new GraphicsTransformationsScreenshotTest(),
+ new BrowserComponentScreenshotTest(),
+ new MediaPlaybackScreenshotTest()
};
public void runSuite() {
- for (String testClass : TEST_CLASSES) {
- runTest(testClass);
+ for (AbstractTest testClass : TEST_CLASSES) {
+ log("CN1SS:INFO:suite starting test=" + testClass);
+ try {
+ testClass.prepare();
+ testClass.runTest();
+ testClass.cleanup();
+ log("CN1SS:INFO:suite finished test=" + testClass);
+ } catch (Throwable t) {
+ log("CN1SS:ERR:suite test=" + testClass + " failed=" + t);
+ t.printStackTrace();
+ }
}
+ log("CN1SS:SUITE:FINISHED");
TestReporting.getInstance().testExecutionFinished(getClass().getName());
}
+ private static void log(String msg) {
+ System.out.println(msg);
+ }
+
@Override
protected void startApplicationInstance() {
Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
diff --git a/scripts/device-runner-app/tests/GraphicsMethodsScreenshotTest.java b/scripts/device-runner-app/tests/GraphicsMethodsScreenshotTest.java
deleted file mode 100644
index 030d89bb58..0000000000
--- a/scripts/device-runner-app/tests/GraphicsMethodsScreenshotTest.java
+++ /dev/null
@@ -1,336 +0,0 @@
-package com.codenameone.examples.hellocodenameone.tests;
-
-import com.codename1.testing.AbstractTest;
-import com.codename1.ui.Component;
-import com.codename1.ui.Display;
-import com.codename1.ui.Form;
-import com.codename1.ui.Graphics;
-import com.codename1.ui.Image;
-import com.codename1.ui.geom.Dimension;
-import com.codename1.ui.layouts.BorderLayout;
-
-public class GraphicsMethodsScreenshotTest extends AbstractTest {
- @Override
- public boolean runTest() throws Exception {
- String[] methods = GRAPHICS_METHODS;
- final MethodCoverageCanvas canvas = new MethodCoverageCanvas();
- final Form[] formHolder = new Form[1];
-
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
- Form form = new Form("Graphics API", new BorderLayout());
- form.add(BorderLayout.CENTER, canvas);
- formHolder[0] = form;
- form.show();
- });
-
- // Allow layout to settle before we start iterating through methods.
- Cn1ssDeviceRunnerHelper.waitForMillis(500);
-
- final boolean[] success = new boolean[] {true};
- int index = 1;
- int total = methods.length;
- for (int i = 0; i < total; i++) {
- String descriptor = methods[i];
- final String label = descriptor + " (" + index + "/" + total + ")";
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
- canvas.setHighlightedMethod(label);
- if (formHolder[0] != null) {
- formHolder[0].revalidate();
- formHolder[0].repaint();
- }
- });
-
- // Give the EDT a short window to repaint before taking the screenshot.
- Cn1ssDeviceRunnerHelper.waitForMillis(160);
-
- final boolean[] shotOk = new boolean[1];
- final String screenshotName = "Graphics." + Cn1ssDeviceRunnerHelper.sanitizeTestName(descriptor);
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> shotOk[0] = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(screenshotName));
- if (!shotOk[0]) {
- success[0] = false;
- }
- index++;
- }
-
- return success[0];
- }
-
- private static final String[] GRAPHICS_METHODS = new String[] {
- "translate(int,int)",
- "getTranslateX()",
- "getTranslateY()",
- "getColor()",
- "setColor(int)",
- "setColor(Paint)",
- "getPaint()",
- "setAndGetColor(int)",
- "getFont()",
- "setFont(Font)",
- "getClipX()",
- "getClip()",
- "setClip(int[])",
- "setClip(Shape)",
- "getClipY()",
- "getClipWidth()",
- "getClipHeight()",
- "clipRect(int,int,int,int)",
- "setClip(int,int,int,int)",
- "pushClip()",
- "popClip()",
- "drawLine(int,int,int,int)",
- "fillRect(int,int,int,int)",
- "drawShadow(Image,int,int,int,int,int,int,int,float)",
- "clearRect(int,int,int,int)",
- "drawRect(int,int,int,int)",
- "drawRect(int,int,int,int,int)",
- "drawRoundRect(int,int,int,int,int,int)",
- "lighterColor(int)",
- "darkerColor(int)",
- "fillRoundRect(int,int,int,int,int,int)",
- "fillArc(int,int,int,int,int,int)",
- "drawArc(int,int,int,int,int,int)",
- "drawString(String,int,int,int)",
- "drawStringBaseline(String,int,int)",
- "drawStringBaseline(String,int,int,int)",
- "drawString(String,int,int)",
- "drawChar(char,int,int)",
- "drawChars(char[],int,int,int,int)",
- "drawImage(Image,int,int)",
- "drawImage(Image,int,int,int,int)",
- "drawShape(Shape,Stroke)",
- "fillShape(Shape)",
- "isTransformSupported()",
- "isPerspectiveTransformSupported()",
- "isShapeSupported()",
- "isShapeClipSupported()",
- "transform(Transform)",
- "getTransform()",
- "setTransform(Transform)",
- "getTransform(Transform)",
- "fillTriangle(int,int,int,int,int,int)",
- "fillRadialGradient(int,int,int,int,int,int)",
- "fillRadialGradient(int,int,int,int,int,int,int,int)",
- "fillRectRadialGradient(int,int,int,int,int,int,float,float,float)",
- "fillLinearGradient(int,int,int,int,int,int,boolean)",
- "fillRect(int,int,int,int,byte)",
- "fillPolygon(int[],int[],int)",
- "drawPolygon(int[],int[],int)",
- "isAlphaSupported()",
- "setAndGetAlpha(int)",
- "concatenateAlpha(int)",
- "getAlpha()",
- "setAlpha(int)",
- "isAntiAliasingSupported()",
- "isAntiAliasedTextSupported()",
- "isAntiAliased()",
- "setAntiAliased(boolean)",
- "isAntiAliasedText()",
- "setAntiAliasedText(boolean)",
- "isAffineSupported()",
- "resetAffine()",
- "scale(float,float)",
- "rotate(float)",
- "rotateRadians(float)",
- "rotate(float,int,int)",
- "rotateRadians(float,int,int)",
- "shear(float,float)",
- "beginNativeGraphicsAccess()",
- "endNativeGraphicsAccess()",
- "tileImage(Image,int,int,int,int)",
- "getScaleX()",
- "getScaleY()",
- "getRenderingHints()",
- "setRenderingHints(int)"
- };
-
- private static final class MethodCoverageCanvas extends Component {
- private String highlightedMethod = "";
- private Image cachedLogo;
-
- void setHighlightedMethod(String method) {
- this.highlightedMethod = method == null ? "" : method;
- repaint();
- }
-
- @Override
- protected Dimension calcPreferredSize() {
- int w = Math.max(Display.getInstance().getDisplayWidth(), 540);
- int h = Math.max(Display.getInstance().getDisplayHeight(), 820);
- return new Dimension(w, h);
- }
-
- @Override
- public void paint(Graphics g) {
- super.paint(g);
- int w = getWidth();
- int h = getHeight();
-
- g.setColor(0x0b1220);
- g.fillRect(0, 0, w, h);
- g.setColor(0x1e293b);
- g.drawRect(4, 4, w - 8, h - 8);
-
- drawShapesAndStrokes(g, w, h);
- drawColorAndAlpha(g, w, h);
- drawImagesAndText(g, w, h);
- drawTransforms(g, w, h);
-
- g.setColor(0xe2e8f0);
- g.drawString("Method under inspection:", 12, h - 52);
- g.setColor(0x22c55e);
- g.drawString(highlightedMethod, 12, h - 30);
- }
-
- private void drawShapesAndStrokes(Graphics g, int w, int h) {
- int areaW = (w - 36) / 2;
- int areaH = (h - 120) / 2;
- int x = 12;
- int y = 12;
-
- g.setColor(0x111827);
- g.fillRect(x, y, areaW, areaH);
- g.setColor(0x475569);
- g.drawRect(x, y, areaW - 1, areaH - 1);
-
- g.setColor(0xfacc15);
- g.drawLine(x + 10, y + 10, x + areaW - 10, y + 18);
- g.setColor(0x22c55e);
- g.fillRect(x + 10, y + 30, areaW / 3, 32);
- g.setColor(0xf97316);
- g.drawRect(x + areaW / 3 + 18, y + 30, areaW / 3, 32);
-
- g.setColor(0x38bdf8);
- g.fillRoundRect(x + 10, y + 70, areaW / 3, 40, 16, 16);
- g.setColor(0xec4899);
- g.drawRoundRect(x + areaW / 3 + 18, y + 70, areaW / 3, 40, 16, 16);
-
- g.setColor(0xa855f7);
- g.fillArc(x + 10, y + 118, 70, 70, 30, 210);
- g.setColor(0x6366f1);
- g.drawArc(x + areaW / 3 + 20, y + 118, 72, 72, 210, 280);
-
- int[] px = new int[] {x + areaW - 80, x + areaW - 34, x + areaW - 58};
- int[] py = new int[] {y + 30, y + 30, y + 76};
- g.setColor(0x7dd3fc);
- g.fillPolygon(px, py, px.length);
- g.setColor(0x0ea5e9);
- g.drawPolygon(px, py, px.length);
-
- g.setColor(0xe5e7eb);
- g.drawString("Strokes + primitives", x + 10, y + areaH - 18);
- }
-
- private void drawColorAndAlpha(Graphics g, int w, int h) {
- int areaW = (w - 36) / 2;
- int areaH = (h - 120) / 2;
- int x = (w + 12) / 2;
- int y = 12;
-
- g.setColor(0x0f172a);
- g.fillRect(x, y, areaW, areaH);
- g.setColor(0x475569);
- g.drawRect(x, y, areaW - 1, areaH - 1);
-
- g.fillLinearGradient(0x22d3ee, 0x2563eb, x + 10, y + 10, areaW - 20, 76, true);
- g.fillRadialGradient(0xf43f5e, 0xf59e0b, x + 12, y + 98, areaW / 2 - 16, areaH - 120);
- g.fillRectRadialGradient(0x10b981, 0x22c55e, x + areaW / 2, y + 98, areaW / 2 - 14, areaH - 120, 0.28f, 0.52f, 0.78f);
-
- int previousAlpha = g.getAlpha();
- g.setAlpha(150);
- g.setColor(0xfef3c7);
- g.fillRect(x + 14, y + 26, areaW / 2, 44);
- g.setAlpha(previousAlpha);
-
- g.setColor(0xe2e8f0);
- g.drawString("Gradients + alpha", x + 12, y + areaH - 18);
- }
-
- private void drawImagesAndText(Graphics g, int w, int h) {
- int areaW = (w - 36) / 2;
- int areaH = (h - 120) / 2;
- int x = 12;
- int y = (h + 24) / 2;
-
- g.setColor(0x0f172a);
- g.fillRect(x, y, areaW, areaH);
- g.setColor(0x334155);
- g.drawRect(x, y, areaW - 1, areaH - 1);
-
- g.setAntiAliasedText(true);
- g.setColor(0x22c55e);
- g.drawString("drawString", x + 10, y + 18);
- g.setColor(0xf97316);
- g.drawStringBaseline("baseline", x + 120, y + 18);
-
- g.setColor(0xf43f5e);
- g.drawChar('G', x + 10, y + 46);
- char[] chars = new char[] {'r', 'a', 'p', 'h', 'i', 'c', 's'};
- g.setColor(0xa855f7);
- g.drawChars(chars, 0, chars.length, x + 32, y + 46);
-
- Image sample = getCachedLogo();
- if (sample != null) {
- g.drawImage(sample, x + 10, y + 74);
- g.drawImage(sample, x + 84, y + 74, 52, 52);
- }
-
- g.setColor(0xe2e8f0);
- g.drawString("Text + images", x + 10, y + areaH - 18);
- g.setAntiAliasedText(false);
- }
-
- private void drawTransforms(Graphics g, int w, int h) {
- int areaW = (w - 36) / 2;
- int areaH = (h - 120) / 2;
- int x = (w + 12) / 2;
- int y = (h + 24) / 2;
-
- g.setColor(0x0f172a);
- g.fillRect(x, y, areaW, areaH);
- g.setColor(0x475569);
- g.drawRect(x, y, areaW - 1, areaH - 1);
-
- int cx = x + areaW / 2;
- int cy = y + areaH / 2;
-
- g.translate(cx, cy);
- g.setColor(0x22c55e);
- g.fillRect(-44, -18, 88, 36);
-
- if (g.isAffineSupported()) {
- g.rotateRadians((float) Math.toRadians(15));
- g.scale(0.9f, 0.9f);
- g.setColor(0xf97316);
- g.fillRoundRect(-58, -26, 116, 52, 14, 14);
- g.shear(0.15f, 0f);
- g.setColor(0x38bdf8);
- g.drawRect(-64, -30, 128, 60);
- g.resetAffine();
- }
-
- g.translate(-cx, -cy);
- g.setColor(0xe2e8f0);
- g.drawString("Transforms", x + 10, y + areaH - 18);
- }
-
- private Image getCachedLogo() {
- if (cachedLogo != null && !cachedLogo.isAnimation()) {
- return cachedLogo;
- }
- try {
- cachedLogo = Image.createImage(64, 64, 0xffe0f2fe);
- Graphics g = cachedLogo.getGraphics();
- g.setColor(0x1d4ed8);
- g.fillRect(4, 4, 56, 56);
- g.setColor(0xf97316);
- g.drawRect(2, 2, 60, 60);
- g.setColor(0xfef3c7);
- g.drawString("CN1", 10, 26);
- } catch (Exception ignored) {
- // Fallback to null if we cannot allocate the image.
- }
- return cachedLogo;
- }
- }
-}
-
diff --git a/scripts/device-runner-app/tests/GraphicsPipelineScreenshotTest.java b/scripts/device-runner-app/tests/GraphicsPipelineScreenshotTest.java
index c247290688..0969c8207f 100644
--- a/scripts/device-runner-app/tests/GraphicsPipelineScreenshotTest.java
+++ b/scripts/device-runner-app/tests/GraphicsPipelineScreenshotTest.java
@@ -8,28 +8,13 @@
import com.codename1.ui.geom.Dimension;
import com.codename1.ui.layouts.BorderLayout;
-public class GraphicsPipelineScreenshotTest extends AbstractTest {
+public class GraphicsPipelineScreenshotTest extends BaseTest {
@Override
public boolean runTest() throws Exception {
- final Form[] formHolder = new Form[1];
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
- Form form = new Form("Graphics Pipeline", new BorderLayout());
- form.add(BorderLayout.CENTER, new GraphicsShowcase());
- formHolder[0] = form;
- form.show();
- });
-
- Cn1ssDeviceRunnerHelper.waitForMillis(1200);
-
- final boolean[] result = new boolean[1];
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
- if (formHolder[0] != null) {
- formHolder[0].revalidate();
- formHolder[0].repaint();
- }
- result[0] = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("GraphicsPipeline");
- });
- return result[0];
+ Form form = createForm("Graphics Pipeline", new BorderLayout(), "GraphicsPipeline");
+ form.add(BorderLayout.CENTER, new GraphicsShowcase());
+ form.show();
+ return waitForDone();
}
private static final class GraphicsShowcase extends Component {
diff --git a/scripts/device-runner-app/tests/MainScreenScreenshotTest.java b/scripts/device-runner-app/tests/MainScreenScreenshotTest.java
index 770ed1f85b..29cf44dc40 100644
--- a/scripts/device-runner-app/tests/MainScreenScreenshotTest.java
+++ b/scripts/device-runner-app/tests/MainScreenScreenshotTest.java
@@ -7,36 +7,29 @@
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.BoxLayout;
-public class MainScreenScreenshotTest extends AbstractTest {
+public class MainScreenScreenshotTest extends BaseTest {
@Override
public boolean runTest() throws Exception {
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
- Form form = new Form("Main Screen", new BorderLayout());
+ Form form = createForm("Main Screen", new BorderLayout(), "MainActivity");
+ Container content = new Container(BoxLayout.y());
+ content.getAllStyles().setBgColor(0x1f2937);
+ content.getAllStyles().setBgTransparency(255);
+ content.getAllStyles().setPadding(6, 6, 6, 6);
+ content.getAllStyles().setFgColor(0xf9fafb);
- Container content = new Container(BoxLayout.y());
- content.getAllStyles().setBgColor(0x1f2937);
- content.getAllStyles().setBgTransparency(255);
- content.getAllStyles().setPadding(6, 6, 6, 6);
- content.getAllStyles().setFgColor(0xf9fafb);
+ Label heading = new Label("Hello Codename One");
+ heading.getAllStyles().setFgColor(0x38bdf8);
+ heading.getAllStyles().setMargin(0, 4, 0, 0);
- Label heading = new Label("Hello Codename One");
- heading.getAllStyles().setFgColor(0x38bdf8);
- heading.getAllStyles().setMargin(0, 4, 0, 0);
+ Label body = new Label("Instrumentation main activity preview");
+ body.getAllStyles().setFgColor(0xf9fafb);
- Label body = new Label("Instrumentation main activity preview");
- body.getAllStyles().setFgColor(0xf9fafb);
+ content.add(heading);
+ content.add(body);
- content.add(heading);
- content.add(body);
+ form.add(BorderLayout.CENTER, content);
+ form.show();
- form.add(BorderLayout.CENTER, content);
- form.show();
- });
-
- Cn1ssDeviceRunnerHelper.waitForMillis(500);
-
- final boolean[] result = new boolean[1];
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> result[0] = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("MainActivity"));
- return result[0];
+ return waitForDone();
}
}
diff --git a/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java b/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java
index bac98fbcb3..477a0cb61f 100644
--- a/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java
+++ b/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java
@@ -15,88 +15,38 @@
import java.io.IOException;
import java.io.OutputStream;
-public class MediaPlaybackScreenshotTest extends AbstractTest {
+public class MediaPlaybackScreenshotTest extends BaseTest {
private static final int SAMPLE_RATE = 44100;
private static final double TONE_FREQUENCY = 440.0;
private static final double TONE_DURATION_SECONDS = 1.2;
@Override
public boolean runTest() throws Exception {
- final Label statusLabel = new Label("Preparing media sample…");
- final Form[] formHolder = new Form[1];
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
- Form form = new Form("Media Playback", new BorderLayout());
- Container content = new Container(BoxLayout.y());
- content.getAllStyles().setPadding(6, 6, 6, 6);
- content.add(new Label("Media playback regression"));
- content.add(new Label("Verifies createMedia() against filesystem URI"));
- content.add(statusLabel);
- form.add(BorderLayout.CENTER, content);
- formHolder[0] = form;
- form.show();
- });
-
+ Form form = createForm("Media Playback", new BorderLayout(), "MediaPlayback");
String tonePath = writeToneWav();
+ final Label statusLabel = new Label("Preparing media sample…");
if (tonePath == null) {
- updateStatus(statusLabel, formHolder[0], "Failed to generate tone file");
- return false;
- }
-
- final String mediaPath = tonePath;
- final Media[] mediaHolder = new Media[1];
- final boolean[] playbackFailed = new boolean[1];
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
- try {
- Media media = MediaManager.createMedia(mediaPath, false);
- if (media == null) {
- updateStatus(statusLabel, formHolder[0], "Media creation returned null");
- playbackFailed[0] = true;
- return;
- }
- media.setTime(0);
- media.play();
- statusLabel.setText("Starting playback…");
- formHolder[0].revalidate();
- mediaHolder[0] = media;
- } catch (IOException ex) {
- TestUtils.log("Unable to create media: " + ex.getMessage());
- updateStatus(statusLabel, formHolder[0], "Unable to create media");
- playbackFailed[0] = true;
+ updateStatus(statusLabel, form, "Failed to generate tone file");
+ } else {
+ Media media = MediaManager.createMedia(tonePath, false);
+ if (media == null) {
+ updateStatus(statusLabel, form, "Media creation returned null");
}
- });
-
- if (playbackFailed[0]) {
- cleanupMedia(mediaHolder[0]);
- FileSystemStorage.getInstance().delete(mediaPath);
- return false;
+ media.setTime(0);
+ media.play();
+ statusLabel.setText("Starting playback…");
}
+ Container content = new Container(BoxLayout.y());
+ content.getAllStyles().setPadding(6, 6, 6, 6);
+ content.add(new Label("Media playback regression"));
+ content.add(new Label("Verifies createMedia() against filesystem URI"));
+ content.add(statusLabel);
+ form.add(BorderLayout.CENTER, content);
- final boolean[] playbackStarted = new boolean[1];
- for (int elapsed = 0; elapsed < 5000 && !playbackStarted[0]; elapsed += 200) {
- Cn1ssDeviceRunnerHelper.waitForMillis(200);
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
- if (mediaHolder[0] != null && mediaHolder[0].isPlaying()) {
- playbackStarted[0] = true;
- }
- });
- }
-
- Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> {
- if (playbackStarted[0]) {
- statusLabel.setText("Media playback started successfully");
- } else {
- statusLabel.setText("Media playback did not start");
- }
- formHolder[0].revalidate();
- });
+ form.show();
Cn1ssDeviceRunnerHelper.waitForMillis(800);
- boolean screenshotSuccess = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("MediaPlayback");
-
- cleanupMedia(mediaHolder[0]);
- FileSystemStorage.getInstance().delete(mediaPath);
-
- return playbackStarted[0] && screenshotSuccess;
+ return waitForDone();
}
private static void updateStatus(Label label, Form form, String message) {