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