From fa6f7b4ffdd335fc0e42bf4733d7ccf6826309d5 Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Fri, 21 Nov 2025 06:42:43 +0200 Subject: [PATCH 1/9] Fixed CI to avoid dynamic classloading Also used callSerially to avoid blocking the start method on Android --- .../main/HelloCodenameOne.java | 60 +------------------ .../tests/Cn1ssDeviceRunner.java | 37 ++++++++---- 2 files changed, 29 insertions(+), 68 deletions(-) diff --git a/scripts/device-runner-app/main/HelloCodenameOne.java b/scripts/device-runner-app/main/HelloCodenameOne.java index 92aec4afd7..9d0584cab8 100644 --- a/scripts/device-runner-app/main/HelloCodenameOne.java +++ b/scripts/device-runner-app/main/HelloCodenameOne.java @@ -10,6 +10,7 @@ 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; @@ -30,9 +31,9 @@ public void start() { } if (!deviceRunnerExecuted) { deviceRunnerExecuted = true; - new Cn1ssDeviceRunner().runSuite(); + CN.callSerially(() -> new Cn1ssDeviceRunner().runSuite()); } - showMainForm(); + new Form("Fallback").show(); } public void stop() { @@ -42,59 +43,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/Cn1ssDeviceRunner.java b/scripts/device-runner-app/tests/Cn1ssDeviceRunner.java index 1de8bfe878..a8548561c2 100644 --- a/scripts/device-runner-app/tests/Cn1ssDeviceRunner.java +++ b/scripts/device-runner-app/tests/Cn1ssDeviceRunner.java @@ -4,26 +4,41 @@ 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 GraphicsMethodsScreenshotTest(), + 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(() -> { From 30dd9506e9e9fcae88f0a9425b05d3cf468bd8fd Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Fri, 21 Nov 2025 09:27:51 +0200 Subject: [PATCH 2/9] Removed redundant coverage generated by codex --- .../main/HelloCodenameOne.java | 2 +- .../tests/Cn1ssDeviceRunner.java | 1 - .../tests/GraphicsMethodsScreenshotTest.java | 336 ------------------ 3 files changed, 1 insertion(+), 338 deletions(-) delete mode 100644 scripts/device-runner-app/tests/GraphicsMethodsScreenshotTest.java diff --git a/scripts/device-runner-app/main/HelloCodenameOne.java b/scripts/device-runner-app/main/HelloCodenameOne.java index 9d0584cab8..23a6e7066a 100644 --- a/scripts/device-runner-app/main/HelloCodenameOne.java +++ b/scripts/device-runner-app/main/HelloCodenameOne.java @@ -33,7 +33,7 @@ public void start() { deviceRunnerExecuted = true; CN.callSerially(() -> new Cn1ssDeviceRunner().runSuite()); } - new Form("Fallback").show(); + mainForm.show(); } public void stop() { diff --git a/scripts/device-runner-app/tests/Cn1ssDeviceRunner.java b/scripts/device-runner-app/tests/Cn1ssDeviceRunner.java index a8548561c2..e68dcff811 100644 --- a/scripts/device-runner-app/tests/Cn1ssDeviceRunner.java +++ b/scripts/device-runner-app/tests/Cn1ssDeviceRunner.java @@ -13,7 +13,6 @@ public final class Cn1ssDeviceRunner extends DeviceRunner { new GraphicsShapesAndGradientsScreenshotTest(), new GraphicsStateAndTextScreenshotTest(), new GraphicsTransformationsScreenshotTest(), - new GraphicsMethodsScreenshotTest(), new BrowserComponentScreenshotTest(), new MediaPlaybackScreenshotTest() }; 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; - } - } -} - From 52b1171c3722781d53824cf5dfa2fc9abfeaf4fe Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Fri, 21 Nov 2025 10:52:47 +0200 Subject: [PATCH 3/9] Cleaned up test code --- .../tests/AbstractGraphicsScreenshotTest.java | 26 ++---- .../tests/BrowserComponentScreenshotTest.java | 50 +++-------- .../tests/GraphicsPipelineScreenshotTest.java | 26 ++---- .../tests/MainScreenScreenshotTest.java | 43 +++++----- .../tests/MediaPlaybackScreenshotTest.java | 85 ++++--------------- 5 files changed, 69 insertions(+), 161 deletions(-) diff --git a/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java b/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java index 5ad65130d6..79597e87d9 100644 --- a/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java +++ b/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java @@ -12,24 +12,14 @@ abstract class AbstractGraphicsScreenshotTest extends AbstractTest { @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(); + Form form = new Form("Graphics", new BorderLayout()) { + @Override + protected void onShowCompleted() { + Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(screenshotName()); } - result[0] = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(screenshotName()); - }); - return result[0]; + } + form.add(BorderLayout.CENTER, createContent()); + form.show(); + return true; } } diff --git a/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java b/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java index 2038b40aec..fd8b977f97 100644 --- a/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java +++ b/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java @@ -9,45 +9,23 @@ public class BrowserComponentScreenshotTest extends AbstractTest { @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; } - - 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(); + Form form = new Form("Browser Test", new BorderLayout()) { + @Override + protected void onShowCompleted() { + TestUtils.waitFor(100); + Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("BrowserComponent"); } - result[0] = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("BrowserComponent"); - }); - return result[0]; + }; + BrowserComponent browser = new BrowserComponent(); + browser.addWebEventListener(BrowserComponent.onLoad, evt -> loadFinished[0] = true); + browser.setPage(buildHtml(), null); + form.add(BorderLayout.CENTER, browser); + form.show(); + TestUtils.waitFor(250); + return true; } private static String buildHtml() { diff --git a/scripts/device-runner-app/tests/GraphicsPipelineScreenshotTest.java b/scripts/device-runner-app/tests/GraphicsPipelineScreenshotTest.java index c247290688..f5b4df67a5 100644 --- a/scripts/device-runner-app/tests/GraphicsPipelineScreenshotTest.java +++ b/scripts/device-runner-app/tests/GraphicsPipelineScreenshotTest.java @@ -11,25 +11,15 @@ public class GraphicsPipelineScreenshotTest extends AbstractTest { @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(); + Form form = new Form("Graphics Pipeline", new BorderLayout()) { + @Override + protected void onShowCompleted() { + Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("GraphicsPipeline"); } - result[0] = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("GraphicsPipeline"); - }); - return result[0]; + }; + form.add(BorderLayout.CENTER, new GraphicsShowcase()); + form.show(); + return true; } 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..4787b57d40 100644 --- a/scripts/device-runner-app/tests/MainScreenScreenshotTest.java +++ b/scripts/device-runner-app/tests/MainScreenScreenshotTest.java @@ -10,33 +10,32 @@ public class MainScreenScreenshotTest extends AbstractTest { @Override public boolean runTest() throws Exception { - Cn1ssDeviceRunnerHelper.runOnEdtSync(() -> { - Form form = new Form("Main Screen", new BorderLayout()); + Form form = new Form("Main Screen", new BorderLayout()) { + @Override + protected void onShowCompleted() { + Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("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 true; } } diff --git a/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java b/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java index bac98fbcb3..a7906dff16 100644 --- a/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java +++ b/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java @@ -22,81 +22,32 @@ public class MediaPlaybackScreenshotTest extends AbstractTest { @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 = new Form("Media Playback", new BorderLayout()); 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(mediaPath, 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 screenshotSuccess; } private static void updateStatus(Label label, Form form, String message) { From 617b3298be8fb294d7d7366d51b25b4379e66231 Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Fri, 21 Nov 2025 17:41:41 +0200 Subject: [PATCH 4/9] Ugh --- .../device-runner-app/tests/AbstractGraphicsScreenshotTest.java | 2 +- .../device-runner-app/tests/BrowserComponentScreenshotTest.java | 1 - .../device-runner-app/tests/MediaPlaybackScreenshotTest.java | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java b/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java index 79597e87d9..5832df9722 100644 --- a/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java +++ b/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java @@ -17,7 +17,7 @@ public boolean runTest() throws Exception { protected void onShowCompleted() { Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(screenshotName()); } - } + }; form.add(BorderLayout.CENTER, createContent()); form.show(); return true; diff --git a/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java b/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java index fd8b977f97..2ae7a4f823 100644 --- a/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java +++ b/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java @@ -20,7 +20,6 @@ protected void onShowCompleted() { } }; BrowserComponent browser = new BrowserComponent(); - browser.addWebEventListener(BrowserComponent.onLoad, evt -> loadFinished[0] = true); browser.setPage(buildHtml(), null); form.add(BorderLayout.CENTER, browser); form.show(); diff --git a/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java b/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java index a7906dff16..8459ba3625 100644 --- a/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java +++ b/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java @@ -28,7 +28,7 @@ public boolean runTest() throws Exception { if (tonePath == null) { updateStatus(statusLabel, form, "Failed to generate tone file"); } else { - Media media = MediaManager.createMedia(mediaPath, false); + Media media = MediaManager.createMedia(tonePath, false); if (media == null) { updateStatus(statusLabel, form, "Media creation returned null"); } From 83baaea1ab798a96255c4010244c0402a54afcf3 Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Fri, 21 Nov 2025 20:35:33 +0200 Subject: [PATCH 5/9] No idea --- .../tests/AbstractGraphicsScreenshotTest.java | 12 ++----- scripts/device-runner-app/tests/BaseTest.java | 32 +++++++++++++++++++ .../tests/BrowserComponentScreenshotTest.java | 13 ++------ .../tests/GraphicsPipelineScreenshotTest.java | 11 ++----- .../tests/MainScreenScreenshotTest.java | 12 ++----- .../tests/MediaPlaybackScreenshotTest.java | 7 ++-- 6 files changed, 47 insertions(+), 40 deletions(-) create mode 100644 scripts/device-runner-app/tests/BaseTest.java diff --git a/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java b/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java index 5832df9722..597d378b09 100644 --- a/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java +++ b/scripts/device-runner-app/tests/AbstractGraphicsScreenshotTest.java @@ -1,25 +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 { - Form form = new Form("Graphics", new BorderLayout()) { - @Override - protected void onShowCompleted() { - Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(screenshotName()); - } - }; + Form form = createForm("Graphics", new BorderLayout(), screenshotName()); form.add(BorderLayout.CENTER, createContent()); form.show(); - return true; + 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..c565f5677a --- /dev/null +++ b/scripts/device-runner-app/tests/BaseTest.java @@ -0,0 +1,32 @@ +package com.codenameone.examples.hellocodenameone.tests; + +import com.codename1.testing.AbstractTest; +import com.codename1.ui.Form; +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() { + Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(imageName); + done = true; + } + }; + } + + protected boolean waitForDone() { + int timeout = 100; + while(!done) { + TestUtils.waitFor(10); + timeout--; + if(timeout == 0) { + return false; + } + } + 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 2ae7a4f823..c521e4c6dc 100644 --- a/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java +++ b/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java @@ -6,25 +6,18 @@ import com.codename1.ui.Form; import com.codename1.ui.layouts.BorderLayout; -public class BrowserComponentScreenshotTest extends AbstractTest { +public class BrowserComponentScreenshotTest extends BaseTest { @Override public boolean runTest() throws Exception { if (!BrowserComponent.isNativeBrowserSupported()) { return true; } - Form form = new Form("Browser Test", new BorderLayout()) { - @Override - protected void onShowCompleted() { - TestUtils.waitFor(100); - Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("BrowserComponent"); - } - }; + Form form = createForm("Browser Test", new BorderLayout(), "BrowserComponent"); BrowserComponent browser = new BrowserComponent(); browser.setPage(buildHtml(), null); form.add(BorderLayout.CENTER, browser); form.show(); - TestUtils.waitFor(250); - return true; + return waitForDone(); } private static String buildHtml() { diff --git a/scripts/device-runner-app/tests/GraphicsPipelineScreenshotTest.java b/scripts/device-runner-app/tests/GraphicsPipelineScreenshotTest.java index f5b4df67a5..0969c8207f 100644 --- a/scripts/device-runner-app/tests/GraphicsPipelineScreenshotTest.java +++ b/scripts/device-runner-app/tests/GraphicsPipelineScreenshotTest.java @@ -8,18 +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 { - Form form = new Form("Graphics Pipeline", new BorderLayout()) { - @Override - protected void onShowCompleted() { - Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("GraphicsPipeline"); - } - }; + Form form = createForm("Graphics Pipeline", new BorderLayout(), "GraphicsPipeline"); form.add(BorderLayout.CENTER, new GraphicsShowcase()); form.show(); - return true; + 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 4787b57d40..29cf44dc40 100644 --- a/scripts/device-runner-app/tests/MainScreenScreenshotTest.java +++ b/scripts/device-runner-app/tests/MainScreenScreenshotTest.java @@ -7,16 +7,10 @@ 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 { - Form form = new Form("Main Screen", new BorderLayout()) { - @Override - protected void onShowCompleted() { - Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("MainActivity"); - } - }; - + Form form = createForm("Main Screen", new BorderLayout(), "MainActivity"); Container content = new Container(BoxLayout.y()); content.getAllStyles().setBgColor(0x1f2937); content.getAllStyles().setBgTransparency(255); @@ -36,6 +30,6 @@ protected void onShowCompleted() { form.add(BorderLayout.CENTER, content); form.show(); - return true; + return waitForDone(); } } diff --git a/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java b/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java index 8459ba3625..477a0cb61f 100644 --- a/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java +++ b/scripts/device-runner-app/tests/MediaPlaybackScreenshotTest.java @@ -15,14 +15,14 @@ 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 { - Form form = new Form("Media Playback", new BorderLayout()); + Form form = createForm("Media Playback", new BorderLayout(), "MediaPlayback"); String tonePath = writeToneWav(); final Label statusLabel = new Label("Preparing media sample…"); if (tonePath == null) { @@ -46,8 +46,7 @@ public boolean runTest() throws Exception { form.show(); Cn1ssDeviceRunnerHelper.waitForMillis(800); - boolean screenshotSuccess = Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot("MediaPlayback"); - return screenshotSuccess; + return waitForDone(); } private static void updateStatus(Label label, Form form, String message) { From e17ec301394325af0279d9d3e70d3b2a903ebf4b Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Fri, 21 Nov 2025 21:16:09 +0200 Subject: [PATCH 6/9] Giving tests more time --- scripts/device-runner-app/tests/BaseTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/device-runner-app/tests/BaseTest.java b/scripts/device-runner-app/tests/BaseTest.java index c565f5677a..1c831e2aed 100644 --- a/scripts/device-runner-app/tests/BaseTest.java +++ b/scripts/device-runner-app/tests/BaseTest.java @@ -2,6 +2,7 @@ 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; @@ -12,8 +13,10 @@ protected Form createForm(String title, Layout layout, final String imageName) { return new Form(title, layout) { @Override protected void onShowCompleted() { - Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(imageName); - done = true; + UITimer.timer(500, false, this, () -> { + Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(imageName); + done = true; + }); } }; } @@ -21,7 +24,7 @@ protected void onShowCompleted() { protected boolean waitForDone() { int timeout = 100; while(!done) { - TestUtils.waitFor(10); + TestUtils.waitFor(20); timeout--; if(timeout == 0) { return false; From 951062ed03f5ecf174fc328445245449e3ec58e5 Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Fri, 21 Nov 2025 22:01:56 +0200 Subject: [PATCH 7/9] Trying to fix the browser component delay logic --- scripts/device-runner-app/tests/BaseTest.java | 6 +++++- .../tests/BrowserComponentScreenshotTest.java | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/device-runner-app/tests/BaseTest.java b/scripts/device-runner-app/tests/BaseTest.java index 1c831e2aed..d3236c3458 100644 --- a/scripts/device-runner-app/tests/BaseTest.java +++ b/scripts/device-runner-app/tests/BaseTest.java @@ -13,7 +13,7 @@ protected Form createForm(String title, Layout layout, final String imageName) { return new Form(title, layout) { @Override protected void onShowCompleted() { - UITimer.timer(500, false, this, () -> { + registerReadyCallback(this, () -> { Cn1ssDeviceRunnerHelper.emitCurrentFormScreenshot(imageName); done = true; }); @@ -21,6 +21,10 @@ protected void onShowCompleted() { }; } + protected void registerReadyCallback(Form parent, Runnable run) { + UITimer.timer(500, false, parent, run); + } + protected boolean waitForDone() { int timeout = 100; while(!done) { diff --git a/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java b/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java index c521e4c6dc..01c4d722a9 100644 --- a/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java +++ b/scripts/device-runner-app/tests/BrowserComponentScreenshotTest.java @@ -4,22 +4,28 @@ 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 BaseTest { + private BrowserComponent browser; @Override public boolean runTest() throws Exception { if (!BrowserComponent.isNativeBrowserSupported()) { return true; } Form form = createForm("Browser Test", new BorderLayout(), "BrowserComponent"); - BrowserComponent browser = new BrowserComponent(); + browser = new BrowserComponent(); browser.setPage(buildHtml(), null); form.add(BorderLayout.CENTER, browser); form.show(); return waitForDone(); } + protected void registerReadyCallback(Form parent, final Runnable run) { + browser.addWebEventListener(BrowserComponent.onLoad, evt -> CN.callSerially(run)); + } + private static String buildHtml() { return "" + "