OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "sync/internal_api/public/data_batch_impl.h" | |
6 | |
7 #include "base/memory/ptr_util.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace syncer_v2 { | |
11 | |
12 TEST(DataBatchImplTest, PutAndNextWithReuse) { | |
13 EntityData* entity1 = new EntityData(); | |
14 EntityData* entity2 = new EntityData(); | |
15 | |
16 DataBatchImpl batch; | |
17 EXPECT_FALSE(batch.HasNext()); | |
18 | |
19 batch.Put("one", base::WrapUnique(entity1)); | |
20 EXPECT_TRUE(batch.HasNext()); | |
21 | |
22 const TagAndData& pair1 = batch.Next(); | |
23 EXPECT_FALSE(batch.HasNext()); | |
24 EXPECT_EQ("one", pair1.first); | |
25 EXPECT_EQ(entity1, pair1.second.get()); | |
26 | |
27 batch.Put("two", base::WrapUnique(entity2)); | |
28 EXPECT_TRUE(batch.HasNext()); | |
29 | |
30 const TagAndData& pair2 = batch.Next(); | |
31 EXPECT_FALSE(batch.HasNext()); | |
32 EXPECT_EQ("two", pair2.first); | |
33 EXPECT_EQ(entity2, pair2.second.get()); | |
34 } | |
35 | |
36 TEST(DataBatchImplTest, PutAndNextInterleaved) { | |
37 EntityData* entity1 = new EntityData(); | |
38 EntityData* entity2 = new EntityData(); | |
39 EntityData* entity3 = new EntityData(); | |
40 | |
41 DataBatchImpl batch; | |
42 EXPECT_FALSE(batch.HasNext()); | |
43 | |
44 batch.Put("one", base::WrapUnique(entity1)); | |
45 EXPECT_TRUE(batch.HasNext()); | |
46 batch.Put("two", base::WrapUnique(entity2)); | |
47 EXPECT_TRUE(batch.HasNext()); | |
48 | |
49 const TagAndData& pair1 = batch.Next(); | |
50 EXPECT_TRUE(batch.HasNext()); | |
51 EXPECT_EQ("one", pair1.first); | |
52 EXPECT_EQ(entity1, pair1.second.get()); | |
53 | |
54 batch.Put("three", base::WrapUnique(entity3)); | |
55 EXPECT_TRUE(batch.HasNext()); | |
56 | |
57 const TagAndData& pair2 = batch.Next(); | |
58 EXPECT_TRUE(batch.HasNext()); | |
59 EXPECT_EQ("two", pair2.first); | |
60 EXPECT_EQ(entity2, pair2.second.get()); | |
61 | |
62 const TagAndData& pair3 = batch.Next(); | |
63 EXPECT_FALSE(batch.HasNext()); | |
64 EXPECT_EQ("three", pair3.first); | |
65 EXPECT_EQ(entity3, pair3.second.get()); | |
66 } | |
67 | |
68 TEST(DataBatchImplTest, PutAndNextSharedTag) { | |
69 EntityData* entity1 = new EntityData(); | |
70 EntityData* entity2 = new EntityData(); | |
71 | |
72 DataBatchImpl batch; | |
73 EXPECT_FALSE(batch.HasNext()); | |
74 | |
75 batch.Put("same", base::WrapUnique(entity1)); | |
76 EXPECT_TRUE(batch.HasNext()); | |
77 batch.Put("same", base::WrapUnique(entity2)); | |
78 EXPECT_TRUE(batch.HasNext()); | |
79 | |
80 const TagAndData& pair1 = batch.Next(); | |
81 EXPECT_TRUE(batch.HasNext()); | |
82 EXPECT_EQ("same", pair1.first); | |
83 EXPECT_EQ(entity1, pair1.second.get()); | |
84 | |
85 const TagAndData& pair2 = batch.Next(); | |
86 EXPECT_FALSE(batch.HasNext()); | |
87 EXPECT_EQ("same", pair2.first); | |
88 EXPECT_EQ(entity2, pair2.second.get()); | |
89 } | |
90 | |
91 } // namespace syncer_v2 | |
OLD | NEW |