Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: components/sync/protocol/proto_compare_value_conversions_unittest.cc

Issue 2374223003: Sync MDP: reimplement value conversions ontop of visitors
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 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 <memory>
6
7 #include "base/json/json_writer.h"
8 #include "base/values.h"
9 #include "components/sync/protocol/app_list_specifics.pb.h"
10 #include "components/sync/protocol/app_notification_specifics.pb.h"
11 #include "components/sync/protocol/app_setting_specifics.pb.h"
12 #include "components/sync/protocol/app_specifics.pb.h"
13 #include "components/sync/protocol/arc_package_specifics.pb.h"
14 #include "components/sync/protocol/autofill_specifics.pb.h"
15 #include "components/sync/protocol/bookmark_specifics.pb.h"
16 #include "components/sync/protocol/dictionary_specifics.pb.h"
17 #include "components/sync/protocol/encryption.pb.h"
18 #include "components/sync/protocol/entity_metadata.pb.h"
19 #include "components/sync/protocol/experiments_specifics.pb.h"
20 #include "components/sync/protocol/extension_setting_specifics.pb.h"
21 #include "components/sync/protocol/extension_specifics.pb.h"
22 #include "components/sync/protocol/favicon_image_specifics.pb.h"
23 #include "components/sync/protocol/favicon_tracking_specifics.pb.h"
24 #include "components/sync/protocol/history_delete_directive_specifics.pb.h"
25 #include "components/sync/protocol/nigori_specifics.pb.h"
26 #include "components/sync/protocol/password_specifics.pb.h"
27 #include "components/sync/protocol/preference_specifics.pb.h"
28 #include "components/sync/protocol/printer_specifics.pb.h"
29 #include "components/sync/protocol/priority_preference_specifics.pb.h"
30 #include "components/sync/protocol/proto_enum_conversions.h"
31 #include "components/sync/protocol/proto_old_value_conversions.h"
32 #include "components/sync/protocol/proto_unittest_serialized_data.h"
33 #include "components/sync/protocol/proto_value_conversions.h"
34 #include "components/sync/protocol/reading_list_specifics.pb.h"
35 #include "components/sync/protocol/search_engine_specifics.pb.h"
36 #include "components/sync/protocol/session_specifics.pb.h"
37 #include "components/sync/protocol/sync.pb.h"
38 #include "components/sync/protocol/theme_specifics.pb.h"
39 #include "components/sync/protocol/typed_url_specifics.pb.h"
40 #include "components/sync/protocol/unique_position.pb.h"
41 #include "testing/gtest/include/gtest/gtest.h"
42
43 namespace syncer {
44 namespace {
45
46 template <class P, typename ...Args>
47 P TypeOfProto(std::unique_ptr<base::DictionaryValue> (*)(const P&, Args...));
48
49 #define COMPARE_CONVERSION2(ProtoToValue, OldProtoToValue) \
50 TEST(ProtoCompareValueConversionsTest, ProtoToValue) { \
51 using Proto = decltype(TypeOfProto(ProtoToValue)); \
52 Proto proto; \
53 const auto& serialized_data = SerializedProto<Proto>::data; \
54 EXPECT_TRUE(proto.ParseFromArray(serialized_data, \
55 sizeof(serialized_data))); \
56 \
57 auto old_value = OldProtoToValue(proto); \
58 std::string old_json; \
59 EXPECT_TRUE(old_value && \
60 base::JSONWriter::Write(*old_value, &old_json)); \
61 \
62 auto value = ProtoToValue(proto); \
63 std::string json; \
64 EXPECT_TRUE(value && \
65 base::JSONWriter::Write(*value, &json)); \
66 \
67 EXPECT_EQ(old_json, json); \
68 }
69
70 #define COMPARE_CONVERSION(ProtoToValue) \
71 COMPARE_CONVERSION2(ProtoToValue, old::ProtoToValue)
72
73 #define COMPARE_CONVERSION_ARG(ProtoToValue, arg) \
74 TEST(ProtoCompareValueConversionsTest, ProtoToValue##_##arg) { \
75 using Proto = decltype(TypeOfProto(ProtoToValue)); \
76 Proto proto; \
77 const auto& serialized_data = SerializedProto<Proto>::data; \
78 EXPECT_TRUE(proto.ParseFromArray(serialized_data, \
79 sizeof(serialized_data))); \
80 \
81 auto old_value = old::ProtoToValue(proto, arg); \
82 std::string old_json; \
83 EXPECT_TRUE(old_value && \
84 base::JSONWriter::Write(*old_value, &old_json)); \
85 \
86 auto value = ProtoToValue(proto, arg); \
87 std::string json; \
88 EXPECT_TRUE(value && \
89 base::JSONWriter::Write(*value, &json)); \
90 \
91 EXPECT_EQ(old_json, json); \
92 }
93
94 COMPARE_CONVERSION(EncryptedDataToValue)
95 COMPARE_CONVERSION(AppListSpecificsToValue)
96 COMPARE_CONVERSION2(AppNotificationSettingsToValue, old::AppSettingsToValue)
97 COMPARE_CONVERSION(LinkedAppIconInfoToValue)
98 COMPARE_CONVERSION(ArcPackageSpecificsToValue)
99 COMPARE_CONVERSION(SessionHeaderToValue)
100 COMPARE_CONVERSION(SessionTabToValue)
101 COMPARE_CONVERSION(SessionWindowToValue)
102 COMPARE_CONVERSION(TabNavigationToValue)
103 COMPARE_CONVERSION(NavigationRedirectToValue)
104 COMPARE_CONVERSION(PasswordSpecificsDataToValue)
105 COMPARE_CONVERSION(GlobalIdDirectiveToValue)
106 COMPARE_CONVERSION(TimeRangeDirectiveToValue)
107 COMPARE_CONVERSION(SessionSpecificsToValue)
108 COMPARE_CONVERSION(PrinterPPDDataToValue)
109 COMPARE_CONVERSION(AppNotificationToValue)
110 COMPARE_CONVERSION(AppSettingSpecificsToValue)
111 COMPARE_CONVERSION(AppSpecificsToValue)
112 COMPARE_CONVERSION(ArticleSpecificsToValue)
113 COMPARE_CONVERSION(AutofillSpecificsToValue)
114 COMPARE_CONVERSION(AutofillProfileSpecificsToValue)
115 COMPARE_CONVERSION(WalletMetadataSpecificsToValue)
116 COMPARE_CONVERSION(AutofillWalletSpecificsToValue)
117 COMPARE_CONVERSION(BookmarkSpecificsToValue)
118 COMPARE_CONVERSION(DeviceInfoSpecificsToValue)
119 COMPARE_CONVERSION(DictionarySpecificsToValue)
120 COMPARE_CONVERSION(ExperimentsSpecificsToValue)
121 COMPARE_CONVERSION(PriorityPreferenceSpecificsToValue)
122 COMPARE_CONVERSION(ExtensionSettingSpecificsToValue)
123 COMPARE_CONVERSION(ExtensionSpecificsToValue)
124 COMPARE_CONVERSION(FaviconImageSpecificsToValue)
125 COMPARE_CONVERSION(FaviconTrackingSpecificsToValue)
126 COMPARE_CONVERSION(HistoryDeleteDirectiveSpecificsToValue)
127 COMPARE_CONVERSION(ManagedUserSettingSpecificsToValue)
128 COMPARE_CONVERSION(ManagedUserSpecificsToValue)
129 COMPARE_CONVERSION(ManagedUserSharedSettingSpecificsToValue)
130 COMPARE_CONVERSION(ManagedUserWhitelistSpecificsToValue)
131 COMPARE_CONVERSION(NigoriSpecificsToValue)
132 COMPARE_CONVERSION(PasswordSpecificsToValue)
133 COMPARE_CONVERSION(PreferenceSpecificsToValue)
134 COMPARE_CONVERSION(PrinterSpecificsToValue)
135 COMPARE_CONVERSION(ReadingListSpecificsToValue)
136 COMPARE_CONVERSION(SyncedNotificationAppInfoSpecificsToValue)
137 COMPARE_CONVERSION(SyncedNotificationSpecificsToValue)
138 COMPARE_CONVERSION(SearchEngineSpecificsToValue)
139 COMPARE_CONVERSION(ThemeSpecificsToValue)
140 COMPARE_CONVERSION(TypedUrlSpecificsToValue)
141 COMPARE_CONVERSION(WalletMaskedCreditCardToValue)
142 COMPARE_CONVERSION(WalletPostalAddressToValue)
143 COMPARE_CONVERSION(WifiCredentialSpecificsToValue)
144 COMPARE_CONVERSION(EntitySpecificsToValue)
145 COMPARE_CONVERSION_ARG(SyncEntityToValue, true)
146 COMPARE_CONVERSION_ARG(SyncEntityToValue, false)
147 COMPARE_CONVERSION_ARG(ClientToServerMessageToValue, true)
148 COMPARE_CONVERSION_ARG(ClientToServerMessageToValue, false)
149 COMPARE_CONVERSION_ARG(ClientToServerResponseToValue, true)
150 COMPARE_CONVERSION_ARG(ClientToServerResponseToValue, false)
151 COMPARE_CONVERSION(DatatypeAssociationStatsToValue)
152 COMPARE_CONVERSION(DebugEventInfoToValue)
153 COMPARE_CONVERSION(DebugInfoToValue)
154 COMPARE_CONVERSION(SyncCycleCompletedEventInfoToValue)
155 COMPARE_CONVERSION(ClientConfigParamsToValue)
156 COMPARE_CONVERSION(AttachmentIdProtoToValue)
157 COMPARE_CONVERSION(EntityMetadataToValue)
158
159 } // namespace
160 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698