OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2006-2008 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 "chrome/browser/sync/engine/syncer_proto_util.h" |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "chrome/browser/sync/engine/syncproto.h" |
| 9 #include "chrome/browser/sync/syncable/blob.h" |
| 10 #include "chrome/browser/sync/syncable/syncable.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 using syncable::Blob; |
| 14 using syncable::SyncName; |
| 15 |
| 16 namespace browser_sync { |
| 17 |
| 18 TEST(SyncerProtoUtil, TestBlobToProtocolBufferBytesUtilityFunctions) { |
| 19 unsigned char test_data1[] = {1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 4, 2, 9}; |
| 20 unsigned char test_data2[] = {1, 99, 3, 4, 5, 6, 7, 8, 0, 1, 4, 2, 9}; |
| 21 unsigned char test_data3[] = {99, 2, 3, 4, 5, 6, 7, 8}; |
| 22 |
| 23 syncable::Blob test_blob1, test_blob2, test_blob3; |
| 24 for (int i = 0; i < arraysize(test_data1); ++i) |
| 25 test_blob1.push_back(test_data1[i]); |
| 26 for (int i = 0; i < arraysize(test_data2); ++i) |
| 27 test_blob2.push_back(test_data2[i]); |
| 28 for (int i = 0; i < arraysize(test_data3); ++i) |
| 29 test_blob3.push_back(test_data3[i]); |
| 30 |
| 31 string test_message1(reinterpret_cast<char*>(test_data1), |
| 32 arraysize(test_data1)); |
| 33 string test_message2(reinterpret_cast<char*>(test_data2), |
| 34 arraysize(test_data2)); |
| 35 string test_message3(reinterpret_cast<char*>(test_data3), |
| 36 arraysize(test_data3)); |
| 37 |
| 38 EXPECT_TRUE(SyncerProtoUtil::ProtoBytesEqualsBlob(test_message1, |
| 39 test_blob1)); |
| 40 EXPECT_FALSE(SyncerProtoUtil::ProtoBytesEqualsBlob(test_message1, |
| 41 test_blob2)); |
| 42 EXPECT_FALSE(SyncerProtoUtil::ProtoBytesEqualsBlob(test_message1, |
| 43 test_blob3)); |
| 44 EXPECT_FALSE(SyncerProtoUtil::ProtoBytesEqualsBlob(test_message2, |
| 45 test_blob1)); |
| 46 EXPECT_TRUE(SyncerProtoUtil::ProtoBytesEqualsBlob(test_message2, |
| 47 test_blob2)); |
| 48 EXPECT_FALSE(SyncerProtoUtil::ProtoBytesEqualsBlob(test_message2, |
| 49 test_blob3)); |
| 50 EXPECT_FALSE(SyncerProtoUtil::ProtoBytesEqualsBlob(test_message3, |
| 51 test_blob1)); |
| 52 EXPECT_FALSE(SyncerProtoUtil::ProtoBytesEqualsBlob(test_message3, |
| 53 test_blob2)); |
| 54 EXPECT_TRUE(SyncerProtoUtil::ProtoBytesEqualsBlob(test_message3, |
| 55 test_blob3)); |
| 56 |
| 57 Blob blob1_copy; |
| 58 EXPECT_FALSE(SyncerProtoUtil::ProtoBytesEqualsBlob(test_message1, |
| 59 blob1_copy)); |
| 60 SyncerProtoUtil::CopyProtoBytesIntoBlob(test_message1, &blob1_copy); |
| 61 EXPECT_TRUE(SyncerProtoUtil::ProtoBytesEqualsBlob(test_message1, |
| 62 blob1_copy)); |
| 63 |
| 64 std::string message2_copy; |
| 65 EXPECT_FALSE(SyncerProtoUtil::ProtoBytesEqualsBlob(message2_copy, |
| 66 test_blob2)); |
| 67 SyncerProtoUtil::CopyBlobIntoProtoBytes(test_blob2, &message2_copy); |
| 68 EXPECT_TRUE(SyncerProtoUtil::ProtoBytesEqualsBlob(message2_copy, |
| 69 test_blob2)); |
| 70 } |
| 71 |
| 72 // Tests NameFromSyncEntity and NameFromCommitEntryResponse when only the |
| 73 // name field is provided. |
| 74 TEST(SyncerProtoUtil, NameExtractionOneName) { |
| 75 SyncEntity one_name_entity; |
| 76 CommitResponse_EntryResponse one_name_response; |
| 77 |
| 78 PathString one_name_string(PSTR("Eggheadednesses")); |
| 79 one_name_entity.set_name("Eggheadednesses"); |
| 80 one_name_response.set_name("Eggheadednesses"); |
| 81 |
| 82 SyncName name_a = SyncerProtoUtil::NameFromSyncEntity(one_name_entity); |
| 83 EXPECT_EQ(one_name_string, name_a.value()); |
| 84 EXPECT_EQ(one_name_string, name_a.non_unique_value()); |
| 85 |
| 86 SyncName name_b = |
| 87 SyncerProtoUtil::NameFromCommitEntryResponse(one_name_response); |
| 88 EXPECT_EQ(one_name_string, name_b.value()); |
| 89 EXPECT_EQ(one_name_string, name_b.non_unique_value()); |
| 90 |
| 91 EXPECT_TRUE(name_a == name_b); |
| 92 } |
| 93 |
| 94 // Tests NameFromSyncEntity and NameFromCommitEntryResponse when both the |
| 95 // name field and the non_unique_name fields are provided. |
| 96 TEST(SyncerProtoUtil, NameExtractionTwoNames) { |
| 97 SyncEntity two_name_entity; |
| 98 CommitResponse_EntryResponse two_name_response; |
| 99 |
| 100 PathString two_name_string_unique(PSTR("Oxyphenbutazone")); |
| 101 two_name_entity.set_name("Oxyphenbutazone"); |
| 102 two_name_response.set_name("Oxyphenbutazone"); |
| 103 PathString two_name_string(PSTR("Neuroanatomists")); |
| 104 two_name_entity.set_non_unique_name("Neuroanatomists"); |
| 105 two_name_response.set_non_unique_name("Neuroanatomists"); |
| 106 |
| 107 SyncName name_a = SyncerProtoUtil::NameFromSyncEntity(two_name_entity); |
| 108 EXPECT_EQ(two_name_string_unique, name_a.value()); |
| 109 EXPECT_EQ(two_name_string, name_a.non_unique_value()); |
| 110 |
| 111 SyncName name_b = |
| 112 SyncerProtoUtil::NameFromCommitEntryResponse(two_name_response); |
| 113 EXPECT_EQ(two_name_string_unique, name_b.value()); |
| 114 EXPECT_EQ(two_name_string, name_b.non_unique_value()); |
| 115 |
| 116 EXPECT_TRUE(name_a == name_b); |
| 117 } |
| 118 |
| 119 } // namespace browser_sync |
OLD | NEW |