OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 8 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 // 31 chars plus the last \0 as full_hash. | 313 // 31 chars plus the last \0 as full_hash. |
314 const std::string hash_in = "12345678902234567890323456789012"; | 314 const std::string hash_in = "12345678902234567890323456789012"; |
315 SBFullHash hash_out = safe_browsing_util::StringToSBFullHash(hash_in); | 315 SBFullHash hash_out = safe_browsing_util::StringToSBFullHash(hash_in); |
316 EXPECT_EQ(0x34333231U, hash_out.prefix); | 316 EXPECT_EQ(0x34333231U, hash_out.prefix); |
317 EXPECT_EQ(0, memcmp(hash_in.data(), hash_out.full_hash, sizeof(SBFullHash))); | 317 EXPECT_EQ(0, memcmp(hash_in.data(), hash_out.full_hash, sizeof(SBFullHash))); |
318 | 318 |
319 std::string hash_final = safe_browsing_util::SBFullHashToString(hash_out); | 319 std::string hash_final = safe_browsing_util::SBFullHashToString(hash_out); |
320 EXPECT_EQ(hash_in, hash_final); | 320 EXPECT_EQ(hash_in, hash_final); |
321 } | 321 } |
322 | 322 |
| 323 TEST(SafeBrowsingUtilTest, FullHashOperators) { |
| 324 const SBFullHash kHash1 = SBFullHashForString("one"); |
| 325 const SBFullHash kHash2 = SBFullHashForString("two"); |
| 326 |
| 327 EXPECT_TRUE(SBFullHashEqual(kHash1, kHash1)); |
| 328 EXPECT_TRUE(SBFullHashEqual(kHash2, kHash2)); |
| 329 EXPECT_FALSE(SBFullHashEqual(kHash1, kHash2)); |
| 330 EXPECT_FALSE(SBFullHashEqual(kHash2, kHash1)); |
| 331 |
| 332 EXPECT_FALSE(SBFullHashLess(kHash1, kHash2)); |
| 333 EXPECT_TRUE(SBFullHashLess(kHash2, kHash1)); |
| 334 |
| 335 EXPECT_FALSE(SBFullHashLess(kHash1, kHash1)); |
| 336 EXPECT_FALSE(SBFullHashLess(kHash2, kHash2)); |
| 337 } |
| 338 |
323 } // namespace | 339 } // namespace |
OLD | NEW |