Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8251126: nsk.share.GoldChecker should read golden file from ${test.src}
Reviewed-by: dholmes
  • Loading branch information
iignatev committed Aug 5, 2020
1 parent e635c5f commit 1e5d70b3d5b339cafbbcc5f5d023141803139cc9
Showing 1 changed file with 17 additions and 30 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -20,52 +20,39 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package nsk.share;

import java.io.*;
import jdk.test.lib.Utils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

public class GoldChecker extends AbstractGoldChecker
{
public class GoldChecker extends AbstractGoldChecker {
private final String goldOutput;

public GoldChecker(String main_class_name) {
goldOutput = readGoldStr(main_class_name + ".gold");
public GoldChecker(String mainClassName) {
goldOutput = readGoldStr(Path.of(Utils.TEST_SRC, mainClassName + ".gold"));
}

@Override
protected String getGoldenString() {
return goldOutput;
}

private String readGoldStr(String gold_file_name) {
RandomAccessFile f;

try {
f = new RandomAccessFile(gold_file_name, "r");
} catch (FileNotFoundException e) {
throw new TestBug("Unable to open golden file '" + gold_file_name + "' for reading");
private String readGoldStr(Path goldenFile) {
if (Files.notExists(goldenFile)) {
throw new TestBug("Unable to open golden file '" + goldenFile + "' for reading");
}

byte[] data;

try {
int len = (int)f.length();
data = new byte[len];
f.read(data);
data = Files.readAllBytes(goldenFile);
} catch (IOException e) {
throw new TestBug("Error reading from golden file'" + gold_file_name + "'");
}

try {
f.close();
} catch (IOException e) {
}

try {
return new String(data, "US-ASCII");
} catch (UnsupportedEncodingException e) {
throw new TestFailure( e );
throw new TestBug("Error reading from golden file '" + goldenFile + "'", e);
}
return new String(data, StandardCharsets.US_ASCII);
}

}

0 comments on commit 1e5d70b

Please sign in to comment.