| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | 5 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 const auto& expected_output = std::get<2>(test_cases[i]); | 262 const auto& expected_output = std::get<2>(test_cases[i]); |
| 263 std::string encoded_ip; | 263 std::string encoded_ip; |
| 264 ASSERT_EQ(success, V4ProtocolManagerUtil::IPAddressToEncodedIPV6Hash( | 264 ASSERT_EQ(success, V4ProtocolManagerUtil::IPAddressToEncodedIPV6Hash( |
| 265 input, &encoded_ip)); | 265 input, &encoded_ip)); |
| 266 if (success) { | 266 if (success) { |
| 267 ASSERT_EQ(expected_output, encoded_ip); | 267 ASSERT_EQ(expected_output, encoded_ip); |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 | 271 |
| 272 TEST_F(V4ProtocolManagerUtilTest, TestFullHashToHashPrefix) { |
| 273 const std::string full_hash = "abcdefgh"; |
| 274 std::vector<std::tuple<bool, std::string, PrefixSize, std::string>> |
| 275 test_cases = { |
| 276 std::make_tuple(true, "", 0, ""), |
| 277 std::make_tuple(false, "", kMinHashPrefixLength, ""), |
| 278 std::make_tuple(true, "a", 1, full_hash), |
| 279 std::make_tuple(true, "abcd", kMinHashPrefixLength, full_hash), |
| 280 std::make_tuple(true, "abcde", kMinHashPrefixLength + 1, full_hash)}; |
| 281 for (size_t i = 0; i < test_cases.size(); i++) { |
| 282 DVLOG(1) << "Running case: " << i; |
| 283 bool success = std::get<0>(test_cases[i]); |
| 284 const auto& expected_prefix = std::get<1>(test_cases[i]); |
| 285 const PrefixSize& prefix_size = std::get<2>(test_cases[i]); |
| 286 const auto& input_full_hash = std::get<3>(test_cases[i]); |
| 287 std::string prefix; |
| 288 ASSERT_EQ(success, V4ProtocolManagerUtil::FullHashToHashPrefix( |
| 289 input_full_hash, prefix_size, &prefix)); |
| 290 if (success) { |
| 291 ASSERT_EQ(expected_prefix, prefix); |
| 292 } |
| 293 } |
| 294 } |
| 295 |
| 272 } // namespace safe_browsing | 296 } // namespace safe_browsing |
| OLD | NEW |