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

Side by Side Diff: sync/internal_api/public/data_batch_impl_unittest.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
(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
OLDNEW
« no previous file with comments | « sync/internal_api/public/data_batch_impl.cc ('k') | sync/internal_api/public/data_type_association_stats.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698