001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.harmony.pack200.tests;
018:
019: import java.io.ByteArrayInputStream;
020: import java.io.IOException;
021: import java.io.InputStream;
022: import java.io.OutputStream;
023:
024: import junit.framework.TestCase;
025:
026: import org.apache.harmony.pack200.BHSDCodec;
027: import org.apache.harmony.pack200.BandSet;
028: import org.apache.harmony.pack200.Codec;
029: import org.apache.harmony.pack200.Pack200Exception;
030: import org.apache.harmony.pack200.Segment;
031: import org.apache.harmony.pack200.SegmentHeader;
032:
033: public class BandSetTest extends TestCase {
034:
035: public class MockSegment extends Segment {
036: public SegmentHeader getSegmentHeader() {
037: return new SegmentHeader();
038: }
039: }
040:
041: private BandSet bandSet = new BandSet(new MockSegment()) {
042:
043: public void pack(OutputStream outputStream) {
044: }
045:
046: public void unpack(InputStream inputStream) throws IOException,
047: Pack200Exception {
048: }
049:
050: };
051:
052: public void testDecodeBandInt() throws IOException,
053: Pack200Exception {
054: BHSDCodec codec = Codec.BYTE1;
055: byte[] bytes = new byte[] { (byte) 3, (byte) 56, (byte) 122,
056: (byte) 78 };
057: InputStream in = new ByteArrayInputStream(bytes);
058: int[] ints = bandSet.decodeBandInt("Test Band", in, codec, 4);
059: for (int i = 0; i < ints.length; i++) {
060: assertEquals("Wrong value in position " + i, ints[i],
061: bytes[i]);
062: }
063: }
064:
065: public void testDecodeBandLong() throws IOException,
066: Pack200Exception {
067: BHSDCodec codec = Codec.BYTE1;
068: byte[] bytes = new byte[] { (byte) 3, (byte) 56, (byte) 122,
069: (byte) 78, (byte) 0, (byte) 255 };
070: InputStream in = new ByteArrayInputStream(bytes);
071: long[] longs = bandSet
072: .decodeBandLong("Test Band", in, codec, 6);
073: for (int i = 0; i < longs.length; i++) {
074: assertEquals("Wrong value in position " + i,
075: (byte) longs[i], bytes[i]);
076: }
077: //TODO: Should test this with other Codecs.
078: }
079:
080: public void testDecodeBandLong2() throws IOException,
081: Pack200Exception {
082:
083: BHSDCodec codec = Codec.DELTA5;
084: byte[] bytes = new byte[] { 3, 1, 2, 3, 4, 5 }; // 3 is decoded to -2 by DELTA5, which signifies a switch to BYTE1
085: InputStream in = new ByteArrayInputStream(bytes);
086: long[] longs = bandSet
087: .decodeBandLong("Test Band", in, codec, 5);
088: for (int i = 0; i < longs.length; i++) {
089: assertEquals("Wrong value in position " + i, longs[i],
090: bytes[i + 1]);
091: }
092: }
093:
094: public void testParseFlags1() {
095:
096: }
097:
098: public void testParseFlags2() {
099:
100: }
101:
102: public void testParseFlags3() {
103:
104: }
105:
106: public void testParseReferences1() {
107:
108: }
109:
110: public void testParseReferences2() {
111:
112: }
113:
114: }
|