Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/AbstractGoldChecker.java
40948 views
/*1* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package nsk.share;23import java.io.UnsupportedEncodingException;2425public abstract class AbstractGoldChecker {2627private final StringBuffer sb = new StringBuffer();2829protected abstract String getGoldenString();3031public void print(boolean b) {32sb.append(String.valueOf(b));33}3435public void print(byte b) {36sb.append(String.valueOf(b));37}3839public void print(char c) {40sb.append(String.valueOf(c));41}4243public void print(int i) {44sb.append(String.valueOf(i));45}4647public void print(long l) {48sb.append(String.valueOf(l));49}5051public void print(float f) {52sb.append(String.valueOf(f));53}5455public void print(double d) {56sb.append(String.valueOf(d));57}5859public void print(String s) {60sb.append(s);61}6263public void println() {64sb.append('\n');65}6667public void println(boolean b) {68sb.append(String.valueOf(b));69sb.append('\n');70}7172public void println(byte b) {73sb.append(String.valueOf(b));74sb.append('\n');75}7677public void println(char c) {78sb.append(String.valueOf(c));79sb.append('\n');80}8182public void println(int i) {83sb.append(String.valueOf(i));84sb.append('\n');85}8687public void println(long l) {88sb.append(String.valueOf(l));89sb.append('\n');90}9192public void println(float f) {93sb.append(String.valueOf(f));94sb.append('\n');95}9697public void println(double d) {98sb.append(String.valueOf(d));99sb.append('\n');100}101102public void println(String s) {103sb.append(s);104sb.append('\n');105}106107public void check() {108String testOutput;109try {110testOutput = new String(sb.toString().getBytes("US-ASCII"), "US-ASCII");111} catch (UnsupportedEncodingException e) {112throw new TestFailure(e);113}114115String goldOutput = getGoldenString();116if (!compare(testOutput, goldOutput)) {117throw new TestFailure(118"Gold comparison failed\n" +119"\n" +120"Test output:\n" +121"============\n" +122"\n" +123testOutput +124"\n" +125"------------\n" +126"\n" +127"Gold output:\n" +128"============\n" +129"\n" +130goldOutput +131"\n" +132"------------\n" +133"\n"134);135}136}137138public boolean compare(String src, String dst) {139int i1 = 0;140int i2 = 0;141142int src_len = src.length();143int dst_len = dst.length();144145while ((i1 < src_len) && (i2 < dst_len)) {146147char c1 = src.charAt(i1++);148if ((c1 == '\r') && (i1 < src_len)) {149c1 = src.charAt(i1++);150}151152char c2 = dst.charAt(i2++);153if ((c2 == '\r') && (i2 < dst_len)) {154c2 = dst.charAt(i2++);155}156157if (c1 != c2) {158return false;159}160}161return (i1 == src_len) && (i2 == dst_len);162}163}164165166