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 */ 17package org.apache.harmony.archive.tests.java.util.zip; 18 19import java.util.zip.Adler32; 20 21public class Adler32Test extends junit.framework.TestCase { 22 23 /** 24 * @tests java.util.zip.Adler32#Adler32() 25 */ 26 public void test_Constructor() { 27 // test method of java.util.zip.Adler32() 28 Adler32 adl = new Adler32(); 29 assertEquals("Constructor of adl32 failed", 1, adl.getValue()); 30 } 31 32 /** 33 * @tests java.util.zip.Adler32#getValue() 34 */ 35 public void test_getValue() { 36 // test methods of java.util.zip.getValue() 37 Adler32 adl = new Adler32(); 38 assertEquals("GetValue should return a zero as a result of construction an object of Adler32", 39 1, adl.getValue()); 40 41 adl.reset(); 42 adl.update(1); 43 // System.out.print("value of adl"+adl.getValue()); 44 // The value of the adl should be 131074 45 assertEquals("update(int) failed to update the checksum to the correct value ", 46 131074, adl.getValue()); 47 adl.reset(); 48 assertEquals("reset failed to reset the checksum value to zero", 1, adl 49 .getValue()); 50 51 adl.reset(); 52 adl.update(Integer.MIN_VALUE); 53 // System.out.print("value of adl " + adl.getValue()); 54 // The value of the adl should be 65537 55 assertEquals("update(min) failed to update the checksum to the correct value ", 56 65537L, adl.getValue()); 57 } 58 59 /** 60 * @tests java.util.zip.Adler32#reset() 61 */ 62 public void test_reset() { 63 // test methods of java.util.zip.reset() 64 Adler32 adl = new Adler32(); 65 adl.update(1); 66 // System.out.print("value of adl"+adl.getValue()); 67 // The value of the adl should be 131074 68 assertEquals("update(int) failed to update the checksum to the correct value ", 69 131074, adl.getValue()); 70 adl.reset(); 71 assertEquals("reset failed to reset the checksum value to zero", 1, adl 72 .getValue()); 73 } 74 75 /** 76 * @tests java.util.zip.Adler32#update(int) 77 */ 78 public void test_updateI() { 79 // test methods of java.util.zip.update(int) 80 Adler32 adl = new Adler32(); 81 adl.update(1); 82 // The value of the adl should be 131074 83 assertEquals("update(int) failed to update the checksum to the correct value ", 84 131074, adl.getValue()); 85 86 adl.reset(); 87 adl.update(Integer.MAX_VALUE); 88 // System.out.print("value of adl " + adl.getValue()); 89 // The value of the adl should be 16777472 90 assertEquals("update(max) failed to update the checksum to the correct value ", 91 16777472L, adl.getValue()); 92 93 adl.reset(); 94 adl.update(Integer.MIN_VALUE); 95 // System.out.print("value of adl " + adl.getValue()); 96 // The value of the adl should be 65537 97 assertEquals("update(min) failed to update the checksum to the correct value ", 98 65537L, adl.getValue()); 99 100 } 101 102 /** 103 * @tests java.util.zip.Adler32#update(byte[]) 104 */ 105 public void test_update$B() { 106 // test method of java.util.zip.update(byte[]) 107 byte byteArray[] = { 1, 2 }; 108 Adler32 adl = new Adler32(); 109 adl.update(byteArray); 110 // System.out.print("value of adl"+adl.getValue()); 111 // The value of the adl should be 393220 112 assertEquals("update(byte[]) failed to update the checksum to the correct value ", 113 393220, adl.getValue()); 114 115 adl.reset(); 116 byte byteEmpty[] = new byte[10000]; 117 adl.update(byteEmpty); 118 // System.out.print("value of adl"+adl.getValue()); 119 // The value of the adl should be 655360001 120 assertEquals("update(byte[]) failed to update the checksum to the correct value ", 121 655360001L, adl.getValue()); 122 123 } 124 125 /** 126 * @tests java.util.zip.Adler32#update(byte[], int, int) 127 */ 128 public void test_update$BII() { 129 // test methods of java.util.zip.update(byte[],int,int) 130 byte[] byteArray = { 1, 2, 3 }; 131 Adler32 adl = new Adler32(); 132 int off = 2;// accessing the 2nd element of byteArray 133 int len = 1; 134 int lenError = 3; 135 int offError = 4; 136 adl.update(byteArray, off, len); 137 // System.out.print("value of adl"+adl.getValue()); 138 // The value of the adl should be 262148 139 assertEquals("update(byte[],int,int) failed to update the checksum to the correct value ", 140 262148, adl.getValue()); 141 int r = 0; 142 143 try { 144 adl.update(byteArray, off, lenError); 145 } catch (ArrayIndexOutOfBoundsException e) { 146 r = 1; 147 } 148 assertEquals("update(byte[],int,int) failed b/c lenError>byte[].length-off", 149 1, r); 150 151 try { 152 adl.update(byteArray, offError, len); 153 } catch (ArrayIndexOutOfBoundsException e) { 154 r = 2; 155 } 156 assertEquals("update(byte[],int,int) failed b/c offError>byte[].length", 157 2, r); 158 159 } 160 161 @Override 162 protected void setUp() { 163 } 164 165 @Override 166 protected void tearDown() { 167 } 168 169} 170