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.util.HashMap;
022: import java.util.Map;
023:
024: import junit.framework.TestCase;
025:
026: import org.apache.harmony.pack200.BHSDCodec;
027: import org.apache.harmony.pack200.Codec;
028: import org.apache.harmony.pack200.CodecEncoding;
029: import org.apache.harmony.pack200.Pack200Exception;
030:
031: /**
032: *
033: */
034: public class CodecEncodingTest extends TestCase {
035:
036: public void testCanonicalEncodings() throws IOException,
037: Pack200Exception {
038: Codec defaultCodec = new BHSDCodec(2, 16, 0, 0);
039: assertEquals(defaultCodec, CodecEncoding.getCodec(0, null,
040: defaultCodec));
041: Map map = new HashMap();
042: // These are the canonical encodings specified by the Pack200 spec
043: map.put(new Integer(1), "(1,256)");
044: map.put(new Integer(2), "(1,256,1)");
045: map.put(new Integer(3), "(1,256,0,1)");
046: map.put(new Integer(4), "(1,256,1,1)");
047: map.put(new Integer(5), "(2,256)");
048: map.put(new Integer(6), "(2,256,1)");
049: map.put(new Integer(7), "(2,256,0,1)");
050: map.put(new Integer(8), "(2,256,1,1)");
051: map.put(new Integer(9), "(3,256)");
052: map.put(new Integer(10), "(3,256,1)");
053: map.put(new Integer(11), "(3,256,0,1)");
054: map.put(new Integer(12), "(3,256,1,1)");
055: map.put(new Integer(13), "(4,256)");
056: map.put(new Integer(14), "(4,256,1)");
057: map.put(new Integer(15), "(4,256,0,1)");
058: map.put(new Integer(16), "(4,256,1,1)");
059: map.put(new Integer(17), "(5,4)");
060: map.put(new Integer(18), "(5,4,1)");
061: map.put(new Integer(19), "(5,4,2)");
062: map.put(new Integer(20), "(5,16)");
063: map.put(new Integer(21), "(5,16,1)");
064: map.put(new Integer(22), "(5,16,2)");
065: map.put(new Integer(23), "(5,32)");
066: map.put(new Integer(24), "(5,32,1)");
067: map.put(new Integer(25), "(5,32,2)");
068: map.put(new Integer(26), "(5,64)");
069: map.put(new Integer(27), "(5,64,1)");
070: map.put(new Integer(28), "(5,64,2)");
071: map.put(new Integer(29), "(5,128)");
072: map.put(new Integer(30), "(5,128,1)");
073: map.put(new Integer(31), "(5,128,2)");
074: map.put(new Integer(32), "(5,4,0,1)");
075: map.put(new Integer(33), "(5,4,1,1)");
076: map.put(new Integer(34), "(5,4,2,1)");
077: map.put(new Integer(35), "(5,16,0,1)");
078: map.put(new Integer(36), "(5,16,1,1)");
079: map.put(new Integer(37), "(5,16,2,1)");
080: map.put(new Integer(38), "(5,32,0,1)");
081: map.put(new Integer(39), "(5,32,1,1)");
082: map.put(new Integer(40), "(5,32,2,1)");
083: map.put(new Integer(41), "(5,64,0,1)");
084: map.put(new Integer(42), "(5,64,1,1)");
085: map.put(new Integer(43), "(5,64,2,1)");
086: map.put(new Integer(44), "(5,128,0,1)");
087: map.put(new Integer(45), "(5,128,1,1)");
088: map.put(new Integer(46), "(5,128,2,1)");
089: map.put(new Integer(47), "(2,192)");
090: map.put(new Integer(48), "(2,224)");
091: map.put(new Integer(49), "(2,240)");
092: map.put(new Integer(50), "(2,248)");
093: map.put(new Integer(51), "(2,252)");
094: map.put(new Integer(52), "(2,8,0,1)");
095: map.put(new Integer(53), "(2,8,1,1)");
096: map.put(new Integer(54), "(2,16,0,1)");
097: map.put(new Integer(55), "(2,16,1,1)");
098: map.put(new Integer(56), "(2,32,0,1)");
099: map.put(new Integer(57), "(2,32,1,1)");
100: map.put(new Integer(58), "(2,64,0,1)");
101: map.put(new Integer(59), "(2,64,1,1)");
102: map.put(new Integer(60), "(2,128,0,1)");
103: map.put(new Integer(61), "(2,128,1,1)");
104: map.put(new Integer(62), "(2,192,0,1)");
105: map.put(new Integer(63), "(2,192,1,1)");
106: map.put(new Integer(64), "(2,224,0,1)");
107: map.put(new Integer(65), "(2,224,1,1)");
108: map.put(new Integer(66), "(2,240,0,1)");
109: map.put(new Integer(67), "(2,240,1,1)");
110: map.put(new Integer(68), "(2,248,0,1)");
111: map.put(new Integer(69), "(2,248,1,1)");
112: map.put(new Integer(70), "(3,192)");
113: map.put(new Integer(71), "(3,224)");
114: map.put(new Integer(72), "(3,240)");
115: map.put(new Integer(73), "(3,248)");
116: map.put(new Integer(74), "(3,252)");
117: map.put(new Integer(75), "(3,8,0,1)");
118: map.put(new Integer(76), "(3,8,1,1)");
119: map.put(new Integer(77), "(3,16,0,1)");
120: map.put(new Integer(78), "(3,16,1,1)");
121: map.put(new Integer(79), "(3,32,0,1)");
122: map.put(new Integer(80), "(3,32,1,1)");
123: map.put(new Integer(81), "(3,64,0,1)");
124: map.put(new Integer(82), "(3,64,1,1)");
125: map.put(new Integer(83), "(3,128,0,1)");
126: map.put(new Integer(84), "(3,128,1,1)");
127: map.put(new Integer(85), "(3,192,0,1)");
128: map.put(new Integer(86), "(3,192,1,1)");
129: map.put(new Integer(87), "(3,224,0,1)");
130: map.put(new Integer(88), "(3,224,1,1)");
131: map.put(new Integer(89), "(3,240,0,1)");
132: map.put(new Integer(90), "(3,240,1,1)");
133: map.put(new Integer(91), "(3,248,0,1)");
134: map.put(new Integer(92), "(3,248,1,1)");
135: map.put(new Integer(93), "(4,192)");
136: map.put(new Integer(94), "(4,224)");
137: map.put(new Integer(95), "(4,240)");
138: map.put(new Integer(96), "(4,248)");
139: map.put(new Integer(97), "(4,252)");
140: map.put(new Integer(98), "(4,8,0,1)");
141: map.put(new Integer(99), "(4,8,1,1)");
142: map.put(new Integer(100), "(4,16,0,1)");
143: map.put(new Integer(101), "(4,16,1,1)");
144: map.put(new Integer(102), "(4,32,0,1)");
145: map.put(new Integer(103), "(4,32,1,1)");
146: map.put(new Integer(104), "(4,64,0,1)");
147: map.put(new Integer(105), "(4,64,1,1)");
148: map.put(new Integer(106), "(4,128,0,1)");
149: map.put(new Integer(107), "(4,128,1,1)");
150: map.put(new Integer(108), "(4,192,0,1)");
151: map.put(new Integer(109), "(4,192,1,1)");
152: map.put(new Integer(110), "(4,224,0,1)");
153: map.put(new Integer(111), "(4,224,1,1)");
154: map.put(new Integer(112), "(4,240,0,1)");
155: map.put(new Integer(113), "(4,240,1,1)");
156: map.put(new Integer(114), "(4,248,0,1)");
157: map.put(new Integer(115), "(4,248,1,1)");
158: for (int i = 1; i <= 115; i++) {
159: assertEquals(map.get(new Integer(i)), CodecEncoding
160: .getCodec(i, null, null).toString());
161: }
162: }
163:
164: public void testArbitraryCodec() throws IOException,
165: Pack200Exception {
166: assertEquals("(1,256)", CodecEncoding.getCodec(
167: 116,
168: new ByteArrayInputStream(
169: new byte[] { 0x00, (byte) 0xFF }), null)
170: .toString());
171: assertEquals("(5,128,2,1)", CodecEncoding.getCodec(
172: 116,
173: new ByteArrayInputStream(
174: new byte[] { 0x25, (byte) 0x7F }), null)
175: .toString());
176: assertEquals("(2,128,1,1)", CodecEncoding.getCodec(
177: 116,
178: new ByteArrayInputStream(
179: new byte[] { 0x0B, (byte) 0x7F }), null)
180: .toString());
181: }
182:
183: }
|