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 13 namespace syncer { 14 namespace { 15 16 class ProtoEnumConversionsTest : public testing::Test { 17 }; 18 19 template <class T> 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 28 TEST_F(ProtoEnumConversionsTest, GetBrowserTypeString) { 29 TestEnumStringFunction( 30 GetBrowserTypeString, 31 sync_pb::SessionWindow::BrowserType_MIN, 32 sync_pb::SessionWindow::BrowserType_MAX); 33 } 34 35 TEST_F(ProtoEnumConversionsTest, GetPageTransitionString) { 36 TestEnumStringFunction( 37 GetPageTransitionString, 38 sync_pb::SyncEnums::PageTransition_MIN, 39 sync_pb::SyncEnums::PageTransition_MAX); 40 } 41 42 TEST_F(ProtoEnumConversionsTest, GetPageTransitionQualifierString) { 43 TestEnumStringFunction( 44 GetPageTransitionRedirectTypeString, 45 sync_pb::SyncEnums::PageTransitionRedirectType_MIN, 46 sync_pb::SyncEnums::PageTransitionRedirectType_MAX); 47 } 48 49 TEST_F(ProtoEnumConversionsTest, GetUpdatesSourceString) { 50 TestEnumStringFunction( 51 GetUpdatesSourceString, 52 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MIN, 53 sync_pb::GetUpdatesCallerInfo::PERIODIC); 54 TestEnumStringFunction( 55 GetUpdatesSourceString, 56 sync_pb::GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE, 57 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource_MAX); 58 } 59 60 TEST_F(ProtoEnumConversionsTest, GetResponseTypeString) { 61 TestEnumStringFunction( 62 GetResponseTypeString, 63 sync_pb::CommitResponse::ResponseType_MIN, 64 sync_pb::CommitResponse::ResponseType_MAX); 65 } 66 67 TEST_F(ProtoEnumConversionsTest, GetErrorTypeString) { 68 // We have a gap, so we need to do two ranges. 69 TestEnumStringFunction( 70 GetErrorTypeString, 71 sync_pb::SyncEnums::ErrorType_MIN, 72 sync_pb::SyncEnums::MIGRATION_DONE); 73 TestEnumStringFunction( 74 GetErrorTypeString, 75 sync_pb::SyncEnums::UNKNOWN, 76 sync_pb::SyncEnums::ErrorType_MAX); 77 78 } 79 80 TEST_F(ProtoEnumConversionsTest, GetActionString) { 81 TestEnumStringFunction( 82 GetActionString, 83 sync_pb::SyncEnums::Action_MIN, 84 sync_pb::SyncEnums::Action_MAX); 85 } 86 87 } // namespace 88 } // namespace syncer 89