| Index: components/safe_browsing_db/prefix_set_unittest.cc
|
| diff --git a/components/safe_browsing_db/prefix_set_unittest.cc b/components/safe_browsing_db/prefix_set_unittest.cc
|
| index d1de0db4d4f00aced907198883f62083c2fb1469..0185afa43a6e6c6bd5c4e9561bacb93755618434 100644
|
| --- a/components/safe_browsing_db/prefix_set_unittest.cc
|
| +++ b/components/safe_browsing_db/prefix_set_unittest.cc
|
| @@ -4,6 +4,10 @@
|
|
|
| #include "components/safe_browsing_db/prefix_set.h"
|
|
|
| +#include <stddef.h>
|
| +#include <stdint.h>
|
| +#include <string.h>
|
| +
|
| #include <algorithm>
|
| #include <iterator>
|
| #include <set>
|
| @@ -19,6 +23,7 @@
|
| #include "base/rand_util.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_util.h"
|
| +#include "build/build_config.h"
|
| #include "components/safe_browsing_db/util.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "testing/platform_test.h"
|
| @@ -35,12 +40,12 @@ const SBPrefix kHighBitSet = 3u * 1000u * 1000u * 1000u;
|
| class PrefixSetTest : public PlatformTest {
|
| protected:
|
| // Constants for the v1 format.
|
| - static const size_t kMagicOffset = 0 * sizeof(uint32);
|
| - static const size_t kVersionOffset = 1 * sizeof(uint32);
|
| - static const size_t kIndexSizeOffset = 2 * sizeof(uint32);
|
| - static const size_t kDeltasSizeOffset = 3 * sizeof(uint32);
|
| - static const size_t kFullHashesSizeOffset = 4 * sizeof(uint32);
|
| - static const size_t kPayloadOffset = 5 * sizeof(uint32);
|
| + static const size_t kMagicOffset = 0 * sizeof(uint32_t);
|
| + static const size_t kVersionOffset = 1 * sizeof(uint32_t);
|
| + static const size_t kIndexSizeOffset = 2 * sizeof(uint32_t);
|
| + static const size_t kDeltasSizeOffset = 3 * sizeof(uint32_t);
|
| + static const size_t kFullHashesSizeOffset = 4 * sizeof(uint32_t);
|
| + static const size_t kPayloadOffset = 5 * sizeof(uint32_t);
|
|
|
| // Generate a set of random prefixes to share between tests. For
|
| // most tests this generation was a large fraction of the test time.
|
| @@ -52,9 +57,10 @@ class PrefixSetTest : public PlatformTest {
|
| // Distribute clusters of prefixes.
|
| for (size_t i = 0; i < 250; ++i) {
|
| // Unsigned for overflow characteristics.
|
| - const uint32 base = static_cast<uint32>(base::RandUint64());
|
| + const uint32_t base = static_cast<uint32_t>(base::RandUint64());
|
| for (size_t j = 0; j < 10; ++j) {
|
| - const uint32 delta = static_cast<uint32>(base::RandUint64() & 0xFFFF);
|
| + const uint32_t delta =
|
| + static_cast<uint32_t>(base::RandUint64() & 0xFFFF);
|
| const SBPrefix prefix = static_cast<SBPrefix>(base + delta);
|
| shared_prefixes_.push_back(prefix);
|
| }
|
| @@ -114,11 +120,11 @@ class PrefixSetTest : public PlatformTest {
|
| return true;
|
| }
|
|
|
| - // Helper function to read the uint32 value at |offset|, increment it
|
| + // Helper function to read the uint32_t value at |offset|, increment it
|
| // by |inc|, and write it back in place. |fp| should be opened in
|
| // r+ mode.
|
| static void IncrementIntAt(FILE* fp, long offset, int inc) {
|
| - uint32 value = 0;
|
| + uint32_t value = 0;
|
|
|
| ASSERT_NE(-1, fseek(fp, offset, SEEK_SET));
|
| ASSERT_EQ(1U, fread(&value, sizeof(value), 1, fp));
|
| @@ -159,11 +165,11 @@ class PrefixSetTest : public PlatformTest {
|
| ASSERT_EQ(file_size, ftell(fp));
|
| }
|
|
|
| - // Open |filename| and increment the uint32 at |offset| by |inc|.
|
| + // Open |filename| and increment the uint32_t at |offset| by |inc|.
|
| // Then re-generate the checksum to account for the new contents.
|
| void ModifyAndCleanChecksum(const base::FilePath& filename, long offset,
|
| int inc) {
|
| - int64 size_64;
|
| + int64_t size_64;
|
| ASSERT_TRUE(base::GetFileSize(filename, &size_64));
|
|
|
| base::ScopedFILE file(base::OpenFile(filename, "r+b"));
|
| @@ -171,7 +177,7 @@ class PrefixSetTest : public PlatformTest {
|
| CleanChecksum(file.get());
|
| file.reset();
|
|
|
| - int64 new_size_64;
|
| + int64_t new_size_64;
|
| ASSERT_TRUE(base::GetFileSize(filename, &new_size_64));
|
| ASSERT_EQ(new_size_64, size_64);
|
| }
|
| @@ -535,7 +541,7 @@ TEST_F(PrefixSetTest, CorruptionDigest) {
|
| base::FilePath filename;
|
| ASSERT_TRUE(GetPrefixSetFile(&filename));
|
|
|
| - int64 size_64;
|
| + int64_t size_64;
|
| ASSERT_TRUE(base::GetFileSize(filename, &size_64));
|
| base::ScopedFILE file(base::OpenFile(filename, "r+b"));
|
| long digest_offset = static_cast<long>(size_64 - sizeof(base::MD5Digest));
|
| @@ -568,15 +574,15 @@ TEST_F(PrefixSetTest, SizeTRecovery) {
|
| base::ScopedFILE file(base::OpenFile(filename, "r+b"));
|
|
|
| // Leave existing magic and version.
|
| - ASSERT_NE(-1, fseek(file.get(), sizeof(uint32) * 2, SEEK_SET));
|
| + ASSERT_NE(-1, fseek(file.get(), sizeof(uint32_t) * 2, SEEK_SET));
|
|
|
| // Indicate two index values and two deltas.
|
| - uint32 val = 2;
|
| + uint32_t val = 2;
|
| ASSERT_EQ(sizeof(val), fwrite(&val, 1, sizeof(val), file.get()));
|
| ASSERT_EQ(sizeof(val), fwrite(&val, 1, sizeof(val), file.get()));
|
|
|
| // Write two index values with 64-bit "size_t".
|
| - std::pair<SBPrefix, uint64> item;
|
| + std::pair<SBPrefix, uint64_t> item;
|
| memset(&item, 0, sizeof(item)); // Includes any padding.
|
| item.first = 17;
|
| item.second = 0;
|
| @@ -586,7 +592,7 @@ TEST_F(PrefixSetTest, SizeTRecovery) {
|
| ASSERT_EQ(sizeof(item), fwrite(&item, 1, sizeof(item), file.get()));
|
|
|
| // Write two delta values.
|
| - uint16 delta = 23;
|
| + uint16_t delta = 23;
|
| ASSERT_EQ(sizeof(delta), fwrite(&delta, 1, sizeof(delta), file.get()));
|
| ASSERT_EQ(sizeof(delta), fwrite(&delta, 1, sizeof(delta), file.get()));
|
|
|
| @@ -646,18 +652,18 @@ TEST_F(PrefixSetTest, ReadSigned) {
|
| base::ScopedFILE file(base::OpenFile(filename, "r+b"));
|
|
|
| // Leave existing magic.
|
| - ASSERT_NE(-1, fseek(file.get(), sizeof(uint32), SEEK_SET));
|
| + ASSERT_NE(-1, fseek(file.get(), sizeof(uint32_t), SEEK_SET));
|
|
|
| // Version 1.
|
| - uint32 version = 1;
|
| + uint32_t version = 1;
|
| ASSERT_EQ(sizeof(version), fwrite(&version, 1, sizeof(version), file.get()));
|
|
|
| // Indicate two index values and two deltas.
|
| - uint32 val = 2;
|
| + uint32_t val = 2;
|
| ASSERT_EQ(sizeof(val), fwrite(&val, 1, sizeof(val), file.get()));
|
| ASSERT_EQ(sizeof(val), fwrite(&val, 1, sizeof(val), file.get()));
|
|
|
| - std::pair<int32, uint32> item;
|
| + std::pair<int32_t, uint32_t> item;
|
| memset(&item, 0, sizeof(item)); // Includes any padding.
|
| item.first = -1000;
|
| item.second = 0;
|
| @@ -667,7 +673,7 @@ TEST_F(PrefixSetTest, ReadSigned) {
|
| ASSERT_EQ(sizeof(item), fwrite(&item, 1, sizeof(item), file.get()));
|
|
|
| // Write two delta values.
|
| - uint16 delta = 23;
|
| + uint16_t delta = 23;
|
| ASSERT_EQ(sizeof(delta), fwrite(&delta, 1, sizeof(delta), file.get()));
|
| ASSERT_EQ(sizeof(delta), fwrite(&delta, 1, sizeof(delta), file.get()));
|
|
|
|
|