Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdline_options_tester/src/Output.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2004, 2018 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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-exception
21
*******************************************************************************/
22
23
import java.util.regex.Matcher;
24
import java.util.regex.Pattern;
25
import java.util.regex.PatternSyntaxException;
26
27
import com.ibm.oti.util.regex.*;
28
29
class Output extends TestCondition {
30
private String _type;
31
private String _matchRegex;
32
private String _matchJavaUtilPattern;
33
private String _matchCase;
34
private String _output; // the output string taken from the file
35
private String _showRegexMatch;
36
37
public Output( String matchRegex, String matchJavaUtilPattern, String showRegexMatch, String matchCase, String type ) {
38
_matchRegex = matchRegex;
39
_matchJavaUtilPattern = matchJavaUtilPattern;
40
_showRegexMatch = showRegexMatch;
41
_matchCase = matchCase;
42
_type = type;
43
_output = "";
44
}
45
46
void setOutput( String s ) {
47
_output = s;
48
}
49
50
int getType() {
51
return parseType( TestSuite.evaluateVariables( _type ) );
52
}
53
54
public boolean isJavaUtilPattern() {
55
return !("no".equalsIgnoreCase( TestSuite.evaluateVariables( _matchJavaUtilPattern ) ));
56
}
57
58
boolean match( Object o ) {
59
String candidate = (String) o;
60
boolean matchRegex = !("no".equalsIgnoreCase(TestSuite.evaluateVariables(_matchRegex)));
61
boolean matchCase = !("no".equalsIgnoreCase(TestSuite.evaluateVariables(_matchCase)));
62
boolean matchJavaUtilPattern = !("no".equalsIgnoreCase(TestSuite.evaluateVariables(_matchJavaUtilPattern)));
63
boolean showRegexMatch = !("no".equalsIgnoreCase(TestSuite.evaluateVariables(_showRegexMatch)));
64
String string = TestSuite.evaluateVariables(_output);
65
66
if ((matchRegex) && (!matchJavaUtilPattern)) {
67
try {
68
Regex regex = new Regex(string, matchCase);
69
boolean retval = regex.matches(candidate);
70
if( retval && showRegexMatch) {
71
System.out.println("\tMatch ("+_type+"): "+candidate);
72
}
73
return retval;
74
} catch (Exception e) {
75
System.out.println("Exception " + e.getClass().toString() + " message " + e.getMessage());
76
System.out.println("OTI Regex:" + string);
77
e.printStackTrace();
78
return false;
79
}
80
} else if ((matchRegex) && (matchJavaUtilPattern)) {
81
/* CMVC 163891: Use of java.util.regex.Pattern/Matcher must be in a separate class, to avoid
82
* problems with the verifier when using the embedded class library.
83
*/
84
return OutputRegexHelper.ContainsMatches(candidate,string,matchCase,showRegexMatch,_type);
85
} else {
86
if (!matchCase) {
87
string = string.toLowerCase();
88
candidate = candidate.toLowerCase();
89
}
90
boolean retval = (candidate.indexOf(string) >= 0);
91
if( retval && showRegexMatch) {
92
System.out.println("\tMatch ("+_type+"): "+candidate);
93
}
94
return retval;
95
}
96
}
97
98
public String toString() {
99
return "Output match: " + TestSuite.evaluateVariables( _output );
100
}
101
}
102
103