universalbasetestsuite.java

来自「cqME :java framework for TCK test.」· Java 代码 · 共 175 行

JAVA
175
字号
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tck.j2me.javatest;import java.io.File;import java.util.Map;import java.util.logging.Logger;import com.sun.javatest.Harness;import com.sun.javatest.TestEnvironment;import com.sun.javatest.util.I18NResourceBundle;import com.sun.tck.cldc.javatest.CldcTCKBaseTestSuite;import com.sun.tck.j2me.execution.javatest.GenericAgentCommand;import com.sun.tck.j2me.services.LifeCycleAwareManager;import com.sun.tck.j2me.services.commService.CommTestSuiteService;/** * A special purpose TestSuite which is aware of two different modes, the * default one is CLDC/MIDP and the other one is CDC. * <p> * In the default mode this test suite delegates the work to the parent test * suite. * <p> * In both modes, it is guaranteed that as soon as {@link #starting(Harness) } * is invoked (which is a typical way to start a test suite), the test suite * will call {@link #loadParameters(TestEnvironment) } and then * {@link #startRun(Harness) } at the beginning of the test execution and will * call {@link #stopRun() } at the end. * <p> * Subclasses may rely on this behavior as long as they don't change the * behavior of {@link #starting(Harness) }. * * @see #starting(Harness) */public class UniversalBaseTestSuite extends CldcTCKBaseTestSuite {    public static final String BASE_CONFIGURATION = "baseConfiguration";    public static final String CDC_MODE = "CDC";    public static final String MIDP_MODE = "MIDP";    private boolean cdcMode = false;    private static final I18NResourceBundle i18n =        I18NResourceBundle.getBundleForClass(J2meBaseTestSuite.class);    private static final Logger log = Logger.getLogger(            UniversalBaseTestSuite.class.getName());    /**     * Creates a TestSuite object.     *     * @param root     *            The root file for this test suite.     * @param tsInfo     *            Test suite properties, typically read from the test suite     *            properties file in the root directory of the test suite.     * @param cl     *            A class loader to be used to load additional classes as     *            required, typically using a class path defined in the test     *            suite properties file.     * @throws com.sun.javatest.TestSuite.Fault     *             if a problem occurs while creating this test suite.     */    protected UniversalBaseTestSuite(File root, Map tsInfo, ClassLoader cl)            throws Fault {        super(root, tsInfo, cl);    }    /**     * This method delegates to super.createTestSuiteService() or does nothing if     * in CDC mode.     */    protected void createTestSuiteServices(Harness harness, LifeCycleAwareManager manager) {        if (isCDCMode()) {            // CommTestSuiteService should be registered prior GenericAgentCommand            // services, because it clears all Communication handlers.            manager.addLifeCycleAware(CommTestSuiteService.SERVICE_NAME,                                       new CommTestSuiteService(harness, getClassLoader()));            manager.addLifeCycleAware("GenericAgentCommand.ExecutionService",                                      GenericAgentCommand.getExecutionService());        } else {            super.createTestSuiteServices(harness, manager);        }    }    /**     * This method is invoked from {@link #starting(Harness) } when the test     * execution is about to start and supposed to be overridden by subclasses     * to provide test suite specific behavior.     *     * @param env     *            The test environment.     * @throws com.sun.javatest.TestSuite.Fault     *             if an error occurred while doing test suite-specific     *             initialization that should cause the test run to be     *             aborted.     * @see #starting(Harness)     */    protected void loadParameters(TestEnvironment env) throws Fault {        setCDCMode(CDC_MODE.equals(getMode(env)));        if (isCDCMode()) {            log.fine("Starting in CDC mode");        } else {            log.fine("Starting in Default/CLDC mode");        }        if (!isCDCMode()) {            super.loadParameters(env);        }    }    /**     * Returns <code>true</code> if this test suite has been started in CDC     * mode.     *     * @return <code>true</code> if this test suite has been started in CDC     *         mode.     */    public boolean isCDCMode() {        return cdcMode;    }    /**     * Convenient method to figure out what execution mode is configured in     * the interview. This implementation looks for     * <code>"baseConfiguration"</code> property in the supplied test     * environment.     *     * @param env     *            The test environment.     * @return Returns the string representation of configured test execution     *         mode.     * @throws com.sun.javatest.TestSuite.Fault     *             in case of misconfiguration.     */    protected String getMode(TestEnvironment env) throws Fault {        try {            String[] envData = env.lookup(BASE_CONFIGURATION);            if (envData != null && envData.length == 1) {                return envData[0];            } else {                throw new Fault(i18n, "ts.noBaseConfig");            }        } catch (TestEnvironment.Fault e) {            throw new Fault(i18n, "ts.noBaseConfig");        }    }    private void setCDCMode(boolean mode) {        this.cdcMode = mode;    }}

⌨️ 快捷键说明

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