• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 "chrome/browser/sync/protocol/proto_enum_conversions.h"
8 
9 #include <string>
10 
11 #include "testing/gtest/include/gtest/gtest.h"
12 
13 namespace browser_sync {
14 namespace {
15 
16 class ProtoEnumConversionsTest : public testing::Test {
17 };
18 
19 template <class T>
TestEnumStringFunction(const char * (* enum_string_fn)(T),int enum_min,int enum_max)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());
25   }
26 }
27 
TEST_F(ProtoEnumConversionsTest,GetBrowserTypeString)28 TEST_F(ProtoEnumConversionsTest, GetBrowserTypeString) {
29   TestEnumStringFunction(
30       GetBrowserTypeString,
31       sync_pb::SessionWindow::BrowserType_MIN,
32       sync_pb::SessionWindow::BrowserType_MAX);
33 }
34 
TEST_F(ProtoEnumConversionsTest,GetPageTransitionString)35 TEST_F(ProtoEnumConversionsTest, GetPageTransitionString) {
36   // We have a gap, so we need to do two ranges.
37   TestEnumStringFunction(
38       GetPageTransitionString,
39       sync_pb::TabNavigation::PageTransition_MIN,
40       sync_pb::TabNavigation::KEYWORD_GENERATED);
41   TestEnumStringFunction(
42       GetPageTransitionString,
43       sync_pb::TabNavigation::CHAIN_START,
44       sync_pb::TabNavigation::PageTransition_MAX);
45 }
46 
TEST_F(ProtoEnumConversionsTest,GetPageTransitionQualifierString)47 TEST_F(ProtoEnumConversionsTest, GetPageTransitionQualifierString) {
48   TestEnumStringFunction(
49       GetPageTransitionQualifierString,
50       sync_pb::TabNavigation::PageTransitionQualifier_MIN,
51       sync_pb::TabNavigation::PageTransitionQualifier_MAX);
52 }
53 
TEST_F(ProtoEnumConversionsTest,GetUpdatesSourceString)54 TEST_F(ProtoEnumConversionsTest, GetUpdatesSourceString) {
55   TestEnumStringFunction(
56       GetUpdatesSourceString,
57       sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MIN,
58       sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MAX);
59 }
60 
61 }  // namespace
62 }  // namespace browser_sync
63