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
3 // found in the LICENSE file.
5 // Keep this file in sync with the .proto files in this directory.
7 #include "sync/protocol/proto_enum_conversions.h"
11 #include "testing/gtest/include/gtest/gtest.h"
16 class ProtoEnumConversionsTest
: public testing::Test
{
20 void TestEnumStringFunction(const char* (*enum_string_fn
)(T
),
21 int enum_min
, int enum_max
) {
22 for (int i
= enum_min
; i
<= enum_max
; ++i
) {
23 const std::string
& str
= enum_string_fn(static_cast<T
>(i
));
24 EXPECT_FALSE(str
.empty());
28 TEST_F(ProtoEnumConversionsTest
, GetAppListItemTypeString
) {
29 TestEnumStringFunction(
30 GetAppListItemTypeString
,
31 sync_pb::AppListSpecifics::AppListItemType_MIN
,
32 sync_pb::AppListSpecifics::AppListItemType_MAX
);
35 TEST_F(ProtoEnumConversionsTest
, GetBrowserTypeString
) {
36 TestEnumStringFunction(
38 sync_pb::SessionWindow::BrowserType_MIN
,
39 sync_pb::SessionWindow::BrowserType_MAX
);
42 TEST_F(ProtoEnumConversionsTest
, GetPageTransitionString
) {
43 TestEnumStringFunction(
44 GetPageTransitionString
,
45 sync_pb::SyncEnums::PageTransition_MIN
,
46 sync_pb::SyncEnums::PageTransition_MAX
);
49 TEST_F(ProtoEnumConversionsTest
, GetPageTransitionQualifierString
) {
50 TestEnumStringFunction(
51 GetPageTransitionRedirectTypeString
,
52 sync_pb::SyncEnums::PageTransitionRedirectType_MIN
,
53 sync_pb::SyncEnums::PageTransitionRedirectType_MAX
);
56 TEST_F(ProtoEnumConversionsTest
, GetWifiCredentialSecurityClassString
) {
57 TestEnumStringFunction(
58 GetWifiCredentialSecurityClassString
,
59 sync_pb::WifiCredentialSpecifics::SecurityClass_MIN
,
60 sync_pb::WifiCredentialSpecifics::SecurityClass_MAX
);
63 TEST_F(ProtoEnumConversionsTest
, GetUpdatesSourceString
) {
64 TestEnumStringFunction(
65 GetUpdatesSourceString
,
66 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MIN
,
67 sync_pb::GetUpdatesCallerInfo::PERIODIC
);
68 TestEnumStringFunction(
69 GetUpdatesSourceString
,
70 sync_pb::GetUpdatesCallerInfo::RETRY
,
71 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MAX
);
74 TEST_F(ProtoEnumConversionsTest
, GetResponseTypeString
) {
75 TestEnumStringFunction(
76 GetResponseTypeString
,
77 sync_pb::CommitResponse::ResponseType_MIN
,
78 sync_pb::CommitResponse::ResponseType_MAX
);
81 TEST_F(ProtoEnumConversionsTest
, GetErrorTypeString
) {
82 // We have a gap, so we need to do two ranges.
83 TestEnumStringFunction(
85 sync_pb::SyncEnums::ErrorType_MIN
,
86 sync_pb::SyncEnums::MIGRATION_DONE
);
87 TestEnumStringFunction(
89 sync_pb::SyncEnums::UNKNOWN
,
90 sync_pb::SyncEnums::ErrorType_MAX
);
94 TEST_F(ProtoEnumConversionsTest
, GetActionString
) {
95 TestEnumStringFunction(
97 sync_pb::SyncEnums::Action_MIN
,
98 sync_pb::SyncEnums::Action_MAX
);
102 } // namespace syncer