Skip to content

Commit a461228

Browse files
Alexandr PliushchouiText-CI
authored andcommitted
Change tests to create results in target folder
DEVSIX-9280 Autoported commit. Original commit hash: [df0bf76]
1 parent 6ff318f commit a461228

File tree

8 files changed

+105
-50
lines changed

8 files changed

+105
-50
lines changed

itext.tests/itext.pdfocr.onnxtr.tests/itext/pdfocr/onnxtr/actions/OnnxTrEventHandlingTest.cs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,19 @@ You should have received a copy of the GNU Affero General Public License
3838
namespace iText.Pdfocr.Onnxtr.Actions {
3939
[NUnit.Framework.Category("IntegrationTest")]
4040
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+
4149
// Section with OcrPdfCreator#createPdfFile related tests
4250
[NUnit.Framework.Test]
4351
public virtual void OcrPdfCreatorCreatePdfFileTest() {
4452
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");
4654
new OcrPdfCreator(OCR_ENGINE).CreatePdfFile(JavaCollectionsUtil.SingletonList(imgFile), outPdfFile);
4755
// check ocr events
4856
NUnit.Framework.Assert.AreEqual(2, eventsHandler.GetEvents().Count);
@@ -60,7 +68,7 @@ public virtual void OcrPdfCreatorCreatePdfFileTest() {
6068
public virtual void OcrPdfCreatorCreatePdfFileNoImageTest() {
6169
FileInfo imgFile = new FileInfo("unknown");
6270
IList<FileInfo> images = JavaCollectionsUtil.SingletonList(imgFile);
63-
FileInfo outPdfFile = FileUtil.CreateTempFile("test", ".pdf");
71+
FileInfo outPdfFile = new FileInfo(DESTINATION_FOLDER + "ocrPdfCreatorCreatePdfFileNoImage.pdf");
6472
OcrPdfCreator ocrPdfCreator = new OcrPdfCreator(OCR_ENGINE);
6573
NUnit.Framework.Assert.Catch(typeof(PdfOcrException), () => ocrPdfCreator.CreatePdfFile(images, outPdfFile
6674
));
@@ -94,7 +102,7 @@ public virtual void OcrPdfCreatorCreatePdfFileNullOutputFileTest() {
94102
[NUnit.Framework.Test]
95103
public virtual void OcrPdfCreatorCreatePdfFileTwoImagesTest() {
96104
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");
98106
new OcrPdfCreator(OCR_ENGINE).CreatePdfFile(JavaUtil.ArraysAsList(imgFile, imgFile), outPdfFile);
99107
// check ocr events
100108
NUnit.Framework.Assert.AreEqual(4, eventsHandler.GetEvents().Count);
@@ -113,7 +121,7 @@ public virtual void OcrPdfCreatorCreatePdfFileTwoImagesTest() {
113121
[NUnit.Framework.Test]
114122
public virtual void OcrPdfCreatorCreatePdfFileTwoRunningsTest() {
115123
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");
117125
new OcrPdfCreator(OCR_ENGINE).CreatePdfFile(JavaCollectionsUtil.SingletonList(imgFile), outPdfFile);
118126
new OcrPdfCreator(OCR_ENGINE).CreatePdfFile(JavaCollectionsUtil.SingletonList(imgFile), outPdfFile);
119127
NUnit.Framework.Assert.AreEqual(4, eventsHandler.GetEvents().Count);
@@ -135,7 +143,7 @@ public virtual void OcrPdfCreatorCreatePdfFileTwoRunningsTest() {
135143
[NUnit.Framework.Test]
136144
public virtual void OcrPdfCreatorCreatePdfTest() {
137145
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");
139147
PdfWriter pdfWriter = new PdfWriter(outPdfFile);
140148
PdfDocument pdfDocument = new OcrPdfCreator(OCR_ENGINE).CreatePdf(JavaCollectionsUtil.SingletonList(imgFile
141149
), pdfWriter);
@@ -155,7 +163,7 @@ public virtual void OcrPdfCreatorCreatePdfTest() {
155163
[LogMessage(PdfOcrLogMessageConstant.CANNOT_READ_INPUT_IMAGE, LogLevel = LogLevelConstants.ERROR)]
156164
public virtual void OcrPdfCreatorCreatePdfNoImageTest() {
157165
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");
159167
PdfWriter pdfWriter = new PdfWriter(outPdfFile);
160168
OcrPdfCreator ocrPdfCreator = new OcrPdfCreator(OCR_ENGINE);
161169
NUnit.Framework.Assert.Catch(typeof(PdfOcrInputException), () => ocrPdfCreator.CreatePdf(images, pdfWriter
@@ -178,7 +186,7 @@ public virtual void OcrPdfCreatorCreatePdfNullWriterTest() {
178186
[NUnit.Framework.Test]
179187
public virtual void OcrPdfCreatorCreatePdfAFileTest() {
180188
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");
182190
OcrPdfCreatorProperties props = new OcrPdfCreatorProperties().SetPdfLang("en-US");
183191
new OcrPdfCreator(OCR_ENGINE, props).CreatePdfAFile(JavaCollectionsUtil.SingletonList(imgFile), outPdfFile
184192
, GetRGBPdfOutputIntent());
@@ -197,7 +205,7 @@ public virtual void OcrPdfCreatorCreatePdfAFileTest() {
197205
[NUnit.Framework.Test]
198206
public virtual void OcrPdfCreatorCreatePdfATest() {
199207
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");
201209
PdfWriter pdfWriter = new PdfWriter(outPdfFile);
202210
OcrPdfCreatorProperties props = new OcrPdfCreatorProperties().SetPdfLang("en-US");
203211
PdfDocument pdfDocument = new OcrPdfCreator(OCR_ENGINE, props).CreatePdfA(JavaCollectionsUtil.SingletonList
@@ -256,7 +264,8 @@ public virtual void DoImageOcrTwoRunningsTest() {
256264
[NUnit.Framework.Test]
257265
public virtual void CreateTxtFileTwoImagesTest() {
258266
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+
));
260269
NUnit.Framework.Assert.AreEqual(4, eventsHandler.GetEvents().Count);
261270
IEvent usageEvent1 = eventsHandler.GetEvents()[0];
262271
ValidateUsageEvent(usageEvent1, EventConfirmationType.ON_DEMAND);
@@ -271,8 +280,8 @@ public virtual void CreateTxtFileTwoImagesTest() {
271280
[NUnit.Framework.Test]
272281
public virtual void CreateTxtFileNullEventHelperTest() {
273282
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));
276285
NUnit.Framework.Assert.AreEqual(4, eventsHandler.GetEvents().Count);
277286
IEvent usageEvent1 = eventsHandler.GetEvents()[0];
278287
ValidateUsageEvent(usageEvent1, EventConfirmationType.ON_DEMAND);
@@ -289,7 +298,7 @@ public virtual void CreateTxtFileNullEventHelperTest() {
289298
public virtual void CreateTxtFileNoImageTest() {
290299
FileInfo imgFile = new FileInfo("no_image");
291300
IList<FileInfo> images = JavaUtil.ArraysAsList(imgFile, imgFile);
292-
FileInfo outPdfFile = FileUtil.CreateTempFile("test", ".txt");
301+
FileInfo outPdfFile = new FileInfo(DESTINATION_FOLDER + " createTxtFileNoImage.pdf");
293302
NUnit.Framework.Assert.Catch(typeof(PdfOcrException), () => OCR_ENGINE.CreateTxtFile(images, outPdfFile));
294303
NUnit.Framework.Assert.AreEqual(0, eventsHandler.GetEvents().Count);
295304
}
@@ -334,7 +343,7 @@ public virtual void CreateTxtFileNullOutFileTest() {
334343
[NUnit.Framework.Test]
335344
public virtual void SetEventCountingMetaInfoTest() {
336345
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");
338347
CreatePdfAndSetEventCountingMetaInfo(OCR_ENGINE, outPdfFile, imgFile, new TestMetaInfo());
339348
// TestMetaInfo from com.itextpdf.pdfocr package which isn't
340349
// registered in ContextManager, it's why core events are passed
@@ -352,7 +361,7 @@ public virtual void SetEventCountingMetaInfoTest() {
352361
[NUnit.Framework.Test]
353362
public virtual void SetEventCountingOnnxTrMetaInfoTest() {
354363
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");
356365
CreatePdfAndSetEventCountingMetaInfo(OCR_ENGINE, outPdfFile, imgFile, new OnnxTrEventHandlingTest.TestOnnxTrMetaInfo
357366
());
358367
// TestOnnxTrMetaInfo from com.itextpdf.pdfocr.onnxtr package which
@@ -369,7 +378,7 @@ public virtual void SetEventCountingOnnxTrMetaInfoTest() {
369378
[NUnit.Framework.Test]
370379
public virtual void CreatePdfFileTestMetaInfoTest() {
371380
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");
373382
CreatePdfFileAndSetMetaInfoToProps(OCR_ENGINE, outPdfFile, imgFile, new TestMetaInfo());
374383
// TestMetaInfo from com.itextpdf.pdfocr package which isn't
375384
// registered in ContextManager, it's why core events are passed
@@ -388,7 +397,7 @@ public virtual void CreatePdfFileTestMetaInfoTest() {
388397
[NUnit.Framework.Test]
389398
public virtual void CreatePdfFileTestOnnxTrMetaInfoTest() {
390399
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");
392401
CreatePdfFileAndSetMetaInfoToProps(OCR_ENGINE, outPdfFile, imgFile, new OnnxTrEventHandlingTest.TestOnnxTrMetaInfo
393402
());
394403
// TestOnnxTrMetaInfo from com.itextpdf.pdfocr.onnxtr package which
@@ -418,8 +427,8 @@ public virtual void DoImageOcrCustomEventHelperTest() {
418427
[NUnit.Framework.Test]
419428
public virtual void CreateTxtFileCustomEventHelperTest() {
420429
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()));
423432
NUnit.Framework.Assert.AreEqual(4, eventsHandler.GetEvents().Count);
424433
IEvent usageEvent1 = eventsHandler.GetEvents()[0];
425434
ValidateUsageEvent(usageEvent1, EventConfirmationType.ON_DEMAND);
@@ -435,7 +444,7 @@ public virtual void CreateTxtFileCustomEventHelperTest() {
435444
[NUnit.Framework.Test]
436445
public virtual void OcrPdfCreatorCreatePdfFileMultipageTiffTest() {
437446
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");
439448
new OcrPdfCreator(OCR_ENGINE).CreatePdfFile(JavaCollectionsUtil.SingletonList(imgFile), outPdfFile);
440449
// check ocr events
441450
// 2 pages in TIFF image
@@ -454,7 +463,8 @@ public virtual void OcrPdfCreatorCreatePdfFileMultipageTiffTest() {
454463
[NUnit.Framework.Test]
455464
public virtual void CreateTxtFileMultipageTiffTest() {
456465
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+
));
458468
// 2 pages in TIFF image
459469
NUnit.Framework.Assert.AreEqual(4, eventsHandler.GetEvents().Count);
460470
for (int i = 0; i < 2; i++) {
@@ -482,7 +492,7 @@ public virtual void DoImageOcrMultipageTiffTest() {
482492
[NUnit.Framework.Test]
483493
public virtual void OcrPdfCreatorMakeSearchableTest() {
484494
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");
486496
try {
487497
new OcrPdfCreator(OCR_ENGINE).MakePdfSearchable(inPdfFile, outPdfFile);
488498
// Check ocr events. No stats events.

itext.tests/itext.pdfocr.tesseract4.tests/itext/pdfocr/actions/Tesseract4EventHandlingExecutableTest.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,22 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2020
You should have received a copy of the GNU Affero General Public License
2121
along with this program. If not, see <https://www.gnu.org/licenses/>.
2222
*/
23+
using System;
2324
using iText.Pdfocr;
2425

2526
namespace iText.Pdfocr.Actions {
2627
[NUnit.Framework.Category("IntegrationTest")]
2728
public class Tesseract4EventHandlingExecutableTest : Tesseract4EventHandlingTest {
29+
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
30+
+ "/test/itext/pdfocr/actions/Tesseract4EventHandlingExecutableTest/";
31+
32+
[NUnit.Framework.OneTimeSetUp]
33+
public static void BeforeTests() {
34+
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
35+
}
36+
2837
public Tesseract4EventHandlingExecutableTest()
29-
: base(IntegrationTestHelper.ReaderType.EXECUTABLE) {
38+
: base(IntegrationTestHelper.ReaderType.EXECUTABLE, DESTINATION_FOLDER) {
3039
}
3140
}
3241
}

itext.tests/itext.pdfocr.tesseract4.tests/itext/pdfocr/actions/Tesseract4EventHandlingLibTest.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,22 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2020
You should have received a copy of the GNU Affero General Public License
2121
along with this program. If not, see <https://www.gnu.org/licenses/>.
2222
*/
23+
using System;
2324
using iText.Pdfocr;
2425

2526
namespace iText.Pdfocr.Actions {
2627
[NUnit.Framework.Category("IntegrationTest")]
2728
public class Tesseract4EventHandlingLibTest : Tesseract4EventHandlingTest {
29+
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
30+
+ "/test/itext/pdfocr/actions/Tesseract4EventHandlingLibTest/";
31+
32+
[NUnit.Framework.OneTimeSetUp]
33+
public static void BeforeTests() {
34+
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
35+
}
36+
2837
public Tesseract4EventHandlingLibTest()
29-
: base(IntegrationTestHelper.ReaderType.LIB) {
38+
: base(IntegrationTestHelper.ReaderType.LIB, DESTINATION_FOLDER) {
3039
}
3140
}
3241
}

0 commit comments

Comments
 (0)