OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/sync/api/entity_data.h" | 5 #include "components/sync/api/entity_data.h" |
6 | 6 |
7 #include "components/sync/base/model_type.h" | 7 #include "components/sync/base/model_type.h" |
8 #include "components/sync/base/unique_position.h" | 8 #include "components/sync/base/unique_position.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace syncer_v2 { | 11 namespace syncer { |
12 | 12 |
13 class EntityDataTest : public testing::Test { | 13 class EntityDataTest : public testing::Test { |
14 protected: | 14 protected: |
15 EntityDataTest() {} | 15 EntityDataTest() {} |
16 ~EntityDataTest() override {} | 16 ~EntityDataTest() override {} |
17 }; | 17 }; |
18 | 18 |
19 TEST_F(EntityDataTest, IsDeleted) { | 19 TEST_F(EntityDataTest, IsDeleted) { |
20 EntityData data; | 20 EntityData data; |
21 EXPECT_TRUE(data.is_deleted()); | 21 EXPECT_TRUE(data.is_deleted()); |
22 | 22 |
23 syncer::AddDefaultFieldValue(syncer::BOOKMARKS, &data.specifics); | 23 AddDefaultFieldValue(BOOKMARKS, &data.specifics); |
24 EXPECT_FALSE(data.is_deleted()); | 24 EXPECT_FALSE(data.is_deleted()); |
25 } | 25 } |
26 | 26 |
27 TEST_F(EntityDataTest, Swap) { | 27 TEST_F(EntityDataTest, Swap) { |
28 EntityData data; | 28 EntityData data; |
29 syncer::AddDefaultFieldValue(syncer::BOOKMARKS, &data.specifics); | 29 AddDefaultFieldValue(BOOKMARKS, &data.specifics); |
30 data.id = "id"; | 30 data.id = "id"; |
31 data.client_tag_hash = "client_tag_hash"; | 31 data.client_tag_hash = "client_tag_hash"; |
32 data.non_unique_name = "non_unique_name"; | 32 data.non_unique_name = "non_unique_name"; |
33 data.creation_time = base::Time::FromTimeT(10); | 33 data.creation_time = base::Time::FromTimeT(10); |
34 data.modification_time = base::Time::FromTimeT(20); | 34 data.modification_time = base::Time::FromTimeT(20); |
35 data.parent_id = "parent_id"; | 35 data.parent_id = "parent_id"; |
36 | 36 |
37 using syncer::UniquePosition; | |
38 UniquePosition unique_position = | 37 UniquePosition unique_position = |
39 UniquePosition::InitialPosition(UniquePosition::RandomSuffix()); | 38 UniquePosition::InitialPosition(UniquePosition::RandomSuffix()); |
40 | 39 |
41 unique_position.ToProto(&data.unique_position); | 40 unique_position.ToProto(&data.unique_position); |
42 | 41 |
43 // Remember addresses of some data within EntitySpecific and UniquePosition | 42 // Remember addresses of some data within EntitySpecific and UniquePosition |
44 // to make sure that the underlying data isn't copied. | 43 // to make sure that the underlying data isn't copied. |
45 const sync_pb::BookmarkSpecifics* bookmark_specifics = | 44 const sync_pb::BookmarkSpecifics* bookmark_specifics = |
46 &data.specifics.bookmark(); | 45 &data.specifics.bookmark(); |
47 const std::string* unique_position_value = &data.unique_position.value(); | 46 const std::string* unique_position_value = &data.unique_position.value(); |
48 | 47 |
49 EntityDataPtr ptr(data.PassToPtr()); | 48 EntityDataPtr ptr(data.PassToPtr()); |
50 | 49 |
51 // Compare addresses of the data wrapped by EntityDataPtr to make sure that | 50 // Compare addresses of the data wrapped by EntityDataPtr to make sure that |
52 // the underlying objects are exactly the same. | 51 // the underlying objects are exactly the same. |
53 EXPECT_EQ(bookmark_specifics, &ptr->specifics.bookmark()); | 52 EXPECT_EQ(bookmark_specifics, &ptr->specifics.bookmark()); |
54 EXPECT_EQ(unique_position_value, &ptr->unique_position.value()); | 53 EXPECT_EQ(unique_position_value, &ptr->unique_position.value()); |
55 | 54 |
56 // Compare other fields. | 55 // Compare other fields. |
57 EXPECT_EQ("id", ptr->id); | 56 EXPECT_EQ("id", ptr->id); |
58 EXPECT_EQ("client_tag_hash", ptr->client_tag_hash); | 57 EXPECT_EQ("client_tag_hash", ptr->client_tag_hash); |
59 EXPECT_EQ("non_unique_name", ptr->non_unique_name); | 58 EXPECT_EQ("non_unique_name", ptr->non_unique_name); |
60 EXPECT_EQ("parent_id", ptr->parent_id); | 59 EXPECT_EQ("parent_id", ptr->parent_id); |
61 EXPECT_EQ(base::Time::FromTimeT(10), ptr->creation_time); | 60 EXPECT_EQ(base::Time::FromTimeT(10), ptr->creation_time); |
62 EXPECT_EQ(base::Time::FromTimeT(20), ptr->modification_time); | 61 EXPECT_EQ(base::Time::FromTimeT(20), ptr->modification_time); |
63 } | 62 } |
64 | 63 |
65 } // namespace syncer_v2 | 64 } // namespace syncer |
OLD | NEW |