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
3 // found in the LICENSE file.
5 #include "sync/api/attachments/attachment.h"
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"
15 using sync_pb::AttachmentId;
21 const char kAttachmentData[] = "some data";
25 class AttachmentTest : public testing::Test {};
27 TEST_F(AttachmentTest, CreateId_UniqueIdIsUnique) {
28 AttachmentId id1 = Attachment::CreateId();
29 AttachmentId id2 = Attachment::CreateId();
30 EXPECT_NE(id1.unique_id(), id2.unique_id());
33 TEST_F(AttachmentTest, Create_UniqueIdIsUnique) {
35 scoped_refptr<base::RefCountedString> bytes(new base::RefCountedString);
36 bytes->data() = kAttachmentData;
37 scoped_ptr<Attachment> a1 = Attachment::Create(bytes);
38 scoped_ptr<Attachment> a2 = Attachment::Create(bytes);
39 EXPECT_NE(a1->GetId().unique_id(), a2->GetId().unique_id());
40 EXPECT_EQ(a1->GetBytes(), a2->GetBytes());
43 TEST_F(AttachmentTest, Create_WithEmptyBytes) {
45 scoped_refptr<base::RefCountedString> emptyBytes(new base::RefCountedString);
46 scoped_ptr<Attachment> a = Attachment::Create(emptyBytes);
47 EXPECT_EQ(emptyBytes, a->GetBytes());
50 TEST_F(AttachmentTest, CreateWithId_HappyCase) {
52 id.set_unique_id("3290482049832");
53 scoped_refptr<base::RefCountedString> bytes(new base::RefCountedString);
54 bytes->data() = kAttachmentData;
55 scoped_ptr<Attachment> a = Attachment::CreateWithId(id, bytes);
56 EXPECT_EQ(id.unique_id(), a->GetId().unique_id());
57 EXPECT_EQ(bytes, a->GetBytes());