OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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/api/sync_attachment.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/ref_counted_memory.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "sync/protocol/sync.pb.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 using sync_pb::SyncAttachmentId; |
| 16 |
| 17 namespace syncer { |
| 18 |
| 19 namespace { |
| 20 |
| 21 const char kAttachmentData[] = "some data"; |
| 22 |
| 23 typedef testing::Test SyncAttachmentTest; |
| 24 |
| 25 TEST_F(SyncAttachmentTest, Create_UniqueIdIsUnique) { |
| 26 SyncAttachmentId id; |
| 27 scoped_refptr<base::RefCountedString> bytes(new base::RefCountedString); |
| 28 bytes->data() = kAttachmentData; |
| 29 scoped_ptr<SyncAttachment> a1 = SyncAttachment::Create(bytes); |
| 30 scoped_ptr<SyncAttachment> a2 = SyncAttachment::Create(bytes); |
| 31 EXPECT_NE(a1->GetId().unique_id(), a2->GetId().unique_id()); |
| 32 EXPECT_EQ(a1->GetBytes(), a2->GetBytes()); |
| 33 } |
| 34 |
| 35 TEST_F(SyncAttachmentTest, Create_WithEmptyBytes) { |
| 36 SyncAttachmentId id; |
| 37 scoped_refptr<base::RefCountedString> emptyBytes(new base::RefCountedString); |
| 38 scoped_ptr<SyncAttachment> a = SyncAttachment::Create(emptyBytes); |
| 39 EXPECT_EQ(emptyBytes, a->GetBytes()); |
| 40 } |
| 41 |
| 42 TEST_F(SyncAttachmentTest, CreateWithId_HappyCase) { |
| 43 SyncAttachmentId id; |
| 44 id.set_unique_id("3290482049832"); |
| 45 scoped_refptr<base::RefCountedString> bytes(new base::RefCountedString); |
| 46 bytes->data() = kAttachmentData; |
| 47 scoped_ptr<SyncAttachment> a = SyncAttachment::CreateWithId(id, bytes); |
| 48 EXPECT_EQ(id.unique_id(), a->GetId().unique_id()); |
| 49 EXPECT_EQ(bytes, a->GetBytes()); |
| 50 } |
| 51 |
| 52 } // namespace |
| 53 |
| 54 } // namespace syncer |
OLD | NEW |