use of com.codename1.io.Log in project CodenameOne by codenameone.
the class TestUtils method assertTextArea.
/**
* Asserts that we have a label with the given text baring the given name
* @param text the text of the label
*/
public static void assertTextArea(String text) {
if (verbose) {
log("assertTextArea(" + text + ")");
}
TextArea l = findTextAreaText(text);
assertBool(l != null, "Null text " + text);
}
use of com.codename1.io.Log in project CodenameOne by codenameone.
the class TestUtils method screenshotTest.
/**
* The screenshot test takes a screenshot of the screen and compares it to
* a prior screenshot, if both are 100% identical the test passes. If not
* the test fails.<br>
* If this is the first time the test is run then the screenshot is taken
* and saved under the given name in the devices storage. The test passes
* for this case but a warning is printed to the console. The name will have
* .png appended to it so it will be identified.<br>
* This test will only work on devices that support the ImageIO API with PNG
* file format.
*
* @param screenshotName the name to use for the storage, must be unique!
* @return true if the screenshots are identical or no prior screenshot exists
* or if the test can't be run on this device. False if a screenshot exists and
* it isn't 100% identical.
*/
public static boolean screenshotTest(String screenshotName) {
if (verbose) {
log("screenshotTest(" + screenshotName + ")");
}
try {
ImageIO io = ImageIO.getImageIO();
if (io == null || !io.isFormatSupported(ImageIO.FORMAT_PNG)) {
log("screenshot test skipped due to no image IO support for PNG format");
return true;
}
Image mute = Image.createImage(Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight());
Display.getInstance().getCurrent().paint(mute.getGraphics());
screenshotName = screenshotName + ".png";
if (Storage.getInstance().exists(screenshotName)) {
int[] rgba = mute.getRGBCached();
Image orig = Image.createImage(Storage.getInstance().createInputStream(screenshotName));
int[] origRgba = orig.getRGBCached();
orig = null;
for (int iter = 0; iter < rgba.length; iter++) {
if (rgba[iter] != origRgba[iter]) {
log("screenshots do not match at offset " + iter + " saving additional image under " + screenshotName + ".fail");
io.save(mute, Storage.getInstance().createOutputStream(screenshotName + ".fail"), ImageIO.FORMAT_PNG, 1);
return false;
}
}
} else {
io.save(mute, Storage.getInstance().createOutputStream(screenshotName), ImageIO.FORMAT_PNG, 1);
}
return true;
} catch (IOException err) {
log(err);
return false;
}
}
use of com.codename1.io.Log in project CodenameOne by codenameone.
the class TestUtils method assertTextArea.
/**
* Asserts that we have a label with the given text baring the given name
* @param path the path to the text area
* @param text the text of the label
*/
public static void assertTextArea(int[] path, String text) {
if (verbose) {
log("assertTextArea(" + toString(path) + ", " + text + ")");
}
TextArea l = (TextArea) getComponentByPath(path);
assertBool(l != null, "Null area " + text);
assertBool(l.getText().equals(text), "assertTextArea: " + l.getText() + " != " + text);
}
use of com.codename1.io.Log in project CodenameOne by codenameone.
the class TestUtils method clickButtonByPath.
/**
* Clicks the button with the given component path
* @param path the path
*/
public static void clickButtonByPath(int[] path) {
if (verbose) {
log("clickButtonByPath(" + toString(path) + ")");
}
Button b = (Button) getComponentByPath(path);
b.pressed();
waitFor(10);
b.released();
waitFor(10);
}
use of com.codename1.io.Log in project CodenameOne by codenameone.
the class TestUtils method assertLabel.
/**
* Asserts that we have a label with the given text baring the given name
* @param path the path of the label
* @param text the text of the label
*/
public static void assertLabel(int[] path, String text) {
if (verbose) {
log("assertLabel(" + toString(path) + ", " + text + ")");
}
Label l = (Label) getComponentByPath(path);
assertBool(l != null, "Null label" + text);
assertBool(text == l.getText() || text.equals(l.getText()), ("" + l.getText()) + " != " + text);
}
Aggregations