diff options
author | Dominik Stadler <centic@apache.org> | 2021-02-15 15:23:49 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2021-02-15 15:23:49 +0000 |
commit | 37d2d474dc7abbd8b51d8d1004c471976f9382d8 (patch) | |
tree | e3d6e720cb964650ac78bed1a0ed2c4cb42c03a0 | |
parent | 7a8f21b98950f250a8c068b51860ee9a61ac0b75 (diff) | |
download | poi-37d2d474dc7abbd8b51d8d1004c471976f9382d8.tar.gz poi-37d2d474dc7abbd8b51d8d1004c471976f9382d8.zip |
Do not fail test which compares two documents if the timestamp in the ZIP header field is different
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886532 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java index c79abea7dc..a82a2a8681 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java @@ -39,6 +39,7 @@ import java.util.List; import java.util.Map; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.filesystem.FileMagic; import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.formula.FormulaParseException; @@ -1827,8 +1828,25 @@ public abstract class BaseTestBugzillaIssues { out1.flush(); out2.flush(); - assertArrayEquals(out1.toByteArray(), out2.toByteArray()); + // to avoid flaky tests if the documents are written at slightly different timestamps + // we clear some bytes which contain timestamps + assertArrayEquals( + removeTimestamp(out1.toByteArray()), + removeTimestamp(out2.toByteArray())); } } } -}
\ No newline at end of file + + private byte[] removeTimestamp(byte[] bytes) { + if (FileMagic.valueOf(bytes) == FileMagic.OOXML) { + // This removes the timestamp in the header of the ZIP-Format + // see "Local file header" at https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT + bytes[10] = 0; + bytes[11] = 0; + bytes[12] = 0; + bytes[13] = 0; + } + + return bytes; + } +} |