diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java index b8d07ce6..79e55f5b 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java @@ -307,7 +307,7 @@ final public class AndrolibResources { mSharedLibrary = flag; } - private String checkTargetSdkVersionBounds() { + public String checkTargetSdkVersionBounds() { int target = Integer.parseInt(mTargetSdkVersion); int min = (mMinSdkVersion != null) ? Integer.parseInt(mMinSdkVersion) : 0; int max = (mMaxSdkVersion != null) ? Integer.parseInt(mMaxSdkVersion) : target; diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/InvalidSdkBoundingTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/InvalidSdkBoundingTest.java new file mode 100644 index 00000000..87100dae --- /dev/null +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/InvalidSdkBoundingTest.java @@ -0,0 +1,78 @@ +/** + * Copyright (C) 2017 Ryszard Wiśniewski + * Copyright (C) 2017 Connor Tumbleson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package brut.androlib; + +import brut.androlib.res.AndrolibResources; +import brut.common.BrutException; +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.junit.*; + +import static org.junit.Assert.assertEquals; + +public class InvalidSdkBoundingTest { + + @Test + public void checkIfInvalidValuesPass() throws BrutException, IOException { + AndrolibResources androlibResources = new AndrolibResources(); + + Map sdkInfo = new LinkedHashMap<>(); + sdkInfo.put("minSdkVersion", "15"); + sdkInfo.put("targetSdkVersion", "25"); + sdkInfo.put("maxSdkVersion", "19"); + + androlibResources.setSdkInfo(sdkInfo); + assertEquals("19", androlibResources.checkTargetSdkVersionBounds()); + } + + @Test + public void checkIfMissingMinPasses() throws BrutException, IOException { + AndrolibResources androlibResources = new AndrolibResources(); + + Map sdkInfo = new LinkedHashMap<>(); + sdkInfo.put("targetSdkVersion", "25"); + sdkInfo.put("maxSdkVersion", "19"); + + androlibResources.setSdkInfo(sdkInfo); + assertEquals("19", androlibResources.checkTargetSdkVersionBounds()); + } + + @Test + public void checkIfMissingMaxPasses() throws BrutException, IOException { + AndrolibResources androlibResources = new AndrolibResources(); + + Map sdkInfo = new LinkedHashMap<>(); + sdkInfo.put("minSdkVersion", "15"); + sdkInfo.put("targetSdkVersion", "25"); + + androlibResources.setSdkInfo(sdkInfo); + assertEquals("25", androlibResources.checkTargetSdkVersionBounds()); + } + + @Test + public void checkIfMissingBothPasses() throws BrutException, IOException { + AndrolibResources androlibResources = new AndrolibResources(); + + Map sdkInfo = new LinkedHashMap<>(); + sdkInfo.put("targetSdkVersion", "25"); + + androlibResources.setSdkInfo(sdkInfo); + assertEquals("25", androlibResources.checkTargetSdkVersionBounds()); + } +} \ No newline at end of file