blob: 19a87e3a01f63846f91fbc7d91514de6ca7f86f7 [file]
/*
* Copyright (C) 2026 The Android Open Source Project
*
* 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.
*/
#include "Optimize.h"
#include "LoadedApk.h"
#include "cmd/Convert.h"
#include "test/Common.h"
#include "test/Test.h"
namespace aapt {
using namespace aapt::test;
using OptimizeTest = CommandTestFixture;
TEST_F(OptimizeTest, ProtoToBinaryKeepsCompressionOptimize) {
StdErrDiagnostics diag;
const std::string compiled_files_dir = GetTestPath("compiled");
ASSERT_TRUE(
CompileFile(GetTestPath("res/xml/test.xml"), "<a b=\"c\"/>", compiled_files_dir, &diag));
const std::string proto_apk = GetTestPath("proto.apk");
ASSERT_TRUE(Link({"--manifest", GetDefaultManifest(), "-o", proto_apk, "--proto-format"},
compiled_files_dir, &diag));
const std::string optimized_apk = GetTestPath("optimized.apk");
ASSERT_THAT(OptimizeCommand().Execute({"-o", optimized_apk, proto_apk}, &std::cerr),
testing::Eq(0));
const std::string binary_apk = GetTestPath("binary.apk");
ASSERT_THAT(ConvertCommand().Execute(
{"-o", binary_apk, "--output-format", "binary", optimized_apk}, &std::cerr),
testing::Eq(0));
std::unique_ptr<LoadedApk> apk = LoadedApk::LoadApkFromPath(binary_apk, &diag);
ASSERT_NE(apk, nullptr);
io::IFile* file = apk->GetFileCollection()->FindFile("res/xml/test.xml");
ASSERT_NE(file, nullptr);
EXPECT_TRUE(file->WasCompressed());
}
} // namespace aapt