Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdLineTests/shareClassTests/utils/src/Utilities/Verifier.java
6005 views
1
/*******************************************************************************
2
* Copyright (c) 2005, 2020 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
package Utilities;
23
24
import java.io.FileInputStream;
25
import java.net.URL;
26
import java.util.Properties;
27
28
import CustomCLs.CustomURLClassLoader;
29
30
/**
31
* @author Matthew Kilner
32
*/
33
public class Verifier {
34
35
StringManipulator manipulator = new StringManipulator();
36
37
public static void main(String[] args) {
38
39
if(args.length != 2){
40
System.out.println("\n Incorrect usage");
41
System.out.println("\n Please specifiy -testfile <filename>");
42
}
43
44
Verifier test = new Verifier();
45
46
String testFile = args[1];
47
48
test.testWrapper(testFile);
49
50
}
51
52
public void testWrapper(String testFileName){
53
54
System.out.println("\n** Running Verifier for properties: "+testFileName+"\n");
55
56
Properties props = new Properties();
57
try{
58
FileInputStream PropertiesFile = new FileInputStream(testFileName);
59
props.load(PropertiesFile);
60
61
PropertiesFile.close();
62
} catch (Exception e){
63
e.printStackTrace();
64
}
65
66
String classPath = props.getProperty("ClassPath");
67
68
String nctls = props.getProperty("NumberOfClassesToVerify");
69
Integer i = Integer.valueOf(nctls);
70
int classesToVerifyCount = i.intValue();
71
72
String[] classesToVerify = new String[classesToVerifyCount];
73
String classesString = props.getProperty("ClassesToVerify");
74
for(int index = 0; index < classesToVerifyCount; index ++){
75
classesToVerify[index] = manipulator.getStringElement(index, classesString);
76
}
77
78
String[] results = new String[classesToVerifyCount];
79
String verifiersResults = props.getProperty("Results");
80
for(int index = 0; index < classesToVerifyCount; index++){
81
results[index] = manipulator.getStringElement(index, verifiersResults);
82
}
83
84
boolean passed = executeTest(classPath, classesToVerify, results);
85
86
if(passed){
87
System.out.println("\nTEST PASSED");
88
} else {
89
System.out.println("\nTEST FAILED");
90
}
91
}
92
93
public boolean executeTest(String classpath, String[] classesToVerify, String[] results){
94
95
System.out.println("\nCreating Verifier.....");
96
URLClassPathCreator vfPathCreator = new URLClassPathCreator(classpath);
97
URL[] vfPath;
98
vfPath = vfPathCreator.createURLClassPath();
99
CustomURLClassLoader verifier = new CustomURLClassLoader(vfPath, this.getClass().getClassLoader());
100
101
System.out.println("\nRunning Verifier.....");
102
boolean result = true;
103
for(int cIndex = 0; cIndex < classesToVerify.length; cIndex++){
104
String className = classesToVerify[cIndex];
105
if(className != null){
106
String expectedResult = results[cIndex];
107
String testResult = String.valueOf(verifier.isClassInSharedCache(className));
108
if(!(expectedResult.equals(testResult))){
109
System.out.println("\nFailure testing class: "+className+" result: "+testResult+" expecting: "+expectedResult);
110
result = false;
111
}
112
}
113
}
114
return result;
115
}
116
}
117
118