midptckbaseinterview.java.svn-base
来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 563 行 · 第 1/2 页
SVN-BASE
563 行
/* * $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.interview;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Properties;import java.util.logging.Level;import java.util.logging.Logger;import com.sun.interview.Question;import com.sun.javatest.CompositeFilter;import com.sun.javatest.ExcludeList;import com.sun.javatest.InterviewParameters;import com.sun.javatest.Keywords;import com.sun.javatest.KeywordsFilter;import com.sun.javatest.Parameters;import com.sun.javatest.TestEnvironment;import com.sun.javatest.TestFilter;import com.sun.javatest.TestFinder;import com.sun.javatest.TestSuite;import com.sun.javatest.interview.BasicInterviewParameters;import com.sun.javatest.util.I18NResourceBundle;import com.sun.tck.j2me.export.javatest.ExportedFilter;import com.sun.tck.j2me.javatest.ExportFilter;import com.sun.tck.j2me.javatest.J2meBaseTestSuite;import com.sun.tck.j2me.javatest.ModifiableTestFilter;import com.sun.tck.j2me.javatest.ModifyingTestFinder;import com.sun.tck.j2me.javatest.TestExportInfo;import com.sun.tck.midp.policy.SecurityInfo;import com.sun.tck.j2me.J2meTckFrameworkInfo;/** * This base top-level interview provides common values and services * for the test suite specific top-level interviews. E.g., it provides * convenient API to enable or disable test keywords related questions * (see {@link #setKeywordsEnabled(boolean)} or to enable or disable * concurrency related questions (see * {@link #setConcurrencyEnabled(boolean)}. * <p> * This interview also simplifies handling of the test filters, see * {@link #getFilters()} and {@link #getFilterKeywords()}, as well as * {@link #getFilterKeywords()} and {@link #getRelevantTestFilter()}. */public abstract class MidpTckBaseInterview extends BasicInterviewParameters { public MidpTckBaseInterview(String id) throws InterviewParameters.Fault { super(id); } /** * Creates interview with distributed mode disable. * Calling this constructor is equivalent to calling * <blockquote> * <code>MidpTckBaseInterview(id, ts, false)</code>, * </blockquote> * @param id the id used to qualify questions in this interview. * @param ts The test suite to which this interview applies. * @throws InterviewParameters.Fault if there is a problem creating this object. */ public MidpTckBaseInterview(String id, J2meBaseTestSuite ts) throws InterviewParameters.Fault { this(id, ts, false); } /** * Creates interview for the specified test suite. * @param id the id used to qualify questions in this interview. * @param ts The test suite to which this interview applies. * @param distributed true if distributed mode is enabled; false otherwise * @throws InterviewParameters.Fault if there is a problem creating this object. */ public MidpTckBaseInterview(String id, J2meBaseTestSuite ts, boolean distributed) throws InterviewParameters.Fault { super(id, ts); midts = ts; setDistrMode(distributed); log.config("Creating BaseInterview with id: " + id); } // We need to override this method in order to set protected // variable midts, which is used by a number of legacy test suites. // // Typically, there are two ways to create interviews: // // 1. To use TestSuite.createInterview() and directly invoke // multi-parameter constructors, like 3-parameter constructor above. // In this case, protected field midts will be properly set. // // 2. To provide 'interview' entry in testsuite.jtt file. Then, the // JavaTest harness will use the default public constructor with no // parameters to instantiate the interview object, and after the // interview object is created, the harness will invoke setTestSuite() // method. If we are not to override it here, the midts field will be // left undefined. And if later some of the existing TCKs would switch // to this second way of creating interviews, they would face tricky // regressions, since some of the code in such interviews depends // on midts to be present and properly defined. /** * Set the test suite for the test run. The test suite may only be * set once. * <p> * This implementation sets {@link #midts} field to the value of * <code>ts</code>. This is needed for compatibility * reasons. The rest is delegated to the super implementation. * * @param ts * The test suite to be set. * @throws NullPointerException * if ts is null. * @throws IllegalStateException * if the test suite has already been set to * something different. */ public void setTestSuite(TestSuite ts) { super.setTestSuite(ts); // compatibility, some interviews use midts if (J2meBaseTestSuite.class.isAssignableFrom(ts.getClass())) { midts = (J2meBaseTestSuite) ts; } } /** * Export values for questions on the current path. * * This implementation provides <code>j2meFwLidDir</code> * entry with the location of j2me tck framework lib directory, * where all framework jars are, and then delegates the rest of * the work to the super implementation. * * @param data The map in which the values will be placed. */ public void export(Map data) { data.put("j2meFwLibDir", J2meTckFrameworkInfo.getFrameworkLibDir().getAbsolutePath()); data.put("command.jtOnly", System.getProperty("TCKCommandClass", JTONLY_COMMAND_CLASS) + " " + System.getProperty("TCKCommandParams", JTONLY_COMMAND_PARAMS)); data.put("commandClass", "com.sun.tck.cdc.lib.ExecCLDCTestOnCDCSameJVMCmd"); super.export(data); } /** * Returns an object which provides access to the integer * specifying the maximum number of tests that may be run in * parallel. * <p> * The method is overridden in order for this base interview to be * able to control when concurrency-related GUI is * enabled/disabled in the "Quick Set" view. * * @see #setConcurrencyEnabled(boolean) */ public Parameters.ConcurrencyParameters getConcurrencyParameters() { if (enableConcurrency) { return super.getConcurrencyParameters(); } else { return concParams; } } /** * Returns the first question concerning the number of tests that * may be run in parallel. * <p> * The method is overridden in order for this base interview to be * able to control when concurrency-related question is enabled or * being hidden in the configuration interview. * * @see #setConcurrencyEnabled(boolean) */ protected Question getConcurrencyFirstQuestion() { if (enableConcurrency) { return super.getConcurrencyFirstQuestion(); } else { return getConcurrencySuccessorQuestion(); } } /** * Returns an object which provides access to the keywords object * which identifies tests to be run according to their keywords. * <p> * The method is overridden in order for this base interview to be * able to control when keywords-related GUI is * enabled/disabled in the "Quick Set" view. * * @see #setKeywordsEnabled(boolean) */ public Parameters.KeywordsParameters getKeywordsParameters() { if (keywordsEnabled) { return super.getKeywordsParameters(); } else { return null; } } public TestFilter[] getFilters() { if (!isValid()) { log.config("Interview is incomplete, no need to enable filters"); return EMPTY_FILTERS; } // interview export must be executed before we create filters. // in export we set some test suite parameters TestEnvironment env = getEnv(); SecurityInfo secInfo = SecurityInfo.Factory.fromEnv(env); log.config("secInfo=" + secInfo); TestFilter[] superFilters = super.getFilters(); String kwExpr = getFilterKeywords(); KeywordsFilter kwFilter = null; if (kwExpr != null && kwExpr.length() > 0) { try { kwFilter = new KeywordsFilter(Keywords.create(Keywords.EXPR, kwExpr)); } catch (Keywords.Fault f) { kwFilter = null; } } TestFilter securityFilter = null; try { if (secInfo != null) { // Midp security policy is defined if (!secInfo.isTrustedAppsSupported()) { // no subset filters in this case } else if (secInfo.isTrustedMode()) { securityFilter = new KeywordsFilter( Keywords.create(Keywords.EXPR, "!untrusted")); } else { securityFilter = new KeywordsFilter( Keywords.create(Keywords.EXPR, "untrusted")); } } else { // No Midp security. // Main test suite filter will deal with this. } } catch (Keywords.Fault f) { log.log(Level.SEVERE, "Cannot create security filter", f); assert false : "Cannot create security filter"; } ExportFilter exportFilter = null; TestExportInfo testExportInfo = TestExportInfo.fromEnv(env); if (testExportInfo.isExport()) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?