attachment_unittest.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 "base/memory/scoped_ptr.h"
12#include "sync/protocol/sync.pb.h"
13#include "testing/gtest/include/gtest/gtest.h"
14
15using sync_pb::AttachmentId;
16
17namespace syncer {
18
19namespace {
20
21const char kAttachmentData[] = "some data";
22
23}  // namespace
24
25class AttachmentTest : public testing::Test {};
26
27TEST_F(AttachmentTest, CreateId_UniqueIdIsUnique) {
28  AttachmentId id1 = Attachment::CreateId();
29  AttachmentId id2 = Attachment::CreateId();
30  EXPECT_NE(id1.unique_id(), id2.unique_id());
31}
32
33TEST_F(AttachmentTest, Create_UniqueIdIsUnique) {
34  AttachmentId id;
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());
41}
42
43TEST_F(AttachmentTest, Create_WithEmptyBytes) {
44  AttachmentId id;
45  scoped_refptr<base::RefCountedString> emptyBytes(new base::RefCountedString);
46  scoped_ptr<Attachment> a = Attachment::Create(emptyBytes);
47  EXPECT_EQ(emptyBytes, a->GetBytes());
48}
49
50TEST_F(AttachmentTest, CreateWithId_HappyCase) {
51  AttachmentId id;
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());
58}
59
60}  // namespace syncer
61