mirror of
https://github.com/revanced/smali.git
synced 2025-05-17 22:47:07 +02:00
Added tests for TryListBuilder and fixed several bugs in TryListBuilder
git-svn-id: https://smali.googlecode.com/svn/trunk@39 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
parent
698a11d2c0
commit
a77aba807f
@ -166,6 +166,18 @@ public class CodeItem extends OffsettedItem<CodeItem> {
|
|||||||
protected Field[] getFields() {
|
protected Field[] getFields() {
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getStartAddress() {
|
||||||
|
return startAddr.getCachedValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEndAddress() {
|
||||||
|
return startAddr.getCachedValue() + insnCount.getCachedValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EncodedCatchHandler getHandler() {
|
||||||
|
return encodedCatchHandlerReference.getReference();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EncodedCatchHandlerReference extends ShortIntegerField {
|
public static class EncodedCatchHandlerReference extends ShortIntegerField {
|
||||||
@ -189,6 +201,10 @@ public class CodeItem extends OffsettedItem<CodeItem> {
|
|||||||
this.encodedCatchHandler = encodedCatchHandler;
|
this.encodedCatchHandler = encodedCatchHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EncodedCatchHandler getReference() {
|
||||||
|
return encodedCatchHandler;
|
||||||
|
}
|
||||||
|
|
||||||
public void copyTo(DexFile dexFile, CachedIntegerValueField _copy) {
|
public void copyTo(DexFile dexFile, CachedIntegerValueField _copy) {
|
||||||
|
|
||||||
EncodedCatchHandlerReference copy = (EncodedCatchHandlerReference)_copy;
|
EncodedCatchHandlerReference copy = (EncodedCatchHandlerReference)_copy;
|
||||||
@ -393,28 +409,55 @@ public class CodeItem extends OffsettedItem<CodeItem> {
|
|||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
return super.place(offset);
|
return super.place(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCatchAllAddress() {
|
||||||
|
if (hasCatchAll) {
|
||||||
|
return catchAllAddress.getCachedValue();
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHandlerCount() {
|
||||||
|
return list.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EncodedTypeAddrPair getHandler(int index) {
|
||||||
|
return list.get(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EncodedTypeAddrPair extends CompositeField<EncodedTypeAddrPair> {
|
public static class EncodedTypeAddrPair extends CompositeField<EncodedTypeAddrPair> {
|
||||||
public final Field[] fields;
|
public final Field[] fields;
|
||||||
|
|
||||||
|
public final IndexedItemReference<TypeIdItem> type;
|
||||||
|
public final Leb128Field handlerAddress;
|
||||||
|
|
||||||
public EncodedTypeAddrPair(DexFile dexFile) {
|
public EncodedTypeAddrPair(DexFile dexFile) {
|
||||||
fields = new Field[] {
|
fields = new Field[] {
|
||||||
new IndexedItemReference<TypeIdItem>(dexFile.TypeIdsSection, new Leb128Field()),
|
type = new IndexedItemReference<TypeIdItem>(dexFile.TypeIdsSection, new Leb128Field()),
|
||||||
new Leb128Field()
|
handlerAddress = new Leb128Field()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public EncodedTypeAddrPair(DexFile dexFile, TypeIdItem type, int handlerOffset) {
|
public EncodedTypeAddrPair(DexFile dexFile, TypeIdItem type, int handlerOffset) {
|
||||||
fields = new Field[] {
|
fields = new Field[] {
|
||||||
new IndexedItemReference<TypeIdItem>(dexFile, type, new Leb128Field()),
|
this.type = new IndexedItemReference<TypeIdItem>(dexFile, type, new Leb128Field()),
|
||||||
new Leb128Field(handlerOffset)
|
this.handlerAddress = new Leb128Field(handlerOffset)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Field[] getFields() {
|
protected Field[] getFields() {
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TypeIdItem getType() {
|
||||||
|
return type.getReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHandlerAddress() {
|
||||||
|
return handlerAddress.getCachedValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class InstructionListField implements Field<InstructionListField> {
|
private class InstructionListField implements Field<InstructionListField> {
|
||||||
|
@ -100,6 +100,7 @@ public class TryListBuilder
|
|||||||
|
|
||||||
TryRange tryRange = new TryRange(address, endAddress);
|
TryRange tryRange = new TryRange(address, endAddress);
|
||||||
tryRange.catchAllHandlerAddress = this.catchAllHandlerAddress;
|
tryRange.catchAllHandlerAddress = this.catchAllHandlerAddress;
|
||||||
|
tryRange.handlers.addAll(this.handlers);
|
||||||
append(tryRange);
|
append(tryRange);
|
||||||
|
|
||||||
this.endAddress = address;
|
this.endAddress = address;
|
||||||
@ -127,10 +128,6 @@ public class TryListBuilder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public TryListBuilder(CodeItem item)
|
|
||||||
{
|
|
||||||
} */
|
|
||||||
|
|
||||||
public Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> encodeTries(DexFile dexFile) {
|
public Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> encodeTries(DexFile dexFile) {
|
||||||
if (firstTryRange.next == lastTryRange) {
|
if (firstTryRange.next == lastTryRange) {
|
||||||
return new Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>>(null, null);
|
return new Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>>(null, null);
|
||||||
@ -217,13 +214,13 @@ public class TryListBuilder
|
|||||||
|
|
||||||
TryRange tryRange = firstTryRange.next;
|
TryRange tryRange = firstTryRange.next;
|
||||||
while (tryRange != lastTryRange) {
|
while (tryRange != lastTryRange) {
|
||||||
if (tryRange.startAddress == startAddress) {
|
if (startAddress == tryRange.startAddress) {
|
||||||
//|-----|
|
//|-----|
|
||||||
//^------
|
//^------
|
||||||
/*Bam. We hit the start of the range right on the head*/
|
/*Bam. We hit the start of the range right on the head*/
|
||||||
startRange = tryRange;
|
startRange = tryRange;
|
||||||
break;
|
break;
|
||||||
} else if (tryRange.startAddress < startAddress && tryRange.endAddress > startAddress) {
|
} else if (startAddress > tryRange.startAddress && startAddress < tryRange.endAddress) {
|
||||||
//|-----|
|
//|-----|
|
||||||
// ^----
|
// ^----
|
||||||
/*Almost. The start of the range being added is in the middle
|
/*Almost. The start of the range being added is in the middle
|
||||||
@ -231,14 +228,25 @@ public class TryListBuilder
|
|||||||
at the start address of the range being added*/
|
at the start address of the range being added*/
|
||||||
startRange = tryRange.split(startAddress);
|
startRange = tryRange.split(startAddress);
|
||||||
break;
|
break;
|
||||||
}else if (tryRange.startAddress > startAddress) {
|
}else if (startAddress < tryRange.startAddress) {
|
||||||
// |-----|
|
if (endAddress <= tryRange.startAddress) {
|
||||||
//^---------
|
// |-----|
|
||||||
/*Oops, too far! We've passed the start of the range being added.
|
//^--^
|
||||||
We need to add a new range just before this one*/
|
/*Oops, totally too far! The new range doesn't overlap any existing
|
||||||
startRange = new TryRange(startAddress, tryRange.startAddress);
|
ones, so we just add it and return*/
|
||||||
tryRange.prepend(startRange);
|
startRange = new TryRange(startAddress, endAddress);
|
||||||
break;
|
tryRange.prepend(startRange);
|
||||||
|
return new Pair<TryRange, TryRange>(startRange, startRange);
|
||||||
|
} else {
|
||||||
|
// |-----|
|
||||||
|
//^---------
|
||||||
|
/*Oops, too far! We've passed the start of the range being added, but
|
||||||
|
the new range does overlap this one. We need to add a new range just
|
||||||
|
before this one*/
|
||||||
|
startRange = new TryRange(startAddress, tryRange.startAddress);
|
||||||
|
tryRange.prepend(startRange);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tryRange = tryRange.next;
|
tryRange = tryRange.next;
|
||||||
@ -250,9 +258,9 @@ public class TryListBuilder
|
|||||||
end before the range being added starts. In either case, we just need
|
end before the range being added starts. In either case, we just need
|
||||||
to add a new range at the end of the list*/
|
to add a new range at the end of the list*/
|
||||||
if (startRange == null) {
|
if (startRange == null) {
|
||||||
TryRange newRange = new TryRange(startAddress, endAddress);
|
startRange = new TryRange(startAddress, endAddress);
|
||||||
lastTryRange.prepend(newRange);
|
lastTryRange.prepend(startRange);
|
||||||
return new Pair<TryRange, TryRange>(newRange, newRange);
|
return new Pair<TryRange, TryRange>(startRange, startRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
tryRange = startRange;
|
tryRange = startRange;
|
||||||
@ -302,6 +310,8 @@ public class TryListBuilder
|
|||||||
TryRange startRange = null;
|
TryRange startRange = null;
|
||||||
TryRange endRange = null;
|
TryRange endRange = null;
|
||||||
|
|
||||||
|
//TODO: need to check for pre-existing exception types in the handler list?
|
||||||
|
|
||||||
Pair<TryRange, TryRange> ranges = getBoundingRanges(startAddress, endAddress);
|
Pair<TryRange, TryRange> ranges = getBoundingRanges(startAddress, endAddress);
|
||||||
startRange = ranges.first;
|
startRange = ranges.first;
|
||||||
endRange = ranges.second;
|
endRange = ranges.second;
|
||||||
|
430
src/test/java/TryListBuilderTest.java
Normal file
430
src/test/java/TryListBuilderTest.java
Normal file
@ -0,0 +1,430 @@
|
|||||||
|
/*
|
||||||
|
* [The "BSD licence"]
|
||||||
|
* Copyright (c) 2009 Ben Gruver
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import org.JesusFreke.dexlib.util.TryListBuilder;
|
||||||
|
import org.JesusFreke.dexlib.util.Pair;
|
||||||
|
import org.JesusFreke.dexlib.TypeIdItem;
|
||||||
|
import org.JesusFreke.dexlib.DexFile;
|
||||||
|
import org.JesusFreke.dexlib.CodeItem;
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public class TryListBuilderTest
|
||||||
|
{
|
||||||
|
|
||||||
|
private static class Handler
|
||||||
|
{
|
||||||
|
public String type;
|
||||||
|
public int handlerAddress;
|
||||||
|
|
||||||
|
public Handler(String type, int handlerAddress) {
|
||||||
|
this.type = type;
|
||||||
|
this.handlerAddress = handlerAddress;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkTry(CodeItem.TryItem tryItem,
|
||||||
|
int startAddress,
|
||||||
|
int endAddress,
|
||||||
|
int catchAllAddress,
|
||||||
|
Handler[] handlers) {
|
||||||
|
|
||||||
|
Assert.assertTrue(tryItem.getStartAddress() == startAddress);
|
||||||
|
Assert.assertTrue(tryItem.getEndAddress() == endAddress);
|
||||||
|
|
||||||
|
CodeItem.EncodedCatchHandler encodedCatchHandler = tryItem.getHandler();
|
||||||
|
|
||||||
|
Assert.assertTrue(encodedCatchHandler.getCatchAllAddress() == catchAllAddress);
|
||||||
|
|
||||||
|
Assert.assertTrue(encodedCatchHandler.getHandlerCount() == handlers.length);
|
||||||
|
|
||||||
|
for (int i=0; i<handlers.length; i++) {
|
||||||
|
CodeItem.EncodedTypeAddrPair typeAddrPair = encodedCatchHandler.getHandler(i);
|
||||||
|
Handler handler = handlers[i];
|
||||||
|
|
||||||
|
Assert.assertTrue(typeAddrPair.getType().toString().compareTo(handler.type) == 0);
|
||||||
|
Assert.assertTrue(typeAddrPair.getHandlerAddress() == handler.handlerAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void singleTryTest() {
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem = new TypeIdItem(dexFile, "Ljava/lang/Exception;");
|
||||||
|
tryListBuilder.addHandler(typeIdItem, 2, 5, 100);
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 1);
|
||||||
|
checkTry(tries.get(0), 2, 5, -1, new Handler[]{new Handler("Ljava/lang/Exception;", 100)});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void singleTryWithCatchAllTest() {
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem = new TypeIdItem(dexFile, "Ljava/lang/Exception;");
|
||||||
|
tryListBuilder.addHandler(typeIdItem, 2, 5, 100);
|
||||||
|
|
||||||
|
tryListBuilder.addCatchAllHandler(2, 5, 101);
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 1);
|
||||||
|
checkTry(tries.get(0), 2, 5, 101, new Handler[]{new Handler("Ljava/lang/Exception;", 100)});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void twoTriesTest1() {
|
||||||
|
//|-----|
|
||||||
|
// |-----|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem = new TypeIdItem(dexFile, "Ljava/lang/Exception;");
|
||||||
|
tryListBuilder.addHandler(typeIdItem, 2, 5, 100);
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem, 5, 10, 101);
|
||||||
|
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 2);
|
||||||
|
checkTry(tries.get(0), 2, 5, -1, new Handler[]{new Handler("Ljava/lang/Exception;", 100)});
|
||||||
|
checkTry(tries.get(1), 5, 10, -1, new Handler[]{new Handler("Ljava/lang/Exception;", 101)});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void twoTriesTest2() {
|
||||||
|
//|-----|
|
||||||
|
// |-----|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem = new TypeIdItem(dexFile, "Ljava/lang/Exception;");
|
||||||
|
tryListBuilder.addHandler(typeIdItem, 2, 5, 100);
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem, 10, 15, 101);
|
||||||
|
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 2);
|
||||||
|
checkTry(tries.get(0), 2, 5, -1, new Handler[]{new Handler("Ljava/lang/Exception;", 100)});
|
||||||
|
checkTry(tries.get(1), 10, 15, -1, new Handler[]{new Handler("Ljava/lang/Exception;", 101)});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void twoTriesTest3() {
|
||||||
|
// |-----|
|
||||||
|
//|-----|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem = new TypeIdItem(dexFile, "Ljava/lang/Exception;");
|
||||||
|
tryListBuilder.addHandler(typeIdItem, 5, 10, 101);
|
||||||
|
tryListBuilder.addHandler(typeIdItem, 2, 5, 100);
|
||||||
|
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 2);
|
||||||
|
checkTry(tries.get(0), 2, 5, -1, new Handler[]{new Handler("Ljava/lang/Exception;", 100)});
|
||||||
|
checkTry(tries.get(1), 5, 10, -1, new Handler[]{new Handler("Ljava/lang/Exception;", 101)});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void twoTriesTest4() {
|
||||||
|
// |-----|
|
||||||
|
//|-----|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem = new TypeIdItem(dexFile, "Ljava/lang/Exception;");
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem, 10, 15, 101);
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem, 2, 5, 100);
|
||||||
|
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 2);
|
||||||
|
checkTry(tries.get(0), 2, 5, -1, new Handler[]{new Handler("Ljava/lang/Exception;", 100)});
|
||||||
|
checkTry(tries.get(1), 10, 15, -1, new Handler[]{new Handler("Ljava/lang/Exception;", 101)});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void twoTriesTest5() {
|
||||||
|
//|-----|
|
||||||
|
//|-----|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem1 = new TypeIdItem(dexFile, "Ljava/lang/Exception1;");
|
||||||
|
TypeIdItem typeIdItem2 = new TypeIdItem(dexFile, "Ljava/lang/Exception2;");
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem1, 2, 5, 100);
|
||||||
|
tryListBuilder.addHandler(typeIdItem2, 2, 5, 101);
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 1);
|
||||||
|
checkTry(tries.get(0), 2, 5, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100), new Handler("Ljava/lang/Exception2;", 101)});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void twoTriesTest6() {
|
||||||
|
//|-----|
|
||||||
|
// |-----|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem1 = new TypeIdItem(dexFile, "Ljava/lang/Exception1;");
|
||||||
|
TypeIdItem typeIdItem2 = new TypeIdItem(dexFile, "Ljava/lang/Exception2;");
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem1, 2, 5, 100);
|
||||||
|
tryListBuilder.addHandler(typeIdItem2, 4, 10, 101);
|
||||||
|
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 3);
|
||||||
|
checkTry(tries.get(0), 2, 4, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
checkTry(tries.get(1), 4, 5, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100), new Handler("Ljava/lang/Exception2;", 101)});
|
||||||
|
checkTry(tries.get(2), 5, 10, -1, new Handler[]{new Handler("Ljava/lang/Exception2;", 101)});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void twoTriesTest7() {
|
||||||
|
// |-----|
|
||||||
|
//|-----|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem1 = new TypeIdItem(dexFile, "Ljava/lang/Exception1;");
|
||||||
|
TypeIdItem typeIdItem2 = new TypeIdItem(dexFile, "Ljava/lang/Exception2;");
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem2, 4, 10, 101);
|
||||||
|
tryListBuilder.addHandler(typeIdItem1, 2, 5, 100);
|
||||||
|
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 3);
|
||||||
|
checkTry(tries.get(0), 2, 4, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
checkTry(tries.get(1), 4, 5, -1, new Handler[]{new Handler("Ljava/lang/Exception2;", 101), new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
checkTry(tries.get(2), 5, 10, -1, new Handler[]{new Handler("Ljava/lang/Exception2;", 101)});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void twoTriesTest8() {
|
||||||
|
//|-----|
|
||||||
|
// |---|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem1 = new TypeIdItem(dexFile, "Ljava/lang/Exception1;");
|
||||||
|
TypeIdItem typeIdItem2 = new TypeIdItem(dexFile, "Ljava/lang/Exception2;");
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem1, 2, 10, 100);
|
||||||
|
tryListBuilder.addHandler(typeIdItem2, 4, 6, 101);
|
||||||
|
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 3);
|
||||||
|
checkTry(tries.get(0), 2, 4, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
checkTry(tries.get(1), 4, 6, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100), new Handler("Ljava/lang/Exception2;", 101)});
|
||||||
|
checkTry(tries.get(2), 6, 10, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void twoTriesTest9() {
|
||||||
|
// |---|
|
||||||
|
//|-----|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem1 = new TypeIdItem(dexFile, "Ljava/lang/Exception1;");
|
||||||
|
TypeIdItem typeIdItem2 = new TypeIdItem(dexFile, "Ljava/lang/Exception2;");
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem2, 4, 6, 101);
|
||||||
|
tryListBuilder.addHandler(typeIdItem1, 2, 10, 100);
|
||||||
|
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 3);
|
||||||
|
checkTry(tries.get(0), 2, 4, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
checkTry(tries.get(1), 4, 6, -1, new Handler[]{new Handler("Ljava/lang/Exception2;", 101), new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
checkTry(tries.get(2), 6, 10, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void twoTriesTest10() {
|
||||||
|
//|-----|
|
||||||
|
//|---|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem1 = new TypeIdItem(dexFile, "Ljava/lang/Exception1;");
|
||||||
|
TypeIdItem typeIdItem2 = new TypeIdItem(dexFile, "Ljava/lang/Exception2;");
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem1, 2, 10, 100);
|
||||||
|
tryListBuilder.addHandler(typeIdItem2, 2, 6, 101);
|
||||||
|
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 2);
|
||||||
|
checkTry(tries.get(0), 2, 6, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100), new Handler("Ljava/lang/Exception2;", 101)});
|
||||||
|
checkTry(tries.get(1), 6, 10, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void twoTriesTest11() {
|
||||||
|
//|---|
|
||||||
|
//|-----|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem1 = new TypeIdItem(dexFile, "Ljava/lang/Exception1;");
|
||||||
|
TypeIdItem typeIdItem2 = new TypeIdItem(dexFile, "Ljava/lang/Exception2;");
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem2, 2, 6, 101);
|
||||||
|
tryListBuilder.addHandler(typeIdItem1, 2, 10, 100);
|
||||||
|
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 2);
|
||||||
|
checkTry(tries.get(0), 2, 6, -1, new Handler[]{new Handler("Ljava/lang/Exception2;", 101), new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
checkTry(tries.get(1), 6, 10, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void twoTriesTest12() {
|
||||||
|
//|-----|
|
||||||
|
// |---|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem1 = new TypeIdItem(dexFile, "Ljava/lang/Exception1;");
|
||||||
|
TypeIdItem typeIdItem2 = new TypeIdItem(dexFile, "Ljava/lang/Exception2;");
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem1, 2, 10, 100);
|
||||||
|
tryListBuilder.addHandler(typeIdItem2, 6, 10, 101);
|
||||||
|
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 2);
|
||||||
|
checkTry(tries.get(0), 2, 6, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
checkTry(tries.get(1), 6, 10, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100), new Handler("Ljava/lang/Exception2;", 101)});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void twoTriesTest13() {
|
||||||
|
// |---|
|
||||||
|
//|-----|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem1 = new TypeIdItem(dexFile, "Ljava/lang/Exception1;");
|
||||||
|
TypeIdItem typeIdItem2 = new TypeIdItem(dexFile, "Ljava/lang/Exception2;");
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem2, 6, 10, 101);
|
||||||
|
tryListBuilder.addHandler(typeIdItem1, 2, 10, 100);
|
||||||
|
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 2);
|
||||||
|
checkTry(tries.get(0), 2, 6, -1, new Handler[]{new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
checkTry(tries.get(1), 6, 10, -1, new Handler[]{new Handler("Ljava/lang/Exception2;", 101), new Handler("Ljava/lang/Exception1;", 100)});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void threeTriesTest1() {
|
||||||
|
// |-----|
|
||||||
|
// |-----|
|
||||||
|
//|--------------------|
|
||||||
|
TryListBuilder tryListBuilder = new TryListBuilder();
|
||||||
|
|
||||||
|
DexFile dexFile = DexFile.makeBlankDexFile();
|
||||||
|
TypeIdItem typeIdItem1 = new TypeIdItem(dexFile, "Ljava/lang/Exception1;");
|
||||||
|
TypeIdItem typeIdItem2 = new TypeIdItem(dexFile, "Ljava/lang/Exception2;");
|
||||||
|
TypeIdItem typeIdItem3= new TypeIdItem(dexFile, "Ljava/lang/Exception3;");
|
||||||
|
|
||||||
|
tryListBuilder.addHandler(typeIdItem1, 2, 4, 100);
|
||||||
|
tryListBuilder.addHandler(typeIdItem2, 6, 10, 101);
|
||||||
|
tryListBuilder.addHandler(typeIdItem3, 0, 12, 102);
|
||||||
|
|
||||||
|
Pair<List<CodeItem.TryItem>, List<CodeItem.EncodedCatchHandler>> retVal = tryListBuilder.encodeTries(dexFile);
|
||||||
|
List<CodeItem.TryItem> tries = retVal.first;
|
||||||
|
|
||||||
|
Handler handler1 = new Handler("Ljava/lang/Exception1;", 100);
|
||||||
|
Handler handler2 = new Handler("Ljava/lang/Exception2;", 101);
|
||||||
|
Handler handler3 = new Handler("Ljava/lang/Exception3;", 102);
|
||||||
|
|
||||||
|
Assert.assertTrue(tries.size() == 5);
|
||||||
|
checkTry(tries.get(0), 0, 2, -1, new Handler[]{handler3});
|
||||||
|
checkTry(tries.get(1), 2, 4, -1, new Handler[]{handler1, handler3});
|
||||||
|
checkTry(tries.get(2), 4, 6, -1, new Handler[]{handler3});
|
||||||
|
checkTry(tries.get(3), 6, 10, -1, new Handler[]{handler2, handler3});
|
||||||
|
checkTry(tries.get(4), 10, 12, -1, new Handler[]{handler3});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user