diff options
author | Jacob Keeler <jacob.keeler@livioradio.com> | 2019-10-03 17:06:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-03 17:06:49 -0400 |
commit | 2b09ea3adf962e25717b6b4cd751173f0aa40d02 (patch) | |
tree | ef1b421e51dd953c4f53a90dc3511273a1db2e17 | |
parent | e4b28634bcbf2e52e940704524029f8f48707bf0 (diff) | |
download | sdl_core-2b09ea3adf962e25717b6b4cd751173f0aa40d02.tar.gz |
Add handling for unknown enum values in vehicle data schema (#3062)6.0.0_RC
4 files changed, 14 insertions, 18 deletions
diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_data_item_schema.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_data_item_schema.cc index bb8ba49213..b7dbdfdd9a 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_data_item_schema.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_data_item_schema.cc @@ -61,7 +61,12 @@ VehicleDataItemSchema::VehicleDataItemSchema(PolicyDataItem& policy_item, return enum_schema; } - return nullptr; + // If an unknown type is present in the policy table, it is assumed that it + // is a future enum type. Since normal validation cannot be performed on + // this value, it is treated as a raw string instead + policy_data_item.type = "String"; + + return GetPODTypeSchema(policy_data_item, schema_type); }; if (*policy_data_item.array) { diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/vehicle_data_item_schema_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/vehicle_data_item_schema_test.cc index 65fecd7d4e..2443310409 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/vehicle_data_item_schema_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/vehicle_data_item_schema_test.cc @@ -387,9 +387,10 @@ TEST_F(VehicleDataItemSchemaTest, ValidateUnknownType) { auto test_schema = PolicyDataItem(test_object_with_invalid_type.schema); auto result = VehicleDataItemSchema::create( test_schema, VehicleDataItemSchema::SchemaType::HMI); - EXPECT_EQ(ErrorCode::ERROR, + test_object_with_invalid_type.data = "CVS_NORMAL"; + EXPECT_EQ(ErrorCode::OK, result->validate(test_object_with_invalid_type.data, &report)); - EXPECT_NE(std::string(""), rpc::PrettyFormat(report)); + EXPECT_EQ(std::string(""), rpc::PrettyFormat(report)); } } // namespace vehicle_info_plugin_test diff --git a/src/components/policy/policy_external/src/policy_table/types.cc b/src/components/policy/policy_external/src/policy_table/types.cc index 73b2002056..f0ea154f94 100644 --- a/src/components/policy/policy_external/src/policy_table/types.cc +++ b/src/components/policy/policy_external/src/policy_table/types.cc @@ -2492,16 +2492,11 @@ bool VehicleDataItem::ValidateNaming(std::string str) const { } bool VehicleDataItem::ValidateTypes() const { - if (IsPrimitiveType() || NULL != EnumSchemaItemFactory::Get(type)) { - // params should be empty for POD types - // and for enum values, generated from API - return (!(params.is_initialized()) || params->empty()); - } - if (VehicleDataItem::kStruct == std::string(type)) { return params.is_initialized() && !(params->empty()) && params.is_valid(); } - return false; + // params should be empty for POD types and for enum values + return (!(params.is_initialized()) || params->empty()); } bool VehicleDataItem::IsPrimitiveType() const { diff --git a/src/components/policy/policy_regular/src/policy_table/types.cc b/src/components/policy/policy_regular/src/policy_table/types.cc index 4032f27f99..3029ebb067 100644 --- a/src/components/policy/policy_regular/src/policy_table/types.cc +++ b/src/components/policy/policy_regular/src/policy_table/types.cc @@ -1940,16 +1940,11 @@ bool VehicleDataItem::ValidateNaming(std::string str) const { } bool VehicleDataItem::ValidateTypes() const { - if (IsPrimitiveType() || NULL != EnumSchemaItemFactory::Get(type)) { - // params should be empty for POD types - // and for enum values, generated from API - return (!(params.is_initialized()) || params->empty()); - } - - if ("Struct" == std::string(type)) { + if (VehicleDataItem::kStruct == std::string(type)) { return params.is_initialized() && !(params->empty()) && params.is_valid(); } - return false; + // params should be empty for POD types and for enum values + return (!(params.is_initialized()) || params->empty()); } bool VehicleDataItem::IsPrimitiveType() const { |