Path: blob/master/test/functional/cmdline_options_tester/src/Output.java
6004 views
/*******************************************************************************1* Copyright (c) 2004, 2018 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122import java.util.regex.Matcher;23import java.util.regex.Pattern;24import java.util.regex.PatternSyntaxException;2526import com.ibm.oti.util.regex.*;2728class Output extends TestCondition {29private String _type;30private String _matchRegex;31private String _matchJavaUtilPattern;32private String _matchCase;33private String _output; // the output string taken from the file34private String _showRegexMatch;3536public Output( String matchRegex, String matchJavaUtilPattern, String showRegexMatch, String matchCase, String type ) {37_matchRegex = matchRegex;38_matchJavaUtilPattern = matchJavaUtilPattern;39_showRegexMatch = showRegexMatch;40_matchCase = matchCase;41_type = type;42_output = "";43}4445void setOutput( String s ) {46_output = s;47}4849int getType() {50return parseType( TestSuite.evaluateVariables( _type ) );51}5253public boolean isJavaUtilPattern() {54return !("no".equalsIgnoreCase( TestSuite.evaluateVariables( _matchJavaUtilPattern ) ));55}5657boolean match( Object o ) {58String candidate = (String) o;59boolean matchRegex = !("no".equalsIgnoreCase(TestSuite.evaluateVariables(_matchRegex)));60boolean matchCase = !("no".equalsIgnoreCase(TestSuite.evaluateVariables(_matchCase)));61boolean matchJavaUtilPattern = !("no".equalsIgnoreCase(TestSuite.evaluateVariables(_matchJavaUtilPattern)));62boolean showRegexMatch = !("no".equalsIgnoreCase(TestSuite.evaluateVariables(_showRegexMatch)));63String string = TestSuite.evaluateVariables(_output);6465if ((matchRegex) && (!matchJavaUtilPattern)) {66try {67Regex regex = new Regex(string, matchCase);68boolean retval = regex.matches(candidate);69if( retval && showRegexMatch) {70System.out.println("\tMatch ("+_type+"): "+candidate);71}72return retval;73} catch (Exception e) {74System.out.println("Exception " + e.getClass().toString() + " message " + e.getMessage());75System.out.println("OTI Regex:" + string);76e.printStackTrace();77return false;78}79} else if ((matchRegex) && (matchJavaUtilPattern)) {80/* CMVC 163891: Use of java.util.regex.Pattern/Matcher must be in a separate class, to avoid81* problems with the verifier when using the embedded class library.82*/83return OutputRegexHelper.ContainsMatches(candidate,string,matchCase,showRegexMatch,_type);84} else {85if (!matchCase) {86string = string.toLowerCase();87candidate = candidate.toLowerCase();88}89boolean retval = (candidate.indexOf(string) >= 0);90if( retval && showRegexMatch) {91System.out.println("\tMatch ("+_type+"): "+candidate);92}93return retval;94}95}9697public String toString() {98return "Output match: " + TestSuite.evaluateVariables( _output );99}100}101102103