proto_enum_conversions_unittest.cc 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "components/sync/protocol/proto_enum_conversions.h"
  5. #include <string>
  6. #include "testing/gmock/include/gmock/gmock.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. namespace syncer {
  9. namespace {
  10. // WARNING: Keep this file in sync with the .proto files in this directory.
  11. using ::testing::Not;
  12. using ::testing::StrEq;
  13. // Iterates through the enum values, checking their string version is non-empty.
  14. // The T##_IsValid() check is needed because some enums have deprecated values,
  15. // so they have gaps in their numeric range.
  16. #define TestEnumStringsNonEmpty(T) \
  17. for (int i = T##_MIN; i <= T##_MAX; ++i) { \
  18. if (T##_IsValid(i)) { \
  19. EXPECT_THAT(ProtoEnumToString(static_cast<T>(i)), Not(StrEq(""))); \
  20. } \
  21. }
  22. TEST(ProtoEnumConversionsTest, GetAppListItemTypeString) {
  23. TestEnumStringsNonEmpty(sync_pb::AppListSpecifics::AppListItemType);
  24. }
  25. TEST(ProtoEnumConversionsTest, GetBrowserTypeString) {
  26. TestEnumStringsNonEmpty(sync_pb::SyncEnums::BrowserType);
  27. }
  28. TEST(ProtoEnumConversionsTest, GetPageTransitionString) {
  29. TestEnumStringsNonEmpty(sync_pb::SyncEnums::PageTransition);
  30. }
  31. TEST(ProtoEnumConversionsTest, GetPageTransitionQualifierString) {
  32. TestEnumStringsNonEmpty(sync_pb::SyncEnums::PageTransitionRedirectType);
  33. }
  34. TEST(ProtoEnumConversionsTest, GetWifiConfigurationSecurityTypeString) {
  35. TestEnumStringsNonEmpty(sync_pb::WifiConfigurationSpecifics::SecurityType);
  36. }
  37. TEST(ProtoEnumConversionsTest,
  38. GetWifiConfigurationAutomaticallyConnectOptionString) {
  39. TestEnumStringsNonEmpty(
  40. sync_pb::WifiConfigurationSpecifics::AutomaticallyConnectOption);
  41. }
  42. TEST(ProtoEnumConversionsTest, GetWifiConfigurationIsPreferredOptionString) {
  43. TestEnumStringsNonEmpty(
  44. sync_pb::WifiConfigurationSpecifics::IsPreferredOption);
  45. }
  46. TEST(ProtoEnumConversionsTest, GetWifiConfigurationMeteredOptionString) {
  47. TestEnumStringsNonEmpty(sync_pb::WifiConfigurationSpecifics::MeteredOption);
  48. }
  49. TEST(ProtoEnumConversionsTest, GetWifiConfigurationProxyOptionString) {
  50. TestEnumStringsNonEmpty(
  51. sync_pb::WifiConfigurationSpecifics::ProxyConfiguration::ProxyOption);
  52. }
  53. TEST(ProtoEnumConversionsTest, GetUpdatesSourceString) {
  54. TestEnumStringsNonEmpty(sync_pb::GetUpdatesCallerInfo::GetUpdatesSource);
  55. }
  56. TEST(ProtoEnumConversionsTest, GetUpdatesOriginString) {
  57. TestEnumStringsNonEmpty(sync_pb::SyncEnums::GetUpdatesOrigin);
  58. }
  59. TEST(ProtoEnumConversionsTest, GetResponseTypeString) {
  60. TestEnumStringsNonEmpty(sync_pb::CommitResponse::ResponseType);
  61. }
  62. TEST(ProtoEnumConversionsTest, GetErrorTypeString) {
  63. TestEnumStringsNonEmpty(sync_pb::SyncEnums::ErrorType);
  64. }
  65. TEST(ProtoEnumConversionsTest, GetActionString) {
  66. TestEnumStringsNonEmpty(sync_pb::SyncEnums::Action);
  67. }
  68. TEST(ProtoEnumConversionsTest, GetConsentStatusString) {
  69. TestEnumStringsNonEmpty(sync_pb::UserConsentTypes::ConsentStatus);
  70. }
  71. } // namespace
  72. } // namespace syncer