01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.tools.zip;
20:
21: import java.util.Calendar;
22: import java.util.Date;
23:
24: import junit.framework.TestCase;
25:
26: public class ZipOutputStreamTest extends TestCase {
27:
28: private Date time;
29: private ZipLong zl;
30:
31: /**
32: * Constructor
33: */
34: public ZipOutputStreamTest(String name) {
35: super (name);
36: }
37:
38: protected void setUp() throws Exception {
39: time = new Date();
40: Calendar cal = Calendar.getInstance();
41: cal.setTime(time);
42: int year = cal.get(Calendar.YEAR);
43: int month = cal.get(Calendar.MONTH) + 1;
44: long value = ((year - 1980) << 25) | (month << 21)
45: | (cal.get(Calendar.DAY_OF_MONTH) << 16)
46: | (cal.get(Calendar.HOUR_OF_DAY) << 11)
47: | (cal.get(Calendar.MINUTE) << 5)
48: | (cal.get(Calendar.SECOND) >> 1);
49:
50: byte[] result = new byte[4];
51: result[0] = (byte) ((value & 0xFF));
52: result[1] = (byte) ((value & 0xFF00) >> 8);
53: result[2] = (byte) ((value & 0xFF0000) >> 16);
54: result[3] = (byte) ((value & 0xFF000000L) >> 24);
55: zl = new ZipLong(result);
56: }
57:
58: protected void tearDown() throws Exception {
59: super .tearDown();
60: }
61:
62: public void testZipLong() throws Exception {
63: ZipLong test = ZipOutputStream.toDosTime(time);
64: assertEquals(test.getValue(), zl.getValue());
65: }
66:
67: public void testAdjustToLong() {
68: assertEquals((long) Integer.MAX_VALUE, ZipOutputStream
69: .adjustToLong(Integer.MAX_VALUE));
70: assertEquals(((long) Integer.MAX_VALUE) + 1, ZipOutputStream
71: .adjustToLong(Integer.MAX_VALUE + 1));
72: assertEquals(2 * ((long) Integer.MAX_VALUE), ZipOutputStream
73: .adjustToLong(2 * Integer.MAX_VALUE));
74: }
75:
76: }
|