Search in sources :

Example 11 with Log

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);
}
Also used : TextArea(com.codename1.ui.TextArea)

Example 12 with Log

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;
    }
}
Also used : IOException(java.io.IOException) Image(com.codename1.ui.Image) ImageIO(com.codename1.ui.util.ImageIO)

Example 13 with Log

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);
}
Also used : TextArea(com.codename1.ui.TextArea)

Example 14 with Log

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);
}
Also used : Button(com.codename1.ui.Button)

Example 15 with Log

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);
}
Also used : Label(com.codename1.ui.Label)

Aggregations

Component (com.codename1.ui.Component)9 IOException (java.io.IOException)9 TextArea (com.codename1.ui.TextArea)8 Label (com.codename1.ui.Label)4 InputStream (java.io.InputStream)4 Button (com.codename1.ui.Button)3 Form (com.codename1.ui.Form)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ParseException (java.text.ParseException)3 Date (java.util.Date)3 TimerTask (java.util.TimerTask)3 Cursor (android.database.Cursor)2 Address (com.codename1.contacts.Address)2 Contact (com.codename1.contacts.Contact)2 BufferedInputStream (com.codename1.io.BufferedInputStream)2 Location (com.codename1.location.Location)2 Command (com.codename1.ui.Command)2 ActionEvent (com.codename1.ui.events.ActionEvent)2 SimpleDateFormat (java.text.SimpleDateFormat)2