Back to Repositories

Testing Large Integer Manifest Processing in Apktool

This test suite validates the handling of large integer values in Android manifest files using AAPT1 in Apktool. It ensures proper decoding and rebuilding of APKs containing manifest files with large integer values, maintaining data integrity throughout the process.

Test Coverage Overview

The test suite focuses on verifying the correct handling of large integers in Android manifest files during APK processing. It covers:

  • Decoding of APKs containing large integer values
  • Rebuilding processed APK files
  • Verification of manifest file integrity
  • Edge case handling for integer overflow scenarios

Implementation Analysis

The testing approach utilizes JUnit framework for systematic validation of AAPT1 functionality. The implementation employs a before-after comparison pattern, where an APK is decoded and rebuilt, then compared with the original to ensure data consistency.

Key technical aspects include:
  • ExtFile usage for APK manipulation
  • ApkDecoder and ApkBuilder integration
  • XML comparison utilities

Technical Details

Testing infrastructure includes:

  • JUnit testing framework
  • AAPT1 configuration settings
  • Custom TestUtils for resource management
  • BrutException handling
  • File system operations for APK manipulation

Best Practices Demonstrated

The test implementation showcases several testing best practices:

  • Proper test setup using @BeforeClass annotation
  • Isolated test environment with temporary directories
  • Clear test case naming convention
  • Comprehensive validation of processing steps
  • Proper resource cleanup and management

ibotpeaches/apktool

brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/LargeIntsInManifestTest.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 java.io.IOException;

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

public class LargeIntsInManifestTest extends BaseTest {
    private static final String TEST_APK = "issue767.apk";

    @BeforeClass
    public static void beforeClass() throws Exception {
        TestUtils.copyResourceDir(LargeIntsInManifestTest.class, "aapt1/issue767", sTmpDir);
    }

    @Test
    public void checkIfLargeIntsAreHandledTest() throws BrutException {
        sConfig.setAaptVersion(1);

        ExtFile testApk = new ExtFile(sTmpDir, TEST_APK);
        ExtFile testDir = new ExtFile(testApk + ".out");
        new ApkDecoder(testApk, sConfig).decode(testDir);

        new ApkBuilder(testDir, sConfig).build(null);

        ExtFile newApk = new ExtFile(testDir, "dist/" + testApk.getName());
        ExtFile newDir = new ExtFile(testApk + ".out.new");
        new ApkDecoder(newApk, sConfig).decode(newDir);

        compareXmlFiles(testDir, newDir, "AndroidManifest.xml");
    }
}