CompareTool { public String compareVisually(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix) throws InterruptedException, IOException { return compareVisually(outPdf, cmpPdf, outPath, differenceImagePrefix, null); } CompareTool();   CompareTool(String gsExec, String compareExec); CompareResult compareByCatalog(PdfDocument outDocument, PdfDocument cmpDocument); CompareTool disableCachedPagesComparison(); CompareTool setCompareByContentErrorsLimit(int compareByContentMaxErrorCount); CompareTool setGenerateCompareByContentXmlReport(boolean generateCompareByContentXmlReport); void setEventCountingMetaInfo(IMetaInfo metaInfo); CompareTool enableEncryptionCompare(); ReaderProperties getOutReaderProperties(); ReaderProperties getCmpReaderProperties(); String compareVisually(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix); String compareVisually(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix, Map<Integer, List<Rectangle>> ignoredAreas); String compareByContent(String outPdf, String cmpPdf, String outPath); String compareByContent(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix); String compareByContent(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix, byte[] outPass, byte[] cmpPass); String compareByContent(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix, Map<Integer, List<Rectangle>> ignoredAreas); String compareByContent(String outPdf, String cmpPdf, String outPath, String differenceImagePrefix, Map<Integer, List<Rectangle>> ignoredAreas, byte[] outPass, byte[] cmpPass); boolean compareDictionaries(PdfDictionary outDict, PdfDictionary cmpDict); CompareResult compareDictionariesStructure(PdfDictionary outDict, PdfDictionary cmpDict); CompareResult compareDictionariesStructure(PdfDictionary outDict, PdfDictionary cmpDict, Set<PdfName> excludedKeys); CompareResult compareStreamsStructure(PdfStream outStream, PdfStream cmpStream); boolean compareStreams(PdfStream outStream, PdfStream cmpStream); boolean compareArrays(PdfArray outArray, PdfArray cmpArray); boolean compareNames(PdfName outName, PdfName cmpName); boolean compareNumbers(PdfNumber outNumber, PdfNumber cmpNumber); boolean compareStrings(PdfString outString, PdfString cmpString); boolean compareBooleans(PdfBoolean outBoolean, PdfBoolean cmpBoolean); String compareXmp(String outPdf, String cmpPdf); String compareXmp(String outPdf, String cmpPdf, boolean ignoreDateAndProducerProperties); boolean compareXmls(byte[] xml1, byte[] xml2); boolean compareXmls(String outXmlFile, String cmpXmlFile); String compareDocumentInfo(String outPdf, String cmpPdf, byte[] outPass, byte[] cmpPass); String compareDocumentInfo(String outPdf, String cmpPdf); String compareLinkAnnotations(String outPdf, String cmpPdf); String compareTagStructures(String outPdf, String cmpPdf);  }
@Test public void gsEnvironmentVariableIsNotSpecifiedExceptionTest() throws IOException, InterruptedException { String outPdf = sourceFolder + "simple_pdf.pdf"; String cmpPdf = sourceFolder + "cmp_simple_pdf.pdf"; new CompareTool(null, null).compareVisually(outPdf, cmpPdf, destinationFolder, "diff_"); Assert.assertTrue(new File(destinationFolder + "diff_1.png").exists()); }
@Test public void gsEnvironmentVariableSpecifiedIncorrectlyTest() throws IOException, InterruptedException { junitExpectedException.expect(CompareTool.CompareToolExecutionException.class); junitExpectedException.expectMessage(IoExceptionMessage.GS_ENVIRONMENT_VARIABLE_IS_NOT_SPECIFIED); String outPdf = sourceFolder + "simple_pdf.pdf"; String cmpPdf = sourceFolder + "cmp_simple_pdf.pdf"; new CompareTool("unspecified", null).compareVisually(outPdf, cmpPdf, destinationFolder, "diff_"); }
@Test public void compareCommandIsNotSpecifiedTest() throws IOException, InterruptedException { String outPdf = sourceFolder + "simple_pdf.pdf"; String cmpPdf = sourceFolder + "cmp_simple_pdf.pdf"; String gsExec = SystemUtil.getPropertyOrEnvironmentVariable(GhostscriptHelper.GHOSTSCRIPT_ENVIRONMENT_VARIABLE); if (gsExec == null) { gsExec = SystemUtil.getPropertyOrEnvironmentVariable("gsExec"); } String result = new CompareTool(gsExec, null) .compareVisually(outPdf, cmpPdf, destinationFolder, "diff_"); Assert.assertFalse(result.contains(IoExceptionMessage.COMPARE_COMMAND_IS_NOT_SPECIFIED)); Assert.assertTrue(new File(destinationFolder + "diff_1.png").exists()); }
@Test @LogMessages(messages = { @LogMessage(messageTemplate = IoExceptionMessage.COMPARE_COMMAND_SPECIFIED_INCORRECTLY)}) public void compareCommandSpecifiedIncorrectlyTest() throws IOException, InterruptedException { String outPdf = sourceFolder + "simple_pdf.pdf"; String cmpPdf = sourceFolder + "cmp_simple_pdf.pdf"; String gsExec = SystemUtil.getPropertyOrEnvironmentVariable(GhostscriptHelper.GHOSTSCRIPT_ENVIRONMENT_VARIABLE); if (gsExec == null) { gsExec = SystemUtil.getPropertyOrEnvironmentVariable("gsExec"); } String result = new CompareTool(gsExec, "unspecified") .compareVisually(outPdf, cmpPdf, destinationFolder, "diff_"); Assert.assertTrue(result.contains(IoExceptionMessage.COMPARE_COMMAND_SPECIFIED_INCORRECTLY)); }
@Test public void compareVisuallyDiffTestTest() throws IOException, InterruptedException { String outPdf = sourceFolder + "compareVisuallyDiffTestTest1.pdf"; String cmpPdf = sourceFolder + "compareVisuallyDiffTestTest2.pdf"; String result = new CompareTool().compareVisually(outPdf, cmpPdf, destinationFolder, "diff_"); System.out.println("\nRESULT:\n" + result); Assert.assertTrue(result.contains("differs on page [1, 2].")); Assert.assertTrue(new File(destinationFolder + "diff_1.png").exists()); Assert.assertTrue(new File(destinationFolder + "diff_2.png").exists()); }