public virtual void GhostScriptEnvVarIsIncorrect()
 {
     NUnit.Framework.Assert.That(() => {
         GhostscriptHelper ghostscriptHelper = new GhostscriptHelper("-");
     }
                                 , NUnit.Framework.Throws.InstanceOf <ArgumentException>().With.Message.EqualTo(IoExceptionMessage.GS_ENVIRONMENT_VARIABLE_IS_NOT_SPECIFIED))
     ;
 }
        public virtual void RunGhostScriptTestForSpecificPage()
        {
            String            inputPdf          = sourceFolder + "imageHandlerUtilTest.pdf";
            GhostscriptHelper ghostscriptHelper = new GhostscriptHelper();

            ghostscriptHelper.RunGhostScriptImageGeneration(inputPdf, destinationFolder, "specificPage.png", "1");
            NUnit.Framework.Assert.AreEqual(1, FileUtil.ListFilesInDirectory(destinationFolder, true).Length);
            NUnit.Framework.Assert.IsTrue(FileUtil.FileExists(destinationFolder + "specificPage.png"));
        }
        public virtual void GhostScriptEnvVarIsExplicitlySpecified()
        {
            String gsExec = SystemUtil.GetEnvironmentVariable(GhostscriptHelper.GHOSTSCRIPT_ENVIRONMENT_VARIABLE);

            if (gsExec == null)
            {
                gsExec = SystemUtil.GetEnvironmentVariable(GhostscriptHelper.GHOSTSCRIPT_ENVIRONMENT_VARIABLE_LEGACY);
            }
            GhostscriptHelper ghostscriptHelper = new GhostscriptHelper(gsExec);

            NUnit.Framework.Assert.IsNotNull(ghostscriptHelper.GetCliExecutionCommand());
        }
        public virtual void RunGhostScriptIncorrectParams()
        {
            String inputPdf         = sourceFolder + "imageHandlerUtilTest.pdf";
            String exceptionMessage = "GhostScript failed for " + inputPdf;

            NUnit.Framework.Assert.That(() => {
                GhostscriptHelper ghostscriptHelper = new GhostscriptHelper();
                ghostscriptHelper.RunGhostScriptImageGeneration(inputPdf, destinationFolder, "outputPageImage.png", "q@W");
            }
                                        , NUnit.Framework.Throws.InstanceOf <GhostscriptHelper.GhostscriptExecutionException>().With.Message.EqualTo(exceptionMessage))
            ;
        }
        public virtual void RunGhostScriptIncorrectOutputDirectory()
        {
            String inputPdf         = sourceFolder + "imageHandlerUtilTest.pdf";
            String exceptionMessage = "Cannot open output directory for " + inputPdf;

            NUnit.Framework.Assert.That(() => {
                GhostscriptHelper ghostscriptHelper = new GhostscriptHelper();
                ghostscriptHelper.RunGhostScriptImageGeneration(inputPdf, "-", "outputPageImage.png", "1");
            }
                                        , NUnit.Framework.Throws.InstanceOf <ArgumentException>().With.Message.EqualTo(exceptionMessage))
            ;
        }
        public virtual void RunGhostScriptTestForSeveralSpecificPages()
        {
            String            inputPdf          = sourceFolder + "imageHandlerUtilTest.pdf";
            GhostscriptHelper ghostscriptHelper = new GhostscriptHelper();
            String            imageFileName     = new FileInfo(inputPdf).Name + "_severalSpecificPages-%03d.png";

            ghostscriptHelper.RunGhostScriptImageGeneration(inputPdf, destinationFolder, imageFileName, "1,3");
            NUnit.Framework.Assert.AreEqual(2, FileUtil.ListFilesInDirectory(destinationFolder, true).Length);
            NUnit.Framework.Assert.IsTrue(FileUtil.FileExists(destinationFolder + "imageHandlerUtilTest.pdf_severalSpecificPages-001.png"
                                                              ));
            NUnit.Framework.Assert.IsTrue(FileUtil.FileExists(destinationFolder + "imageHandlerUtilTest.pdf_severalSpecificPages-002.png"
                                                              ));
        }
Exemplo n.º 7
0
        public virtual void GhostScriptImageGenerationTest()
        {
            String            filename          = "resultantImage.png";
            String            psFile            = sourceFolder + "simple.ps";
            String            resultantImage    = destinationFolder + filename;
            String            cmpResultantImage = sourceFolder + "cmp_" + filename;
            String            diff = destinationFolder + "diff_" + filename;
            GhostscriptHelper ghostscriptHelper = new GhostscriptHelper();

            ghostscriptHelper.RunGhostScriptImageGeneration(psFile, destinationFolder, filename);
            NUnit.Framework.Assert.IsTrue(FileUtil.FileExists(resultantImage));
            ImageMagickHelper imageMagickHelper = new ImageMagickHelper();

            NUnit.Framework.Assert.IsTrue(imageMagickHelper.RunImageMagickImageCompare(resultantImage, cmpResultantImage
                                                                                       , diff));
        }
Exemplo n.º 8
0
        public virtual void DSaferParamInGhostScriptHelperTest()
        {
            String cmpPdf = sourceFolder + "maliciousPsInvokingCalcExe.ps";
            String maliciousPsInvokingCalcExe = destinationFolder + "maliciousPsInvokingCalcExe.png";
            int    majorVersion = 0;
            int    minorVersion = 0;
            bool   isWindows    = IdentifyOsType().ToLowerInvariant().Contains("win");

            if (isWindows)
            {
                String gsExec = SystemUtil.GetEnvironmentVariable(GhostscriptHelper.GHOSTSCRIPT_ENVIRONMENT_VARIABLE);
                if (gsExec == null)
                {
                    gsExec = SystemUtil.GetEnvironmentVariable(GhostscriptHelper.GHOSTSCRIPT_ENVIRONMENT_VARIABLE_LEGACY);
                }
                String[] pathParts = iText.IO.Util.StringUtil.Split(gsExec, "\\d\\.\\d\\d");
                for (int i = 0; i < pathParts.Length; i++)
                {
                    gsExec = gsExec.Replace(pathParts[i], "");
                }
                String[] version = iText.IO.Util.StringUtil.Split(gsExec, "\\.");
                majorVersion = Convert.ToInt32(version[0], System.Globalization.CultureInfo.InvariantCulture);
                minorVersion = Convert.ToInt32(version[1], System.Globalization.CultureInfo.InvariantCulture);
            }
            try {
                GhostscriptHelper ghostscriptHelper = new GhostscriptHelper();
                ghostscriptHelper.RunGhostScriptImageGeneration(cmpPdf, destinationFolder, "maliciousPsInvokingCalcExe.png"
                                                                );
                if (isWindows)
                {
                    NUnit.Framework.Assert.IsTrue((majorVersion > 9 || (majorVersion == 9 && minorVersion >= 50)));
                }
            }
            catch (GhostscriptHelper.GhostscriptExecutionException) {
                if (isWindows)
                {
                    NUnit.Framework.Assert.IsTrue((majorVersion < 9 || (majorVersion == 9 && minorVersion < 50)));
                }
            }
            NUnit.Framework.Assert.IsFalse(FileUtil.FileExists(maliciousPsInvokingCalcExe));
        }
        public virtual void GhostScriptEnvVarIsNull()
        {
            GhostscriptHelper ghostscriptHelper = new GhostscriptHelper(null);

            NUnit.Framework.Assert.IsNotNull(ghostscriptHelper.GetCliExecutionCommand());
        }