Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import com.codename1.io.Storage;
import com.codename1.junit.FormTest;
import com.codename1.junit.UITestBase;
import com.codename1.ui.Display;
import com.codename1.testing.TestUtils;
import com.codename1.ui.Image;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -53,7 +51,10 @@ void testBackgroundLoadPopulatesImageData() throws Exception {
StorageImageAsync image = StorageImageAsync.create("async", placeholder);
image.getInternal();

waitForImageData(image);
while(image.getInternal() == placeholder) {
TestUtils.waitFor(10);
}

assertArrayEquals(encoded, image.getImageData());

Image loaded = image.getInternal();
Expand Down Expand Up @@ -83,25 +84,6 @@ void testIsAnimationAlwaysTrue() {
assertTrue(image.isAnimation());
}

private void waitForImageData(StorageImageAsync image) throws Exception {
Method processSerialCalls = Display.class.getDeclaredMethod("processSerialCalls");
processSerialCalls.setAccessible(true);
long start = System.currentTimeMillis();
while (getImageDataField(image) == null) {
processSerialCalls.invoke(Display.getInstance());
if (System.currentTimeMillis() - start > 2000) {
fail("Timed out waiting for image data to load");
}
Thread.sleep(10);
}
}

private byte[] getImageDataField(StorageImageAsync image) throws Exception {
Field field = StorageImageAsync.class.getDeclaredField("imageData");
field.setAccessible(true);
return (byte[]) field.get(image);
}

private boolean isImageCreated(StorageImageAsync image) throws Exception {
Field field = StorageImageAsync.class.getDeclaredField("imageCreated");
field.setAccessible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ public TestCodenameOneImplementation(boolean timeoutSupported) {
public void setDisplaySize(int width, int height) {
this.displayWidth = width;
this.displayHeight = height;
sizeChanged(width, height);
}

public void setDeviceDensity(int density) {
Expand Down
Loading