Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/AbstractGoldChecker.java
40948 views
1
/*
2
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
package nsk.share;
24
import java.io.UnsupportedEncodingException;
25
26
public abstract class AbstractGoldChecker {
27
28
private final StringBuffer sb = new StringBuffer();
29
30
protected abstract String getGoldenString();
31
32
public void print(boolean b) {
33
sb.append(String.valueOf(b));
34
}
35
36
public void print(byte b) {
37
sb.append(String.valueOf(b));
38
}
39
40
public void print(char c) {
41
sb.append(String.valueOf(c));
42
}
43
44
public void print(int i) {
45
sb.append(String.valueOf(i));
46
}
47
48
public void print(long l) {
49
sb.append(String.valueOf(l));
50
}
51
52
public void print(float f) {
53
sb.append(String.valueOf(f));
54
}
55
56
public void print(double d) {
57
sb.append(String.valueOf(d));
58
}
59
60
public void print(String s) {
61
sb.append(s);
62
}
63
64
public void println() {
65
sb.append('\n');
66
}
67
68
public void println(boolean b) {
69
sb.append(String.valueOf(b));
70
sb.append('\n');
71
}
72
73
public void println(byte b) {
74
sb.append(String.valueOf(b));
75
sb.append('\n');
76
}
77
78
public void println(char c) {
79
sb.append(String.valueOf(c));
80
sb.append('\n');
81
}
82
83
public void println(int i) {
84
sb.append(String.valueOf(i));
85
sb.append('\n');
86
}
87
88
public void println(long l) {
89
sb.append(String.valueOf(l));
90
sb.append('\n');
91
}
92
93
public void println(float f) {
94
sb.append(String.valueOf(f));
95
sb.append('\n');
96
}
97
98
public void println(double d) {
99
sb.append(String.valueOf(d));
100
sb.append('\n');
101
}
102
103
public void println(String s) {
104
sb.append(s);
105
sb.append('\n');
106
}
107
108
public void check() {
109
String testOutput;
110
try {
111
testOutput = new String(sb.toString().getBytes("US-ASCII"), "US-ASCII");
112
} catch (UnsupportedEncodingException e) {
113
throw new TestFailure(e);
114
}
115
116
String goldOutput = getGoldenString();
117
if (!compare(testOutput, goldOutput)) {
118
throw new TestFailure(
119
"Gold comparison failed\n" +
120
"\n" +
121
"Test output:\n" +
122
"============\n" +
123
"\n" +
124
testOutput +
125
"\n" +
126
"------------\n" +
127
"\n" +
128
"Gold output:\n" +
129
"============\n" +
130
"\n" +
131
goldOutput +
132
"\n" +
133
"------------\n" +
134
"\n"
135
);
136
}
137
}
138
139
public boolean compare(String src, String dst) {
140
int i1 = 0;
141
int i2 = 0;
142
143
int src_len = src.length();
144
int dst_len = dst.length();
145
146
while ((i1 < src_len) && (i2 < dst_len)) {
147
148
char c1 = src.charAt(i1++);
149
if ((c1 == '\r') && (i1 < src_len)) {
150
c1 = src.charAt(i1++);
151
}
152
153
char c2 = dst.charAt(i2++);
154
if ((c2 == '\r') && (i2 < dst_len)) {
155
c2 = dst.charAt(i2++);
156
}
157
158
if (c1 != c2) {
159
return false;
160
}
161
}
162
return (i1 == src_len) && (i2 == dst_len);
163
}
164
}
165
166