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