summaryrefslogtreecommitdiffstats
path: root/sync/api/attachments/attachment_unittest.cc
blob: b61d6231a498be6cfb7ac8659a376bc07e903b7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "sync/api/attachments/attachment.h"

#include <string>

#include "base/memory/ref_counted.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_ptr.h"
#include "sync/protocol/sync.pb.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace syncer {

namespace {

const char kAttachmentData[] = "some data";

}  // namespace

class AttachmentTest : public testing::Test {};

TEST_F(AttachmentTest, Create_UniqueIdIsUnique) {
  scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString);
  some_data->data() = kAttachmentData;
  scoped_ptr<Attachment> a1 = Attachment::Create(some_data);
  scoped_ptr<Attachment> a2 = Attachment::Create(some_data);
  EXPECT_NE(a1->GetId(), a2->GetId());
  EXPECT_EQ(a1->GetData(), a2->GetData());
}

TEST_F(AttachmentTest, Create_WithEmptyData) {
  scoped_refptr<base::RefCountedString> emptyData(new base::RefCountedString);
  scoped_ptr<Attachment> a = Attachment::Create(emptyData);
  EXPECT_EQ(emptyData, a->GetData());
}

TEST_F(AttachmentTest, CreateWithId_HappyCase) {
  AttachmentId id = AttachmentId::Create();
  scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString);
  some_data->data() = kAttachmentData;
  scoped_ptr<Attachment> a = Attachment::CreateWithId(id, some_data);
  EXPECT_EQ(id, a->GetId());
  EXPECT_EQ(some_data, a->GetData());
}

}  // namespace syncer