OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sync/internal_api/public/base/attachment_id_proto.h" | 5 #include "sync/internal_api/public/base/attachment_id_proto.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "testing/gmock/include/gmock/gmock-matchers.h" | 8 #include "testing/gmock/include/gmock/gmock-matchers.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace syncer { | 11 namespace syncer { |
12 | 12 |
13 typedef testing::Test AttachmentIdProtoTest; | 13 typedef testing::Test AttachmentIdProtoTest; |
14 | 14 |
15 // Verify that that we generate a proto with a properly formatted unique_id | 15 // Verify that that we generate a proto with a properly formatted unique_id |
16 // field. | 16 // field. |
17 TEST(AttachmentIdProtoTest, UniqueIdFormat) { | 17 TEST(AttachmentIdProtoTest, UniqueIdFormat) { |
18 sync_pb::AttachmentIdProto id_proto = CreateAttachmentIdProto(0, 0); | 18 sync_pb::AttachmentIdProto id_proto = CreateAttachmentIdProto(0, 0); |
19 ASSERT_TRUE(id_proto.has_unique_id()); | 19 ASSERT_TRUE(id_proto.has_unique_id()); |
20 // gtest's regular expression support is pretty poor so we cannot test as | 20 // gtest's regular expression support is pretty poor so we cannot test as |
21 // closely as we would like. | 21 // closely as we would like. |
22 EXPECT_THAT(id_proto.unique_id(), | 22 EXPECT_THAT(id_proto.unique_id(), |
23 testing::MatchesRegex( | 23 testing::MatchesRegex( |
24 "\\w\\w\\w\\w\\w\\w\\w\\w-\\w\\w\\w\\w-\\w\\w\\w\\w-" | 24 "\\w\\w\\w\\w\\w\\w\\w\\w-\\w\\w\\w\\w-\\w\\w\\w\\w-" |
25 "\\w\\w\\w\\w-\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w")); | 25 "\\w\\w\\w\\w-\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w")); |
26 EXPECT_EQ(base::StringToLowerASCII(id_proto.unique_id()), | 26 EXPECT_EQ(base::ToLowerASCII(id_proto.unique_id()), id_proto.unique_id()); |
27 id_proto.unique_id()); | |
28 } | 27 } |
29 | 28 |
30 TEST(AttachmentIdProtoTest, CreateAttachmentMetadata_Empty) { | 29 TEST(AttachmentIdProtoTest, CreateAttachmentMetadata_Empty) { |
31 google::protobuf::RepeatedPtrField<sync_pb::AttachmentIdProto> ids; | 30 google::protobuf::RepeatedPtrField<sync_pb::AttachmentIdProto> ids; |
32 sync_pb::AttachmentMetadata metadata = CreateAttachmentMetadata(ids); | 31 sync_pb::AttachmentMetadata metadata = CreateAttachmentMetadata(ids); |
33 EXPECT_EQ(0, metadata.record_size()); | 32 EXPECT_EQ(0, metadata.record_size()); |
34 } | 33 } |
35 | 34 |
36 TEST(AttachmentIdProtoTest, CreateAttachmentMetadata_NonEmpty) { | 35 TEST(AttachmentIdProtoTest, CreateAttachmentMetadata_NonEmpty) { |
37 google::protobuf::RepeatedPtrField<sync_pb::AttachmentIdProto> ids; | 36 google::protobuf::RepeatedPtrField<sync_pb::AttachmentIdProto> ids; |
38 *ids.Add() = CreateAttachmentIdProto(0, 0); | 37 *ids.Add() = CreateAttachmentIdProto(0, 0); |
39 *ids.Add() = CreateAttachmentIdProto(0, 0); | 38 *ids.Add() = CreateAttachmentIdProto(0, 0); |
40 *ids.Add() = CreateAttachmentIdProto(0, 0); | 39 *ids.Add() = CreateAttachmentIdProto(0, 0); |
41 sync_pb::AttachmentMetadata metadata = CreateAttachmentMetadata(ids); | 40 sync_pb::AttachmentMetadata metadata = CreateAttachmentMetadata(ids); |
42 ASSERT_EQ(3, metadata.record_size()); | 41 ASSERT_EQ(3, metadata.record_size()); |
43 for (int i = 0; i < metadata.record_size(); ++i) { | 42 for (int i = 0; i < metadata.record_size(); ++i) { |
44 EXPECT_EQ(ids.Get(i).SerializeAsString(), | 43 EXPECT_EQ(ids.Get(i).SerializeAsString(), |
45 metadata.record(i).id().SerializeAsString()); | 44 metadata.record(i).id().SerializeAsString()); |
46 EXPECT_TRUE(metadata.record(i).is_on_server()); | 45 EXPECT_TRUE(metadata.record(i).is_on_server()); |
47 } | 46 } |
48 } | 47 } |
49 | 48 |
50 } // namespace syncer | 49 } // namespace syncer |
OLD | NEW |