@@ -38,11 +38,19 @@ You should have received a copy of the GNU Affero General Public License
38
38
namespace iText . Pdfocr . Onnxtr . Actions {
39
39
[ NUnit . Framework . Category ( "IntegrationTest" ) ]
40
40
public class OnnxTrEventHandlingTest : IntegrationEventHandlingTestHelper {
41
+ private static readonly String DESTINATION_FOLDER = NUnit . Framework . TestContext . CurrentContext . TestDirectory
42
+ + "/test/itext/pdfocr/onnxtr/actions/OnnxTrEventHandlingTest" ;
43
+
44
+ [ NUnit . Framework . OneTimeSetUp ]
45
+ public static void BeforeTests ( ) {
46
+ CreateOrClearDestinationFolder ( DESTINATION_FOLDER ) ;
47
+ }
48
+
41
49
// Section with OcrPdfCreator#createPdfFile related tests
42
50
[ NUnit . Framework . Test ]
43
51
public virtual void OcrPdfCreatorCreatePdfFileTest ( ) {
44
52
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "numbers_01.jpg" ) ;
45
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , " .pdf") ;
53
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + "ocrPdfCreatorCreatePdfFile .pdf") ;
46
54
new OcrPdfCreator ( OCR_ENGINE ) . CreatePdfFile ( JavaCollectionsUtil . SingletonList ( imgFile ) , outPdfFile ) ;
47
55
// check ocr events
48
56
NUnit . Framework . Assert . AreEqual ( 2 , eventsHandler . GetEvents ( ) . Count ) ;
@@ -60,7 +68,7 @@ public virtual void OcrPdfCreatorCreatePdfFileTest() {
60
68
public virtual void OcrPdfCreatorCreatePdfFileNoImageTest ( ) {
61
69
FileInfo imgFile = new FileInfo ( "unknown" ) ;
62
70
IList < FileInfo > images = JavaCollectionsUtil . SingletonList ( imgFile ) ;
63
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , " .pdf") ;
71
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + "ocrPdfCreatorCreatePdfFileNoImage .pdf") ;
64
72
OcrPdfCreator ocrPdfCreator = new OcrPdfCreator ( OCR_ENGINE ) ;
65
73
NUnit . Framework . Assert . Catch ( typeof ( PdfOcrException ) , ( ) => ocrPdfCreator . CreatePdfFile ( images , outPdfFile
66
74
) ) ;
@@ -94,7 +102,7 @@ public virtual void OcrPdfCreatorCreatePdfFileNullOutputFileTest() {
94
102
[ NUnit . Framework . Test ]
95
103
public virtual void OcrPdfCreatorCreatePdfFileTwoImagesTest ( ) {
96
104
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "numbers_01.jpg" ) ;
97
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , " .pdf") ;
105
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + "ocrPdfCreatorCreatePdfFileTwoImages .pdf") ;
98
106
new OcrPdfCreator ( OCR_ENGINE ) . CreatePdfFile ( JavaUtil . ArraysAsList ( imgFile , imgFile ) , outPdfFile ) ;
99
107
// check ocr events
100
108
NUnit . Framework . Assert . AreEqual ( 4 , eventsHandler . GetEvents ( ) . Count ) ;
@@ -113,7 +121,7 @@ public virtual void OcrPdfCreatorCreatePdfFileTwoImagesTest() {
113
121
[ NUnit . Framework . Test ]
114
122
public virtual void OcrPdfCreatorCreatePdfFileTwoRunningsTest ( ) {
115
123
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "numbers_01.jpg" ) ;
116
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , ".pdf ") ;
124
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + "ocrPdfCreatorCreatePdfFileTwoRunnings ") ;
117
125
new OcrPdfCreator ( OCR_ENGINE ) . CreatePdfFile ( JavaCollectionsUtil . SingletonList ( imgFile ) , outPdfFile ) ;
118
126
new OcrPdfCreator ( OCR_ENGINE ) . CreatePdfFile ( JavaCollectionsUtil . SingletonList ( imgFile ) , outPdfFile ) ;
119
127
NUnit . Framework . Assert . AreEqual ( 4 , eventsHandler . GetEvents ( ) . Count ) ;
@@ -135,7 +143,7 @@ public virtual void OcrPdfCreatorCreatePdfFileTwoRunningsTest() {
135
143
[ NUnit . Framework . Test ]
136
144
public virtual void OcrPdfCreatorCreatePdfTest ( ) {
137
145
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "numbers_01.jpg" ) ;
138
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , " .pdf") ;
146
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + "ocrPdfCreatorCreatePdf .pdf") ;
139
147
PdfWriter pdfWriter = new PdfWriter ( outPdfFile ) ;
140
148
PdfDocument pdfDocument = new OcrPdfCreator ( OCR_ENGINE ) . CreatePdf ( JavaCollectionsUtil . SingletonList ( imgFile
141
149
) , pdfWriter ) ;
@@ -155,7 +163,7 @@ public virtual void OcrPdfCreatorCreatePdfTest() {
155
163
[ LogMessage ( PdfOcrLogMessageConstant . CANNOT_READ_INPUT_IMAGE , LogLevel = LogLevelConstants . ERROR ) ]
156
164
public virtual void OcrPdfCreatorCreatePdfNoImageTest ( ) {
157
165
IList < FileInfo > images = JavaCollectionsUtil . SingletonList ( new FileInfo ( "no_image" ) ) ;
158
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , " .pdf") ;
166
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + "ocrPdfCreatorCreatePdfNoImage .pdf") ;
159
167
PdfWriter pdfWriter = new PdfWriter ( outPdfFile ) ;
160
168
OcrPdfCreator ocrPdfCreator = new OcrPdfCreator ( OCR_ENGINE ) ;
161
169
NUnit . Framework . Assert . Catch ( typeof ( PdfOcrInputException ) , ( ) => ocrPdfCreator . CreatePdf ( images , pdfWriter
@@ -178,7 +186,7 @@ public virtual void OcrPdfCreatorCreatePdfNullWriterTest() {
178
186
[ NUnit . Framework . Test ]
179
187
public virtual void OcrPdfCreatorCreatePdfAFileTest ( ) {
180
188
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "numbers_01.jpg" ) ;
181
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , " .pdf") ;
189
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + "ocrPdfCreatorCreatePdfAFile .pdf") ;
182
190
OcrPdfCreatorProperties props = new OcrPdfCreatorProperties ( ) . SetPdfLang ( "en-US" ) ;
183
191
new OcrPdfCreator ( OCR_ENGINE , props ) . CreatePdfAFile ( JavaCollectionsUtil . SingletonList ( imgFile ) , outPdfFile
184
192
, GetRGBPdfOutputIntent ( ) ) ;
@@ -197,7 +205,7 @@ public virtual void OcrPdfCreatorCreatePdfAFileTest() {
197
205
[ NUnit . Framework . Test ]
198
206
public virtual void OcrPdfCreatorCreatePdfATest ( ) {
199
207
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "numbers_01.jpg" ) ;
200
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , " .pdf") ;
208
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + "ocrPdfCreatorCreatePdfA .pdf") ;
201
209
PdfWriter pdfWriter = new PdfWriter ( outPdfFile ) ;
202
210
OcrPdfCreatorProperties props = new OcrPdfCreatorProperties ( ) . SetPdfLang ( "en-US" ) ;
203
211
PdfDocument pdfDocument = new OcrPdfCreator ( OCR_ENGINE , props ) . CreatePdfA ( JavaCollectionsUtil . SingletonList
@@ -256,7 +264,8 @@ public virtual void DoImageOcrTwoRunningsTest() {
256
264
[ NUnit . Framework . Test ]
257
265
public virtual void CreateTxtFileTwoImagesTest ( ) {
258
266
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "numbers_01.jpg" ) ;
259
- OCR_ENGINE . CreateTxtFile ( JavaUtil . ArraysAsList ( imgFile , imgFile ) , FileUtil . CreateTempFile ( "test" , ".txt" ) ) ;
267
+ OCR_ENGINE . CreateTxtFile ( JavaUtil . ArraysAsList ( imgFile , imgFile ) , new FileInfo ( DESTINATION_FOLDER + "createTxtFileTwoImages.txt"
268
+ ) ) ;
260
269
NUnit . Framework . Assert . AreEqual ( 4 , eventsHandler . GetEvents ( ) . Count ) ;
261
270
IEvent usageEvent1 = eventsHandler . GetEvents ( ) [ 0 ] ;
262
271
ValidateUsageEvent ( usageEvent1 , EventConfirmationType . ON_DEMAND ) ;
@@ -271,8 +280,8 @@ public virtual void CreateTxtFileTwoImagesTest() {
271
280
[ NUnit . Framework . Test ]
272
281
public virtual void CreateTxtFileNullEventHelperTest ( ) {
273
282
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "numbers_01.jpg" ) ;
274
- OCR_ENGINE . CreateTxtFile ( JavaUtil . ArraysAsList ( imgFile , imgFile ) , FileUtil . CreateTempFile ( "test" , " .txt") ,
275
- new OcrProcessContext ( null ) ) ;
283
+ OCR_ENGINE . CreateTxtFile ( JavaUtil . ArraysAsList ( imgFile , imgFile ) , new FileInfo ( DESTINATION_FOLDER + "createTxtFileNullEventHelper .txt"
284
+ ) , new OcrProcessContext ( null ) ) ;
276
285
NUnit . Framework . Assert . AreEqual ( 4 , eventsHandler . GetEvents ( ) . Count ) ;
277
286
IEvent usageEvent1 = eventsHandler . GetEvents ( ) [ 0 ] ;
278
287
ValidateUsageEvent ( usageEvent1 , EventConfirmationType . ON_DEMAND ) ;
@@ -289,7 +298,7 @@ public virtual void CreateTxtFileNullEventHelperTest() {
289
298
public virtual void CreateTxtFileNoImageTest ( ) {
290
299
FileInfo imgFile = new FileInfo ( "no_image" ) ;
291
300
IList < FileInfo > images = JavaUtil . ArraysAsList ( imgFile , imgFile ) ;
292
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , ".txt ") ;
301
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + " createTxtFileNoImage.pdf ") ;
293
302
NUnit . Framework . Assert . Catch ( typeof ( PdfOcrException ) , ( ) => OCR_ENGINE . CreateTxtFile ( images , outPdfFile ) ) ;
294
303
NUnit . Framework . Assert . AreEqual ( 0 , eventsHandler . GetEvents ( ) . Count ) ;
295
304
}
@@ -334,7 +343,7 @@ public virtual void CreateTxtFileNullOutFileTest() {
334
343
[ NUnit . Framework . Test ]
335
344
public virtual void SetEventCountingMetaInfoTest ( ) {
336
345
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "numbers_01.jpg" ) ;
337
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , " .pdf") ;
346
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + "setEventCountingMetaInfo .pdf") ;
338
347
CreatePdfAndSetEventCountingMetaInfo ( OCR_ENGINE , outPdfFile , imgFile , new TestMetaInfo ( ) ) ;
339
348
// TestMetaInfo from com.itextpdf.pdfocr package which isn't
340
349
// registered in ContextManager, it's why core events are passed
@@ -352,7 +361,7 @@ public virtual void SetEventCountingMetaInfoTest() {
352
361
[ NUnit . Framework . Test ]
353
362
public virtual void SetEventCountingOnnxTrMetaInfoTest ( ) {
354
363
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "numbers_01.jpg" ) ;
355
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , " .pdf") ;
364
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + " setEventCountingOnnxTrMetaInfo .pdf") ;
356
365
CreatePdfAndSetEventCountingMetaInfo ( OCR_ENGINE , outPdfFile , imgFile , new OnnxTrEventHandlingTest . TestOnnxTrMetaInfo
357
366
( ) ) ;
358
367
// TestOnnxTrMetaInfo from com.itextpdf.pdfocr.onnxtr package which
@@ -369,7 +378,7 @@ public virtual void SetEventCountingOnnxTrMetaInfoTest() {
369
378
[ NUnit . Framework . Test ]
370
379
public virtual void CreatePdfFileTestMetaInfoTest ( ) {
371
380
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "numbers_01.jpg" ) ;
372
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , " .pdf") ;
381
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + "createPdfFileTestMetaInfo .pdf") ;
373
382
CreatePdfFileAndSetMetaInfoToProps ( OCR_ENGINE , outPdfFile , imgFile , new TestMetaInfo ( ) ) ;
374
383
// TestMetaInfo from com.itextpdf.pdfocr package which isn't
375
384
// registered in ContextManager, it's why core events are passed
@@ -388,7 +397,7 @@ public virtual void CreatePdfFileTestMetaInfoTest() {
388
397
[ NUnit . Framework . Test ]
389
398
public virtual void CreatePdfFileTestOnnxTrMetaInfoTest ( ) {
390
399
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "numbers_01.jpg" ) ;
391
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , " .pdf") ;
400
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + "createPdfFileTestOnnxTrMetaInfo .pdf") ;
392
401
CreatePdfFileAndSetMetaInfoToProps ( OCR_ENGINE , outPdfFile , imgFile , new OnnxTrEventHandlingTest . TestOnnxTrMetaInfo
393
402
( ) ) ;
394
403
// TestOnnxTrMetaInfo from com.itextpdf.pdfocr.onnxtr package which
@@ -418,8 +427,8 @@ public virtual void DoImageOcrCustomEventHelperTest() {
418
427
[ NUnit . Framework . Test ]
419
428
public virtual void CreateTxtFileCustomEventHelperTest ( ) {
420
429
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "numbers_01.jpg" ) ;
421
- OCR_ENGINE . CreateTxtFile ( JavaUtil . ArraysAsList ( imgFile , imgFile ) , FileUtil . CreateTempFile ( "test" , " .txt") ,
422
- new OcrProcessContext ( new OnnxTrEventHandlingTest . CustomEventHelper ( ) ) ) ;
430
+ OCR_ENGINE . CreateTxtFile ( JavaUtil . ArraysAsList ( imgFile , imgFile ) , new FileInfo ( DESTINATION_FOLDER + "createTxtFileCustomEventHelper .txt"
431
+ ) , new OcrProcessContext ( new OnnxTrEventHandlingTest . CustomEventHelper ( ) ) ) ;
423
432
NUnit . Framework . Assert . AreEqual ( 4 , eventsHandler . GetEvents ( ) . Count ) ;
424
433
IEvent usageEvent1 = eventsHandler . GetEvents ( ) [ 0 ] ;
425
434
ValidateUsageEvent ( usageEvent1 , EventConfirmationType . ON_DEMAND ) ;
@@ -435,7 +444,7 @@ public virtual void CreateTxtFileCustomEventHelperTest() {
435
444
[ NUnit . Framework . Test ]
436
445
public virtual void OcrPdfCreatorCreatePdfFileMultipageTiffTest ( ) {
437
446
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "two_pages.tiff" ) ;
438
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , " .pdf") ;
447
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + "ocrPdfCreatorCreatePdfFileMultipageTiff .pdf") ;
439
448
new OcrPdfCreator ( OCR_ENGINE ) . CreatePdfFile ( JavaCollectionsUtil . SingletonList ( imgFile ) , outPdfFile ) ;
440
449
// check ocr events
441
450
// 2 pages in TIFF image
@@ -454,7 +463,8 @@ public virtual void OcrPdfCreatorCreatePdfFileMultipageTiffTest() {
454
463
[ NUnit . Framework . Test ]
455
464
public virtual void CreateTxtFileMultipageTiffTest ( ) {
456
465
FileInfo imgFile = new FileInfo ( TEST_IMAGE_DIRECTORY + "two_pages.tiff" ) ;
457
- OCR_ENGINE . CreateTxtFile ( JavaUtil . ArraysAsList ( imgFile ) , FileUtil . CreateTempFile ( "test" , ".txt" ) ) ;
466
+ OCR_ENGINE . CreateTxtFile ( JavaUtil . ArraysAsList ( imgFile ) , new FileInfo ( DESTINATION_FOLDER + "createTxtFileMultipageTiff.txt"
467
+ ) ) ;
458
468
// 2 pages in TIFF image
459
469
NUnit . Framework . Assert . AreEqual ( 4 , eventsHandler . GetEvents ( ) . Count ) ;
460
470
for ( int i = 0 ; i < 2 ; i ++ ) {
@@ -482,7 +492,7 @@ public virtual void DoImageOcrMultipageTiffTest() {
482
492
[ NUnit . Framework . Test ]
483
493
public virtual void OcrPdfCreatorMakeSearchableTest ( ) {
484
494
FileInfo inPdfFile = new FileInfo ( TEST_PDFS_DIRECTORY + "2pages.pdf" ) ;
485
- FileInfo outPdfFile = FileUtil . CreateTempFile ( "test" , " .pdf") ;
495
+ FileInfo outPdfFile = new FileInfo ( DESTINATION_FOLDER + "ocrPdfCreatorMakeSearchable .pdf") ;
486
496
try {
487
497
new OcrPdfCreator ( OCR_ENGINE ) . MakePdfSearchable ( inPdfFile , outPdfFile ) ;
488
498
// Check ocr events. No stats events.
0 commit comments