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.
4
5// Keep this file in sync with the .proto files in this directory.
6
7#include "sync/protocol/proto_enum_conversions.h"
8
9#include <string>
10
11#include "testing/gtest/include/gtest/gtest.h"
12
13namespace syncer {
14namespace {
15
16class ProtoEnumConversionsTest : public testing::Test {
17};
18
19template <class T>
20void 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());
25  }
26}
27
28TEST_F(ProtoEnumConversionsTest, GetAppListItemTypeString) {
29  TestEnumStringFunction(
30      GetAppListItemTypeString,
31      sync_pb::AppListSpecifics::AppListItemType_MIN,
32      sync_pb::AppListSpecifics::AppListItemType_MAX);
33}
34
35TEST_F(ProtoEnumConversionsTest, GetBrowserTypeString) {
36  TestEnumStringFunction(
37      GetBrowserTypeString,
38      sync_pb::SessionWindow::BrowserType_MIN,
39      sync_pb::SessionWindow::BrowserType_MAX);
40}
41
42TEST_F(ProtoEnumConversionsTest, GetPageTransitionString) {
43  TestEnumStringFunction(
44      GetPageTransitionString,
45      sync_pb::SyncEnums::PageTransition_MIN,
46      sync_pb::SyncEnums::PageTransition_MAX);
47}
48
49TEST_F(ProtoEnumConversionsTest, GetPageTransitionQualifierString) {
50  TestEnumStringFunction(
51      GetPageTransitionRedirectTypeString,
52      sync_pb::SyncEnums::PageTransitionRedirectType_MIN,
53      sync_pb::SyncEnums::PageTransitionRedirectType_MAX);
54}
55
56TEST_F(ProtoEnumConversionsTest, GetUpdatesSourceString) {
57  TestEnumStringFunction(
58      GetUpdatesSourceString,
59      sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MIN,
60      sync_pb::GetUpdatesCallerInfo::PERIODIC);
61  TestEnumStringFunction(
62      GetUpdatesSourceString,
63      sync_pb::GetUpdatesCallerInfo::RETRY,
64      sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MAX);
65}
66
67TEST_F(ProtoEnumConversionsTest, GetResponseTypeString) {
68  TestEnumStringFunction(
69      GetResponseTypeString,
70      sync_pb::CommitResponse::ResponseType_MIN,
71      sync_pb::CommitResponse::ResponseType_MAX);
72}
73
74TEST_F(ProtoEnumConversionsTest, GetErrorTypeString) {
75  // We have a gap, so we need to do two ranges.
76  TestEnumStringFunction(
77      GetErrorTypeString,
78      sync_pb::SyncEnums::ErrorType_MIN,
79      sync_pb::SyncEnums::MIGRATION_DONE);
80  TestEnumStringFunction(
81      GetErrorTypeString,
82      sync_pb::SyncEnums::UNKNOWN,
83      sync_pb::SyncEnums::ErrorType_MAX);
84
85}
86
87TEST_F(ProtoEnumConversionsTest, GetActionString) {
88  TestEnumStringFunction(
89      GetActionString,
90      sync_pb::SyncEnums::Action_MIN,
91      sync_pb::SyncEnums::Action_MAX);
92}
93
94}  // namespace
95}  // namespace syncer
96