OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sync/api/attachments/attachment.h" | 5 #include "sync/api/attachments/attachment.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "sync/protocol/sync.pb.h" | 11 #include "sync/protocol/sync.pb.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
14 | 13 |
15 namespace syncer { | 14 namespace syncer { |
16 | 15 |
17 namespace { | 16 namespace { |
18 | 17 |
19 const char kAttachmentData[] = "some data"; | 18 const char kAttachmentData[] = "some data"; |
20 | 19 |
21 } // namespace | 20 } // namespace |
22 | 21 |
23 class AttachmentTest : public testing::Test {}; | 22 class AttachmentTest : public testing::Test {}; |
24 | 23 |
25 TEST_F(AttachmentTest, Create_UniqueIdIsUnique) { | 24 TEST_F(AttachmentTest, Create_UniqueIdIsUnique) { |
26 scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString); | 25 scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString); |
27 some_data->data() = kAttachmentData; | 26 some_data->data() = kAttachmentData; |
28 scoped_ptr<Attachment> a1 = Attachment::Create(some_data); | 27 Attachment a1 = Attachment::Create(some_data); |
29 scoped_ptr<Attachment> a2 = Attachment::Create(some_data); | 28 Attachment a2 = Attachment::Create(some_data); |
30 EXPECT_NE(a1->GetId(), a2->GetId()); | 29 EXPECT_NE(a1.GetId(), a2.GetId()); |
31 EXPECT_EQ(a1->GetData(), a2->GetData()); | 30 EXPECT_EQ(a1.GetData(), a2.GetData()); |
32 } | 31 } |
33 | 32 |
34 TEST_F(AttachmentTest, Create_WithEmptyData) { | 33 TEST_F(AttachmentTest, Create_WithEmptyData) { |
35 scoped_refptr<base::RefCountedString> emptyData(new base::RefCountedString); | 34 scoped_refptr<base::RefCountedString> empty_data(new base::RefCountedString); |
36 scoped_ptr<Attachment> a = Attachment::Create(emptyData); | 35 Attachment a = Attachment::Create(empty_data); |
37 EXPECT_EQ(emptyData, a->GetData()); | 36 EXPECT_EQ(empty_data, a.GetData()); |
38 } | 37 } |
39 | 38 |
40 TEST_F(AttachmentTest, CreateWithId_HappyCase) { | 39 TEST_F(AttachmentTest, CreateWithId_HappyCase) { |
41 AttachmentId id = AttachmentId::Create(); | 40 AttachmentId id = AttachmentId::Create(); |
42 scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString); | 41 scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString); |
43 some_data->data() = kAttachmentData; | 42 some_data->data() = kAttachmentData; |
44 scoped_ptr<Attachment> a = Attachment::CreateWithId(id, some_data); | 43 Attachment a = Attachment::CreateWithId(id, some_data); |
45 EXPECT_EQ(id, a->GetId()); | 44 EXPECT_EQ(id, a.GetId()); |
46 EXPECT_EQ(some_data, a->GetData()); | 45 EXPECT_EQ(some_data, a.GetData()); |
47 } | 46 } |
48 | 47 |
49 } // namespace syncer | 48 } // namespace syncer |
OLD | NEW |