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.bytecode;
18:
19: import junit.framework.TestCase;
20:
21: import org.apache.harmony.pack200.bytecode.CPMember;
22: import org.apache.harmony.pack200.bytecode.CPUTF8;
23: import org.apache.harmony.pack200.bytecode.ClassConstantPool;
24:
25: public class ConstantPoolTest extends TestCase {
26: private ClassConstantPool pool;
27:
28: public void setUp() {
29: pool = new ClassConstantPool();
30: }
31:
32: public void testDuplicateUTF8() {
33: CPUTF8 u1 = new CPUTF8("thing",
34: ClassConstantPool.DOMAIN_NORMALASCIIZ);
35: CPUTF8 u2 = new CPUTF8("thing",
36: ClassConstantPool.DOMAIN_NORMALASCIIZ);
37: pool.add(u1);
38: pool.add(u2);
39: assertEquals(1, pool.size());
40: }
41:
42: public void testDuplicateField() {
43: CPMember cp1 = new CPMember("name:I", 0, null);
44: pool.add(cp1);
45: assertEquals(2, pool.size());
46: CPMember cp2 = new CPMember("name:I", 0, null);
47: pool.add(cp2);
48: assertEquals(2, pool.size());
49: }
50:
51: public void testIndex() {
52: pool.add(new CPUTF8("OtherThing",
53: ClassConstantPool.DOMAIN_NORMALASCIIZ));
54: CPUTF8 u1 = new CPUTF8("thing",
55: ClassConstantPool.DOMAIN_NORMALASCIIZ);
56: pool.add(u1);
57: pool.resolve();
58: assertTrue(pool.indexOf(u1) > 0);
59: }
60: }
|