otatest.java

来自「cqME :java framework for TCK test.」· Java 代码 · 共 926 行 · 第 1/3 页

JAVA
926
字号
     * Overall status depends on the installation code to be equal to the     * given expectedCode. If codes do not match, the failed status will be     * returned.     *     * @param attr     *            Additional attributes to set.     * @param name     *            Application suite's name.     * @param comment     *            Comments to be presented during installation process, or     *            <code>null</code> if there is no need for custom comments.     * @param expectedCode     *            Expected installation status code.     * @return Overall status of the operation.     * @see OTAHandler#installNegativeWithNotification(String, String)     */    protected Status installNegativeWithNotification(Attributes attr, String name,                                     String comment, String expectedCode) {        resetNotifications();        status = null;        operation = "installNegative2";        this.name = name;        this.expectedCode = expectedCode;        // Set list of midlets(jars) and jads that can be downloaded        String JADNAME = name + ".jad";        String JARNAME = name + ".jar";        otaServer.setAdditionalAttributes(attr, JADNAME);        String[] allowedNames = new String[]{JADNAME, JARNAME};        otaServer.setURLs(allowedNames);        String url = address + "/" + JADNAME;        ref.println("Installing " + JARNAME + "\n");        NotifySender sender = new NotifySender();        sender.start();        try {            Status handlerStatus = handler.installNegativeWithNotification(                    url, comment);            if (handlerStatus != null && !handlerStatus.isPassed()) {                return handlerStatus;            }            return (status != null) ? status : handlerStatus;        } finally {            sender.stop();        }    }    /**     * Requests the handler to install the suite with the specified name,     * expecting that the installation should be successful.     * <p>     * Before that, instructs the OTA server to restrict GET requests to     * "applicationName.jar" and "applicationName.jad" only (if the provided     * application name is "applicationName"), and sets additional attributes.     *     * @param attr     *            Additional attributes to set.     * @param name     *            Application suite's name.     * @param comment     *            Comments to be presented during installation process, or     *            <code>null</code> if there is no need for custom comments.     * @return Overall status of the operation.     * @see OTAHandler#installNegativeWithNotification(String, String)     */    protected Status installWithNotification(Attributes attr, String name,            String comment) {        return installWithNotification(attr, name, comment, (String[]) null,                (String) null);    }    /**     * Requests the handler to install the suite with the specified name,     * expecting that the installation should be successful, providing full     * user-specified interactive interface.     * <p>     * Before that, instructs the OTA server to restrict GET requests to     * "applicationName.jar" and "applicationName.jad" only (if the provided     * application name is "applicationName"), and sets additional attributes.     *     * @param attr     *            Additional attributes to set.     * @param name     *            Application suite's name.     * @param comments     *            Comments to be presented during installation process, or     *            <code>null</code> if there is no need for custom comments.     * @param question     *            The question to ask while preparing for application     *            installation.     * @return Overall status of the operation.     * @see OTAHandler#installNegativeWithNotification(String, String)     */    protected Status installWithNotification(Attributes attr, String name,            String[] comments, String question) {        return installWithNotification(attr, name, (String) null, comments,                question);    }    private Status installWithNotification(Attributes attr, String name, String comment,            String[] comments, String question) {        resetNotifications();        status = null;        operation = "install";        this.name = name;        ref.println("Installing " + name + "\n");        String JADNAME = name + ".jad";        String JARNAME = name + ".jar";        otaServer.setAdditionalAttributes(attr, JADNAME);        String[] allowedNames = new String[]{JADNAME, JARNAME};        otaServer.setURLs(allowedNames);        String url = address + "/" + JADNAME;        NotifySender sender = new NotifySender();        sender.start();        try {            Status handlerStatus;            if (comments != null) {                handlerStatus = handler.installWithNotification(                        url, comments, question);            } else {                handlerStatus = handler.installWithNotification(url, comment);            }            if (handlerStatus != null && !handlerStatus.isPassed()) {                return handlerStatus;            }            return (status != null) ? status : handlerStatus;        } finally {            sender.stop();        }    }    /**     * Sets the test frame's size.     *     * This method provides means to control the frame size. It has effect only     * with {@link InteractiveOTAHandler}.     *     * @param width     *                Width of test frame.     * @param height     *                Height of test frame.     * @deprecated The method should not be used since the GUI tries to     *                   determine its size automatically. Setting the frame     *                   size explicitly is against 508 requirements.     */    protected void setInfoFrameSize(int width, int height) {        // do nothing intentionally    }    /**     * Prevents the application from being signed.     * <p>     * This method should be used in tests that require some particular     * application to be unsigned.     * <p>     * Note: In order to take effect, this method should be invoked BEFORE     * install methods for the given application.     *     * @param appName     *                The application name.     */    protected void excludeFromSigning(String appName) {        otaServer.excludeFromSigning(appName);    }    /**     * Removes the application from the set of applications that should not be     * signed. Does nothing if the application is not in the set.     *     * @param appName     *                The application name.     */    protected void unexcludeFromSigning(String appName) {        otaServer.unexcludeFromSigning(appName);    }protected class NotifySender implements Runnable {    private Thread notificationThread;    private volatile boolean stopping = true;    long now = System.currentTimeMillis();    long end = now + timeout;    void start() {        stopping = false;        notificationThread = new Thread(this);        notificationThread.start();    }    void stop() {        assert stopping == false;        stopping = true;        Thread dyingThread = notificationThread;        notificationThread = null;        dyingThread.interrupt();        try {            // theoretically, there is no need to use timeout here,            // but practically, it makes sense in those rare cases            // when dying thread cannot die for some reason, so            // we avoid hangup            dyingThread.join(timeout);        } catch (InterruptedException e) {            e.printStackTrace(log);        }    }    private boolean isStopping() {        return stopping;    }    public void run() {        try {            if (operation.equals("installNegative1") ||                    operation.equals("installNegative2")) {                while (!otaServer.getInstallNotification()) {                    synchronized (otaServer) {                        otaServer.wait(100);                    }                    now = System.currentTimeMillis();                    if (now > end) {                        status = Status.failed("No install notification at all "                                 + "received in " + timeout/1000 + " seconds");                        break;                    }                }                if (otaServer.getInstallNotification(name, "900")) {                    status = Status.failed("Install notification with code 900 received "                             + "when it should not (installation failure expected)");                    Status ret = handler.removeAll((String) null);                    if (ret != null && !ret.isPassed())                        status = ret;                }                if (operation.equals("installNegative2") &&                        !otaServer.getInstallNotification(name, expectedCode))                     status = Status.failed("No install notification with code " +                             expectedCode + " received in " + timeout/1000 + " seconds.");            } else if (operation.equals("install")) {                while (!otaServer.getInstallNotification(name, "900")) {                    synchronized (otaServer) {                        otaServer.wait(100);                    }                    now = System.currentTimeMillis();                    if (now > end) {                        status = Status.failed("No install notification with code 900 "                                 + "received in " + timeout/1000 + " seconds");                        break;                    }                }            } else if (operation.equals("run")) {                while (!otaServer.getRunNotification()) {                    synchronized (otaServer) {                        otaServer.wait(100);                    }                    now = System.currentTimeMillis();                    if (now > end) {                        status = Status.failed("No run notification received in " +                                 timeout/1000 + " seconds");                        break;                    }                }            } else if (operation.equals("remove")) {                while (!otaServer.getRemoveNotification()) {                    synchronized (otaServer) {                        otaServer.wait(100);                    }                    now = System.currentTimeMillis();                    if (now > end) {                        status = Status.failed("No remove notification received in " +                                 timeout/1000 + " seconds");                        break;                    }                }            }            if (status ==  null) {                status = Status.passed("OKAY");            }            handler.setStatus(status);        } catch (InterruptedException ie) {            if (!isStopping()) {                // unexpected interrupted exception                ie.printStackTrace(log);                status = Status.failed("Unexpected " + ie);            } else {                // explicit interruption from stop(),                // this status is going to be ignored                status = Status.failed("Interrupted");            }            handler.setStatus(status);        }    }}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?