exportedfilter.java

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

JAVA
147
字号
/* * $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.export.javatest;import com.sun.javatest.TestDescription;import com.sun.javatest.TestFilter;import com.sun.javatest.util.I18NResourceBundle;import com.sun.tck.j2me.javatest.TestExportInfo;import java.io.DataInputStream;import java.io.File;import java.io.IOException;import java.util.HashSet;import java.util.Set;import java.util.jar.JarFile;import java.util.zip.ZipEntry;/** * <code>TestFilter</code> for running exported tests. Filters out all tests not * included in the exported bundle specified in the interview. */public class ExportedFilter extends TestFilter {        /**     * Creates a new instance of <code>ExportedFilter</code> with specified     * <code>TestExportInfo</code>.     *      * @param   testExportInfo  <code>TestExportInfo</code> instance to use for     *      obtaining all information related to test export.     */    public ExportedFilter(TestExportInfo testExportInfo) {        bundleName = testExportInfo.getExportedTest();    }    /**     * Returns the description of this test filter.     *     * @return string with description.     */    public String getDescription() {        return i18n.getString("ef.descr");    }    /**     * Returns the name of this test filter.     *     * @return string with name.     */    public String getName() {        return i18n.getString("ef.name");    }    /**     * Returns a boolean that indicates whether or not the specified test     * description is accepted.     *     * @param   testDescription  <code>TestDescription</code> instance with     *      test definition.     *     * @return <code>true</code> if the test defined in specified test     *          description is contained in the exported bundle.     */    public boolean accepts(TestDescription testDescription)            throws TestFilter.Fault {        return getTests().contains(testDescription.getRootRelativeURL());    }    /**     * Returns the reason for rejecting tests by this test filter.     *     * @return String with reason.     */    public String getReason() {        return i18n.getString("ef.reason", bundleName);    }    private static final I18NResourceBundle i18n =        I18NResourceBundle.getBundleForClass(ExportedFilter.class);        private String bundleName;    private Set<String> tests;        /**     * Reads the exported bundle (JAR file) specified by user for this     * test run. Extract information about contained tests from      * <code>getNextTest</code> resource files and returns the set with     * test IDs.     *     * @return Set of test IDs contained in the exported bundle.     */    private Set<String> getTests() throws TestFilter.Fault {        JarFile jarFile;                if (tests == null) {            ZipEntry zipEntry = null;            try {                jarFile = new JarFile(new File(bundleName));            } catch (IOException e) {                throw new TestFilter.Fault(i18n, "ef.cannot.open.bundle",                        bundleName);            }            tests = new HashSet<String>();            try {                for (int i = 0;                        (zipEntry = jarFile.getEntry("getNextTest" + i)) != null;                       i++) {                    DataInputStream in = new DataInputStream(                            jarFile.getInputStream(zipEntry));                    tests.add(in.readUTF());                    in.close();                }            } catch (IOException e) {                throw new TestFilter.Fault(i18n, "ef.error.reading.bundle",                        bundleName);            } finally {                try {                    jarFile.close();                } catch (IOException e) {}            }        }        return tests;    }}

⌨️ 快捷键说明

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