~ubuntu-branches/ubuntu/maverick/libcommons-compress-java/maverick

« back to all changes in this revision

Viewing changes to src/test/org/apache/commons/compress/archivers/zip/ZipLongTestCase.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-12-17 15:17:09 UTC
  • Revision ID: james.westby@ubuntu.com-20071217151709-dqfo6iq1zxyssgf6
Tags: upstream-0~svn604876
ImportĀ upstreamĀ versionĀ 0~svn604876

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
9
 *
 
10
 * http://www.apache.org/licenses/LICENSE-2.0
 
11
 *
 
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
 
17
 * under the License.
 
18
 */
 
19
 
 
20
package org.apache.commons.compress.archivers.zip;
 
21
 
 
22
import org.apache.commons.compress.archivers.zip.ZipLong;
 
23
 
 
24
import junit.framework.TestCase;
 
25
 
 
26
/**
 
27
 * JUnit 3 testcases for org.apache.tools.zip.ZipLong.
 
28
 *
 
29
 * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
 
30
 */
 
31
public class ZipLongTestCase
 
32
    extends TestCase
 
33
{
 
34
 
 
35
    public ZipLongTestCase( final String name )
 
36
    {
 
37
        super( name );
 
38
    }
 
39
 
 
40
    /**
 
41
     * Test conversion to bytes.
 
42
     */
 
43
    public void testToBytes()
 
44
    {
 
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 ] );
 
52
    }
 
53
 
 
54
    /**
 
55
     * Test conversion from bytes.
 
56
     */
 
57
    public void testFromBytes()
 
58
    {
 
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() );
 
62
    }
 
63
 
 
64
    /**
 
65
     * Test the contract of the equals method.
 
66
     */
 
67
    public void testEquals()
 
68
    {
 
69
        final ZipLong zipLong1 = new ZipLong( 0x12345678 );
 
70
        final ZipLong zipLong2 = new ZipLong( 0x12345678 );
 
71
        final ZipLong zipLong3 = new ZipLong( 0x87654321 );
 
72
 
 
73
        assertTrue( "reflexive", zipLong1.equals( zipLong1 ) );
 
74
 
 
75
        assertTrue( "works", zipLong1.equals( zipLong2 ) );
 
76
        assertTrue( "works, part two", !zipLong1.equals( zipLong3 ) );
 
77
 
 
78
        assertTrue( "symmetric", zipLong2.equals( zipLong1 ) );
 
79
 
 
80
        assertTrue( "null handling", !zipLong1.equals( null ) );
 
81
        assertTrue( "non ZipLong handling", !zipLong1.equals( new Integer( 0x1234 ) ) );
 
82
    }
 
83
 
 
84
    /**
 
85
     * Test sign handling.
 
86
     */
 
87
    public void testSign()
 
88
    {
 
89
        final ZipLong zipLong =
 
90
            new ZipLong( new byte[]{(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF} );
 
91
        assertEquals( 0x00000000FFFFFFFFl, zipLong.getValue() );
 
92
    }
 
93
}