platformsuitabilityfilter.java

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

JAVA
168
字号
/* * $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.platform;import java.util.HashSet;import java.util.Set;import com.sun.javatest.TestDescription;import com.sun.javatest.TestEnvironment;import com.sun.javatest.TestFilter;import com.sun.javatest.util.I18NResourceBundle;/** * A general purpose filter that filters out tests unsuitable for the base * platform configured in the interview. For example: MIDP-specific tests * should not be run in CLDC mode, and CDC-specific tests should not be run in * MIDP mode. * <p> * The filter uses simple rules while determining the suitability of the test: * it looks for "suitableForPlatform" key in the test description. * <ul> * <li>If the key is present then the filter checks whether value provided in * the test description matches the platform name obtained from the test * environment.</li> * <li>If the key is missing, that means the test hasn't specified what * platform it should be ran on, and thus is suitable for all modes, with one * exception: tests, marked with "trusted" and "untrusted" keywords and with * no platforms specified are considered to be MIDP only.</li> * </ul> * <p> * Tests may be marked to be suitable for multiple platforms, e.g. * * <pre> *     suitableForPlatform: cldc, midp, cdc * </pre> * * Such marked test explicitly states that it suitable for all three * platforms. * <p> * The bottom line is that the test will be selected for all platforms it was * explicitly marked. * * @see #SUITABLE_PLATFORM_KEY * @see BasePlatformInfo#getPlatformName() */public class PlatformSuitabilityFilter extends TestFilter {    private BasePlatformInfo platformInfo;    /**     * A key to lookup from the TestDescription test's suitable platforms.     */    public static final String SUITABLE_PLATFORM_KEY = "suitableForPlatform";    /**     * Creates filter instance.     * @param env The Test Environment.     */    public PlatformSuitabilityFilter(TestEnvironment env) {        platformInfo = BasePlatformInfo.fromEnv(env);    }    /**     * Gets the name of this filter.     *     * @return The name of this filter.     */    public String getName() {        return i18n.getString("tf.platformFilter.name");    }    /**     * Gets the description of this filter.     *     * @return The description of this filter.     */    public String getDescription() {        return i18n.getString("tf.platformFilter.description");    }    /**     * Gets the reason why this filter would reject a test, as might be used     * in reports.     *     * @return A rejection reason for this filter.     */    public String getReason() {        return i18n.getString("tf.platformFilter.reason");    }    /**     * Determines whether a TestDescription should be accepted or rejected by     * this filter, as described above.     *     * @param td     *            The TestDescription to check.     * @return <code>true</code> if the test description should be included     *         in collection; false otherwise.     * @throws TestFilter.Fault     *             if an error occurs while trying to determine if this test     *             should be accepted or not.     */    public boolean accepts(TestDescription td) throws Fault {        if (platformInfo == null || platformInfo.getPlatformName() == null) {            // nothing to do, platform is undefined            return true;        }        Set modes = new HashSet();        String modesString = td.getParameter(SUITABLE_PLATFORM_KEY);        if (modesString != null) {            String[] modesArray = modesString.split("[\\s,]+");            for (int i = 0; i < modesArray.length; i++) {                String mode = modesArray[i];                modes.add(mode.toLowerCase());            }        }        if (modes.isEmpty()) {            // no explicit platforms specified            // one special case: trusted/untrusted keywords.            // such tests applicable only for MIDP            Set kwds = td.getKeywordTable();            if (kwds.contains("trusted") || kwds.contains("untrusted")) {                if (platformInfo.isMidp()) {                    return true;                } else {                    return false;                }            }            // in general, all tests without explicitly specified platforms            // should be applicable to all modes.            return true;        }        return modes.contains(platformInfo.getPlatformName().toLowerCase());    }    private static final I18NResourceBundle i18n =        I18NResourceBundle.getBundleForClass(PlatformSuitabilityFilter.class);}

⌨️ 快捷键说明

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