Skip to content

Commit

Permalink
Adapt tests
Browse files Browse the repository at this point in the history
Summary: Adapt for other storage schema of extracted resource files.

Reviewed By: wsanville

Differential Revision: D48470692

fbshipit-source-id: 5ac0b7f7a3b5ae580cad75c91e57387b53ed9f78
  • Loading branch information
agampe authored and facebook-github-bot committed Aug 18, 2023
1 parent 4a35181 commit 3829e35
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions test/instr/ApkDedupResourceVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ const std::vector<std::string> REMOVED_FILE_PATHS = {
} // namespace

TEST_F(PreVerify, ApkDedupResourceTest) {
const auto& resource_arsc_file = resources["resources.arsc"];
const auto& resource_arsc_file = resources.at("resources.arsc");
auto res_table = ResourcesArscFile(resource_arsc_file);
dedupresource_preverify(classes, &res_table);
}

TEST_F(PostVerify, ApkDedupResourceTest) {
const auto& resource_arsc_file = resources["resources.arsc"];
const auto& resource_arsc_file = resources.at("resources.arsc");
auto res_table = ResourcesArscFile(resource_arsc_file);
dedupresource_postverify(classes, &res_table);
// Perform post validation only relevant to .apk files.
Expand Down
4 changes: 2 additions & 2 deletions test/instr/ApkObfuscateResourcesVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#include "ObfuscateResourcesVerifyHelper.h"

TEST_F(PreVerify, ApkObfuscateResourceTest) {
const auto& resource_arsc_file = resources["resources.arsc"];
const auto& resource_arsc_file = resources.at("resources.arsc");
auto res_table = ResourcesArscFile(resource_arsc_file);
obfuscateresource_preverify(&res_table);
}

TEST_F(PostVerify, ApkObfuscateResourceTest) {
const auto& resource_arsc_file = resources["resources.arsc"];
const auto& resource_arsc_file = resources.at("resources.arsc");
auto res_table = ResourcesArscFile(resource_arsc_file);
obfuscateresource_postverify(&res_table);

Expand Down
4 changes: 2 additions & 2 deletions test/instr/ApkOptimizeResourcesNullifyVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#include "OptimizeResourcesVerifyImpl.h"

TEST_F(PreVerify, ApkOptimizeResourcesTest) {
const auto& resource_arsc_file = resources["resources.arsc"];
const auto& resource_arsc_file = resources.at("resources.arsc");
auto res_table = ResourcesArscFile(resource_arsc_file);
preverify_nullify_impl(classes, &res_table);
}

TEST_F(PostVerify, ApkOptimizeResourcesTest) {
const auto& resource_arsc_file = resources["resources.arsc"];
const auto& resource_arsc_file = resources.at("resources.arsc");
auto res_table = ResourcesArscFile(resource_arsc_file);
postverify_nullify_impl(classes, &res_table);
// Perform post validation only relevant to .apk files.
Expand Down
4 changes: 2 additions & 2 deletions test/instr/ApkOptimizeResourcesVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#include "OptimizeResourcesVerifyImpl.h"

TEST_F(PreVerify, ApkOptimizeResourcesTest) {
const auto& resource_arsc_file = resources["resources.arsc"];
const auto& resource_arsc_file = resources.at("resources.arsc");
auto res_table = ResourcesArscFile(resource_arsc_file);
preverify_impl(classes, &res_table);
}

TEST_F(PostVerify, ApkOptimizeResourcesTest) {
const auto& resource_arsc_file = resources["resources.arsc"];
const auto& resource_arsc_file = resources.at("resources.arsc");
auto res_table = ResourcesArscFile(resource_arsc_file);
postverify_impl(classes, &res_table);
// Perform post validation only relevant to .apk files.
Expand Down
2 changes: 1 addition & 1 deletion test/instr/ApkSplitResourceTablesVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "verify/VerifyUtil.h"

TEST_F(PostVerify, VerifyNewTypeCreated) {
auto resources_path = resources["resources.arsc"];
auto resources_path = resources.at("resources.arsc");
ResourcesArscFile arsc_file(resources_path);
auto& table_snapshot = arsc_file.get_table_snapshot();
// Actual lookup, data type validation will differ for .apk. Do that in the
Expand Down
16 changes: 15 additions & 1 deletion test/instr/VerifyUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/regex.hpp>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <gtest/gtest.h>
#include <sstream>
Expand Down Expand Up @@ -168,17 +169,30 @@ ResourceFiles decode_resource_paths(const char* location, const char* suffix) {
ResourceFiles files;
std::istringstream input;
input.str(location);

std::string long_suffix = suffix + std::string("__/out");
auto match_dir = [&suffix, &long_suffix](const auto& path) {
if (boost::algorithm::ends_with(path, suffix)) {
return true;
}
return boost::algorithm::ends_with(path, long_suffix);
};

for (std::string file_path; std::getline(input, file_path, ':');) {
auto pos = file_path.rfind('/');
always_assert(pos >= 0 && pos + 1 < file_path.length());
auto directory = file_path.substr(0, pos);
if (boost::algorithm::ends_with(directory, suffix)) {
if (match_dir(directory)) {
auto original_name = file_path.substr(pos + 1);
// Undo simple escaping at buck_imports/redex_utils
boost::replace_all(original_name, "zC", ":");
boost::replace_all(original_name, "zS", "/");
boost::replace_all(original_name, "zZ", "z");
files.emplace(original_name, file_path);
always_assert_log(std::filesystem::exists(file_path),
"%s -> %s does not exist!",
original_name.c_str(),
file_path.c_str());
}
}
return files;
Expand Down

0 comments on commit 3829e35

Please sign in to comment.