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 junit.framework.TestCase;
020:
021: import org.apache.harmony.pack200.CpBands;
022: import org.apache.harmony.pack200.Segment;
023: import org.apache.harmony.pack200.SegmentConstantPool;
024:
025: /**
026: * Tests for org.apache.harmony.pack200.SegmentConstantPool.
027: */
028: public class SegmentConstantPoolTest extends TestCase {
029:
030: public class MockSegmentConstantPool extends SegmentConstantPool {
031: public MockSegmentConstantPool() {
032: super (new CpBands(new Segment()));
033: };
034:
035: public int matchSpecificPoolEntryIndex(String[] classNameArray,
036: String desiredClassName, int desiredIndex) {
037: return super .matchSpecificPoolEntryIndex(classNameArray,
038: desiredClassName, desiredIndex);
039: };
040:
041: public int matchSpecificPoolEntryIndex(String[] classNameArray,
042: String[] methodNameArray, String desiredClassName,
043: String desiredMethodRegex, int desiredIndex) {
044: return super .matchSpecificPoolEntryIndex(classNameArray,
045: methodNameArray, desiredClassName,
046: desiredMethodRegex, desiredIndex);
047: };
048: }
049:
050: String[] testClassArray = { "Object", "Object", "java/lang/String",
051: "java/lang/String", "Object", "Other" };
052: String[] testMethodArray = { "<init>()", "clone()", "equals()",
053: "<init>", "isNull()", "Other" };
054:
055: public void testMatchSpecificPoolEntryIndex_SingleArray()
056: throws Exception {
057: MockSegmentConstantPool mockInstance = new MockSegmentConstantPool();
058: // Elements should be found at the proper position.
059: assertEquals(0, mockInstance.matchSpecificPoolEntryIndex(
060: testClassArray, "Object", 0));
061: assertEquals(1, mockInstance.matchSpecificPoolEntryIndex(
062: testClassArray, "Object", 1));
063: assertEquals(2, mockInstance.matchSpecificPoolEntryIndex(
064: testClassArray, "java/lang/String", 0));
065: assertEquals(3, mockInstance.matchSpecificPoolEntryIndex(
066: testClassArray, "java/lang/String", 1));
067: assertEquals(4, mockInstance.matchSpecificPoolEntryIndex(
068: testClassArray, "Object", 2));
069: assertEquals(5, mockInstance.matchSpecificPoolEntryIndex(
070: testClassArray, "Other", 0));
071:
072: // Elements that don't exist shouldn't be found
073: assertEquals(-1, mockInstance.matchSpecificPoolEntryIndex(
074: testClassArray, "NotThere", 0));
075:
076: // Elements that exist but don't have the requisite number
077: // of hits shouldn't be found.
078: assertEquals(-1, mockInstance.matchSpecificPoolEntryIndex(
079: testClassArray, "java/lang/String", 2));
080: }
081:
082: public void testMatchSpecificPoolEntryIndex_DoubleArray()
083: throws Exception {
084: MockSegmentConstantPool mockInstance = new MockSegmentConstantPool();
085: // Elements should be found at the proper position.
086: assertEquals(0, mockInstance.matchSpecificPoolEntryIndex(
087: testClassArray, testMethodArray, "Object", "<init>.*",
088: 0));
089: assertEquals(1, mockInstance
090: .matchSpecificPoolEntryIndex(testClassArray,
091: testMethodArray, "Object", "clone.*", 0));
092: assertEquals(2, mockInstance.matchSpecificPoolEntryIndex(
093: testClassArray, testMethodArray, "java/lang/String",
094: "equals.*", 0));
095: assertEquals(3, mockInstance.matchSpecificPoolEntryIndex(
096: testClassArray, testMethodArray, "java/lang/String",
097: "<init>.*", 0));
098: assertEquals(4, mockInstance.matchSpecificPoolEntryIndex(
099: testClassArray, testMethodArray, "Object", "isNull.*",
100: 0));
101: assertEquals(5, mockInstance.matchSpecificPoolEntryIndex(
102: testClassArray, testMethodArray, "Other", "Other", 0));
103:
104: // Elements that don't exist shouldn't be found
105: assertEquals(-1, mockInstance.matchSpecificPoolEntryIndex(
106: testClassArray, testMethodArray, "NotThere",
107: "NotThere", 0));
108: assertEquals(-1, mockInstance.matchSpecificPoolEntryIndex(
109: testClassArray, testMethodArray, "Object", "NotThere",
110: 0));
111:
112: // Elements that exist but don't have the requisite number
113: // of hits shouldn't be found.
114: assertEquals(-1, mockInstance.matchSpecificPoolEntryIndex(
115: testClassArray, testMethodArray, "java/lang/String",
116: "<init>.*", 1));
117: }
118:
119: }
|