Commit b831f717 authored by Lutz Justen's avatar Lutz Justen Committed by Commit Bot

Clean up policy_test_utils

Just a bunch of random cleanups, no real changes:
- Don't have default switch case, so that we'll get a compile error
  if someone adds values.
- os << foo; return os   ==>   return os << foo;
- Use base value's operator<< instead of duplicating it.
- Use range based loops.
- Clang format.

BUG=None
TEST=Tryjobs

Change-Id: I766d7eba43e5ed93cebec4734e9acafc46bcb8ca
Reviewed-on: https://chromium-review.googlesource.com/1063835Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Commit-Queue: Lutz Justen <ljusten@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561818}
parent 89fe4fe2
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/json/json_writer.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/values.h" #include "base/values.h"
...@@ -70,8 +69,8 @@ CFPropertyListRef ValueToProperty(const base::Value& value) { ...@@ -70,8 +69,8 @@ CFPropertyListRef ValueToProperty(const base::Value& value) {
case base::Value::Type::INTEGER: { case base::Value::Type::INTEGER: {
int int_value; int int_value;
if (value.GetAsInteger(&int_value)) { if (value.GetAsInteger(&int_value)) {
return CFNumberCreate( return CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType,
kCFAllocatorDefault, kCFNumberIntType, &int_value); &int_value);
} }
break; break;
} }
...@@ -79,8 +78,8 @@ CFPropertyListRef ValueToProperty(const base::Value& value) { ...@@ -79,8 +78,8 @@ CFPropertyListRef ValueToProperty(const base::Value& value) {
case base::Value::Type::DOUBLE: { case base::Value::Type::DOUBLE: {
double double_value; double double_value;
if (value.GetAsDouble(&double_value)) { if (value.GetAsDouble(&double_value)) {
return CFNumberCreate( return CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType,
kCFAllocatorDefault, kCFNumberDoubleType, &double_value); &double_value);
} }
break; break;
} }
...@@ -96,11 +95,9 @@ CFPropertyListRef ValueToProperty(const base::Value& value) { ...@@ -96,11 +95,9 @@ CFPropertyListRef ValueToProperty(const base::Value& value) {
const base::DictionaryValue* dict_value; const base::DictionaryValue* dict_value;
if (value.GetAsDictionary(&dict_value)) { if (value.GetAsDictionary(&dict_value)) {
// |dict| is owned by the caller. // |dict| is owned by the caller.
CFMutableDictionaryRef dict = CFMutableDictionaryRef dict = CFDictionaryCreateMutable(
CFDictionaryCreateMutable(kCFAllocatorDefault, kCFAllocatorDefault, dict_value->size(),
dict_value->size(), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
for (base::DictionaryValue::Iterator iterator(*dict_value); for (base::DictionaryValue::Iterator iterator(*dict_value);
!iterator.IsAtEnd(); iterator.Advance()) { !iterator.IsAtEnd(); iterator.Advance()) {
// CFDictionaryAddValue() retains both |key| and |value|, so make sure // CFDictionaryAddValue() retains both |key| and |value|, so make sure
...@@ -148,8 +145,7 @@ CFPropertyListRef ValueToProperty(const base::Value& value) { ...@@ -148,8 +145,7 @@ CFPropertyListRef ValueToProperty(const base::Value& value) {
} // namespace policy } // namespace policy
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os, const policy::PolicyBundle& bundle) {
const policy::PolicyBundle& bundle) {
os << "{" << std::endl; os << "{" << std::endl;
for (policy::PolicyBundle::const_iterator iter = bundle.begin(); for (policy::PolicyBundle::const_iterator iter = bundle.begin();
iter != bundle.end(); ++iter) { iter != bundle.end(); ++iter) {
...@@ -161,82 +157,53 @@ std::ostream& operator<<(std::ostream& os, ...@@ -161,82 +157,53 @@ std::ostream& operator<<(std::ostream& os,
std::ostream& operator<<(std::ostream& os, policy::PolicyScope scope) { std::ostream& operator<<(std::ostream& os, policy::PolicyScope scope) {
switch (scope) { switch (scope) {
case policy::POLICY_SCOPE_USER: { case policy::POLICY_SCOPE_USER:
os << "POLICY_SCOPE_USER"; return os << "POLICY_SCOPE_USER";
break; case policy::POLICY_SCOPE_MACHINE:
} return os << "POLICY_SCOPE_MACHINE";
case policy::POLICY_SCOPE_MACHINE: {
os << "POLICY_SCOPE_MACHINE";
break;
}
default: {
os << "POLICY_SCOPE_UNKNOWN(" << int(scope) << ")";
}
} }
return os; return os << "POLICY_SCOPE_UNKNOWN(" << int(scope) << ")";
} }
std::ostream& operator<<(std::ostream& os, policy::PolicyLevel level) { std::ostream& operator<<(std::ostream& os, policy::PolicyLevel level) {
switch (level) { switch (level) {
case policy::POLICY_LEVEL_RECOMMENDED: { case policy::POLICY_LEVEL_RECOMMENDED:
os << "POLICY_LEVEL_RECOMMENDED"; return os << "POLICY_LEVEL_RECOMMENDED";
break; case policy::POLICY_LEVEL_MANDATORY:
} return os << "POLICY_LEVEL_MANDATORY";
case policy::POLICY_LEVEL_MANDATORY: {
os << "POLICY_LEVEL_MANDATORY";
break;
}
default: {
os << "POLICY_LEVEL_UNKNOWN(" << int(level) << ")";
}
} }
return os; return os << "POLICY_LEVEL_UNKNOWN(" << int(level) << ")";
} }
std::ostream& operator<<(std::ostream& os, policy::PolicyDomain domain) { std::ostream& operator<<(std::ostream& os, policy::PolicyDomain domain) {
switch (domain) { switch (domain) {
case policy::POLICY_DOMAIN_CHROME: { case policy::POLICY_DOMAIN_CHROME:
os << "POLICY_DOMAIN_CHROME"; return os << "POLICY_DOMAIN_CHROME";
break; case policy::POLICY_DOMAIN_EXTENSIONS:
} return os << "POLICY_DOMAIN_EXTENSIONS";
case policy::POLICY_DOMAIN_EXTENSIONS: { case policy::POLICY_DOMAIN_SIGNIN_EXTENSIONS:
os << "POLICY_DOMAIN_EXTENSIONS"; return os << "POLICY_DOMAIN_SIGNIN_EXTENSIONS";
case policy::POLICY_DOMAIN_SIZE:
break; break;
}
case policy::POLICY_DOMAIN_SIGNIN_EXTENSIONS: {
os << "POLICY_DOMAIN_SIGNIN_EXTENSIONS";
break;
}
default: {
os << "POLICY_DOMAIN_UNKNOWN(" << int(domain) << ")";
}
} }
return os; return os << "POLICY_DOMAIN_UNKNOWN(" << int(domain) << ")";
} }
std::ostream& operator<<(std::ostream& os, const policy::PolicyMap& policies) { std::ostream& operator<<(std::ostream& os, const policy::PolicyMap& policies) {
os << "{" << std::endl; os << "{" << std::endl;
for (policy::PolicyMap::const_iterator iter = policies.begin(); for (const auto& iter : policies)
iter != policies.end(); ++iter) { os << " \"" << iter.first << "\": " << iter.second << "," << std::endl;
os << " \"" << iter->first << "\": " << iter->second << "," << std::endl;
}
os << "}"; os << "}";
return os; return os;
} }
std::ostream& operator<<(std::ostream& os, const policy::PolicyMap::Entry& e) { std::ostream& operator<<(std::ostream& os, const policy::PolicyMap::Entry& e) {
std::string value; return os << "{" << std::endl
base::JSONWriter::WriteWithOptions( << " \"level\": " << e.level << "," << std::endl
*e.value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &value); << " \"scope\": " << e.scope << "," << std::endl
os << "{" << std::endl << " \"value\": " << *e.value << "}";
<< " \"level\": " << e.level << "," << std::endl
<< " \"scope\": " << e.scope << "," << std::endl
<< " \"value\": " << value
<< "}";
return os;
} }
std::ostream& operator<<(std::ostream& os, const policy::PolicyNamespace& ns) { std::ostream& operator<<(std::ostream& os, const policy::PolicyNamespace& ns) {
os << ns.domain << "/" << ns.component_id; return os << ns.domain << "/" << ns.component_id;
return os;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment