| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/sync_file_system/drive_backend/metadata_database.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <unordered_map> |
| 9 #include <utility> | 10 #include <utility> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 99 |
| 99 template <typename Key, typename Value> | 100 template <typename Key, typename Value> |
| 100 void ExpectEquivalent(const std::map<Key, Value>& left, | 101 void ExpectEquivalent(const std::map<Key, Value>& left, |
| 101 const std::map<Key, Value>& right) { | 102 const std::map<Key, Value>& right) { |
| 102 ExpectEquivalentMaps(left, right); | 103 ExpectEquivalentMaps(left, right); |
| 103 } | 104 } |
| 104 | 105 |
| 105 template <typename Key, typename Value> | 106 template <typename Key, typename Value> |
| 106 void ExpectEquivalent(const base::hash_map<Key, Value>& left, | 107 void ExpectEquivalent(const base::hash_map<Key, Value>& left, |
| 107 const base::hash_map<Key, Value>& right) { | 108 const base::hash_map<Key, Value>& right) { |
| 109 // Convert from a hash container to an ordered container for comparison. |
| 108 ExpectEquivalentMaps(std::map<Key, Value>(left.begin(), left.end()), | 110 ExpectEquivalentMaps(std::map<Key, Value>(left.begin(), left.end()), |
| 109 std::map<Key, Value>(right.begin(), right.end())); | 111 std::map<Key, Value>(right.begin(), right.end())); |
| 110 } | 112 } |
| 111 | 113 |
| 112 template <typename Key, typename Value> | 114 template <typename Key, typename Value> |
| 113 void ExpectEquivalent( | 115 void ExpectEquivalent( |
| 114 const base::ScopedPtrHashMap<Key, std::unique_ptr<Value>>& left, | 116 const std::unordered_map<Key, std::unique_ptr<Value>>& left, |
| 115 const base::ScopedPtrHashMap<Key, std::unique_ptr<Value>>& right) { | 117 const std::unordered_map<Key, std::unique_ptr<Value>>& right) { |
| 116 ExpectEquivalentMaps(std::map<Key, Value*>(left.begin(), left.end()), | 118 // Convert from a hash container to an ordered container for comparison. |
| 117 std::map<Key, Value*>(right.begin(), right.end())); | 119 std::map<Key, Value*> left_ordered; |
| 120 std::map<Key, Value*> right_ordered; |
| 121 for (const auto& item : left) |
| 122 left_ordered[item.first] = item.second.get(); |
| 123 for (const auto& item : right) |
| 124 right_ordered[item.first] = item.second.get(); |
| 125 |
| 126 ExpectEquivalentMaps(left_ordered, right_ordered); |
| 118 } | 127 } |
| 119 | 128 |
| 120 template <typename Container> | 129 template <typename Container> |
| 121 void ExpectEquivalentSets(const Container& left, const Container& right); | 130 void ExpectEquivalentSets(const Container& left, const Container& right); |
| 122 | 131 |
| 123 template <typename Value, typename Comparator> | 132 template <typename Value, typename Comparator> |
| 124 void ExpectEquivalent(const std::set<Value, Comparator>& left, | 133 void ExpectEquivalent(const std::set<Value, Comparator>& left, |
| 125 const std::set<Value, Comparator>& right) { | 134 const std::set<Value, Comparator>& right) { |
| 126 return ExpectEquivalentSets(left, right); | 135 return ExpectEquivalentSets(left, right); |
| 127 } | 136 } |
| 128 | 137 |
| 129 template <typename Value> | 138 template <typename Value> |
| 130 void ExpectEquivalent(const base::hash_set<Value>& left, | 139 void ExpectEquivalent(const base::hash_set<Value>& left, |
| 131 const base::hash_set<Value>& right) { | 140 const base::hash_set<Value>& right) { |
| 141 // Convert from a hash container to an ordered container for comparison. |
| 132 return ExpectEquivalentSets(std::set<Value>(left.begin(), left.end()), | 142 return ExpectEquivalentSets(std::set<Value>(left.begin(), left.end()), |
| 133 std::set<Value>(right.begin(), right.end())); | 143 std::set<Value>(right.begin(), right.end())); |
| 134 } | 144 } |
| 135 | 145 |
| 136 void ExpectEquivalent(const TrackerIDSet& left, | 146 void ExpectEquivalent(const TrackerIDSet& left, |
| 137 const TrackerIDSet& right) { | 147 const TrackerIDSet& right) { |
| 138 { | 148 { |
| 139 SCOPED_TRACE("Expect equivalent active_tracker"); | 149 SCOPED_TRACE("Expect equivalent active_tracker"); |
| 140 EXPECT_EQ(left.active_tracker(), right.active_tracker()); | 150 EXPECT_EQ(left.active_tracker(), right.active_tracker()); |
| 141 } | 151 } |
| (...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 EXPECT_TRUE(file->HasKey("details")); | 1165 EXPECT_TRUE(file->HasKey("details")); |
| 1156 | 1166 |
| 1157 ASSERT_TRUE(files->GetDictionary(1, &file)); | 1167 ASSERT_TRUE(files->GetDictionary(1, &file)); |
| 1158 EXPECT_TRUE(file->GetString("title", &str) && str == "file_0"); | 1168 EXPECT_TRUE(file->GetString("title", &str) && str == "file_0"); |
| 1159 EXPECT_TRUE(file->GetString("type", &str) && str == "file"); | 1169 EXPECT_TRUE(file->GetString("type", &str) && str == "file"); |
| 1160 EXPECT_TRUE(file->HasKey("details")); | 1170 EXPECT_TRUE(file->HasKey("details")); |
| 1161 } | 1171 } |
| 1162 | 1172 |
| 1163 } // namespace drive_backend | 1173 } // namespace drive_backend |
| 1164 } // namespace sync_file_system | 1174 } // namespace sync_file_system |
| OLD | NEW |