From 3b87cf8d8ffd83f04c7878becca135affdeb42f8 Mon Sep 17 00:00:00 2001 From: Dmitry Chubrick Date: Tue, 27 Sep 2022 10:41:04 +0300 Subject: [PATCH] Fix a few known problems related to Android * Different fields order in JSON serialization * Ignore veraPdf validator * Different behavior of DeflaterOutputStream * Ignore test with OutOfMemory exception * Fix different behavior of ZipFileWriter\Reader DEVSIX-7066 --- .../itextpdf/commons/utils/JsonUtilTest.java | 48 +++++++++++++++---- .../commons/utils/ZipFileReaderTest.java | 1 + .../commons/utils/ZipFileWriterTest.java | 7 +++ .../JsonUtilTest/classWithEnumAndroid.json | 8 ++++ .../JsonUtilTest/complexStructureAndroid.json | 36 ++++++++++++++ .../minimalClassWithEnumAndroid.json | 1 + .../minimalComplexStructureAndroid.json | 1 + .../kernel/pdf/xobject/GetImageBytesTest.java | 4 ++ .../test/VeraPdfLoggerValidationTest.java | 6 +-- 9 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/classWithEnumAndroid.json create mode 100644 commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/complexStructureAndroid.json create mode 100644 commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/minimalClassWithEnumAndroid.json create mode 100644 commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/minimalComplexStructureAndroid.json diff --git a/commons/src/test/java/com/itextpdf/commons/utils/JsonUtilTest.java b/commons/src/test/java/com/itextpdf/commons/utils/JsonUtilTest.java index 653ce3acfb..063fb2c9ca 100644 --- a/commons/src/test/java/com/itextpdf/commons/utils/JsonUtilTest.java +++ b/commons/src/test/java/com/itextpdf/commons/utils/JsonUtilTest.java @@ -51,6 +51,14 @@ public class JsonUtilTest extends ExtendedITextTest { private static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/"; + private static boolean isRunOnJava = false; + + // Android-Excise-Start + static { + isRunOnJava = true; + } + // Android-Excise-End + @Test public void utf8CharsetStringTest() { Assert.assertEquals("\"©\"", JsonUtil.serializeToString("©")); @@ -77,9 +85,15 @@ public void serializeInstanceWithEnumStringTest() throws IOException { @Test public void serializeInstanceWithEnumStreamTest() throws IOException { - String path = SOURCE_FOLDER + "classWithEnum.json"; + String cmp; + if (isRunOnJava) { + cmp = SOURCE_FOLDER + "classWithEnum.json"; + } else { + // Test is run on Android, so field order will be different from Java. + cmp = SOURCE_FOLDER + "classWithEnumAndroid.json"; + } - try (InputStream inputStream = FileUtil.getInputStreamForFile(path); + try (InputStream inputStream = FileUtil.getInputStreamForFile(cmp); ByteArrayOutputStream baos = convertInputStreamToOutput(inputStream); ByteArrayOutputStream serializationResult = new ByteArrayOutputStream()) { JsonUtil.serializeToStream(serializationResult, createClassWithEnumObject()); @@ -102,9 +116,15 @@ public void serializeToMinimalInstanceWithEnumStringTest() throws IOException { @Test public void serializeToMinimalInstanceWithEnumStreamTest() throws IOException { - String path = SOURCE_FOLDER + "minimalClassWithEnum.json"; + String cmp; + if (isRunOnJava) { + cmp = SOURCE_FOLDER + "minimalClassWithEnum.json"; + } else { + // Test is run on Android, so field order will be different from Java. + cmp = SOURCE_FOLDER + "minimalClassWithEnumAndroid.json"; + } - try (InputStream inputStream = FileUtil.getInputStreamForFile(path); + try (InputStream inputStream = FileUtil.getInputStreamForFile(cmp); ByteArrayOutputStream baos = convertInputStreamToOutput(inputStream); ByteArrayOutputStream serializationResult = new ByteArrayOutputStream()) { JsonUtil.serializeToMinimalStream(serializationResult, createClassWithEnumObject()); @@ -175,9 +195,15 @@ public void serializeComplexStructureStringTest() throws IOException { @Test public void serializeComplexStructureStreamTest() throws IOException { - String path = SOURCE_FOLDER + "complexStructure.json"; + String cmp; + if (isRunOnJava) { + cmp = SOURCE_FOLDER + "complexStructure.json"; + } else { + // Test is run on Android, so field order will be different from Java. + cmp = SOURCE_FOLDER + "complexStructureAndroid.json"; + } - try (InputStream inputStream = FileUtil.getInputStreamForFile(path); + try (InputStream inputStream = FileUtil.getInputStreamForFile(cmp); ByteArrayOutputStream baos = convertInputStreamToOutput(inputStream); ByteArrayOutputStream serializationResult = new ByteArrayOutputStream()) { JsonUtil.serializeToStream(serializationResult, createComplexStructureObject()); @@ -200,9 +226,15 @@ public void serializeToMinimalComplexStructureStringTest() throws IOException { @Test public void serializeToMinimalComplexStructureStreamTest() throws IOException { - String path = SOURCE_FOLDER + "minimalComplexStructure.json"; + String cmp; + if (isRunOnJava) { + cmp = SOURCE_FOLDER + "minimalComplexStructure.json"; + } else { + // Test is run on Android, so field order will be different from Java. + cmp = SOURCE_FOLDER + "minimalComplexStructureAndroid.json"; + } - try (InputStream inputStream = FileUtil.getInputStreamForFile(path); + try (InputStream inputStream = FileUtil.getInputStreamForFile(cmp); ByteArrayOutputStream baos = convertInputStreamToOutput(inputStream); ByteArrayOutputStream serializationResult = new ByteArrayOutputStream()) { JsonUtil.serializeToMinimalStream(serializationResult, createComplexStructureObject()); diff --git a/commons/src/test/java/com/itextpdf/commons/utils/ZipFileReaderTest.java b/commons/src/test/java/com/itextpdf/commons/utils/ZipFileReaderTest.java index fe61535243..8e0529d678 100644 --- a/commons/src/test/java/com/itextpdf/commons/utils/ZipFileReaderTest.java +++ b/commons/src/test/java/com/itextpdf/commons/utils/ZipFileReaderTest.java @@ -58,6 +58,7 @@ public void constructorWithNonZipPathTest() { } @Test + // Android-Ignore (TODO DEVSIX-6906 fix different behavior of ZipFileWriter\Reader) public void getFileNamesFromEmptyZipTest() throws IOException { try (ZipFileReader fileReader = new ZipFileReader(SOURCE_FOLDER + "emptyZip.zip")) { Set nameSet = fileReader.getFileNames(); diff --git a/commons/src/test/java/com/itextpdf/commons/utils/ZipFileWriterTest.java b/commons/src/test/java/com/itextpdf/commons/utils/ZipFileWriterTest.java index e77bcac050..dabc66a3f9 100644 --- a/commons/src/test/java/com/itextpdf/commons/utils/ZipFileWriterTest.java +++ b/commons/src/test/java/com/itextpdf/commons/utils/ZipFileWriterTest.java @@ -99,6 +99,7 @@ public void constructorWithDirectoryPathTest() throws IOException { } @Test + // Android-Ignore (TODO DEVSIX-6906 fix different behavior of ZipFileWriter\Reader) public void emptyZipCreationTest() throws IOException { final String pathToFile = DESTINATION_FOLDER + "emptyZipCreation.zip"; @@ -113,6 +114,7 @@ public void emptyZipCreationTest() throws IOException { } @Test + // Android-Ignore (TODO DEVSIX-6906 fix different behavior of ZipFileWriter\Reader) public void addNullFileEntryTest() throws IOException { final String pathToFile = DESTINATION_FOLDER + "addNullFileEntry.zip"; @@ -124,6 +126,7 @@ public void addNullFileEntryTest() throws IOException { } @Test + // Android-Ignore (TODO DEVSIX-6906 fix different behavior of ZipFileWriter\Reader) public void addEntryWithNotExistingFileTest() throws IOException { try (ZipFileWriter writer = new ZipFileWriter( DESTINATION_FOLDER + "addEntryWithNotExistingFile.zip")) { @@ -133,6 +136,7 @@ public void addEntryWithNotExistingFileTest() throws IOException { } @Test + // Android-Ignore (TODO DEVSIX-6906 fix different behavior of ZipFileWriter\Reader) public void addNullStreamEntryTest() throws IOException { final String pathToFile = DESTINATION_FOLDER + "addNullStreamEntry.zip"; @@ -144,6 +148,7 @@ public void addNullStreamEntryTest() throws IOException { } @Test + // Android-Ignore (TODO DEVSIX-6906 fix different behavior of ZipFileWriter\Reader) public void addNullJsonEntryTest() throws IOException { final String pathToFile = DESTINATION_FOLDER + "addNullJsonEntry.zip"; @@ -155,6 +160,7 @@ public void addNullJsonEntryTest() throws IOException { } @Test + // Android-Ignore (TODO DEVSIX-6906 fix different behavior of ZipFileWriter\Reader) public void addEntryWhenWriterIsClosedTest() throws IOException { final String pathToFile = DESTINATION_FOLDER + "addEntryWhenWriterIsClosed.zip"; @@ -276,6 +282,7 @@ public void addSeveralEntriesToZipTest() throws IOException { } @Test + // Android-Ignore (TODO DEVSIX-6906 fix different behavior of ZipFileWriter\Reader) public void addEntryWithNullFileNameTest() throws IOException { final String pathToFile = DESTINATION_FOLDER + "addEntryWithNullFileName.zip"; final String firstTextFilePath = SOURCE_FOLDER + "testFile.txt"; diff --git a/commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/classWithEnumAndroid.json b/commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/classWithEnumAndroid.json new file mode 100644 index 0000000000..5195d93d53 --- /dev/null +++ b/commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/classWithEnumAndroid.json @@ -0,0 +1,8 @@ +{ + "enumArray": [ + "FIRST_VALUE", + "FIRST_VALUE", + "SECOND_VALUE" + ], + "firstValue": "SECOND_VALUE" +} \ No newline at end of file diff --git a/commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/complexStructureAndroid.json b/commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/complexStructureAndroid.json new file mode 100644 index 0000000000..90b6ce09ed --- /dev/null +++ b/commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/complexStructureAndroid.json @@ -0,0 +1,36 @@ +{ + "childsMap": { + "ChildMapkey": { + "arrayStr": [ + "someStr1", + "someStr2" + ], + "grandsons": [ + { + "integer": 13, + "name": "someName" + }, + { + "integer": 0, + "name": "" + } + ] + }, + "ChildMapKey2": { + "arrayStr": [ + "" + ], + "grandsons": [ + { + "integer": 0, + "name": "" + } + ] + } + }, + "map": { + "FirstMapKey": 15, + "SecondMapKey": 8 + }, + "str": "StringFieldValue" +} \ No newline at end of file diff --git a/commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/minimalClassWithEnumAndroid.json b/commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/minimalClassWithEnumAndroid.json new file mode 100644 index 0000000000..f04eccd43b --- /dev/null +++ b/commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/minimalClassWithEnumAndroid.json @@ -0,0 +1 @@ +{"enumArray":["FIRST_VALUE","FIRST_VALUE","SECOND_VALUE"],"firstValue":"SECOND_VALUE"} \ No newline at end of file diff --git a/commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/minimalComplexStructureAndroid.json b/commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/minimalComplexStructureAndroid.json new file mode 100644 index 0000000000..7ea189c9a2 --- /dev/null +++ b/commons/src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/minimalComplexStructureAndroid.json @@ -0,0 +1 @@ +{"childsMap":{"ChildMapkey":{"arrayStr":["someStr1","someStr2"],"grandsons":[{"integer":13,"name":"someName"},{"integer":0,"name":""}]},"ChildMapKey2":{"arrayStr":[""],"grandsons":[{"integer":0,"name":""}]}},"map":{"FirstMapKey":15,"SecondMapKey":8},"str":"StringFieldValue"} \ No newline at end of file diff --git a/kernel/src/test/java/com/itextpdf/kernel/pdf/xobject/GetImageBytesTest.java b/kernel/src/test/java/com/itextpdf/kernel/pdf/xobject/GetImageBytesTest.java index fdc719132a..aa5a8ae913 100644 --- a/kernel/src/test/java/com/itextpdf/kernel/pdf/xobject/GetImageBytesTest.java +++ b/kernel/src/test/java/com/itextpdf/kernel/pdf/xobject/GetImageBytesTest.java @@ -165,12 +165,14 @@ public void testJPXDecode() throws Exception { @Test // TODO: DEVSIX-3538 (update test after fix) + // Android-Ignore (TODO DEVSIX-7079 increase memory available for virtual machine while test running) public void testSeparationCSWithICCBasedAsAlternative() throws Exception { testFile("separationCSWithICCBasedAsAlternative.pdf", "Im1", "png"); } @Test // TODO: DEVSIX-3538 (update test after fix) + // Android-Ignore (TODO DEVSIX-6445 fix different DeflaterOutputStream behavior) public void testSeparationCSWithDeviceCMYKAsAlternative() throws Exception { Assert.assertThrows(UnsupportedOperationException.class, () -> { @@ -185,12 +187,14 @@ public void testGrayScalePng() throws Exception { @Test // TODO: DEVSIX-3538 (update test after fix) + // Android-Ignore (TODO DEVSIX-6445 fix different DeflaterOutputStream behavior) public void testSeparationCSWithDeviceRGBAsAlternative() throws Exception { testFile("separationCSWithDeviceRgbAsAlternative.pdf", "Im1", "png"); } @Test // TODO: DEVSIX-3538 (update test after fix) + // Android-Ignore (TODO DEVSIX-6445 fix different DeflaterOutputStream behavior) public void testSeparationCSWithDeviceRGBAsAlternative2() throws Exception { testFile("spotColorImagesSmall.pdf", "Im1", "png"); } diff --git a/pdftest/src/test/java/com/itextpdf/test/VeraPdfLoggerValidationTest.java b/pdftest/src/test/java/com/itextpdf/test/VeraPdfLoggerValidationTest.java index 61de29efe9..8618d92b5d 100644 --- a/pdftest/src/test/java/com/itextpdf/test/VeraPdfLoggerValidationTest.java +++ b/pdftest/src/test/java/com/itextpdf/test/VeraPdfLoggerValidationTest.java @@ -43,7 +43,7 @@ This file is part of the iText (R) project. package com.itextpdf.test; import com.itextpdf.test.annotations.type.UnitTest; -import com.itextpdf.test.pdfa.VeraPdfValidator; +import com.itextpdf.test.pdfa.VeraPdfValidator; // Android-Skip import com.itextpdf.test.utils.FileUtil; import java.io.IOException; @@ -76,9 +76,9 @@ public void checkValidatorLogsTest() throws IOException { + "WARNING: Invalid embedded cff font. Charset range exceeds number of glyphs\n" + "WARNING: Missing OutputConditionIdentifier in an output intent dictionary\n" + "WARNING: The Top DICT does not begin with ROS operator"; - Assert.assertEquals(expectedWarningsForFileWithWarnings, new VeraPdfValidator().validate(DESTINATION_FOLDER + fileNameWithWarnings)); + Assert.assertEquals(expectedWarningsForFileWithWarnings, new VeraPdfValidator().validate(DESTINATION_FOLDER + fileNameWithWarnings)); // Android-Skip //We check that the logs are empty after the first check - Assert.assertNull(new VeraPdfValidator().validate(DESTINATION_FOLDER + fileNameWithoutWarnings)); + Assert.assertNull(new VeraPdfValidator().validate(DESTINATION_FOLDER + fileNameWithoutWarnings)); // Android-Skip } }