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; |
| 63 uint64 hashes_array[] = { 11, 22, 33 }; | |
| 64 EntryMetadata entries_array[] = { | 64 EntryMetadata entries_array[] = { |
|
pasko
2013/05/16 18:13:21
Since we have hashes_array now, to avoid repeating
digit1
2013/05/17 08:45:38
Done.
| |
| 65 EntryMetadata(11, Time::FromInternalValue(22), 33), | 65 EntryMetadata(Time::FromInternalValue(22), 33), |
| 66 EntryMetadata(22, Time::FromInternalValue(33), 44), | 66 EntryMetadata(Time::FromInternalValue(33), 44), |
| 67 EntryMetadata(33, Time::FromInternalValue(44), 55) | 67 EntryMetadata(Time::FromInternalValue(44), 55) |
| 68 }; | 68 }; |
| 69 SimpleIndexFile::IndexMetadata index_metadata(arraysize(entries_array), 456); | 69 SimpleIndexFile::IndexMetadata index_metadata(arraysize(entries_array), 456); |
| 70 for (uint32 i = 0; i < arraysize(entries_array); ++i) { | 70 for (uint32 i = 0; i < arraysize(entries_array); ++i) { |
| 71 SimpleIndex::InsertInEntrySet(entries_array[i], &entries); | 71 SimpleIndex::InsertInEntrySet(hashes_array[i], entries_array[i], &entries); |
| 72 } | 72 } |
| 73 | 73 |
| 74 scoped_ptr<Pickle> pickle = SimpleIndexFile::Serialize( | 74 scoped_ptr<Pickle> pickle = SimpleIndexFile::Serialize( |
| 75 index_metadata, entries); | 75 index_metadata, entries); |
| 76 EXPECT_TRUE(pickle.get() != NULL); | 76 EXPECT_TRUE(pickle.get() != NULL); |
| 77 | 77 |
| 78 scoped_ptr<SimpleIndex::EntrySet> new_entries = SimpleIndexFile::Deserialize( | 78 scoped_ptr<SimpleIndex::EntrySet> new_entries = SimpleIndexFile::Deserialize( |
| 79 reinterpret_cast<const char*>(pickle->data()), | 79 reinterpret_cast<const char*>(pickle->data()), |
| 80 pickle->size()); | 80 pickle->size()); |
| 81 EXPECT_TRUE(new_entries.get() != NULL); | 81 EXPECT_TRUE(new_entries.get() != NULL); |
| 82 EXPECT_EQ(entries.size(), new_entries->size()); | 82 EXPECT_EQ(entries.size(), new_entries->size()); |
| 83 | 83 |
| 84 for (uint32 i = 0; i < arraysize(entries_array); ++i) { | 84 for (uint32 i = 0; i < arraysize(entries_array); ++i) { |
| 85 SimpleIndex::EntrySet::iterator it = | 85 SimpleIndex::EntrySet::iterator it = new_entries->find(hashes_array[i]); |
| 86 new_entries->find(entries_array[i].GetHashKey()); | |
| 87 EXPECT_TRUE(new_entries->end() != it); | 86 EXPECT_TRUE(new_entries->end() != it); |
| 88 EXPECT_TRUE(CompareTwoEntryMetadata(it->second, entries_array[i])); | 87 EXPECT_TRUE(CompareTwoEntryMetadata(it->second, entries_array[i])); |
| 89 } | 88 } |
| 90 } | 89 } |
| 91 | 90 |
| 92 } | 91 } |
| OLD | NEW |