View Javadoc
1   /*
2    *  This file is part of the Wayback archival access software
3    *   (http://archive-access.sourceforge.net/projects/wayback/).
4    *
5    *  Licensed to the Internet Archive (IA) by one or more individual 
6    *  contributors. 
7    *
8    *  The IA licenses this file to You under the Apache License, Version 2.0
9    *  (the "License"); you may not use this file except in compliance with
10   *  the License.  You may obtain a copy of the License at
11   *
12   *      http://www.apache.org/licenses/LICENSE-2.0
13   *
14   *  Unless required by applicable law or agreed to in writing, software
15   *  distributed under the License is distributed on an "AS IS" BASIS,
16   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   *  See the License for the specific language governing permissions and
18   *  limitations under the License.
19   */
20  package org.archive.wayback.util;
21  
22  import junit.framework.TestCase;
23  
24  /**
25   * @author brad
26   *
27   */
28  public class BitArrayTest extends TestCase {
29  
30  	/**
31  	 * Test method for {@link org.archive.wayback.util.BitArray#get(int)}.
32  	 */
33  	public void testGet() {
34  		byte bytes[] = "Here is some data!".getBytes();
35  		byte bytes2[] = "Here is some data!".getBytes();
36  		int bits = bytes.length * 8;
37  		sun.security.util.BitArray sba = 
38  			new sun.security.util.BitArray(bits, bytes);
39  		org.archive.wayback.util.BitArray wba = 
40  			new org.archive.wayback.util.BitArray(bytes2);
41  		for(int i = 0; i < bits; i++) {
42  			boolean want = sba.get(i);
43  			boolean got = wba.get(i);
44  			if(want != got) {
45  				got = wba.get(i);
46  			}
47  			assertEquals(want,got);
48  		}
49  	}
50  
51  	/**
52  	 * Test method for {@link org.archive.wayback.util.BitArray#set(int, boolean)}.
53  	 */
54  	public void testSet() {
55  		byte bytes[] = "Here is some data!".getBytes();
56  		byte bytes2[] = "Here is some data!".getBytes();
57  		int bits = bytes.length * 8;
58  		sun.security.util.BitArray sba = 
59  			new sun.security.util.BitArray(bits, bytes);
60  		org.archive.wayback.util.BitArray wba = 
61  			new org.archive.wayback.util.BitArray(bytes2);
62  		for(int i = 0; i < bits; i++) {
63  			boolean want = sba.get(i);
64  			boolean got = wba.get(i);
65  			boolean not = !want;
66  			assertTrue(ByteOp.cmp(sba.toByteArray(), wba.getBytes()));
67  			sba.set(i,not);
68  			wba.set(i,not);
69  			assertTrue(ByteOp.cmp(sba.toByteArray(), wba.getBytes()));
70  			assertEquals(not,wba.get(i));
71  			sba.set(i,got);
72  			wba.set(i,got);
73  			assertEquals(sba.get(i),wba.get(i));			
74  			assertTrue(ByteOp.cmp(sba.toByteArray(), wba.getBytes()));
75  		}
76  		
77  	}
78  }