@@ -47,15 +47,15 @@ source product.
47
47
48
48
namespace iText . IO . Util {
49
49
public class GhostscriptHelperTest : ExtendedITextTest {
50
- private static readonly String sourceFolder = iText . Test . TestUtil . GetParentProjectDirectory ( NUnit . Framework . TestContext
50
+ private static readonly String SOURCE_FOLDER = iText . Test . TestUtil . GetParentProjectDirectory ( NUnit . Framework . TestContext
51
51
. CurrentContext . TestDirectory ) + "/resources/itext/io/util/GhostscriptHelperTest/" ;
52
52
53
- private static readonly String destinationFolder = NUnit . Framework . TestContext . CurrentContext . TestDirectory
53
+ private static readonly String DESTINATION_FOLDER = NUnit . Framework . TestContext . CurrentContext . TestDirectory
54
54
+ "/test/itext/io/GhostscriptHelperTest/" ;
55
55
56
56
[ NUnit . Framework . SetUp ]
57
57
public virtual void SetUp ( ) {
58
- CreateOrClearDestinationFolder ( destinationFolder ) ;
58
+ CreateOrClearDestinationFolder ( DESTINATION_FOLDER ) ;
59
59
}
60
60
61
61
[ NUnit . Framework . Test ]
@@ -88,7 +88,7 @@ public virtual void GhostScriptEnvVarIsIncorrect() {
88
88
89
89
[ NUnit . Framework . Test ]
90
90
public virtual void RunGhostScriptIncorrectOutputDirectory ( ) {
91
- String inputPdf = sourceFolder + "imageHandlerUtilTest.pdf" ;
91
+ String inputPdf = SOURCE_FOLDER + "imageHandlerUtilTest.pdf" ;
92
92
String exceptionMessage = "Cannot open output directory for " + inputPdf ;
93
93
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ( ) ;
94
94
Exception e = NUnit . Framework . Assert . Catch ( typeof ( ArgumentException ) , ( ) => ghostscriptHelper . RunGhostScriptImageGeneration
@@ -98,61 +98,61 @@ public virtual void RunGhostScriptIncorrectOutputDirectory() {
98
98
99
99
[ NUnit . Framework . Test ]
100
100
public virtual void RunGhostScriptIncorrectParams ( ) {
101
- String inputPdf = sourceFolder + "imageHandlerUtilTest.pdf" ;
101
+ String inputPdf = SOURCE_FOLDER + "imageHandlerUtilTest.pdf" ;
102
102
String exceptionMessage = "GhostScript failed for " + inputPdf ;
103
103
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ( ) ;
104
104
Exception e = NUnit . Framework . Assert . Catch ( typeof ( GhostscriptHelper . GhostscriptExecutionException ) , ( ) =>
105
- ghostscriptHelper . RunGhostScriptImageGeneration ( inputPdf , destinationFolder , "outputPageImage.png" , "q@W"
105
+ ghostscriptHelper . RunGhostScriptImageGeneration ( inputPdf , DESTINATION_FOLDER , "outputPageImage.png" , "q@W"
106
106
) ) ;
107
107
NUnit . Framework . Assert . AreEqual ( exceptionMessage , e . Message ) ;
108
108
}
109
109
110
110
[ NUnit . Framework . Test ]
111
111
public virtual void RunGhostScriptTestForSpecificPage ( ) {
112
- String inputPdf = sourceFolder + "imageHandlerUtilTest.pdf" ;
112
+ String inputPdf = SOURCE_FOLDER + "imageHandlerUtilTest.pdf" ;
113
113
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ( ) ;
114
- ghostscriptHelper . RunGhostScriptImageGeneration ( inputPdf , destinationFolder , "specificPage.png" , "1" ) ;
115
- NUnit . Framework . Assert . AreEqual ( 1 , FileUtil . ListFilesInDirectory ( destinationFolder , true ) . Length ) ;
116
- NUnit . Framework . Assert . IsTrue ( FileUtil . FileExists ( destinationFolder + "specificPage.png" ) ) ;
114
+ ghostscriptHelper . RunGhostScriptImageGeneration ( inputPdf , DESTINATION_FOLDER , "specificPage.png" , "1" ) ;
115
+ NUnit . Framework . Assert . AreEqual ( 1 , FileUtil . ListFilesInDirectory ( DESTINATION_FOLDER , true ) . Length ) ;
116
+ NUnit . Framework . Assert . IsTrue ( FileUtil . FileExists ( DESTINATION_FOLDER + "specificPage.png" ) ) ;
117
117
}
118
118
119
119
[ NUnit . Framework . Test ]
120
120
public virtual void RunGhostScriptTestForSeveralSpecificPages ( ) {
121
- String inputPdf = sourceFolder + "imageHandlerUtilTest.pdf" ;
121
+ String inputPdf = SOURCE_FOLDER + "imageHandlerUtilTest.pdf" ;
122
122
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ( ) ;
123
123
String imageFileName = new FileInfo ( inputPdf ) . Name + "_severalSpecificPages-%03d.png" ;
124
- ghostscriptHelper . RunGhostScriptImageGeneration ( inputPdf , destinationFolder , imageFileName , "1,3" ) ;
125
- NUnit . Framework . Assert . AreEqual ( 2 , FileUtil . ListFilesInDirectory ( destinationFolder , true ) . Length ) ;
126
- NUnit . Framework . Assert . IsTrue ( FileUtil . FileExists ( destinationFolder + "imageHandlerUtilTest.pdf_severalSpecificPages-001.png"
124
+ ghostscriptHelper . RunGhostScriptImageGeneration ( inputPdf , DESTINATION_FOLDER , imageFileName , "1,3" ) ;
125
+ NUnit . Framework . Assert . AreEqual ( 2 , FileUtil . ListFilesInDirectory ( DESTINATION_FOLDER , true ) . Length ) ;
126
+ NUnit . Framework . Assert . IsTrue ( FileUtil . FileExists ( DESTINATION_FOLDER + "imageHandlerUtilTest.pdf_severalSpecificPages-001.png"
127
127
) ) ;
128
- NUnit . Framework . Assert . IsTrue ( FileUtil . FileExists ( destinationFolder + "imageHandlerUtilTest.pdf_severalSpecificPages-002.png"
128
+ NUnit . Framework . Assert . IsTrue ( FileUtil . FileExists ( DESTINATION_FOLDER + "imageHandlerUtilTest.pdf_severalSpecificPages-002.png"
129
129
) ) ;
130
130
}
131
131
132
132
[ NUnit . Framework . Test ]
133
133
public virtual void RunGhostScriptTestForAllPages ( ) {
134
- String inputPdf = sourceFolder + "imageHandlerUtilTest.pdf" ;
134
+ String inputPdf = SOURCE_FOLDER + "imageHandlerUtilTest.pdf" ;
135
135
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ( ) ;
136
136
String imageFileName = new FileInfo ( inputPdf ) . Name + "_allPages-%03d.png" ;
137
- ghostscriptHelper . RunGhostScriptImageGeneration ( inputPdf , destinationFolder , imageFileName ) ;
138
- NUnit . Framework . Assert . AreEqual ( 3 , FileUtil . ListFilesInDirectory ( destinationFolder , true ) . Length ) ;
139
- NUnit . Framework . Assert . IsTrue ( FileUtil . FileExists ( destinationFolder + "imageHandlerUtilTest.pdf_allPages-001.png"
137
+ ghostscriptHelper . RunGhostScriptImageGeneration ( inputPdf , DESTINATION_FOLDER , imageFileName ) ;
138
+ NUnit . Framework . Assert . AreEqual ( 3 , FileUtil . ListFilesInDirectory ( DESTINATION_FOLDER , true ) . Length ) ;
139
+ NUnit . Framework . Assert . IsTrue ( FileUtil . FileExists ( DESTINATION_FOLDER + "imageHandlerUtilTest.pdf_allPages-001.png"
140
140
) ) ;
141
- NUnit . Framework . Assert . IsTrue ( FileUtil . FileExists ( destinationFolder + "imageHandlerUtilTest.pdf_allPages-002.png"
141
+ NUnit . Framework . Assert . IsTrue ( FileUtil . FileExists ( DESTINATION_FOLDER + "imageHandlerUtilTest.pdf_allPages-002.png"
142
142
) ) ;
143
- NUnit . Framework . Assert . IsTrue ( FileUtil . FileExists ( destinationFolder + "imageHandlerUtilTest.pdf_allPages-003.png"
143
+ NUnit . Framework . Assert . IsTrue ( FileUtil . FileExists ( DESTINATION_FOLDER + "imageHandlerUtilTest.pdf_allPages-003.png"
144
144
) ) ;
145
145
}
146
146
147
147
[ NUnit . Framework . Test ]
148
148
public virtual void DSaferParamInGhostScriptHelperTest ( ) {
149
- String input = sourceFolder + "unsafePostScript.ps" ;
149
+ String input = SOURCE_FOLDER + "unsafePostScript.ps" ;
150
150
String outputName = "unsafePostScript.png" ;
151
- String maliciousResult1 = destinationFolder + "output1.txt" ;
152
- String maliciousResult2 = destinationFolder + "output2.txt" ;
151
+ String maliciousResult1 = DESTINATION_FOLDER + "output1.txt" ;
152
+ String maliciousResult2 = DESTINATION_FOLDER + "output2.txt" ;
153
153
try {
154
154
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ( ) ;
155
- ghostscriptHelper . RunGhostScriptImageGeneration ( input , destinationFolder , outputName ) ;
155
+ ghostscriptHelper . RunGhostScriptImageGeneration ( input , DESTINATION_FOLDER , outputName ) ;
156
156
}
157
157
catch ( GhostscriptHelper . GhostscriptExecutionException ) {
158
158
System . Console . Out . WriteLine ( "Error code was returned on processing of malicious script with -dSAFER option enabled. "
@@ -166,12 +166,12 @@ public virtual void DSaferParamInGhostScriptHelperTest() {
166
166
[ NUnit . Framework . Test ]
167
167
public virtual void GhostScriptImageGenerationTest ( ) {
168
168
String filename = "resultantImage.png" ;
169
- String psFile = sourceFolder + "simple.ps" ;
170
- String resultantImage = destinationFolder + filename ;
171
- String cmpResultantImage = sourceFolder + "cmp_" + filename ;
172
- String diff = destinationFolder + "diff_" + filename ;
169
+ String psFile = SOURCE_FOLDER + "simple.ps" ;
170
+ String resultantImage = DESTINATION_FOLDER + filename ;
171
+ String cmpResultantImage = SOURCE_FOLDER + "cmp_" + filename ;
172
+ String diff = DESTINATION_FOLDER + "diff_" + filename ;
173
173
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ( ) ;
174
- ghostscriptHelper . RunGhostScriptImageGeneration ( psFile , destinationFolder , filename ) ;
174
+ ghostscriptHelper . RunGhostScriptImageGeneration ( psFile , DESTINATION_FOLDER , filename ) ;
175
175
NUnit . Framework . Assert . IsTrue ( FileUtil . FileExists ( resultantImage ) ) ;
176
176
ImageMagickHelper imageMagickHelper = new ImageMagickHelper ( ) ;
177
177
NUnit . Framework . Assert . IsTrue ( imageMagickHelper . RunImageMagickImageCompare ( resultantImage , cmpResultantImage
0 commit comments