01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: package org.apache.harmony.pack200.tests;
18:
19: import java.io.ByteArrayInputStream;
20: import java.io.IOException;
21:
22: import junit.framework.TestCase;
23:
24: import org.apache.harmony.pack200.BHSDCodec;
25: import org.apache.harmony.pack200.CodecEncoding;
26: import org.apache.harmony.pack200.Pack200Exception;
27:
28: /**
29: * Tests for BHSDCodec
30: */
31: public class BHSDCodecTest extends TestCase {
32:
33: public void testEncodeDecode() throws IOException, Pack200Exception {
34: for (int i = 1; i < 116; i++) {
35:
36: BHSDCodec codec = (BHSDCodec) CodecEncoding.getCodec(i,
37: null, null);
38:
39: // Test encode-decode with a selection of numbers within the range of the codec
40: long delta = (codec.largest() - codec.smallest()) / 4;
41: for (long j = codec.smallest(); j <= codec.largest() + 1; j += delta) {
42: byte[] encoded = codec.encode(j, 0);
43: long decoded = codec.decode(new ByteArrayInputStream(
44: encoded), 0);
45: if (j != decoded) {
46: fail("Failed with codec: " + codec + " expected: "
47: + j + ", got: " + decoded);
48: }
49: }
50:
51: // Test encode-decode with 0
52: assertEquals(0, codec.decode(new ByteArrayInputStream(codec
53: .encode(0, 0)), 0));
54: }
55: }
56:
57: }
|