buffet: GCD command defintion. Compound object type support.
Added support for "object" type. Refactored parameter validation
to make sure we have object schema context when we validate
a value of parameter.
Parameter |schema| was used in two different contexts, as both
a base parameter definition and as a custom object definition.
Renamed the former to be 'base_schema' and latter as
'object_schema' to remove the confusion.
Extracted common data type manipulation functions into
schema_utils.cc/.h files.
BUG=chromium:374860
TEST=All unit tests pass.
Change-Id: I6c3549849a258bcc94b3d754acd14e072438d140
Reviewed-on: https://chromium-review.googlesource.com/204793
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/prop_constraints.cc b/buffet/commands/prop_constraints.cc
index 2376588..5ea9314 100644
--- a/buffet/commands/prop_constraints.cc
+++ b/buffet/commands/prop_constraints.cc
@@ -3,25 +3,12 @@
// found in the LICENSE file.
#include "buffet/commands/prop_constraints.h"
+#include "buffet/commands/prop_values.h"
#include "buffet/commands/schema_constants.h"
#include "buffet/string_utils.h"
namespace buffet {
-// Specializations of TypedValueToJson<T>() for supported C++ types.
-std::unique_ptr<base::Value> TypedValueToJson(bool value) {
- return std::unique_ptr<base::Value>(base::Value::CreateBooleanValue(value));
-}
-std::unique_ptr<base::Value> TypedValueToJson(int value) {
- return std::unique_ptr<base::Value>(base::Value::CreateIntegerValue(value));
-}
-std::unique_ptr<base::Value> TypedValueToJson(double value) {
- return std::unique_ptr<base::Value>(base::Value::CreateDoubleValue(value));
-}
-std::unique_ptr<base::Value> TypedValueToJson(const std::string& value) {
- return std::unique_ptr<base::Value>(base::Value::CreateStringValue(value));
-}
-
// Constraint ----------------------------------------------------------------
Constraint::~Constraint() {}
@@ -76,7 +63,7 @@
std::unique_ptr<base::Value> ConstraintStringLength::ToJson(
ErrorPtr* error) const {
- return TypedValueToJson(limit_.value);
+ return TypedValueToJson(limit_.value, error);
}
// ConstraintStringLengthMin --------------------------------------------------
@@ -85,9 +72,10 @@
ConstraintStringLengthMin::ConstraintStringLengthMin(int limit)
: ConstraintStringLength(limit) {}
-bool ConstraintStringLengthMin::Validate(const Any& value,
+bool ConstraintStringLengthMin::Validate(const PropValue& value,
ErrorPtr* error) const {
- std::string str = value.Get<std::string>();
+ CHECK(value.GetString()) << "Expecting a string value for this constraint";
+ const std::string& str = value.GetString()->GetValue();
int length = static_cast<int>(str.size());
if (length < limit_.value) {
if (limit_.value == 1) {
@@ -116,9 +104,10 @@
ConstraintStringLengthMax::ConstraintStringLengthMax(int limit)
: ConstraintStringLength(limit) {}
-bool ConstraintStringLengthMax::Validate(const Any& value,
+bool ConstraintStringLengthMax::Validate(const PropValue& value,
ErrorPtr* error) const {
- std::string str = value.Get<std::string>();
+ CHECK(value.GetString()) << "Expecting a string value for this constraint";
+ const std::string& str = value.GetString()->GetValue();
int length = static_cast<int>(str.size());
if (length > limit_.value) {
Error::AddToPrintf(error, commands::errors::kDomain,