OLD | NEW |
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 // Syncer unit tests. Unfortunately a lot of these tests | 5 // Syncer unit tests. Unfortunately a lot of these tests |
6 // are outdated and need to be reworked and updated. | 6 // are outdated and need to be reworked and updated. |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <list> | 10 #include <list> |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 using syncable::GET_BY_ID; | 83 using syncable::GET_BY_ID; |
84 using syncable::GET_BY_CLIENT_TAG; | 84 using syncable::GET_BY_CLIENT_TAG; |
85 using syncable::GET_BY_SERVER_TAG; | 85 using syncable::GET_BY_SERVER_TAG; |
86 using syncable::ID; | 86 using syncable::ID; |
87 using syncable::IS_DEL; | 87 using syncable::IS_DEL; |
88 using syncable::IS_DIR; | 88 using syncable::IS_DIR; |
89 using syncable::IS_UNAPPLIED_UPDATE; | 89 using syncable::IS_UNAPPLIED_UPDATE; |
90 using syncable::IS_UNSYNCED; | 90 using syncable::IS_UNSYNCED; |
91 using syncable::META_HANDLE; | 91 using syncable::META_HANDLE; |
92 using syncable::MTIME; | 92 using syncable::MTIME; |
93 using syncable::NEXT_ID; | |
94 using syncable::NON_UNIQUE_NAME; | 93 using syncable::NON_UNIQUE_NAME; |
95 using syncable::PARENT_ID; | 94 using syncable::PARENT_ID; |
96 using syncable::PREV_ID; | |
97 using syncable::BASE_SERVER_SPECIFICS; | 95 using syncable::BASE_SERVER_SPECIFICS; |
98 using syncable::SERVER_IS_DEL; | 96 using syncable::SERVER_IS_DEL; |
99 using syncable::SERVER_PARENT_ID; | 97 using syncable::SERVER_PARENT_ID; |
100 using syncable::SERVER_ORDINAL_IN_PARENT; | 98 using syncable::SERVER_ORDINAL_IN_PARENT; |
101 using syncable::SERVER_SPECIFICS; | 99 using syncable::SERVER_SPECIFICS; |
102 using syncable::SERVER_VERSION; | 100 using syncable::SERVER_VERSION; |
103 using syncable::UNIQUE_CLIENT_TAG; | 101 using syncable::UNIQUE_CLIENT_TAG; |
104 using syncable::UNIQUE_SERVER_TAG; | 102 using syncable::UNIQUE_SERVER_TAG; |
105 using syncable::SPECIFICS; | 103 using syncable::SPECIFICS; |
106 using syncable::SYNCING; | 104 using syncable::SYNCING; |
(...skipping 4395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4502 | 4500 |
4503 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4501 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4504 | 4502 |
4505 Id prev_id; | 4503 Id prev_id; |
4506 DCHECK(prev_id.IsRoot()); | 4504 DCHECK(prev_id.IsRoot()); |
4507 PosMap::iterator next = position_map_.begin(); | 4505 PosMap::iterator next = position_map_.begin(); |
4508 for (PosMap::iterator i = next++; i != position_map_.end(); ++i) { | 4506 for (PosMap::iterator i = next++; i != position_map_.end(); ++i) { |
4509 Id id = i->second; | 4507 Id id = i->second; |
4510 Entry entry_with_id(&trans, GET_BY_ID, id); | 4508 Entry entry_with_id(&trans, GET_BY_ID, id); |
4511 EXPECT_TRUE(entry_with_id.good()); | 4509 EXPECT_TRUE(entry_with_id.good()); |
4512 EXPECT_EQ(prev_id, entry_with_id.Get(PREV_ID)); | 4510 EXPECT_EQ(prev_id, entry_with_id.GetPredecessorId()); |
4513 EXPECT_EQ( | 4511 EXPECT_EQ( |
4514 i->first, | 4512 i->first, |
4515 NodeOrdinalToInt64(entry_with_id.Get(SERVER_ORDINAL_IN_PARENT))); | 4513 NodeOrdinalToInt64(entry_with_id.Get(SERVER_ORDINAL_IN_PARENT))); |
4516 if (next == position_map_.end()) { | 4514 if (next == position_map_.end()) { |
4517 EXPECT_EQ(Id(), entry_with_id.Get(NEXT_ID)); | 4515 EXPECT_EQ(Id(), entry_with_id.GetSuccessorId()); |
4518 } else { | 4516 } else { |
4519 EXPECT_EQ(next->second, entry_with_id.Get(NEXT_ID)); | 4517 EXPECT_EQ(next->second, entry_with_id.GetSuccessorId()); |
4520 next++; | 4518 next++; |
4521 } | 4519 } |
4522 prev_id = id; | 4520 prev_id = id; |
4523 } | 4521 } |
4524 } | 4522 } |
4525 | 4523 |
4526 void AddRootItemWithPosition(int64 position) { | 4524 void AddRootItemWithPosition(int64 position) { |
4527 string id = string("ServerId") + base::Int64ToString(next_update_id_++); | 4525 string id = string("ServerId") + base::Int64ToString(next_update_id_++); |
4528 string name = "my name is my id -- " + id; | 4526 string name = "my name is my id -- " + id; |
4529 int revision = next_revision_++; | 4527 int revision = next_revision_++; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4629 | 4627 |
4630 void ExpectLocalOrderIsByServerId() { | 4628 void ExpectLocalOrderIsByServerId() { |
4631 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4629 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4632 Id null_id; | 4630 Id null_id; |
4633 Entry low(&trans, GET_BY_ID, low_id_); | 4631 Entry low(&trans, GET_BY_ID, low_id_); |
4634 Entry mid(&trans, GET_BY_ID, mid_id_); | 4632 Entry mid(&trans, GET_BY_ID, mid_id_); |
4635 Entry high(&trans, GET_BY_ID, high_id_); | 4633 Entry high(&trans, GET_BY_ID, high_id_); |
4636 EXPECT_TRUE(low.good()); | 4634 EXPECT_TRUE(low.good()); |
4637 EXPECT_TRUE(mid.good()); | 4635 EXPECT_TRUE(mid.good()); |
4638 EXPECT_TRUE(high.good()); | 4636 EXPECT_TRUE(high.good()); |
4639 EXPECT_TRUE(low.Get(PREV_ID) == null_id); | 4637 EXPECT_TRUE(low.GetPredecessorId() == null_id); |
4640 EXPECT_TRUE(mid.Get(PREV_ID) == low_id_); | 4638 EXPECT_TRUE(mid.GetPredecessorId() == low_id_); |
4641 EXPECT_TRUE(high.Get(PREV_ID) == mid_id_); | 4639 EXPECT_TRUE(high.GetPredecessorId() == mid_id_); |
4642 EXPECT_TRUE(high.Get(NEXT_ID) == null_id); | 4640 EXPECT_TRUE(high.GetSuccessorId() == null_id); |
4643 EXPECT_TRUE(mid.Get(NEXT_ID) == high_id_); | 4641 EXPECT_TRUE(mid.GetSuccessorId() == high_id_); |
4644 EXPECT_TRUE(low.Get(NEXT_ID) == mid_id_); | 4642 EXPECT_TRUE(low.GetSuccessorId() == mid_id_); |
4645 } | 4643 } |
4646 | 4644 |
4647 protected: | 4645 protected: |
4648 // When there's a tiebreak on the numeric position, it's supposed to be | 4646 // When there's a tiebreak on the numeric position, it's supposed to be |
4649 // broken by string comparison of the ids. These ids are in increasing | 4647 // broken by string comparison of the ids. These ids are in increasing |
4650 // order. | 4648 // order. |
4651 const Id low_id_; | 4649 const Id low_id_; |
4652 const Id mid_id_; | 4650 const Id mid_id_; |
4653 const Id high_id_; | 4651 const Id high_id_; |
4654 | 4652 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4699 | 4697 |
4700 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | 4698 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { |
4701 Add(mid_id_); | 4699 Add(mid_id_); |
4702 Add(low_id_); | 4700 Add(low_id_); |
4703 Add(high_id_); | 4701 Add(high_id_); |
4704 SyncShareNudge(); | 4702 SyncShareNudge(); |
4705 ExpectLocalOrderIsByServerId(); | 4703 ExpectLocalOrderIsByServerId(); |
4706 } | 4704 } |
4707 | 4705 |
4708 } // namespace syncer | 4706 } // namespace syncer |
OLD | NEW |