Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: sync/syncable/directory_backing_store_unittest.cc

Issue 1545553003: Switch to standard integer types in sync/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/syncable/directory_backing_store.cc ('k') | sync/syncable/directory_change_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "sync/syncable/directory_backing_store.h" 5 #include "sync/syncable/directory_backing_store.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
7 #include <map> 10 #include <map>
8 #include <string> 11 #include <string>
9 12
10 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
11 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 17 #include "base/run_loop.h"
15 #include "base/stl_util.h" 18 #include "base/stl_util.h"
16 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "build/build_config.h"
18 #include "sql/connection.h" 22 #include "sql/connection.h"
19 #include "sql/statement.h" 23 #include "sql/statement.h"
20 #include "sql/test/scoped_error_ignorer.h" 24 #include "sql/test/scoped_error_ignorer.h"
21 #include "sql/test/test_helpers.h" 25 #include "sql/test/test_helpers.h"
22 #include "sync/base/sync_export.h" 26 #include "sync/base/sync_export.h"
23 #include "sync/internal_api/public/base/node_ordinal.h" 27 #include "sync/internal_api/public/base/node_ordinal.h"
24 #include "sync/protocol/bookmark_specifics.pb.h" 28 #include "sync/protocol/bookmark_specifics.pb.h"
25 #include "sync/protocol/sync.pb.h" 29 #include "sync/protocol/sync.pb.h"
26 #include "sync/syncable/directory.h" 30 #include "sync/syncable/directory.h"
27 #include "sync/syncable/on_disk_directory_backing_store.h" 31 #include "sync/syncable/on_disk_directory_backing_store.h"
(...skipping 18 matching lines...) Expand all
46 scoped_ptr<EntryKernel> entry(new EntryKernel()); 50 scoped_ptr<EntryKernel> entry(new EntryKernel());
47 std::string id_string = base::Int64ToString(id) + id_suffix; 51 std::string id_string = base::Int64ToString(id) + id_suffix;
48 entry->put(ID, Id::CreateFromClientString(id_string)); 52 entry->put(ID, Id::CreateFromClientString(id_string));
49 entry->put(META_HANDLE, id); 53 entry->put(META_HANDLE, id);
50 entry->mark_dirty(NULL); 54 entry->mark_dirty(NULL);
51 return entry; 55 return entry;
52 } 56 }
53 57
54 } // namespace 58 } // namespace
55 59
56 SYNC_EXPORT extern const int32 kCurrentDBVersion; 60 SYNC_EXPORT extern const int32_t kCurrentDBVersion;
57 61
58 class MigrationTest : public testing::TestWithParam<int> { 62 class MigrationTest : public testing::TestWithParam<int> {
59 public: 63 public:
60 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); } 64 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); }
61 65
62 protected: 66 protected:
63 std::string GetUsername() { 67 std::string GetUsername() {
64 return "nick@chromium.org"; 68 return "nick@chromium.org";
65 } 69 }
66 70
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 277
274 // Helper functions for testing. 278 // Helper functions for testing.
275 279
276 enum ShouldIncludeDeletedItems { 280 enum ShouldIncludeDeletedItems {
277 INCLUDE_DELETED_ITEMS, 281 INCLUDE_DELETED_ITEMS,
278 DONT_INCLUDE_DELETED_ITEMS 282 DONT_INCLUDE_DELETED_ITEMS
279 }; 283 };
280 284
281 // Returns a map from metahandle -> expected legacy time (in proto 285 // Returns a map from metahandle -> expected legacy time (in proto
282 // format). 286 // format).
283 std::map<int64, int64> GetExpectedLegacyMetaProtoTimes( 287 std::map<int64_t, int64_t> GetExpectedLegacyMetaProtoTimes(
284 enum ShouldIncludeDeletedItems include_deleted) { 288 enum ShouldIncludeDeletedItems include_deleted) {
285 std::map<int64, int64> expected_legacy_meta_proto_times; 289 std::map<int64_t, int64_t> expected_legacy_meta_proto_times;
286 expected_legacy_meta_proto_times[1] = LEGACY_META_PROTO_TIMES(1); 290 expected_legacy_meta_proto_times[1] = LEGACY_META_PROTO_TIMES(1);
287 if (include_deleted == INCLUDE_DELETED_ITEMS) { 291 if (include_deleted == INCLUDE_DELETED_ITEMS) {
288 expected_legacy_meta_proto_times[2] = LEGACY_META_PROTO_TIMES(2); 292 expected_legacy_meta_proto_times[2] = LEGACY_META_PROTO_TIMES(2);
289 expected_legacy_meta_proto_times[4] = LEGACY_META_PROTO_TIMES(4); 293 expected_legacy_meta_proto_times[4] = LEGACY_META_PROTO_TIMES(4);
290 expected_legacy_meta_proto_times[5] = LEGACY_META_PROTO_TIMES(5); 294 expected_legacy_meta_proto_times[5] = LEGACY_META_PROTO_TIMES(5);
291 } 295 }
292 expected_legacy_meta_proto_times[6] = LEGACY_META_PROTO_TIMES(6); 296 expected_legacy_meta_proto_times[6] = LEGACY_META_PROTO_TIMES(6);
293 expected_legacy_meta_proto_times[7] = LEGACY_META_PROTO_TIMES(7); 297 expected_legacy_meta_proto_times[7] = LEGACY_META_PROTO_TIMES(7);
294 expected_legacy_meta_proto_times[8] = LEGACY_META_PROTO_TIMES(8); 298 expected_legacy_meta_proto_times[8] = LEGACY_META_PROTO_TIMES(8);
295 expected_legacy_meta_proto_times[9] = LEGACY_META_PROTO_TIMES(9); 299 expected_legacy_meta_proto_times[9] = LEGACY_META_PROTO_TIMES(9);
296 expected_legacy_meta_proto_times[10] = LEGACY_META_PROTO_TIMES(10); 300 expected_legacy_meta_proto_times[10] = LEGACY_META_PROTO_TIMES(10);
297 expected_legacy_meta_proto_times[11] = LEGACY_META_PROTO_TIMES(11); 301 expected_legacy_meta_proto_times[11] = LEGACY_META_PROTO_TIMES(11);
298 expected_legacy_meta_proto_times[12] = LEGACY_META_PROTO_TIMES(12); 302 expected_legacy_meta_proto_times[12] = LEGACY_META_PROTO_TIMES(12);
299 expected_legacy_meta_proto_times[13] = LEGACY_META_PROTO_TIMES(13); 303 expected_legacy_meta_proto_times[13] = LEGACY_META_PROTO_TIMES(13);
300 expected_legacy_meta_proto_times[14] = LEGACY_META_PROTO_TIMES(14); 304 expected_legacy_meta_proto_times[14] = LEGACY_META_PROTO_TIMES(14);
301 return expected_legacy_meta_proto_times; 305 return expected_legacy_meta_proto_times;
302 } 306 }
303 307
304 // Returns a map from metahandle -> expected time (in proto format). 308 // Returns a map from metahandle -> expected time (in proto format).
305 std::map<int64, int64> GetExpectedMetaProtoTimes( 309 std::map<int64_t, int64_t> GetExpectedMetaProtoTimes(
306 enum ShouldIncludeDeletedItems include_deleted) { 310 enum ShouldIncludeDeletedItems include_deleted) {
307 std::map<int64, int64> expected_meta_proto_times; 311 std::map<int64_t, int64_t> expected_meta_proto_times;
308 expected_meta_proto_times[1] = META_PROTO_TIMES(1); 312 expected_meta_proto_times[1] = META_PROTO_TIMES(1);
309 if (include_deleted == INCLUDE_DELETED_ITEMS) { 313 if (include_deleted == INCLUDE_DELETED_ITEMS) {
310 expected_meta_proto_times[2] = META_PROTO_TIMES(2); 314 expected_meta_proto_times[2] = META_PROTO_TIMES(2);
311 expected_meta_proto_times[4] = META_PROTO_TIMES(4); 315 expected_meta_proto_times[4] = META_PROTO_TIMES(4);
312 expected_meta_proto_times[5] = META_PROTO_TIMES(5); 316 expected_meta_proto_times[5] = META_PROTO_TIMES(5);
313 } 317 }
314 expected_meta_proto_times[6] = META_PROTO_TIMES(6); 318 expected_meta_proto_times[6] = META_PROTO_TIMES(6);
315 expected_meta_proto_times[7] = META_PROTO_TIMES(7); 319 expected_meta_proto_times[7] = META_PROTO_TIMES(7);
316 expected_meta_proto_times[8] = META_PROTO_TIMES(8); 320 expected_meta_proto_times[8] = META_PROTO_TIMES(8);
317 expected_meta_proto_times[9] = META_PROTO_TIMES(9); 321 expected_meta_proto_times[9] = META_PROTO_TIMES(9);
318 expected_meta_proto_times[10] = META_PROTO_TIMES(10); 322 expected_meta_proto_times[10] = META_PROTO_TIMES(10);
319 expected_meta_proto_times[11] = META_PROTO_TIMES(11); 323 expected_meta_proto_times[11] = META_PROTO_TIMES(11);
320 expected_meta_proto_times[12] = META_PROTO_TIMES(12); 324 expected_meta_proto_times[12] = META_PROTO_TIMES(12);
321 expected_meta_proto_times[13] = META_PROTO_TIMES(13); 325 expected_meta_proto_times[13] = META_PROTO_TIMES(13);
322 expected_meta_proto_times[14] = META_PROTO_TIMES(14); 326 expected_meta_proto_times[14] = META_PROTO_TIMES(14);
323 return expected_meta_proto_times; 327 return expected_meta_proto_times;
324 } 328 }
325 329
326 // Returns a map from metahandle -> expected time (as a Time object). 330 // Returns a map from metahandle -> expected time (as a Time object).
327 std::map<int64, base::Time> GetExpectedMetaTimes() { 331 std::map<int64_t, base::Time> GetExpectedMetaTimes() {
328 std::map<int64, base::Time> expected_meta_times; 332 std::map<int64_t, base::Time> expected_meta_times;
329 const std::map<int64, int64>& expected_meta_proto_times = 333 const std::map<int64_t, int64_t>& expected_meta_proto_times =
330 GetExpectedMetaProtoTimes(INCLUDE_DELETED_ITEMS); 334 GetExpectedMetaProtoTimes(INCLUDE_DELETED_ITEMS);
331 for (std::map<int64, int64>::const_iterator it = 335 for (std::map<int64_t, int64_t>::const_iterator it =
332 expected_meta_proto_times.begin(); 336 expected_meta_proto_times.begin();
333 it != expected_meta_proto_times.end(); ++it) { 337 it != expected_meta_proto_times.end(); ++it) {
334 expected_meta_times[it->first] = ProtoTimeToTime(it->second); 338 expected_meta_times[it->first] = ProtoTimeToTime(it->second);
335 } 339 }
336 return expected_meta_times; 340 return expected_meta_times;
337 } 341 }
338 342
339 // Extracts a map from metahandle -> time (in proto format) from the 343 // Extracts a map from metahandle -> time (in proto format) from the
340 // given database. 344 // given database.
341 std::map<int64, int64> GetMetaProtoTimes(sql::Connection *db) { 345 std::map<int64_t, int64_t> GetMetaProtoTimes(sql::Connection* db) {
342 sql::Statement s(db->GetCachedStatement( 346 sql::Statement s(db->GetCachedStatement(
343 SQL_FROM_HERE, 347 SQL_FROM_HERE,
344 "SELECT metahandle, mtime, server_mtime, ctime, server_ctime " 348 "SELECT metahandle, mtime, server_mtime, ctime, server_ctime "
345 "FROM metas")); 349 "FROM metas"));
346 EXPECT_EQ(5, s.ColumnCount()); 350 EXPECT_EQ(5, s.ColumnCount());
347 std::map<int64, int64> meta_times; 351 std::map<int64_t, int64_t> meta_times;
348 while (s.Step()) { 352 while (s.Step()) {
349 int64 metahandle = s.ColumnInt64(0); 353 int64_t metahandle = s.ColumnInt64(0);
350 int64 mtime = s.ColumnInt64(1); 354 int64_t mtime = s.ColumnInt64(1);
351 int64 server_mtime = s.ColumnInt64(2); 355 int64_t server_mtime = s.ColumnInt64(2);
352 int64 ctime = s.ColumnInt64(3); 356 int64_t ctime = s.ColumnInt64(3);
353 int64 server_ctime = s.ColumnInt64(4); 357 int64_t server_ctime = s.ColumnInt64(4);
354 EXPECT_EQ(mtime, server_mtime); 358 EXPECT_EQ(mtime, server_mtime);
355 EXPECT_EQ(mtime, ctime); 359 EXPECT_EQ(mtime, ctime);
356 EXPECT_EQ(mtime, server_ctime); 360 EXPECT_EQ(mtime, server_ctime);
357 meta_times[metahandle] = mtime; 361 meta_times[metahandle] = mtime;
358 } 362 }
359 EXPECT_TRUE(s.Succeeded()); 363 EXPECT_TRUE(s.Succeeded());
360 return meta_times; 364 return meta_times;
361 } 365 }
362 366
363 ::testing::AssertionResult AssertTimesMatch(const char* t1_expr, 367 ::testing::AssertionResult AssertTimesMatch(const char* t1_expr,
(...skipping 22 matching lines...) Expand all
386 expected_time, entry_kernel.ref(SERVER_CTIME)); 390 expected_time, entry_kernel.ref(SERVER_CTIME));
387 EXPECT_PRED_FORMAT2(AssertTimesMatch, 391 EXPECT_PRED_FORMAT2(AssertTimesMatch,
388 expected_time, entry_kernel.ref(MTIME)); 392 expected_time, entry_kernel.ref(MTIME));
389 EXPECT_PRED_FORMAT2(AssertTimesMatch, 393 EXPECT_PRED_FORMAT2(AssertTimesMatch,
390 expected_time, entry_kernel.ref(SERVER_MTIME)); 394 expected_time, entry_kernel.ref(SERVER_MTIME));
391 } 395 }
392 396
393 // Expect that all the entries in |entries| have times matching those in 397 // Expect that all the entries in |entries| have times matching those in
394 // the given map (from metahandle to expect time). 398 // the given map (from metahandle to expect time).
395 void ExpectTimes(const Directory::MetahandlesMap& handles_map, 399 void ExpectTimes(const Directory::MetahandlesMap& handles_map,
396 const std::map<int64, base::Time>& expected_times) { 400 const std::map<int64_t, base::Time>& expected_times) {
397 for (Directory::MetahandlesMap::const_iterator it = handles_map.begin(); 401 for (Directory::MetahandlesMap::const_iterator it = handles_map.begin();
398 it != handles_map.end(); ++it) { 402 it != handles_map.end(); ++it) {
399 int64 meta_handle = it->first; 403 int64_t meta_handle = it->first;
400 SCOPED_TRACE(meta_handle); 404 SCOPED_TRACE(meta_handle);
401 std::map<int64, base::Time>::const_iterator it2 = 405 std::map<int64_t, base::Time>::const_iterator it2 =
402 expected_times.find(meta_handle); 406 expected_times.find(meta_handle);
403 if (it2 == expected_times.end()) { 407 if (it2 == expected_times.end()) {
404 ADD_FAILURE() << "Could not find expected time for " << meta_handle; 408 ADD_FAILURE() << "Could not find expected time for " << meta_handle;
405 continue; 409 continue;
406 } 410 }
407 ExpectTime(*it->second, it2->second); 411 ExpectTime(*it->second, it2->second);
408 } 412 }
409 } 413 }
410 414
411 } // namespace 415 } // namespace
(...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1852 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064," 1856 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,"
1853 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);")); 1857 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);"));
1854 ASSERT_TRUE(connection->CommitTransaction()); 1858 ASSERT_TRUE(connection->CommitTransaction());
1855 } 1859 }
1856 1860
1857 1861
1858 // Helper definitions to create the version 81 DB tables. 1862 // Helper definitions to create the version 81 DB tables.
1859 namespace { 1863 namespace {
1860 1864
1861 const int V80_ROW_COUNT = 13; 1865 const int V80_ROW_COUNT = 13;
1862 const int64 V80_POSITIONS[V80_ROW_COUNT] = { 1866 const int64_t V80_POSITIONS[V80_ROW_COUNT] = {
1863 0, 1867 0, -2097152, -3145728, 1048576, -4194304, 1048576, 1048576,
1864 -2097152, 1868 1048576, 2097152, -1048576, 0, -917504, 1048576};
1865 -3145728,
1866 1048576,
1867 -4194304,
1868 1048576,
1869 1048576,
1870 1048576,
1871 2097152,
1872 -1048576,
1873 0,
1874 -917504,
1875 1048576
1876 };
1877 1869
1878 std::string V81_Ordinal(int n) { 1870 std::string V81_Ordinal(int n) {
1879 return Int64ToNodeOrdinal(V80_POSITIONS[n]).ToInternalValue(); 1871 return Int64ToNodeOrdinal(V80_POSITIONS[n]).ToInternalValue();
1880 } 1872 }
1881 1873
1882 } // namespace 1874 } // namespace
1883 1875
1884 // Unlike the earlier versions, the rows for version 81 are generated 1876 // Unlike the earlier versions, the rows for version 81 are generated
1885 // programmatically to accurately handle unprintable characters for the 1877 // programmatically to accurately handle unprintable characters for the
1886 // server_ordinal_in_parent field. 1878 // server_ordinal_in_parent field.
(...skipping 2166 matching lines...) Expand 10 before | Expand all | Expand 10 after
4053 Directory::MetahandlesMap handles_map; 4045 Directory::MetahandlesMap handles_map;
4054 JournalIndex delete_journals; 4046 JournalIndex delete_journals;
4055 MetahandleSet metahandles_to_purge; 4047 MetahandleSet metahandles_to_purge;
4056 Directory::KernelLoadInfo kernel_load_info; 4048 Directory::KernelLoadInfo kernel_load_info;
4057 STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map); 4049 STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map);
4058 4050
4059 dbs->Load(&handles_map, &delete_journals, &metahandles_to_purge, 4051 dbs->Load(&handles_map, &delete_journals, &metahandles_to_purge,
4060 &kernel_load_info); 4052 &kernel_load_info);
4061 size_t initial_size = handles_map.size(); 4053 size_t initial_size = handles_map.size();
4062 ASSERT_LT(0U, initial_size) << "Test requires handles_map to delete."; 4054 ASSERT_LT(0U, initial_size) << "Test requires handles_map to delete.";
4063 int64 first_to_die = handles_map.begin()->second->ref(META_HANDLE); 4055 int64_t first_to_die = handles_map.begin()->second->ref(META_HANDLE);
4064 MetahandleSet to_delete; 4056 MetahandleSet to_delete;
4065 to_delete.insert(first_to_die); 4057 to_delete.insert(first_to_die);
4066 EXPECT_TRUE(dbs->DeleteEntries(to_delete)); 4058 EXPECT_TRUE(dbs->DeleteEntries(to_delete));
4067 4059
4068 STLDeleteValues(&handles_map); 4060 STLDeleteValues(&handles_map);
4069 metahandles_to_purge.clear(); 4061 metahandles_to_purge.clear();
4070 dbs->LoadEntries(&handles_map, &metahandles_to_purge); 4062 dbs->LoadEntries(&handles_map, &metahandles_to_purge);
4071 4063
4072 EXPECT_EQ(initial_size - 1, handles_map.size()); 4064 EXPECT_EQ(initial_size - 1, handles_map.size());
4073 bool delete_failed = false; 4065 bool delete_failed = false;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
4239 ASSERT_FALSE(dbs->SaveChanges(snapshot)); 4231 ASSERT_FALSE(dbs->SaveChanges(snapshot));
4240 // At this point the handler has been posted but not executed. 4232 // At this point the handler has been posted but not executed.
4241 ASSERT_FALSE(was_called); 4233 ASSERT_FALSE(was_called);
4242 // Pump the message loop and see that it is executed. 4234 // Pump the message loop and see that it is executed.
4243 base::RunLoop().RunUntilIdle(); 4235 base::RunLoop().RunUntilIdle();
4244 ASSERT_TRUE(was_called); 4236 ASSERT_TRUE(was_called);
4245 } 4237 }
4246 4238
4247 } // namespace syncable 4239 } // namespace syncable
4248 } // namespace syncer 4240 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/directory_backing_store.cc ('k') | sync/syncable/directory_change_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698