Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Unified Diff: components/safe_browsing_db/v4_protocol_manager_util_unittest.cc

Issue 2928793002: Use the substr API correctly in FullHashToHashPrefix. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/safe_browsing_db/v4_protocol_manager_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/safe_browsing_db/v4_protocol_manager_util_unittest.cc
diff --git a/components/safe_browsing_db/v4_protocol_manager_util_unittest.cc b/components/safe_browsing_db/v4_protocol_manager_util_unittest.cc
index 0680d3cc060eea2bf1c9b9702abd8363667663dd..8018a9a896fd4973205a618129ed80a561df775d 100644
--- a/components/safe_browsing_db/v4_protocol_manager_util_unittest.cc
+++ b/components/safe_browsing_db/v4_protocol_manager_util_unittest.cc
@@ -269,4 +269,28 @@ TEST_F(V4ProtocolManagerUtilTest, TestIPAddressToEncodedIPV6) {
}
}
+TEST_F(V4ProtocolManagerUtilTest, TestFullHashToHashPrefix) {
+ const std::string full_hash = "abcdefgh";
+ std::vector<std::tuple<bool, std::string, PrefixSize, std::string>>
+ test_cases = {
+ std::make_tuple(true, "", 0, ""),
+ std::make_tuple(false, "", kMinHashPrefixLength, ""),
+ std::make_tuple(true, "a", 1, full_hash),
+ std::make_tuple(true, "abcd", kMinHashPrefixLength, full_hash),
+ std::make_tuple(true, "abcde", kMinHashPrefixLength + 1, full_hash)};
+ for (size_t i = 0; i < test_cases.size(); i++) {
+ DVLOG(1) << "Running case: " << i;
+ bool success = std::get<0>(test_cases[i]);
+ const auto& expected_prefix = std::get<1>(test_cases[i]);
+ const PrefixSize& prefix_size = std::get<2>(test_cases[i]);
+ const auto& input_full_hash = std::get<3>(test_cases[i]);
+ std::string prefix;
+ ASSERT_EQ(success, V4ProtocolManagerUtil::FullHashToHashPrefix(
+ input_full_hash, prefix_size, &prefix));
+ if (success) {
+ ASSERT_EQ(expected_prefix, prefix);
+ }
+ }
+}
+
} // namespace safe_browsing
« no previous file with comments | « components/safe_browsing_db/v4_protocol_manager_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698