j2mebasetestsuite.java.svn-base
来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 498 行 · 第 1/2 页
SVN-BASE
498 行
/* * $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 com.sun.javatest.CompositeFilter;import com.sun.javatest.DefaultTestRunner;import com.sun.javatest.Harness;import com.sun.javatest.InterviewParameters;import com.sun.javatest.Keywords;import com.sun.javatest.KeywordsFilter;import com.sun.javatest.Script;import com.sun.javatest.TestDescription;import com.sun.javatest.TestEnvironment;import com.sun.javatest.TestFilter;import com.sun.javatest.TestFinder;import com.sun.javatest.TestRunner;import com.sun.javatest.WorkDirectory;import com.sun.javatest.util.BackupPolicy;import com.sun.javatest.util.I18NResourceBundle;import com.sun.tck.j2me.export.javatest.ExportedBundlingService;import com.sun.tck.j2me.interview.BasicTckInterview;import com.sun.tck.j2me.platform.BasePlatformInfo;import com.sun.tck.j2me.platform.PlatformSuitabilityFilter;import com.sun.tck.midp.policy.DoubleDutyTestModifier;import com.sun.tck.midp.policy.PermissionFilter;import com.sun.tck.midp.policy.PermissionSet;import com.sun.tck.midp.policy.SecurityInfo;import com.sun.tck.j2me.services.testBundlingService.J2meTestBundlingService;import com.sun.tck.j2me.services.testBundlingService.TestBundlingService;import java.io.File;import java.net.URL;import java.util.ArrayList;import java.util.Arrays;import java.util.HashSet;import java.util.List;import java.util.Map;import java.util.Set;import java.util.logging.Logger;public class J2meBaseTestSuite extends DistributedTestSuite { /** * The name of a test suite property that identifies a class that * implements {@link TestDescriptionModifier}. If this property is * omitted then the default modifier is used * ({@link DoubleDutyTestModifier}). * <p> * Set this property to "disable" in order to disable test modifier. */ public static final String TESTS_MODIFIER = "tests.modifier"; private static final I18NResourceBundle i18n = I18NResourceBundle.getBundleForClass(J2meBaseTestSuite.class); private static final Logger log = Logger.getLogger( J2meBaseTestSuite.class.getName()); private boolean untrusted = false; private boolean isMIDPmode = false; private boolean isInteractiveAgentEnabled = true; private PermissionSet platform_policy = null; private SecurityInfo secInfo; private volatile TestDescriptionModifier tdModifier = null; private volatile TestRunner testRunner; public J2meBaseTestSuite(File root, Map tsInfo, ClassLoader cl) throws Fault { super(root, tsInfo, cl); // TestDescriptionModifier class name should be read // from testsuite.jtt (class name cannot be read from interview, since // the modifier is used in TestFinder and finder is created before // interview. String tdModifierName = getTestSuiteInfo(TESTS_MODIFIER); if (tdModifierName == null) { // "legacy" TCK tdModifier = new DoubleDutyTestModifier(); ((DoubleDutyTestModifier) tdModifier).setLegacyMode(true); } else if ("disable".equalsIgnoreCase(tdModifierName)) { tdModifier = null; } else { Class tdmClass = loadClass(tdModifierName, cl); tdModifier = (TestDescriptionModifier) newInstance(tdmClass); } log.config("Created TestModifier: " + tdModifier); String interactiveAgent = getTestSuiteInfo("agent.interactive"); if ("disable".equalsIgnoreCase(interactiveAgent)) { isInteractiveAgentEnabled = false; } else { isInteractiveAgentEnabled = true; } } protected void loadParameters(TestEnvironment env) throws Fault { super.loadParameters(env); isMIDPmode = MIDP_MODE.equals(getMode(env)); secInfo = SecurityInfo.Factory.fromEnv(env); updateSecurityMode(secInfo); } /** * Returns an instance of J2meTestBundlingService. */ protected TestBundlingService createTestBundler(Harness harness) { if (isRunningExportedTests()) { return new ExportedBundlingService(harness, getClassLoader(), testExportInfo); } return new J2meTestBundlingService(harness, getClassLoader(), tdModifier, untrusted, isMIDPmode); } /** * Creates and initializes a TestRunner that can be used to run * a series of tests. * * @return The TestRunner that can be used to run a series of tests. */ public TestRunner createTestRunner() { // create our own Runner if tdModifier is defined if (tdModifier != null) { testRunner = new DefaultTestRunner() { // Current algorithm to handle excluded test cases for // double-duty tests is as follows: get exclude test cases // from BOTH, modified test and original test, and return // their union. public String[] getExcludedTestCases(TestDescription td) { if (tdModifier.isModifiedTest(td)) { TestDescription origTd = tdModifier.getOriginalDescription(td); assert origTd != null : "original description is null"; String[] origExclCases = super.getExcludedTestCases(origTd); String[] modifExclCases = super.getExcludedTestCases(td); String[] exclCases = union( origExclCases, modifExclCases); return exclCases; } else { // handle non-modified tests as usual return super.getExcludedTestCases(td); } } private String[] union(String[] a1, String[] a2) { if (a1 == null) { return a2; } if (a2 == null) { return a1; } // both a1 and a2 are not null Set unionSet = new HashSet(); unionSet.addAll(Arrays.asList(a1)); unionSet.addAll(Arrays.asList(a2)); return (String[]) unionSet.toArray( new String[unionSet.size()]); } }; } else { testRunner = super.createTestRunner(); } log.config("Initialized test runner: " + testRunner + " in thread: " + Thread.currentThread()); return testRunner; } public InterviewParameters createInterview() throws Fault { // Interview, explicitly specified in the testsuite.jtt file, // takes precedence. if (getTestSuiteInfo("interview") != null) { return super.createInterview(); } String customInterviewClass = getTestSuiteInfo("interview.custom.classname"); try { return BasicTckInterview.createBuilder(this) .setDistributed(shouldEnableDistrTests()) .setSubInterview(customInterviewClass) .build(); } catch (com.sun.interview.Interview.Fault fault) { throw new com.sun.javatest.TestSuite.Fault(i18n, "ts.errorInitInterview", fault.getMessage()); } } public Script createScript(TestDescription td, String[] exclTestCases, TestEnvironment scriptEnv, WorkDirectory workDir, BackupPolicy backupPolicy) throws Fault { log.finer("creating Script in thread " + Thread.currentThread()); Script baseScript = super.createScript( td, exclTestCases, scriptEnv, workDir, backupPolicy); return baseScript; } /** * Gets a list of associated files for a specified test description. * <p> * This implementation returns all the files from the super implementation * plus source files referenced in the test description's "Jad-addon" and * "Manifest-addon" entries. * * @param td * The test description for which the associated files are * required * @return a list of associated files for this test description */ public URL[] getFilesForTest(TestDescription td) { TestSourcesExtractor sourcesExtractor = new TestSourcesExtractor(td);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?