You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ZipOutputStreamTest.java 2.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * 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. package org.apache.tools.zip;
  19. import org.junit.Before;
  20. import org.junit.Test;
  21. import java.util.Calendar;
  22. import java.util.Date;
  23. import static org.junit.Assert.assertEquals;
  24. public class ZipOutputStreamTest {
  25. private Date time;
  26. private ZipLong zl;
  27. @Before
  28. public void setUp() {
  29. time = new Date();
  30. Calendar cal = Calendar.getInstance();
  31. cal.setTime(time);
  32. int year = cal.get(Calendar.YEAR);
  33. int month = cal.get(Calendar.MONTH) + 1;
  34. long value = ((year - 1980) << 25)
  35. | (month << 21)
  36. | (cal.get(Calendar.DAY_OF_MONTH) << 16)
  37. | (cal.get(Calendar.HOUR_OF_DAY) << 11)
  38. | (cal.get(Calendar.MINUTE) << 5)
  39. | (cal.get(Calendar.SECOND) >> 1);
  40. byte[] result = new byte[4];
  41. result[0] = (byte) ((value & 0xFF));
  42. result[1] = (byte) ((value & 0xFF00) >> 8);
  43. result[2] = (byte) ((value & 0xFF0000) >> 16);
  44. result[3] = (byte) ((value & 0xFF000000L) >> 24);
  45. zl = new ZipLong(result);
  46. }
  47. @Test
  48. public void testZipLong() {
  49. ZipLong test = ZipOutputStream.toDosTime(time);
  50. assertEquals(test.getValue(), zl.getValue());
  51. }
  52. @Test
  53. public void testAdjustToLong() {
  54. assertEquals((long) Integer.MAX_VALUE,
  55. ZipOutputStream.adjustToLong(Integer.MAX_VALUE));
  56. assertEquals(((long) Integer.MAX_VALUE) + 1,
  57. ZipOutputStream.adjustToLong(Integer.MAX_VALUE + 1));
  58. assertEquals(2 * ((long) Integer.MAX_VALUE),
  59. ZipOutputStream.adjustToLong(2 * Integer.MAX_VALUE));
  60. }
  61. }