| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/sync/protocol/proto_enum_conversions.h" | 5 #include "components/sync/protocol/proto_enum_conversions.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 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 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // Keep this file in sync with the .proto files in this directory. | 14 // Keep this file in sync with the .proto files in this directory. |
| 15 class ProtoEnumConversionsTest : public testing::Test {}; | 15 class ProtoEnumConversionsTest : public testing::Test {}; |
| 16 | 16 |
| 17 template <class T> | 17 template <class T> |
| 18 void TestEnumStringFunction(const char* (*enum_string_fn)(T), | 18 void TestEnumStringFunction(T enum_min, T enum_max) { |
| 19 int enum_min, | |
| 20 int enum_max) { | |
| 21 for (int i = enum_min; i <= enum_max; ++i) { | 19 for (int i = enum_min; i <= enum_max; ++i) { |
| 22 const std::string& str = enum_string_fn(static_cast<T>(i)); | 20 const std::string& str = ProtoEnumToString(static_cast<T>(i)); |
| 23 EXPECT_FALSE(str.empty()); | 21 EXPECT_FALSE(str.empty()); |
| 24 } | 22 } |
| 25 } | 23 } |
| 26 | 24 |
| 27 TEST_F(ProtoEnumConversionsTest, GetAppListItemTypeString) { | 25 TEST_F(ProtoEnumConversionsTest, GetAppListItemTypeString) { |
| 28 TestEnumStringFunction(GetAppListItemTypeString, | 26 TestEnumStringFunction(sync_pb::AppListSpecifics::AppListItemType_MIN, |
| 29 sync_pb::AppListSpecifics::AppListItemType_MIN, | |
| 30 sync_pb::AppListSpecifics::AppListItemType_MAX); | 27 sync_pb::AppListSpecifics::AppListItemType_MAX); |
| 31 } | 28 } |
| 32 | 29 |
| 33 TEST_F(ProtoEnumConversionsTest, GetBrowserTypeString) { | 30 TEST_F(ProtoEnumConversionsTest, GetBrowserTypeString) { |
| 34 TestEnumStringFunction(GetBrowserTypeString, | 31 TestEnumStringFunction(sync_pb::SessionWindow::BrowserType_MIN, |
| 35 sync_pb::SessionWindow::BrowserType_MIN, | |
| 36 sync_pb::SessionWindow::BrowserType_MAX); | 32 sync_pb::SessionWindow::BrowserType_MAX); |
| 37 } | 33 } |
| 38 | 34 |
| 39 TEST_F(ProtoEnumConversionsTest, GetPageTransitionString) { | 35 TEST_F(ProtoEnumConversionsTest, GetPageTransitionString) { |
| 40 TestEnumStringFunction(GetPageTransitionString, | 36 TestEnumStringFunction(sync_pb::SyncEnums::PageTransition_MIN, |
| 41 sync_pb::SyncEnums::PageTransition_MIN, | |
| 42 sync_pb::SyncEnums::PageTransition_MAX); | 37 sync_pb::SyncEnums::PageTransition_MAX); |
| 43 } | 38 } |
| 44 | 39 |
| 45 TEST_F(ProtoEnumConversionsTest, GetPageTransitionQualifierString) { | 40 TEST_F(ProtoEnumConversionsTest, GetPageTransitionQualifierString) { |
| 46 TestEnumStringFunction(GetPageTransitionRedirectTypeString, | 41 TestEnumStringFunction(sync_pb::SyncEnums::PageTransitionRedirectType_MIN, |
| 47 sync_pb::SyncEnums::PageTransitionRedirectType_MIN, | |
| 48 sync_pb::SyncEnums::PageTransitionRedirectType_MAX); | 42 sync_pb::SyncEnums::PageTransitionRedirectType_MAX); |
| 49 } | 43 } |
| 50 | 44 |
| 51 TEST_F(ProtoEnumConversionsTest, GetWifiCredentialSecurityClassString) { | 45 TEST_F(ProtoEnumConversionsTest, GetWifiCredentialSecurityClassString) { |
| 52 TestEnumStringFunction(GetWifiCredentialSecurityClassString, | 46 TestEnumStringFunction(sync_pb::WifiCredentialSpecifics::SecurityClass_MIN, |
| 53 sync_pb::WifiCredentialSpecifics::SecurityClass_MIN, | |
| 54 sync_pb::WifiCredentialSpecifics::SecurityClass_MAX); | 47 sync_pb::WifiCredentialSpecifics::SecurityClass_MAX); |
| 55 } | 48 } |
| 56 | 49 |
| 57 TEST_F(ProtoEnumConversionsTest, GetUpdatesSourceString) { | 50 TEST_F(ProtoEnumConversionsTest, GetUpdatesSourceString) { |
| 58 TestEnumStringFunction(GetUpdatesSourceString, | 51 TestEnumStringFunction(sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MIN, |
| 59 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MIN, | |
| 60 sync_pb::GetUpdatesCallerInfo::PERIODIC); | 52 sync_pb::GetUpdatesCallerInfo::PERIODIC); |
| 61 TestEnumStringFunction(GetUpdatesSourceString, | 53 TestEnumStringFunction(sync_pb::GetUpdatesCallerInfo::RETRY, |
| 62 sync_pb::GetUpdatesCallerInfo::RETRY, | |
| 63 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MAX); | 54 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MAX); |
| 64 } | 55 } |
| 65 | 56 |
| 66 TEST_F(ProtoEnumConversionsTest, GetResponseTypeString) { | 57 TEST_F(ProtoEnumConversionsTest, GetResponseTypeString) { |
| 67 TestEnumStringFunction(GetResponseTypeString, | 58 TestEnumStringFunction(sync_pb::CommitResponse::ResponseType_MIN, |
| 68 sync_pb::CommitResponse::ResponseType_MIN, | |
| 69 sync_pb::CommitResponse::ResponseType_MAX); | 59 sync_pb::CommitResponse::ResponseType_MAX); |
| 70 } | 60 } |
| 71 | 61 |
| 72 TEST_F(ProtoEnumConversionsTest, GetErrorTypeString) { | 62 TEST_F(ProtoEnumConversionsTest, GetErrorTypeString) { |
| 73 // We have a gap, so we need to do two ranges. | 63 // We have a gap, so we need to do two ranges. |
| 74 TestEnumStringFunction(GetErrorTypeString, sync_pb::SyncEnums::ErrorType_MIN, | 64 TestEnumStringFunction(sync_pb::SyncEnums::ErrorType_MIN, |
| 75 sync_pb::SyncEnums::MIGRATION_DONE); | 65 sync_pb::SyncEnums::MIGRATION_DONE); |
| 76 TestEnumStringFunction(GetErrorTypeString, sync_pb::SyncEnums::UNKNOWN, | 66 TestEnumStringFunction(sync_pb::SyncEnums::UNKNOWN, |
| 77 sync_pb::SyncEnums::ErrorType_MAX); | 67 sync_pb::SyncEnums::ErrorType_MAX); |
| 78 } | 68 } |
| 79 | 69 |
| 80 TEST_F(ProtoEnumConversionsTest, GetActionString) { | 70 TEST_F(ProtoEnumConversionsTest, GetActionString) { |
| 81 TestEnumStringFunction(GetActionString, sync_pb::SyncEnums::Action_MIN, | 71 TestEnumStringFunction(sync_pb::SyncEnums::Action_MIN, |
| 82 sync_pb::SyncEnums::Action_MAX); | 72 sync_pb::SyncEnums::Action_MAX); |
| 83 } | 73 } |
| 84 | 74 |
| 85 } // namespace | 75 } // namespace |
| 86 } // namespace syncer | 76 } // namespace syncer |
| OLD | NEW |