1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.compress.archivers.zip;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertNull;
21
22 import java.nio.file.attribute.FileTime;
23 import java.time.Instant;
24 import java.util.Date;
25
26 import org.junit.jupiter.api.Test;
27
28 public class X000A_NTFSTest {
29
30 @Test
31 public void testSimpleRoundtrip() throws Exception {
32 final X000A_NTFS xf = new X000A_NTFS();
33 xf.setModifyJavaTime(new Date(0));
34
35 xf.setAccessJavaTime(new Date(-11644473601000L));
36 xf.setCreateJavaTime(null);
37 final byte[] b = xf.getLocalFileDataData();
38
39 final X000A_NTFS xf2 = new X000A_NTFS();
40 xf2.parseFromLocalFileData(b, 0, b.length);
41 assertEquals(new Date(0), xf2.getModifyJavaTime());
42 assertEquals(new Date(-11644473601000L), xf2.getAccessJavaTime());
43 assertNull(xf2.getCreateJavaTime());
44 }
45
46 @Test
47 public void testSimpleRoundtripWithHighPrecisionDatesWithBigValues() throws Exception {
48 final X000A_NTFS xf = new X000A_NTFS();
49 xf.setModifyFileTime(FileTime.from(Instant.ofEpochSecond(123456789101L, 123456700)));
50
51 xf.setAccessFileTime(FileTime.from(Instant.ofEpochSecond(-11644473601L)));
52
53 xf.setCreateFileTime(FileTime.from(Instant.ofEpochSecond(-11644473600L, 765432100)));
54 final byte[] b = xf.getLocalFileDataData();
55
56 final X000A_NTFS xf2 = new X000A_NTFS();
57 xf2.parseFromLocalFileData(b, 0, b.length);
58 assertEquals(FileTime.from(Instant.ofEpochSecond(123456789101L, 123456700)), xf2.getModifyFileTime());
59 assertEquals(new Date(123456789101123L), xf2.getModifyJavaTime());
60 assertEquals(FileTime.from(Instant.ofEpochSecond(-11644473601L)), xf2.getAccessFileTime());
61 assertEquals(new Date(-11644473601000L), xf2.getAccessJavaTime());
62 assertEquals(FileTime.from(Instant.ofEpochSecond(-11644473600L, 765432100)), xf2.getCreateFileTime());
63 assertEquals(new Date(-11644473599235L).toInstant(), xf2.getCreateJavaTime().toInstant());
64 }
65
66 @Test
67 public void testSimpleRoundtripWithHighPrecisionDatesWithSmallValues() throws Exception {
68 final X000A_NTFS xf = new X000A_NTFS();
69
70 xf.setModifyFileTime(FileTime.from(Instant.ofEpochSecond(0, 1234)));
71
72 xf.setAccessFileTime(FileTime.from(Instant.ofEpochSecond(-11644473601L)));
73 xf.setCreateFileTime(null);
74 final byte[] b = xf.getLocalFileDataData();
75
76 final X000A_NTFS xf2 = new X000A_NTFS();
77 xf2.parseFromLocalFileData(b, 0, b.length);
78 assertEquals(FileTime.from(Instant.ofEpochSecond(0, 1200)), xf2.getModifyFileTime());
79 assertEquals(new Date(0), xf2.getModifyJavaTime());
80 assertEquals(FileTime.from(Instant.ofEpochSecond(-11644473601L)), xf2.getAccessFileTime());
81 assertEquals(new Date(-11644473601000L), xf2.getAccessJavaTime());
82 assertNull(xf2.getCreateFileTime());
83 assertNull(xf2.getCreateJavaTime());
84 }
85 }