Back to Repositories

Testing Android Oreo Sparse Resource Handling in Apktool

This test suite validates Android Oreo sparse resource handling in Apktool, focusing on APK decoding and building operations with AAPT1. It verifies proper handling of sparse resources introduced in Android 8.0 (Oreo) and ensures compatibility with version-specific resource files.

Test Coverage Overview

The test suite provides comprehensive coverage of sparse resource handling in Android Oreo applications.

Key areas tested include:
  • APK decoding and rebuilding process
  • Directory structure verification
  • Version-specific resource file handling (values-v26)
  • AAPT1 compatibility with sparse resources

Implementation Analysis

The testing approach utilizes JUnit framework with a structured setup-execute-verify pattern. The implementation leverages BeforeClass for test environment preparation and individual test methods for specific validations.

Technical patterns include:
  • Resource directory copying and verification
  • APK manipulation through ApkDecoder and ApkBuilder
  • File system operations validation

Technical Details

Testing infrastructure includes:
  • JUnit 4 testing framework
  • Custom BaseTest extension
  • ExtFile utility for enhanced file operations
  • TestUtils for resource management
  • Configured AAPT1 version setting
  • Temporary directory management for test artifacts

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Proper test setup isolation using BeforeClass
  • Clear test method naming conventions
  • Specific assertion checks
  • Resource cleanup management
  • Logging for test progression tracking
  • Modular test case organization

ibotpeaches/apktool

brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/AndroidOreoSparseTest.java

            
/*
 *  Copyright (C) 2010 Ryszard Wiśniewski <[email protected]>
 *  Copyright (C) 2010 Connor Tumbleson <[email protected]>
 *
 *  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
 *
 *       https://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.aapt1;

import brut.androlib.ApkBuilder;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.directory.ExtFile;
import brut.common.BrutException;

import java.io.File;

import org.junit.*;
import static org.junit.Assert.*;

public class AndroidOreoSparseTest extends BaseTest {

    @BeforeClass
    public static void beforeClass() throws Exception {
        sTestOrigDir = new ExtFile(sTmpDir, "issue1594-orig");
        sTestNewDir = new ExtFile(sTmpDir, "issue1594-new");

        LOGGER.info("Unpacking sparse.apk...");
        TestUtils.copyResourceDir(AndroidOreoSparseTest.class, "aapt1/issue1594", sTestOrigDir);

        sConfig.setAaptVersion(1);

        LOGGER.info("Decoding sparse.apk...");
        ExtFile testApk = new ExtFile(sTestOrigDir, "sparse.apk");
        new ApkDecoder(testApk, sConfig).decode(sTestNewDir);

        LOGGER.info("Building sparse.apk...");
        new ApkBuilder(sTestNewDir, sConfig).build(testApk);
    }

    @Test
    public void buildAndDecodeTest() {
        assertTrue(sTestNewDir.isDirectory());
        assertTrue(sTestOrigDir.isDirectory());
    }

    @Test
    public void ensureStringsOreoTest() {
        assertTrue(new File(sTestNewDir, "res/values-v26/strings.xml").isFile());
    }
}