diff options
author | 2018-11-29 09:53:17 +0100 | |
---|---|---|
committer | 2018-12-20 15:29:06 -0800 | |
commit | b877902199770b5c6b70c796394fd5f6f45ac536 (patch) | |
tree | 1cc0b87369e9916f71776c8103b21d6841fc9e10 | |
parent | fe88a7d7f2915c44107f35f3ce5a7917896ed075 (diff) |
idmap2: fix clang-tidy warnings [readability-*]
Bug: 120024673
Test: mmm frameworks/base/cmds/idmap2; check output
Change-Id: I1565afac8d34e4347d8c946228d1134211e8b435
22 files changed, 160 insertions, 135 deletions
diff --git a/cmds/idmap2/idmap2/Create.cpp b/cmds/idmap2/idmap2/Create.cpp index 291eaeb9c211..b07567331e85 100644 --- a/cmds/idmap2/idmap2/Create.cpp +++ b/cmds/idmap2/idmap2/Create.cpp @@ -32,9 +32,12 @@ using android::ApkAssets; using android::idmap2::BinaryStreamVisitor; using android::idmap2::CommandLineOptions; using android::idmap2::Idmap; +using android::idmap2::utils::kIdmapFilePermissionMask; bool Create(const std::vector<std::string>& args, std::ostream& out_error) { - std::string target_apk_path, overlay_apk_path, idmap_path; + std::string target_apk_path; + std::string overlay_apk_path; + std::string idmap_path; const CommandLineOptions opts = CommandLineOptions("idmap2 create") @@ -68,7 +71,7 @@ bool Create(const std::vector<std::string>& args, std::ostream& out_error) { return false; } - umask(0133); // u=rw,g=r,o=r + umask(kIdmapFilePermissionMask); std::ofstream fout(idmap_path); if (fout.fail()) { out_error << "failed to open idmap path " << idmap_path << std::endl; diff --git a/cmds/idmap2/idmap2/Lookup.cpp b/cmds/idmap2/idmap2/Lookup.cpp index 8d0cee5b938d..cfb5dd5b30a9 100644 --- a/cmds/idmap2/idmap2/Lookup.cpp +++ b/cmds/idmap2/idmap2/Lookup.cpp @@ -63,10 +63,12 @@ namespace { Result<ResourceId> WARN_UNUSED ParseResReference(const AssetManager2& am, const std::string& res, const std::string& fallback_package) { + static constexpr const int kBaseHex = 16; + // first, try to parse as a hex number char* endptr = nullptr; ResourceId resid; - resid = strtol(res.c_str(), &endptr, 16); + resid = strtol(res.c_str(), &endptr, kBaseHex); if (*endptr == '\0') { return {resid}; } @@ -155,7 +157,9 @@ Result<std::string> GetTargetPackageNameFromManifest(const std::string& apk_path bool Lookup(const std::vector<std::string>& args, std::ostream& out_error) { std::vector<std::string> idmap_paths; - std::string config_str, resid_str; + std::string config_str; + std::string resid_str; + const CommandLineOptions opts = CommandLineOptions("idmap2 lookup") .MandatoryOption("--idmap-path", "input: path to idmap file to load", &idmap_paths) diff --git a/cmds/idmap2/idmap2/Main.cpp b/cmds/idmap2/idmap2/Main.cpp index 5d9ea778915a..8eaf05f5fac7 100644 --- a/cmds/idmap2/idmap2/Main.cpp +++ b/cmds/idmap2/idmap2/Main.cpp @@ -29,7 +29,7 @@ using android::idmap2::CommandLineOptions; -typedef std::map<std::string, std::function<int(const std::vector<std::string>&, std::ostream&)>> +typedef std::map<std::string, std::function<bool(const std::vector<std::string>&, std::ostream&)>> NameToFunctionMap; static void PrintUsage(const NameToFunctionMap& commands, std::ostream& out) { diff --git a/cmds/idmap2/idmap2/Scan.cpp b/cmds/idmap2/idmap2/Scan.cpp index 00c49e38e8b2..ef560d1ee710 100644 --- a/cmds/idmap2/idmap2/Scan.cpp +++ b/cmds/idmap2/idmap2/Scan.cpp @@ -44,7 +44,7 @@ std::unique_ptr<std::vector<std::string>> FindApkFiles(const std::vector<std::st const auto predicate = [](unsigned char type, const std::string& path) -> bool { static constexpr size_t kExtLen = 4; // strlen(".apk") return type == DT_REG && path.size() > kExtLen && - !path.compare(path.size() - kExtLen, kExtLen, ".apk"); + path.compare(path.size() - kExtLen, kExtLen, ".apk") == 0; }; // pass apk paths through a set to filter out duplicates std::set<std::string> paths; @@ -63,7 +63,9 @@ std::unique_ptr<std::vector<std::string>> FindApkFiles(const std::vector<std::st bool Scan(const std::vector<std::string>& args, std::ostream& out_error) { std::vector<std::string> input_directories; - std::string target_package_name, target_apk_path, output_directory; + std::string target_package_name; + std::string target_apk_path; + std::string output_directory; bool recursive = false; const CommandLineOptions opts = @@ -112,7 +114,7 @@ bool Scan(const std::vector<std::string>& args, std::ostream& out_error) { } auto iter = tag->find("isStatic"); - if (iter == tag->end() || std::stoul(iter->second) == 0u) { + if (iter == tag->end() || std::stoul(iter->second) == 0U) { continue; } diff --git a/cmds/idmap2/idmap2/Verify.cpp b/cmds/idmap2/idmap2/Verify.cpp index b5fa438b5b9f..4d4a0e769174 100644 --- a/cmds/idmap2/idmap2/Verify.cpp +++ b/cmds/idmap2/idmap2/Verify.cpp @@ -27,6 +27,7 @@ using android::idmap2::IdmapHeader; bool Verify(const std::vector<std::string>& args, std::ostream& out_error) { std::string idmap_path; + const CommandLineOptions opts = CommandLineOptions("idmap2 verify") .MandatoryOption("--idmap-path", "input: path to idmap file to verify", &idmap_path); diff --git a/cmds/idmap2/idmap2d/Idmap2Service.cpp b/cmds/idmap2/idmap2d/Idmap2Service.cpp index 86b00f1d6e95..7b16093434fb 100644 --- a/cmds/idmap2/idmap2d/Idmap2Service.cpp +++ b/cmds/idmap2/idmap2d/Idmap2Service.cpp @@ -39,10 +39,11 @@ using android::binder::Status; using android::idmap2::BinaryStreamVisitor; using android::idmap2::Idmap; using android::idmap2::IdmapHeader; +using android::idmap2::utils::kIdmapFilePermissionMask; namespace { -static constexpr const char* kIdmapCacheDir = "/data/resource-cache"; +constexpr const char* kIdmapCacheDir = "/data/resource-cache"; Status ok() { return Status::ok(); @@ -69,13 +70,12 @@ Status Idmap2Service::removeIdmap(const std::string& overlay_apk_path, int32_t user_id ATTRIBUTE_UNUSED, bool* _aidl_return) { assert(_aidl_return); const std::string idmap_path = Idmap::CanonicalIdmapPathFor(kIdmapCacheDir, overlay_apk_path); - if (unlink(idmap_path.c_str()) == 0) { - *_aidl_return = true; - return ok(); - } else { + if (unlink(idmap_path.c_str()) != 0) { *_aidl_return = false; return error("failed to unlink " + idmap_path + ": " + strerror(errno)); } + *_aidl_return = true; + return ok(); } Status Idmap2Service::verifyIdmap(const std::string& overlay_apk_path, @@ -119,7 +119,7 @@ Status Idmap2Service::createIdmap(const std::string& target_apk_path, return error(err.str()); } - umask(0133); // u=rw,g=r,o=r + umask(kIdmapFilePermissionMask); const std::string idmap_path = Idmap::CanonicalIdmapPathFor(kIdmapCacheDir, overlay_apk_path); std::ofstream fout(idmap_path); if (fout.fail()) { diff --git a/cmds/idmap2/idmap2d/Main.cpp b/cmds/idmap2/idmap2d/Main.cpp index d64a87b8ee15..4393dcc130ec 100644 --- a/cmds/idmap2/idmap2d/Main.cpp +++ b/cmds/idmap2/idmap2d/Main.cpp @@ -37,7 +37,7 @@ using android::status_t; using android::os::Idmap2Service; int main(int argc ATTRIBUTE_UNUSED, char** argv ATTRIBUTE_UNUSED) { - IPCThreadState::self()->disableBackgroundScheduling(true); + IPCThreadState::disableBackgroundScheduling(true); status_t ret = BinderService<Idmap2Service>::publish(); if (ret != android::OK) { return EXIT_FAILURE; diff --git a/cmds/idmap2/include/idmap2/FileUtils.h b/cmds/idmap2/include/idmap2/FileUtils.h index 05c6d31d395d..84cc69a95ac5 100644 --- a/cmds/idmap2/include/idmap2/FileUtils.h +++ b/cmds/idmap2/include/idmap2/FileUtils.h @@ -25,6 +25,9 @@ namespace android { namespace idmap2 { namespace utils { + +constexpr const mode_t kIdmapFilePermissionMask = 0133; // u=rw,g=r,o=r + typedef std::function<bool(unsigned char type /* DT_* from dirent.h */, const std::string& path)> FindFilesPredicate; std::unique_ptr<std::vector<std::string>> FindFiles(const std::string& root, bool recurse, diff --git a/cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp b/cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp index 29969a23250b..b7765bc3d836 100644 --- a/cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp +++ b/cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp @@ -64,15 +64,15 @@ void BinaryStreamVisitor::visit(const IdmapData::Header& header) { Write16(header.GetTypeCount()); } -void BinaryStreamVisitor::visit(const IdmapData::TypeEntry& te) { - const uint16_t entryCount = te.GetEntryCount(); +void BinaryStreamVisitor::visit(const IdmapData::TypeEntry& type_entry) { + const uint16_t entryCount = type_entry.GetEntryCount(); - Write16(te.GetTargetTypeId()); - Write16(te.GetOverlayTypeId()); + Write16(type_entry.GetTargetTypeId()); + Write16(type_entry.GetOverlayTypeId()); Write16(entryCount); - Write16(te.GetEntryOffset()); + Write16(type_entry.GetEntryOffset()); for (uint16_t i = 0; i < entryCount; i++) { - EntryId entry_id = te.GetEntry(i); + EntryId entry_id = type_entry.GetEntry(i); Write32(entry_id != kNoEntry ? static_cast<uint32_t>(entry_id) : kPadding); } } diff --git a/cmds/idmap2/libidmap2/FileUtils.cpp b/cmds/idmap2/libidmap2/FileUtils.cpp index 4ac4c04d0bfc..88d40d1f523d 100644 --- a/cmds/idmap2/libidmap2/FileUtils.cpp +++ b/cmds/idmap2/libidmap2/FileUtils.cpp @@ -34,12 +34,12 @@ namespace utils { std::unique_ptr<std::vector<std::string>> FindFiles(const std::string& root, bool recurse, const FindFilesPredicate& predicate) { DIR* dir = opendir(root.c_str()); - if (!dir) { + if (dir == nullptr) { return nullptr; } std::unique_ptr<std::vector<std::string>> vector(new std::vector<std::string>()); struct dirent* dirent; - while ((dirent = readdir(dir))) { + while ((dirent = readdir(dir)) != nullptr) { const std::string path = root + "/" + dirent->d_name; if (predicate(dirent->d_type, path)) { vector->push_back(path); @@ -68,8 +68,10 @@ std::unique_ptr<std::string> ReadFile(const std::string& path) { } std::unique_ptr<std::string> ReadFile(int fd) { + static constexpr const size_t kBufSize = 1024; + std::unique_ptr<std::string> str(new std::string()); - char buf[1024]; + char buf[kBufSize]; ssize_t r; while ((r = read(fd, buf, sizeof(buf))) > 0) { str->append(buf, r); diff --git a/cmds/idmap2/libidmap2/Idmap.cpp b/cmds/idmap2/libidmap2/Idmap.cpp index 1ef326793cb4..0ddc224d032f 100644 --- a/cmds/idmap2/libidmap2/Idmap.cpp +++ b/cmds/idmap2/libidmap2/Idmap.cpp @@ -196,8 +196,9 @@ std::unique_ptr<const IdmapData::Header> IdmapData::Header::FromBinaryStream(std std::unique_ptr<const IdmapData::TypeEntry> IdmapData::TypeEntry::FromBinaryStream( std::istream& stream) { std::unique_ptr<IdmapData::TypeEntry> data(new IdmapData::TypeEntry()); - - uint16_t target_type16, overlay_type16, entry_count; + uint16_t target_type16; + uint16_t overlay_type16; + uint16_t entry_count; if (!Read16(stream, &target_type16) || !Read16(stream, &overlay_type16) || !Read16(stream, &entry_count) || !Read16(stream, &data->entry_offset_)) { return nullptr; @@ -282,25 +283,25 @@ std::unique_ptr<const Idmap> Idmap::FromApkAssets(const std::string& target_apk_ } const LoadedArsc* target_arsc = target_apk_assets.GetLoadedArsc(); - if (!target_arsc) { + if (target_arsc == nullptr) { out_error << "error: failed to load target resources.arsc" << std::endl; return nullptr; } const LoadedArsc* overlay_arsc = overlay_apk_assets.GetLoadedArsc(); - if (!overlay_arsc) { + if (overlay_arsc == nullptr) { out_error << "error: failed to load overlay resources.arsc" << std::endl; return nullptr; } const LoadedPackage* target_pkg = GetPackageAtIndex0(*target_arsc); - if (!target_pkg) { + if (target_pkg == nullptr) { out_error << "error: failed to load target package from resources.arsc" << std::endl; return nullptr; } const LoadedPackage* overlay_pkg = GetPackageAtIndex0(*overlay_arsc); - if (!overlay_pkg) { + if (overlay_pkg == nullptr) { out_error << "error: failed to load overlay package from resources.arsc" << std::endl; return nullptr; } diff --git a/cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp b/cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp index fb3bc5ba9ae8..b36df24a0da7 100644 --- a/cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp +++ b/cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp @@ -49,17 +49,18 @@ void PrettyPrintVisitor::visit(const IdmapData::Header& header ATTRIBUTE_UNUSED) last_seen_package_id_ = header.GetTargetPackageId(); } -void PrettyPrintVisitor::visit(const IdmapData::TypeEntry& te) { +void PrettyPrintVisitor::visit(const IdmapData::TypeEntry& type_entry) { const bool target_package_loaded = !target_am_.GetApkAssets().empty(); - for (uint16_t i = 0; i < te.GetEntryCount(); i++) { - const EntryId entry = te.GetEntry(i); + for (uint16_t i = 0; i < type_entry.GetEntryCount(); i++) { + const EntryId entry = type_entry.GetEntry(i); if (entry == kNoEntry) { continue; } const ResourceId target_resid = - RESID(last_seen_package_id_, te.GetTargetTypeId(), te.GetEntryOffset() + i); - const ResourceId overlay_resid = RESID(last_seen_package_id_, te.GetOverlayTypeId(), entry); + RESID(last_seen_package_id_, type_entry.GetTargetTypeId(), type_entry.GetEntryOffset() + i); + const ResourceId overlay_resid = + RESID(last_seen_package_id_, type_entry.GetOverlayTypeId(), entry); stream_ << base::StringPrintf("0x%08x -> 0x%08x", target_resid, overlay_resid); if (target_package_loaded) { diff --git a/cmds/idmap2/libidmap2/RawPrintVisitor.cpp b/cmds/idmap2/libidmap2/RawPrintVisitor.cpp index 7c24445ef902..a6bf5fb6e687 100644 --- a/cmds/idmap2/libidmap2/RawPrintVisitor.cpp +++ b/cmds/idmap2/libidmap2/RawPrintVisitor.cpp @@ -59,22 +59,23 @@ void RawPrintVisitor::visit(const IdmapData::Header& header) { last_seen_package_id_ = header.GetTargetPackageId(); } -void RawPrintVisitor::visit(const IdmapData::TypeEntry& te) { +void RawPrintVisitor::visit(const IdmapData::TypeEntry& type_entry) { const bool target_package_loaded = !target_am_.GetApkAssets().empty(); - print(static_cast<uint16_t>(te.GetTargetTypeId()), "target type"); - print(static_cast<uint16_t>(te.GetOverlayTypeId()), "overlay type"); - print(static_cast<uint16_t>(te.GetEntryCount()), "entry count"); - print(static_cast<uint16_t>(te.GetEntryOffset()), "entry offset"); + print(static_cast<uint16_t>(type_entry.GetTargetTypeId()), "target type"); + print(static_cast<uint16_t>(type_entry.GetOverlayTypeId()), "overlay type"); + print(static_cast<uint16_t>(type_entry.GetEntryCount()), "entry count"); + print(static_cast<uint16_t>(type_entry.GetEntryOffset()), "entry offset"); - for (uint16_t i = 0; i < te.GetEntryCount(); i++) { - const EntryId entry = te.GetEntry(i); + for (uint16_t i = 0; i < type_entry.GetEntryCount(); i++) { + const EntryId entry = type_entry.GetEntry(i); if (entry == kNoEntry) { print(kPadding, "no entry"); } else { - const ResourceId target_resid = - RESID(last_seen_package_id_, te.GetTargetTypeId(), te.GetEntryOffset() + i); - const ResourceId overlay_resid = RESID(last_seen_package_id_, te.GetOverlayTypeId(), entry); + const ResourceId target_resid = RESID(last_seen_package_id_, type_entry.GetTargetTypeId(), + type_entry.GetEntryOffset() + i); + const ResourceId overlay_resid = + RESID(last_seen_package_id_, type_entry.GetOverlayTypeId(), entry); Result<std::string> name; if (target_package_loaded) { name = utils::ResToTypeEntryName(target_am_, target_resid); diff --git a/cmds/idmap2/tests/BinaryStreamVisitorTests.cpp b/cmds/idmap2/tests/BinaryStreamVisitorTests.cpp index 8b552dcc1265..a6c7ed582001 100644 --- a/cmds/idmap2/tests/BinaryStreamVisitorTests.cpp +++ b/cmds/idmap2/tests/BinaryStreamVisitorTests.cpp @@ -52,14 +52,14 @@ TEST(BinaryStreamVisitorTests, CreateBinaryStreamViaBinaryStreamVisitor) { ASSERT_EQ(idmap1->GetHeader()->GetTargetCrc(), idmap2->GetHeader()->GetTargetCrc()); ASSERT_EQ(idmap1->GetHeader()->GetTargetPath(), idmap2->GetHeader()->GetTargetPath()); - ASSERT_EQ(idmap1->GetData().size(), 1u); + ASSERT_EQ(idmap1->GetData().size(), 1U); ASSERT_EQ(idmap1->GetData().size(), idmap2->GetData().size()); const auto& data1 = idmap1->GetData()[0]; const auto& data2 = idmap2->GetData()[0]; ASSERT_EQ(data1->GetHeader()->GetTargetPackageId(), data2->GetHeader()->GetTargetPackageId()); - ASSERT_EQ(data1->GetTypeEntries().size(), 2u); + ASSERT_EQ(data1->GetTypeEntries().size(), 2U); ASSERT_EQ(data1->GetTypeEntries().size(), data2->GetTypeEntries().size()); ASSERT_EQ(data1->GetTypeEntries()[0]->GetEntry(0), data2->GetTypeEntries()[0]->GetEntry(0)); ASSERT_EQ(data1->GetTypeEntries()[0]->GetEntry(1), data2->GetTypeEntries()[0]->GetEntry(1)); diff --git a/cmds/idmap2/tests/CommandLineOptionsTests.cpp b/cmds/idmap2/tests/CommandLineOptionsTests.cpp index b04b25660ee4..aafe1a413e0c 100644 --- a/cmds/idmap2/tests/CommandLineOptionsTests.cpp +++ b/cmds/idmap2/tests/CommandLineOptionsTests.cpp @@ -44,8 +44,8 @@ namespace android { namespace idmap2 { TEST(CommandLineOptionsTests, Flag) { - bool foo = true, bar = false; - + bool foo = true; + bool bar = false; CommandLineOptions opts = CommandLineOptions("test").OptionalFlag("--foo", "", &foo).OptionalFlag("--bar", "", &bar); @@ -63,7 +63,8 @@ TEST(CommandLineOptionsTests, Flag) { } TEST(CommandLineOptionsTests, MandatoryOption) { - std::string foo, bar; + std::string foo; + std::string bar; CommandLineOptions opts = CommandLineOptions("test") .MandatoryOption("--foo", "", &foo) .MandatoryOption("--bar", "", &bar); @@ -92,13 +93,14 @@ TEST(CommandLineOptionsTests, MandatoryOptionMultipleArgsAndExpectedOnceOrMore) std::ostream fakeStdErr(nullptr); bool success = opts.Parse({"--foo", "FOO", "--foo", "BAR"}, fakeStdErr); ASSERT_TRUE(success); - ASSERT_EQ(args.size(), 2u); + ASSERT_EQ(args.size(), 2U); ASSERT_EQ(args[0], "FOO"); ASSERT_EQ(args[1], "BAR"); } TEST(CommandLineOptionsTests, OptionalOption) { - std::string foo, bar; + std::string foo; + std::string bar; CommandLineOptions opts = CommandLineOptions("test") .OptionalOption("--foo", "", &foo) .OptionalOption("--bar", "", &bar); @@ -123,7 +125,8 @@ TEST(CommandLineOptionsTests, OptionalOption) { } TEST(CommandLineOptionsTests, CornerCases) { - std::string foo, bar; + std::string foo; + std::string bar; bool baz = false; CommandLineOptions opts = CommandLineOptions("test") .MandatoryOption("--foo", "", &foo) @@ -150,7 +153,7 @@ TEST(CommandLineOptionsTests, ConvertArgvToVector) { nullptr, }; std::unique_ptr<std::vector<std::string>> v = CommandLineOptions::ConvertArgvToVector(3, argv); - ASSERT_EQ(v->size(), 2ul); + ASSERT_EQ(v->size(), 2UL); ASSERT_EQ((*v)[0], "--foo"); ASSERT_EQ((*v)[1], "FOO"); } @@ -161,12 +164,16 @@ TEST(CommandLineOptionsTests, ConvertArgvToVectorNoArgs) { nullptr, }; std::unique_ptr<std::vector<std::string>> v = CommandLineOptions::ConvertArgvToVector(1, argv); - ASSERT_EQ(v->size(), 0ul); + ASSERT_EQ(v->size(), 0UL); } TEST(CommandLineOptionsTests, Usage) { - std::string arg1, arg2, arg3, arg4; - bool arg5 = false, arg6 = false; + std::string arg1; + std::string arg2; + std::string arg3; + std::string arg4; + bool arg5 = false; + bool arg6 = false; std::vector<std::string> arg7; CommandLineOptions opts = CommandLineOptions("test") .MandatoryOption("--aa", "description-aa", &arg1) diff --git a/cmds/idmap2/tests/FileUtilsTests.cpp b/cmds/idmap2/tests/FileUtilsTests.cpp index 0c6439ab8c0c..6584ee32a509 100644 --- a/cmds/idmap2/tests/FileUtilsTests.cpp +++ b/cmds/idmap2/tests/FileUtilsTests.cpp @@ -39,7 +39,7 @@ TEST(FileUtilsTests, FindFilesFindEverythingNonRecursive) { [](unsigned char type ATTRIBUTE_UNUSED, const std::string& path ATTRIBUTE_UNUSED) -> bool { return true; }); ASSERT_THAT(v, NotNull()); - ASSERT_EQ(v->size(), 4u); + ASSERT_EQ(v->size(), 4U); ASSERT_EQ( std::set<std::string>(v->begin(), v->end()), std::set<std::string>({root + "/.", root + "/..", root + "/overlay", root + "/target"})); @@ -48,10 +48,10 @@ TEST(FileUtilsTests, FindFilesFindEverythingNonRecursive) { TEST(FileUtilsTests, FindFilesFindApkFilesRecursive) { const auto& root = GetTestDataPath(); auto v = utils::FindFiles(root, true, [](unsigned char type, const std::string& path) -> bool { - return type == DT_REG && path.size() > 4 && !path.compare(path.size() - 4, 4, ".apk"); + return type == DT_REG && path.size() > 4 && path.compare(path.size() - 4, 4, ".apk") == 0; }); ASSERT_THAT(v, NotNull()); - ASSERT_EQ(v->size(), 4u); + ASSERT_EQ(v->size(), 4U); ASSERT_EQ(std::set<std::string>(v->begin(), v->end()), std::set<std::string>({root + "/target/target.apk", root + "/overlay/overlay.apk", root + "/overlay/overlay-static-1.apk", diff --git a/cmds/idmap2/tests/Idmap2BinaryTests.cpp b/cmds/idmap2/tests/Idmap2BinaryTests.cpp index 5c4e8576985b..1f0ce182dc93 100644 --- a/cmds/idmap2/tests/Idmap2BinaryTests.cpp +++ b/cmds/idmap2/tests/Idmap2BinaryTests.cpp @@ -59,7 +59,7 @@ static void AssertIdmap(const Idmap& idmap, const std::string& target_apk_path, ASSERT_EQ(idmap.GetHeader()->GetVersion(), kIdmapCurrentVersion); ASSERT_EQ(idmap.GetHeader()->GetTargetPath(), target_apk_path); ASSERT_EQ(idmap.GetHeader()->GetOverlayPath(), overlay_apk_path); - ASSERT_EQ(idmap.GetData().size(), 1u); + ASSERT_EQ(idmap.GetData().size(), 1U); } #define ASSERT_IDMAP(idmap_ref, target_apk_path, overlay_apk_path) \ diff --git a/cmds/idmap2/tests/IdmapTests.cpp b/cmds/idmap2/tests/IdmapTests.cpp index 0379aa491682..dc80e0e145ac 100644 --- a/cmds/idmap2/tests/IdmapTests.cpp +++ b/cmds/idmap2/tests/IdmapTests.cpp @@ -50,10 +50,10 @@ TEST(IdmapTests, CreateIdmapHeaderFromBinaryStream) { std::istringstream stream(raw); std::unique_ptr<const IdmapHeader> header = IdmapHeader::FromBinaryStream(stream); ASSERT_THAT(header, NotNull()); - ASSERT_EQ(header->GetMagic(), 0x504d4449u); - ASSERT_EQ(header->GetVersion(), 0x01u); - ASSERT_EQ(header->GetTargetCrc(), 0x1234u); - ASSERT_EQ(header->GetOverlayCrc(), 0x5678u); + ASSERT_EQ(header->GetMagic(), 0x504d4449U); + ASSERT_EQ(header->GetVersion(), 0x01U); + ASSERT_EQ(header->GetTargetCrc(), 0x1234U); + ASSERT_EQ(header->GetOverlayCrc(), 0x5678U); ASSERT_EQ(header->GetTargetPath().to_string(), "target.apk"); ASSERT_EQ(header->GetOverlayPath().to_string(), "overlay.apk"); } @@ -77,8 +77,8 @@ TEST(IdmapTests, CreateIdmapDataHeaderFromBinaryStream) { std::unique_ptr<const IdmapData::Header> header = IdmapData::Header::FromBinaryStream(stream); ASSERT_THAT(header, NotNull()); - ASSERT_EQ(header->GetTargetPackageId(), 0x7fu); - ASSERT_EQ(header->GetTypeCount(), 2u); + ASSERT_EQ(header->GetTargetPackageId(), 0x7fU); + ASSERT_EQ(header->GetTypeCount(), 2U); } TEST(IdmapTests, CreateIdmapDataResourceTypeFromBinaryStream) { @@ -89,11 +89,11 @@ TEST(IdmapTests, CreateIdmapDataResourceTypeFromBinaryStream) { std::unique_ptr<const IdmapData::TypeEntry> data = IdmapData::TypeEntry::FromBinaryStream(stream); ASSERT_THAT(data, NotNull()); - ASSERT_EQ(data->GetTargetTypeId(), 0x02u); - ASSERT_EQ(data->GetOverlayTypeId(), 0x02u); - ASSERT_EQ(data->GetEntryCount(), 1u); - ASSERT_EQ(data->GetEntryOffset(), 0u); - ASSERT_EQ(data->GetEntry(0), 0u); + ASSERT_EQ(data->GetTargetTypeId(), 0x02U); + ASSERT_EQ(data->GetOverlayTypeId(), 0x02U); + ASSERT_EQ(data->GetEntryCount(), 1U); + ASSERT_EQ(data->GetEntryOffset(), 0U); + ASSERT_EQ(data->GetEntry(0), 0U); } TEST(IdmapTests, CreateIdmapDataFromBinaryStream) { @@ -104,24 +104,24 @@ TEST(IdmapTests, CreateIdmapDataFromBinaryStream) { std::unique_ptr<const IdmapData> data = IdmapData::FromBinaryStream(stream); ASSERT_THAT(data, NotNull()); - ASSERT_EQ(data->GetHeader()->GetTargetPackageId(), 0x7fu); - ASSERT_EQ(data->GetHeader()->GetTypeCount(), 2u); + ASSERT_EQ(data->GetHeader()->GetTargetPackageId(), 0x7fU); + ASSERT_EQ(data->GetHeader()->GetTypeCount(), 2U); const std::vector<std::unique_ptr<const IdmapData::TypeEntry>>& types = data->GetTypeEntries(); - ASSERT_EQ(types.size(), 2u); - - ASSERT_EQ(types[0]->GetTargetTypeId(), 0x02u); - ASSERT_EQ(types[0]->GetOverlayTypeId(), 0x02u); - ASSERT_EQ(types[0]->GetEntryCount(), 1u); - ASSERT_EQ(types[0]->GetEntryOffset(), 0u); - ASSERT_EQ(types[0]->GetEntry(0), 0x0000u); - - ASSERT_EQ(types[1]->GetTargetTypeId(), 0x03u); - ASSERT_EQ(types[1]->GetOverlayTypeId(), 0x03u); - ASSERT_EQ(types[1]->GetEntryCount(), 3u); - ASSERT_EQ(types[1]->GetEntryOffset(), 3u); - ASSERT_EQ(types[1]->GetEntry(0), 0x0000u); + ASSERT_EQ(types.size(), 2U); + + ASSERT_EQ(types[0]->GetTargetTypeId(), 0x02U); + ASSERT_EQ(types[0]->GetOverlayTypeId(), 0x02U); + ASSERT_EQ(types[0]->GetEntryCount(), 1U); + ASSERT_EQ(types[0]->GetEntryOffset(), 0U); + ASSERT_EQ(types[0]->GetEntry(0), 0x0000U); + + ASSERT_EQ(types[1]->GetTargetTypeId(), 0x03U); + ASSERT_EQ(types[1]->GetOverlayTypeId(), 0x03U); + ASSERT_EQ(types[1]->GetEntryCount(), 3U); + ASSERT_EQ(types[1]->GetEntryOffset(), 3U); + ASSERT_EQ(types[1]->GetEntry(0), 0x0000U); ASSERT_EQ(types[1]->GetEntry(1), kNoEntry); - ASSERT_EQ(types[1]->GetEntry(2), 0x0001u); + ASSERT_EQ(types[1]->GetEntry(2), 0x0001U); } TEST(IdmapTests, CreateIdmapFromBinaryStream) { @@ -133,35 +133,35 @@ TEST(IdmapTests, CreateIdmapFromBinaryStream) { ASSERT_THAT(idmap, NotNull()); ASSERT_THAT(idmap->GetHeader(), NotNull()); - ASSERT_EQ(idmap->GetHeader()->GetMagic(), 0x504d4449u); - ASSERT_EQ(idmap->GetHeader()->GetVersion(), 0x01u); - ASSERT_EQ(idmap->GetHeader()->GetTargetCrc(), 0x1234u); - ASSERT_EQ(idmap->GetHeader()->GetOverlayCrc(), 0x5678u); + ASSERT_EQ(idmap->GetHeader()->GetMagic(), 0x504d4449U); + ASSERT_EQ(idmap->GetHeader()->GetVersion(), 0x01U); + ASSERT_EQ(idmap->GetHeader()->GetTargetCrc(), 0x1234U); + ASSERT_EQ(idmap->GetHeader()->GetOverlayCrc(), 0x5678U); ASSERT_EQ(idmap->GetHeader()->GetTargetPath().to_string(), "target.apk"); ASSERT_EQ(idmap->GetHeader()->GetOverlayPath().to_string(), "overlay.apk"); const std::vector<std::unique_ptr<const IdmapData>>& dataBlocks = idmap->GetData(); - ASSERT_EQ(dataBlocks.size(), 1u); + ASSERT_EQ(dataBlocks.size(), 1U); const std::unique_ptr<const IdmapData>& data = dataBlocks[0]; - ASSERT_EQ(data->GetHeader()->GetTargetPackageId(), 0x7fu); - ASSERT_EQ(data->GetHeader()->GetTypeCount(), 2u); + ASSERT_EQ(data->GetHeader()->GetTargetPackageId(), 0x7fU); + ASSERT_EQ(data->GetHeader()->GetTypeCount(), 2U); const std::vector<std::unique_ptr<const IdmapData::TypeEntry>>& types = data->GetTypeEntries(); - ASSERT_EQ(types.size(), 2u); - - ASSERT_EQ(types[0]->GetTargetTypeId(), 0x02u); - ASSERT_EQ(types[0]->GetOverlayTypeId(), 0x02u); - ASSERT_EQ(types[0]->GetEntryCount(), 1u); - ASSERT_EQ(types[0]->GetEntryOffset(), 0u); - ASSERT_EQ(types[0]->GetEntry(0), 0x0000u); - - ASSERT_EQ(types[1]->GetTargetTypeId(), 0x03u); - ASSERT_EQ(types[1]->GetOverlayTypeId(), 0x03u); - ASSERT_EQ(types[1]->GetEntryCount(), 3u); - ASSERT_EQ(types[1]->GetEntryOffset(), 3u); - ASSERT_EQ(types[1]->GetEntry(0), 0x0000u); + ASSERT_EQ(types.size(), 2U); + + ASSERT_EQ(types[0]->GetTargetTypeId(), 0x02U); + ASSERT_EQ(types[0]->GetOverlayTypeId(), 0x02U); + ASSERT_EQ(types[0]->GetEntryCount(), 1U); + ASSERT_EQ(types[0]->GetEntryOffset(), 0U); + ASSERT_EQ(types[0]->GetEntry(0), 0x0000U); + + ASSERT_EQ(types[1]->GetTargetTypeId(), 0x03U); + ASSERT_EQ(types[1]->GetOverlayTypeId(), 0x03U); + ASSERT_EQ(types[1]->GetEntryCount(), 3U); + ASSERT_EQ(types[1]->GetEntryOffset(), 3U); + ASSERT_EQ(types[1]->GetEntry(0), 0x0000U); ASSERT_EQ(types[1]->GetEntry(1), kNoEntry); - ASSERT_EQ(types[1]->GetEntry(2), 0x0001u); + ASSERT_EQ(types[1]->GetEntry(2), 0x0001U); } TEST(IdmapTests, GracefullyFailToCreateIdmapFromCorruptBinaryStream) { @@ -189,8 +189,8 @@ TEST(IdmapTests, CreateIdmapFromApkAssets) { ASSERT_THAT(idmap, NotNull()); ASSERT_THAT(idmap->GetHeader(), NotNull()); - ASSERT_EQ(idmap->GetHeader()->GetMagic(), 0x504d4449u); - ASSERT_EQ(idmap->GetHeader()->GetVersion(), 0x01u); + ASSERT_EQ(idmap->GetHeader()->GetMagic(), 0x504d4449U); + ASSERT_EQ(idmap->GetHeader()->GetVersion(), 0x01U); ASSERT_EQ(idmap->GetHeader()->GetTargetCrc(), 0xf5ad1d1d); ASSERT_EQ(idmap->GetHeader()->GetOverlayCrc(), 0xd470336b); ASSERT_EQ(idmap->GetHeader()->GetTargetPath().to_string(), target_apk_path); @@ -198,30 +198,30 @@ TEST(IdmapTests, CreateIdmapFromApkAssets) { ASSERT_EQ(idmap->GetHeader()->GetOverlayPath(), overlay_apk_path); const std::vector<std::unique_ptr<const IdmapData>>& dataBlocks = idmap->GetData(); - ASSERT_EQ(dataBlocks.size(), 1u); + ASSERT_EQ(dataBlocks.size(), 1U); const std::unique_ptr<const IdmapData>& data = dataBlocks[0]; - ASSERT_EQ(data->GetHeader()->GetTargetPackageId(), 0x7fu); - ASSERT_EQ(data->GetHeader()->GetTypeCount(), 2u); + ASSERT_EQ(data->GetHeader()->GetTargetPackageId(), 0x7fU); + ASSERT_EQ(data->GetHeader()->GetTypeCount(), 2U); const std::vector<std::unique_ptr<const IdmapData::TypeEntry>>& types = data->GetTypeEntries(); - ASSERT_EQ(types.size(), 2u); - - ASSERT_EQ(types[0]->GetTargetTypeId(), 0x01u); - ASSERT_EQ(types[0]->GetOverlayTypeId(), 0x01u); - ASSERT_EQ(types[0]->GetEntryCount(), 1u); - ASSERT_EQ(types[0]->GetEntryOffset(), 0u); - ASSERT_EQ(types[0]->GetEntry(0), 0x0000u); - - ASSERT_EQ(types[1]->GetTargetTypeId(), 0x02u); - ASSERT_EQ(types[1]->GetOverlayTypeId(), 0x02u); - ASSERT_EQ(types[1]->GetEntryCount(), 4u); - ASSERT_EQ(types[1]->GetEntryOffset(), 3u); - ASSERT_EQ(types[1]->GetEntry(0), 0x0000u); + ASSERT_EQ(types.size(), 2U); + + ASSERT_EQ(types[0]->GetTargetTypeId(), 0x01U); + ASSERT_EQ(types[0]->GetOverlayTypeId(), 0x01U); + ASSERT_EQ(types[0]->GetEntryCount(), 1U); + ASSERT_EQ(types[0]->GetEntryOffset(), 0U); + ASSERT_EQ(types[0]->GetEntry(0), 0x0000U); + + ASSERT_EQ(types[1]->GetTargetTypeId(), 0x02U); + ASSERT_EQ(types[1]->GetOverlayTypeId(), 0x02U); + ASSERT_EQ(types[1]->GetEntryCount(), 4U); + ASSERT_EQ(types[1]->GetEntryOffset(), 3U); + ASSERT_EQ(types[1]->GetEntry(0), 0x0000U); ASSERT_EQ(types[1]->GetEntry(1), kNoEntry); - ASSERT_EQ(types[1]->GetEntry(2), 0x0001u); - ASSERT_EQ(types[1]->GetEntry(3), 0x0002u); + ASSERT_EQ(types[1]->GetEntry(2), 0x0001U); + ASSERT_EQ(types[1]->GetEntry(3), 0x0002U); } TEST(IdmapTests, FailToCreateIdmapFromApkAssetsIfPathTooLong) { diff --git a/cmds/idmap2/tests/Main.cpp b/cmds/idmap2/tests/Main.cpp index f2469eaf57cc..0f683ffd8eef 100644 --- a/cmds/idmap2/tests/Main.cpp +++ b/cmds/idmap2/tests/Main.cpp @@ -25,7 +25,7 @@ namespace android { namespace idmap2 { -const std::string GetTestDataPath() { +std::string GetTestDataPath() { return base::GetExecutableDirectory() + "/tests/data"; } diff --git a/cmds/idmap2/tests/ResourceUtilsTests.cpp b/cmds/idmap2/tests/ResourceUtilsTests.cpp index 7f60d7529a61..c8578d3b340a 100644 --- a/cmds/idmap2/tests/ResourceUtilsTests.cpp +++ b/cmds/idmap2/tests/ResourceUtilsTests.cpp @@ -52,13 +52,13 @@ class ResourceUtilsTests : public Idmap2Tests { }; TEST_F(ResourceUtilsTests, ResToTypeEntryName) { - Result<std::string> name = utils::ResToTypeEntryName(GetAssetManager(), 0x7f010000u); + Result<std::string> name = utils::ResToTypeEntryName(GetAssetManager(), 0x7f010000U); ASSERT_TRUE(name); ASSERT_EQ(*name, "integer/int1"); } TEST_F(ResourceUtilsTests, ResToTypeEntryNameNoSuchResourceId) { - Result<std::string> name = utils::ResToTypeEntryName(GetAssetManager(), 0x7f123456u); + Result<std::string> name = utils::ResToTypeEntryName(GetAssetManager(), 0x7f123456U); ASSERT_FALSE(name); } diff --git a/cmds/idmap2/tests/TestHelpers.h b/cmds/idmap2/tests/TestHelpers.h index 18dc541021c1..356db7af1385 100644 --- a/cmds/idmap2/tests/TestHelpers.h +++ b/cmds/idmap2/tests/TestHelpers.h @@ -117,7 +117,7 @@ const unsigned char idmap_raw_data[] = { const unsigned int idmap_raw_data_len = 565; -const std::string GetTestDataPath(); +std::string GetTestDataPath(); class Idmap2Tests : public testing::Test { protected: diff --git a/cmds/idmap2/tests/XmlTests.cpp b/cmds/idmap2/tests/XmlTests.cpp index 97ff03e0f9e3..40758b42e1ff 100644 --- a/cmds/idmap2/tests/XmlTests.cpp +++ b/cmds/idmap2/tests/XmlTests.cpp @@ -58,11 +58,11 @@ TEST(XmlTests, FindTag) { auto attrs = xml->FindTag("c"); ASSERT_THAT(attrs, NotNull()); - ASSERT_EQ(attrs->size(), 4u); + ASSERT_EQ(attrs->size(), 4U); ASSERT_EQ(attrs->at("type_string"), "fortytwo"); ASSERT_EQ(std::stoi(attrs->at("type_int_dec")), 42); ASSERT_EQ(std::stoi(attrs->at("type_int_hex")), 42); - ASSERT_NE(std::stoul(attrs->at("type_int_boolean")), 0u); + ASSERT_NE(std::stoul(attrs->at("type_int_boolean")), 0U); auto fail = xml->FindTag("does-not-exist"); ASSERT_THAT(fail, IsNull()); |