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

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

Issue 10989063: Changed DB to store node positions as Ordinals. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Minor changes and corrections Created 8 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <string> 5 #include <string>
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/scoped_temp_dir.h" 14 #include "base/scoped_temp_dir.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/synchronization/condition_variable.h" 16 #include "base/synchronization/condition_variable.h"
17 #include "base/test/values_test_util.h" 17 #include "base/test/values_test_util.h"
18 #include "base/threading/platform_thread.h" 18 #include "base/threading/platform_thread.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "sync/internal_api/public/base/ordinal.h"
21 #include "sync/internal_api/public/base/node_ordinal.h"
20 #include "sync/protocol/bookmark_specifics.pb.h" 22 #include "sync/protocol/bookmark_specifics.pb.h"
21 #include "sync/syncable/directory_backing_store.h" 23 #include "sync/syncable/directory_backing_store.h"
22 #include "sync/syncable/directory_change_delegate.h" 24 #include "sync/syncable/directory_change_delegate.h"
23 #include "sync/syncable/in_memory_directory_backing_store.h" 25 #include "sync/syncable/in_memory_directory_backing_store.h"
24 #include "sync/syncable/metahandle_set.h" 26 #include "sync/syncable/metahandle_set.h"
25 #include "sync/syncable/mutable_entry.h" 27 #include "sync/syncable/mutable_entry.h"
26 #include "sync/syncable/on_disk_directory_backing_store.h" 28 #include "sync/syncable/on_disk_directory_backing_store.h"
27 #include "sync/syncable/read_transaction.h" 29 #include "sync/syncable/read_transaction.h"
28 #include "sync/syncable/syncable_proto_util.h" 30 #include "sync/syncable/syncable_proto_util.h"
29 #include "sync/syncable/syncable_util.h" 31 #include "sync/syncable/syncable_util.h"
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 EXPECT_TRUE(server_knows.good()); 1361 EXPECT_TRUE(server_knows.good());
1360 1362
1361 Entry not_is_del(&trans, GET_BY_ID, not_is_del_id); 1363 Entry not_is_del(&trans, GET_BY_ID, not_is_del_id);
1362 EXPECT_TRUE(not_is_del.good()); 1364 EXPECT_TRUE(not_is_del.good());
1363 1365
1364 Entry zombie(&trans, GET_BY_ID, zombie_id); 1366 Entry zombie(&trans, GET_BY_ID, zombie_id);
1365 EXPECT_FALSE(zombie.good()); 1367 EXPECT_FALSE(zombie.good());
1366 } 1368 }
1367 } 1369 }
1368 1370
1371 TEST_F(SyncableDirectoryTest, OrdinalHandlesNullValues) {
1372 TestIdFactory id_factory;
1373 Id null_child_id;
1374 const char null_cstr[] = "\0null\0test";
1375 std::string null_str(null_cstr, null_cstr + 9);
rlarocque 2012/10/02 01:39:50 That second parameter is likely to be bigger than
1376 int64 null_ord = NodeOrdinalToInt64(
1377 NodeOrdinal(null_str));
1378
1379 {
1380 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1381
1382 MutableEntry parent(&trans, CREATE, id_factory.root(), "parent");
1383 parent.Put(IS_DIR, true);
1384 parent.Put(IS_UNSYNCED, true);
1385
1386 MutableEntry child(&trans, CREATE, parent.Get(ID), "child");
1387 child.Put(IS_UNSYNCED, true);
1388 child.Put(SERVER_POSITION_IN_PARENT, null_ord);
1389
1390 null_child_id = child.Get(ID);
1391 }
1392
1393 EXPECT_EQ(OPENED, SimulateSaveAndReloadDir());
1394
1395 {
1396 ReadTransaction trans(FROM_HERE, dir_.get());
1397
1398 Entry null_ordinal_child(&trans, GET_BY_ID, null_child_id);
1399 EXPECT_EQ(null_ord,
1400 null_ordinal_child.Get(SERVER_POSITION_IN_PARENT));
1401 }
1402
1403 }
1404
1369 // An OnDirectoryBackingStore that can be set to always fail SaveChanges. 1405 // An OnDirectoryBackingStore that can be set to always fail SaveChanges.
1370 class TestBackingStore : public OnDiskDirectoryBackingStore { 1406 class TestBackingStore : public OnDiskDirectoryBackingStore {
1371 public: 1407 public:
1372 TestBackingStore(const std::string& dir_name, 1408 TestBackingStore(const std::string& dir_name,
1373 const FilePath& backing_filepath); 1409 const FilePath& backing_filepath);
1374 1410
1375 virtual ~TestBackingStore(); 1411 virtual ~TestBackingStore();
1376 1412
1377 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot) 1413 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot)
1378 OVERRIDE; 1414 OVERRIDE;
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
2090 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); 2126 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true));
2091 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); 2127 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true));
2092 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); 2128 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false));
2093 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); 2129 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false));
2094 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); 2130 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true));
2095 } 2131 }
2096 2132
2097 } // namespace 2133 } // namespace
2098 } // namespace syncable 2134 } // namespace syncable
2099 } // namespace syncer 2135 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698