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
, GetBrowserTypeString
) {
29 TestEnumStringFunction(
31 sync_pb::SessionWindow::BrowserType_MIN
,
32 sync_pb::SessionWindow::BrowserType_MAX
);
35 TEST_F(ProtoEnumConversionsTest
, GetPageTransitionString
) {
36 // We have a gap, so we need to do two ranges.
37 TestEnumStringFunction(
38 GetPageTransitionString
,
39 sync_pb::SyncEnums::PageTransition_MIN
,
40 sync_pb::SyncEnums::KEYWORD_GENERATED
);
41 TestEnumStringFunction(
42 GetPageTransitionString
,
43 sync_pb::SyncEnums::CHAIN_START
,
44 sync_pb::SyncEnums::PageTransition_MAX
);
47 TEST_F(ProtoEnumConversionsTest
, GetPageTransitionQualifierString
) {
48 TestEnumStringFunction(
49 GetPageTransitionQualifierString
,
50 sync_pb::SyncEnums::PageTransitionQualifier_MIN
,
51 sync_pb::SyncEnums::PageTransitionQualifier_MAX
);
54 TEST_F(ProtoEnumConversionsTest
, GetUpdatesSourceString
) {
55 TestEnumStringFunction(
56 GetUpdatesSourceString
,
57 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MIN
,
58 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION
);
59 TestEnumStringFunction(
60 GetUpdatesSourceString
,
61 sync_pb::GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE
,
62 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MAX
);
65 TEST_F(ProtoEnumConversionsTest
, GetResponseTypeString
) {
66 TestEnumStringFunction(
67 GetResponseTypeString
,
68 sync_pb::CommitResponse::ResponseType_MIN
,
69 sync_pb::CommitResponse::ResponseType_MAX
);
72 TEST_F(ProtoEnumConversionsTest
, GetErrorTypeString
) {
73 // We have a gap, so we need to do two ranges.
74 TestEnumStringFunction(
76 sync_pb::SyncEnums::ErrorType_MIN
,
77 sync_pb::SyncEnums::MIGRATION_DONE
);
78 TestEnumStringFunction(
80 sync_pb::SyncEnums::UNKNOWN
,
81 sync_pb::SyncEnums::ErrorType_MAX
);
85 TEST_F(ProtoEnumConversionsTest
, GetActionString
) {
86 TestEnumStringFunction(
88 sync_pb::SyncEnums::Action_MIN
,
89 sync_pb::SyncEnums::Action_MAX
);