2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the
7
* "License"); you may not use this file except in compliance
8
* with the License. You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing,
13
* software distributed under the License is distributed on an
14
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
* KIND, either express or implied. See the License for the
16
* specific language governing permissions and limitations
20
package org.apache.commons.compress.archivers.zip;
22
import org.apache.commons.compress.archivers.zip.ZipLong;
24
import junit.framework.TestCase;
27
* JUnit 3 testcases for org.apache.tools.zip.ZipLong.
29
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
31
public class ZipLongTestCase
35
public ZipLongTestCase( final String name )
41
* Test conversion to bytes.
43
public void testToBytes()
45
final ZipLong zipLong = new ZipLong( 0x12345678 );
46
final byte[] result = zipLong.getBytes();
47
assertEquals( "length getBytes", 4, result.length );
48
assertEquals( "first byte getBytes", 0x78, result[ 0 ] );
49
assertEquals( "second byte getBytes", 0x56, result[ 1 ] );
50
assertEquals( "third byte getBytes", 0x34, result[ 2 ] );
51
assertEquals( "fourth byte getBytes", 0x12, result[ 3 ] );
55
* Test conversion from bytes.
57
public void testFromBytes()
59
final byte[] value = new byte[]{0x78, 0x56, 0x34, 0x12};
60
final ZipLong zipLong = new ZipLong( value );
61
assertEquals( "value from bytes", 0x12345678, zipLong.getValue() );
65
* Test the contract of the equals method.
67
public void testEquals()
69
final ZipLong zipLong1 = new ZipLong( 0x12345678 );
70
final ZipLong zipLong2 = new ZipLong( 0x12345678 );
71
final ZipLong zipLong3 = new ZipLong( 0x87654321 );
73
assertTrue( "reflexive", zipLong1.equals( zipLong1 ) );
75
assertTrue( "works", zipLong1.equals( zipLong2 ) );
76
assertTrue( "works, part two", !zipLong1.equals( zipLong3 ) );
78
assertTrue( "symmetric", zipLong2.equals( zipLong1 ) );
80
assertTrue( "null handling", !zipLong1.equals( null ) );
81
assertTrue( "non ZipLong handling", !zipLong1.equals( new Integer( 0x1234 ) ) );
87
public void testSign()
89
final ZipLong zipLong =
90
new ZipLong( new byte[]{(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF} );
91
assertEquals( 0x00000000FFFFFFFFl, zipLong.getValue() );