Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reliably calculate chart test data location both on Windows and Linux #321

Merged
merged 2 commits into from
Jun 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.HashMap;
import java.util.Map;

import junit.framework.TestCase;
import utility.ImageUtil;
import utility.ImageUtil.ImageCompParam;

/**
* Base chart test case.
Expand All @@ -44,7 +47,7 @@ private static String getOSName( )
}
return "_" + name; //$NON-NLS-1$
}

/*
* (non-Javadoc)
*
Expand Down Expand Up @@ -136,16 +139,16 @@ protected boolean compareBytes( String golden, String output )
String outputFrom = this.genOutputFile( output );
String outputTo = this.getOutputResourceFolder( ) + "/" + this.getFullQualifiedClassName( ) + "/diffOutput/" + output;


File parentOutput = new File( outputTo ).getParentFile( );

if ( parentOutput != null )
{
parentOutput.mkdirs( );
}

this.copyFile( outputFrom, outputTo );

File parentGolden = new File( goldenTo ).getParentFile( );

if ( parentGolden != null )
Expand Down Expand Up @@ -492,12 +495,33 @@ protected final void copyFile( String from, String to ) throws IOException
protected boolean compareImages( String golden, String output )
throws Exception
{
Image result = ImageUtil.compare(golden, output);
String goldenFile =
TEST_FOLDER +
File.separator +
getFullQualifiedClassName( ).replace( '.', '/' ) +
File.separator +
GOLDEN_FOLDER +
File.separator +
golden;

String outputFile =
genOutputFolder() +
File.separator +
output;

Map<ImageCompParam, Integer> params = new HashMap<ImageCompParam, Integer>();
params.put(ImageCompParam.TOLERANCE, 4);

Image result =
ImageUtil.compare(
new File(goldenFile).getAbsolutePath(),
new File(outputFile).getAbsolutePath(),
params);
if(result == null) {
return true;
}
ImageUtil.saveJPG(result, output + ".diff");
ImageUtil.saveJPG(result, new File(outputFile + ".diff").getAbsolutePath());
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public static Image compare(String golden, String actual) throws IOException {
}

public static Image compare(String golden, String actual, Map<ImageCompParam, Integer> params) throws IOException {
if (mergeDefaultCompParams(params).get(ImageCompParam.DEBUG) > 0) {
System.out.print("Golden: " + golden);
System.out.print("Actual: " + actual);
}
return compare(loadImageFromFile(golden), loadImageFromFile(actual), params);
}

Expand Down