use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class TestUtils method findLabelText.
/**
* Finds a component with the given name, works even with UI's that weren't created with the GUI builder
* @param text the text of the label/button
* @return the component with the given label text within the tree
*/
private static Label findLabelText(Container root, String text) {
if (verbose) {
log("findLabelText(" + root + ", " + text + ")");
}
int count = root.getComponentCount();
for (int iter = 0; iter < count; iter++) {
Component c = root.getComponentAt(iter);
if (c instanceof Label) {
String n = ((Label) c).getText();
if (n != null && n.equals(text)) {
return (Label) c;
}
// will work for cases of upcase due to Android theme upcasing of buttons
n = (String) c.getClientProperty("cn1$origText");
if (n != null && n.equals(text)) {
return (Label) c;
}
continue;
}
if (c instanceof Container) {
Label l = findLabelText((Container) c, text);
if (l != null) {
return l;
}
}
}
return null;
}
use of com.codename1.rad.models.Property.Name 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.rad.models.Property.Name 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().paintComponent(mute.getGraphics(), true);
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.rad.models.Property.Name in project CodenameOne by codenameone.
the class TestUtils method setText.
/**
* Sets the text for the given component
* @param name the name of the component
* @param text the text to set
*/
public static void setText(String name, String text) {
if (verbose) {
log("setText(" + name + ", " + text + ")");
}
Component c = findByName(name);
if (c instanceof Label) {
((Label) c).setText(text);
return;
}
((TextArea) c).setText(text);
Display.getInstance().onEditingComplete(c, text);
}
use of com.codename1.rad.models.Property.Name 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);
}
Aggregations