| Index: components/sync/protocol/proto_compare_value_conversions_unittest.cc
|
| diff --git a/components/sync/protocol/proto_compare_value_conversions_unittest.cc b/components/sync/protocol/proto_compare_value_conversions_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7371ee38ea26378a8245e068be19583e0fb5ea96
|
| --- /dev/null
|
| +++ b/components/sync/protocol/proto_compare_value_conversions_unittest.cc
|
| @@ -0,0 +1,160 @@
|
| +// Copyright (c) 2016 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 <memory>
|
| +
|
| +#include "base/json/json_writer.h"
|
| +#include "base/values.h"
|
| +#include "components/sync/protocol/app_list_specifics.pb.h"
|
| +#include "components/sync/protocol/app_notification_specifics.pb.h"
|
| +#include "components/sync/protocol/app_setting_specifics.pb.h"
|
| +#include "components/sync/protocol/app_specifics.pb.h"
|
| +#include "components/sync/protocol/arc_package_specifics.pb.h"
|
| +#include "components/sync/protocol/autofill_specifics.pb.h"
|
| +#include "components/sync/protocol/bookmark_specifics.pb.h"
|
| +#include "components/sync/protocol/dictionary_specifics.pb.h"
|
| +#include "components/sync/protocol/encryption.pb.h"
|
| +#include "components/sync/protocol/entity_metadata.pb.h"
|
| +#include "components/sync/protocol/experiments_specifics.pb.h"
|
| +#include "components/sync/protocol/extension_setting_specifics.pb.h"
|
| +#include "components/sync/protocol/extension_specifics.pb.h"
|
| +#include "components/sync/protocol/favicon_image_specifics.pb.h"
|
| +#include "components/sync/protocol/favicon_tracking_specifics.pb.h"
|
| +#include "components/sync/protocol/history_delete_directive_specifics.pb.h"
|
| +#include "components/sync/protocol/nigori_specifics.pb.h"
|
| +#include "components/sync/protocol/password_specifics.pb.h"
|
| +#include "components/sync/protocol/preference_specifics.pb.h"
|
| +#include "components/sync/protocol/printer_specifics.pb.h"
|
| +#include "components/sync/protocol/priority_preference_specifics.pb.h"
|
| +#include "components/sync/protocol/proto_enum_conversions.h"
|
| +#include "components/sync/protocol/proto_old_value_conversions.h"
|
| +#include "components/sync/protocol/proto_unittest_serialized_data.h"
|
| +#include "components/sync/protocol/proto_value_conversions.h"
|
| +#include "components/sync/protocol/reading_list_specifics.pb.h"
|
| +#include "components/sync/protocol/search_engine_specifics.pb.h"
|
| +#include "components/sync/protocol/session_specifics.pb.h"
|
| +#include "components/sync/protocol/sync.pb.h"
|
| +#include "components/sync/protocol/theme_specifics.pb.h"
|
| +#include "components/sync/protocol/typed_url_specifics.pb.h"
|
| +#include "components/sync/protocol/unique_position.pb.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace syncer {
|
| +namespace {
|
| +
|
| +template <class P, typename ...Args>
|
| +P TypeOfProto(std::unique_ptr<base::DictionaryValue> (*)(const P&, Args...));
|
| +
|
| +#define COMPARE_CONVERSION2(ProtoToValue, OldProtoToValue) \
|
| + TEST(ProtoCompareValueConversionsTest, ProtoToValue) { \
|
| + using Proto = decltype(TypeOfProto(ProtoToValue)); \
|
| + Proto proto; \
|
| + const auto& serialized_data = SerializedProto<Proto>::data; \
|
| + EXPECT_TRUE(proto.ParseFromArray(serialized_data, \
|
| + sizeof(serialized_data))); \
|
| + \
|
| + auto old_value = OldProtoToValue(proto); \
|
| + std::string old_json; \
|
| + EXPECT_TRUE(old_value && \
|
| + base::JSONWriter::Write(*old_value, &old_json)); \
|
| + \
|
| + auto value = ProtoToValue(proto); \
|
| + std::string json; \
|
| + EXPECT_TRUE(value && \
|
| + base::JSONWriter::Write(*value, &json)); \
|
| + \
|
| + EXPECT_EQ(old_json, json); \
|
| + }
|
| +
|
| +#define COMPARE_CONVERSION(ProtoToValue) \
|
| + COMPARE_CONVERSION2(ProtoToValue, old::ProtoToValue)
|
| +
|
| +#define COMPARE_CONVERSION_ARG(ProtoToValue, arg) \
|
| + TEST(ProtoCompareValueConversionsTest, ProtoToValue##_##arg) { \
|
| + using Proto = decltype(TypeOfProto(ProtoToValue)); \
|
| + Proto proto; \
|
| + const auto& serialized_data = SerializedProto<Proto>::data; \
|
| + EXPECT_TRUE(proto.ParseFromArray(serialized_data, \
|
| + sizeof(serialized_data))); \
|
| + \
|
| + auto old_value = old::ProtoToValue(proto, arg); \
|
| + std::string old_json; \
|
| + EXPECT_TRUE(old_value && \
|
| + base::JSONWriter::Write(*old_value, &old_json)); \
|
| + \
|
| + auto value = ProtoToValue(proto, arg); \
|
| + std::string json; \
|
| + EXPECT_TRUE(value && \
|
| + base::JSONWriter::Write(*value, &json)); \
|
| + \
|
| + EXPECT_EQ(old_json, json); \
|
| + }
|
| +
|
| +COMPARE_CONVERSION(EncryptedDataToValue)
|
| +COMPARE_CONVERSION(AppListSpecificsToValue)
|
| +COMPARE_CONVERSION2(AppNotificationSettingsToValue, old::AppSettingsToValue)
|
| +COMPARE_CONVERSION(LinkedAppIconInfoToValue)
|
| +COMPARE_CONVERSION(ArcPackageSpecificsToValue)
|
| +COMPARE_CONVERSION(SessionHeaderToValue)
|
| +COMPARE_CONVERSION(SessionTabToValue)
|
| +COMPARE_CONVERSION(SessionWindowToValue)
|
| +COMPARE_CONVERSION(TabNavigationToValue)
|
| +COMPARE_CONVERSION(NavigationRedirectToValue)
|
| +COMPARE_CONVERSION(PasswordSpecificsDataToValue)
|
| +COMPARE_CONVERSION(GlobalIdDirectiveToValue)
|
| +COMPARE_CONVERSION(TimeRangeDirectiveToValue)
|
| +COMPARE_CONVERSION(SessionSpecificsToValue)
|
| +COMPARE_CONVERSION(PrinterPPDDataToValue)
|
| +COMPARE_CONVERSION(AppNotificationToValue)
|
| +COMPARE_CONVERSION(AppSettingSpecificsToValue)
|
| +COMPARE_CONVERSION(AppSpecificsToValue)
|
| +COMPARE_CONVERSION(ArticleSpecificsToValue)
|
| +COMPARE_CONVERSION(AutofillSpecificsToValue)
|
| +COMPARE_CONVERSION(AutofillProfileSpecificsToValue)
|
| +COMPARE_CONVERSION(WalletMetadataSpecificsToValue)
|
| +COMPARE_CONVERSION(AutofillWalletSpecificsToValue)
|
| +COMPARE_CONVERSION(BookmarkSpecificsToValue)
|
| +COMPARE_CONVERSION(DeviceInfoSpecificsToValue)
|
| +COMPARE_CONVERSION(DictionarySpecificsToValue)
|
| +COMPARE_CONVERSION(ExperimentsSpecificsToValue)
|
| +COMPARE_CONVERSION(PriorityPreferenceSpecificsToValue)
|
| +COMPARE_CONVERSION(ExtensionSettingSpecificsToValue)
|
| +COMPARE_CONVERSION(ExtensionSpecificsToValue)
|
| +COMPARE_CONVERSION(FaviconImageSpecificsToValue)
|
| +COMPARE_CONVERSION(FaviconTrackingSpecificsToValue)
|
| +COMPARE_CONVERSION(HistoryDeleteDirectiveSpecificsToValue)
|
| +COMPARE_CONVERSION(ManagedUserSettingSpecificsToValue)
|
| +COMPARE_CONVERSION(ManagedUserSpecificsToValue)
|
| +COMPARE_CONVERSION(ManagedUserSharedSettingSpecificsToValue)
|
| +COMPARE_CONVERSION(ManagedUserWhitelistSpecificsToValue)
|
| +COMPARE_CONVERSION(NigoriSpecificsToValue)
|
| +COMPARE_CONVERSION(PasswordSpecificsToValue)
|
| +COMPARE_CONVERSION(PreferenceSpecificsToValue)
|
| +COMPARE_CONVERSION(PrinterSpecificsToValue)
|
| +COMPARE_CONVERSION(ReadingListSpecificsToValue)
|
| +COMPARE_CONVERSION(SyncedNotificationAppInfoSpecificsToValue)
|
| +COMPARE_CONVERSION(SyncedNotificationSpecificsToValue)
|
| +COMPARE_CONVERSION(SearchEngineSpecificsToValue)
|
| +COMPARE_CONVERSION(ThemeSpecificsToValue)
|
| +COMPARE_CONVERSION(TypedUrlSpecificsToValue)
|
| +COMPARE_CONVERSION(WalletMaskedCreditCardToValue)
|
| +COMPARE_CONVERSION(WalletPostalAddressToValue)
|
| +COMPARE_CONVERSION(WifiCredentialSpecificsToValue)
|
| +COMPARE_CONVERSION(EntitySpecificsToValue)
|
| +COMPARE_CONVERSION_ARG(SyncEntityToValue, true)
|
| +COMPARE_CONVERSION_ARG(SyncEntityToValue, false)
|
| +COMPARE_CONVERSION_ARG(ClientToServerMessageToValue, true)
|
| +COMPARE_CONVERSION_ARG(ClientToServerMessageToValue, false)
|
| +COMPARE_CONVERSION_ARG(ClientToServerResponseToValue, true)
|
| +COMPARE_CONVERSION_ARG(ClientToServerResponseToValue, false)
|
| +COMPARE_CONVERSION(DatatypeAssociationStatsToValue)
|
| +COMPARE_CONVERSION(DebugEventInfoToValue)
|
| +COMPARE_CONVERSION(DebugInfoToValue)
|
| +COMPARE_CONVERSION(SyncCycleCompletedEventInfoToValue)
|
| +COMPARE_CONVERSION(ClientConfigParamsToValue)
|
| +COMPARE_CONVERSION(AttachmentIdProtoToValue)
|
| +COMPARE_CONVERSION(EntityMetadataToValue)
|
| +
|
| +} // namespace
|
| +} // namespace syncer
|
|
|