| 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 using sync_pb::AttachmentId; | 14 using sync_pb::AttachmentId; |
| 16 | 15 |
| 17 namespace syncer { | 16 namespace syncer { |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 const char kAttachmentData[] = "some data"; | 20 const char kAttachmentData[] = "some data"; |
| 22 | 21 |
| 23 } // namespace | 22 } // namespace |
| 24 | 23 |
| 25 class AttachmentTest : public testing::Test {}; | 24 class AttachmentTest : public testing::Test {}; |
| 26 | 25 |
| 27 TEST_F(AttachmentTest, CreateId_UniqueIdIsUnique) { | 26 TEST_F(AttachmentTest, CreateId_UniqueIdIsUnique) { |
| 28 AttachmentId id1 = Attachment::CreateId(); | 27 AttachmentId id1 = Attachment::CreateId(); |
| 29 AttachmentId id2 = Attachment::CreateId(); | 28 AttachmentId id2 = Attachment::CreateId(); |
| 30 EXPECT_NE(id1.unique_id(), id2.unique_id()); | 29 EXPECT_NE(id1.unique_id(), id2.unique_id()); |
| 31 } | 30 } |
| 32 | 31 |
| 33 TEST_F(AttachmentTest, Create_UniqueIdIsUnique) { | 32 TEST_F(AttachmentTest, Create_UniqueIdIsUnique) { |
| 34 AttachmentId id; | 33 AttachmentId id; |
| 35 scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString); | 34 scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString); |
| 36 some_data->data() = kAttachmentData; | 35 some_data->data() = kAttachmentData; |
| 37 scoped_ptr<Attachment> a1 = Attachment::Create(some_data); | 36 Attachment a1 = Attachment::Create(some_data); |
| 38 scoped_ptr<Attachment> a2 = Attachment::Create(some_data); | 37 Attachment a2 = Attachment::Create(some_data); |
| 39 EXPECT_NE(a1->GetId().unique_id(), a2->GetId().unique_id()); | 38 EXPECT_NE(a1.GetId().unique_id(), a2.GetId().unique_id()); |
| 40 EXPECT_EQ(a1->GetData(), a2->GetData()); | 39 EXPECT_EQ(a1.GetData(), a2.GetData()); |
| 41 } | 40 } |
| 42 | 41 |
| 43 TEST_F(AttachmentTest, Create_WithEmptyData) { | 42 TEST_F(AttachmentTest, Create_WithEmptyData) { |
| 44 AttachmentId id; | 43 AttachmentId id; |
| 45 scoped_refptr<base::RefCountedString> emptyData(new base::RefCountedString); | 44 scoped_refptr<base::RefCountedString> empty_data(new base::RefCountedString); |
| 46 scoped_ptr<Attachment> a = Attachment::Create(emptyData); | 45 Attachment a = Attachment::Create(empty_data); |
| 47 EXPECT_EQ(emptyData, a->GetData()); | 46 EXPECT_EQ(empty_data, a.GetData()); |
| 48 } | 47 } |
| 49 | 48 |
| 50 TEST_F(AttachmentTest, CreateWithId_HappyCase) { | 49 TEST_F(AttachmentTest, CreateWithId_HappyCase) { |
| 51 AttachmentId id; | 50 AttachmentId id; |
| 52 id.set_unique_id("3290482049832"); | 51 id.set_unique_id("3290482049832"); |
| 53 scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString); | 52 scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString); |
| 54 some_data->data() = kAttachmentData; | 53 some_data->data() = kAttachmentData; |
| 55 scoped_ptr<Attachment> a = Attachment::CreateWithId(id, some_data); | 54 Attachment a = Attachment::CreateWithId(id, some_data); |
| 56 EXPECT_EQ(id.unique_id(), a->GetId().unique_id()); | 55 EXPECT_EQ(id.unique_id(), a.GetId().unique_id()); |
| 57 EXPECT_EQ(some_data, a->GetData()); | 56 EXPECT_EQ(some_data, a.GetData()); |
| 58 } | 57 } |
| 59 | 58 |
| 60 } // namespace syncer | 59 } // namespace syncer |
| OLD | NEW |