Chromium Code Reviews| 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 "base/hash.h" | 5 #include "base/hash.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 EXPECT_EQ(new_index_metadata.GetNumberOfEntries(), | 45 EXPECT_EQ(new_index_metadata.GetNumberOfEntries(), |
| 46 index_metadata.GetNumberOfEntries()); | 46 index_metadata.GetNumberOfEntries()); |
| 47 EXPECT_EQ(new_index_metadata.cache_size_, index_metadata.cache_size_); | 47 EXPECT_EQ(new_index_metadata.cache_size_, index_metadata.cache_size_); |
| 48 | 48 |
| 49 EXPECT_TRUE(new_index_metadata.CheckIndexMetadata()); | 49 EXPECT_TRUE(new_index_metadata.CheckIndexMetadata()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 class SimpleIndexFileTest : public testing::Test { | 52 class SimpleIndexFileTest : public testing::Test { |
| 53 public: | 53 public: |
| 54 bool CompareTwoEntryMetadata(const EntryMetadata& a, const EntryMetadata& b) { | 54 bool CompareTwoEntryMetadata(const EntryMetadata& a, const EntryMetadata& b) { |
| 55 return a.hash_key_ == b.hash_key_ && | 55 return a.last_used_time_ == b.last_used_time_ && |
| 56 a.last_used_time_ == b.last_used_time_ && | 56 a.entry_size_ == b.entry_size_; |
| 57 a.entry_size_ == b.entry_size_; | |
| 58 } | 57 } |
| 59 | 58 |
| 60 }; | 59 }; |
| 61 | 60 |
| 62 TEST_F(SimpleIndexFileTest, Serialize) { | 61 TEST_F(SimpleIndexFileTest, Serialize) { |
| 63 SimpleIndex::EntrySet entries; | 62 SimpleIndex::EntrySet entries; |
| 64 EntryMetadata entries_array[] = { | 63 static const uint64 kHashes[] = { 11, 22, 33 }; |
|
gavinp
2013/05/17 14:54:17
I don't think the static here is helpful.
digit1
2013/05/17 15:07:33
Without static, this actually creates a temporary
gavinp
2013/05/17 15:37:45
Wow, interesting.
What a mess compilers are; I kn
| |
| 65 EntryMetadata(11, Time::FromInternalValue(22), 33), | 64 static const size_t kNumHashes = arraysize(kHashes); |
| 66 EntryMetadata(22, Time::FromInternalValue(33), 44), | 65 EntryMetadata metadata_entries[kNumHashes]; |
| 67 EntryMetadata(33, Time::FromInternalValue(44), 55) | 66 |
| 68 }; | 67 SimpleIndexFile::IndexMetadata index_metadata(static_cast<uint64>(kNumHashes), |
| 69 SimpleIndexFile::IndexMetadata index_metadata(arraysize(entries_array), 456); | 68 456); |
| 70 for (uint32 i = 0; i < arraysize(entries_array); ++i) { | 69 for (size_t i = 0; i < kNumHashes; ++i) { |
| 71 SimpleIndex::InsertInEntrySet(entries_array[i], &entries); | 70 uint64 hash = kHashes[i]; |
| 71 metadata_entries[i] = | |
| 72 EntryMetadata(Time::FromInternalValue(hash), hash); | |
| 73 SimpleIndex::InsertInEntrySet(hash, metadata_entries[i], &entries); | |
| 72 } | 74 } |
| 73 | 75 |
| 74 scoped_ptr<Pickle> pickle = SimpleIndexFile::Serialize( | 76 scoped_ptr<Pickle> pickle = SimpleIndexFile::Serialize( |
| 75 index_metadata, entries); | 77 index_metadata, entries); |
| 76 EXPECT_TRUE(pickle.get() != NULL); | 78 EXPECT_TRUE(pickle.get() != NULL); |
| 77 | 79 |
| 78 scoped_ptr<SimpleIndex::EntrySet> new_entries = SimpleIndexFile::Deserialize( | 80 scoped_ptr<SimpleIndex::EntrySet> new_entries = SimpleIndexFile::Deserialize( |
| 79 reinterpret_cast<const char*>(pickle->data()), | 81 reinterpret_cast<const char*>(pickle->data()), |
| 80 pickle->size()); | 82 pickle->size()); |
| 81 EXPECT_TRUE(new_entries.get() != NULL); | 83 EXPECT_TRUE(new_entries.get() != NULL); |
| 82 EXPECT_EQ(entries.size(), new_entries->size()); | 84 EXPECT_EQ(entries.size(), new_entries->size()); |
| 83 | 85 |
| 84 for (uint32 i = 0; i < arraysize(entries_array); ++i) { | 86 for (size_t i = 0; i < kNumHashes; ++i) { |
| 85 SimpleIndex::EntrySet::iterator it = | 87 SimpleIndex::EntrySet::iterator it = new_entries->find(kHashes[i]); |
| 86 new_entries->find(entries_array[i].GetHashKey()); | |
| 87 EXPECT_TRUE(new_entries->end() != it); | 88 EXPECT_TRUE(new_entries->end() != it); |
| 88 EXPECT_TRUE(CompareTwoEntryMetadata(it->second, entries_array[i])); | 89 EXPECT_TRUE(CompareTwoEntryMetadata(it->second, metadata_entries[i])); |
| 89 } | 90 } |
| 90 } | 91 } |
| 91 | 92 |
| 92 } | 93 } |
| OLD | NEW |