summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components/application_manager/src/application_manager_impl.cc76
-rw-r--r--src/components/formatters/include/formatters/CSmartFactory.hpp16
-rw-r--r--src/components/formatters/test/CSmartFactory_test.cc8
-rw-r--r--src/components/formatters/test/formatter_json_rpc_test.cc8
-rw-r--r--src/components/smart_objects/include/smart_objects/array_schema_item.h5
-rw-r--r--src/components/smart_objects/include/smart_objects/enum_schema_item.h6
-rw-r--r--src/components/smart_objects/include/smart_objects/object_schema_item.h11
-rw-r--r--src/components/smart_objects/include/smart_objects/schema_item.h6
-rw-r--r--src/components/smart_objects/include/smart_objects/smart_schema.h5
-rw-r--r--src/components/smart_objects/src/array_schema_item.cc5
-rw-r--r--src/components/smart_objects/src/object_schema_item.cc40
-rw-r--r--src/components/smart_objects/src/schema_item.cc2
-rw-r--r--src/components/smart_objects/src/smart_schema.cc4
-rw-r--r--src/components/smart_objects/test/ArraySchemaItem_test.cc4
-rw-r--r--src/components/smart_objects/test/CObjectSchemaItem_test.cc26
-rw-r--r--src/components/smart_objects/test/EnumSchemaItem_test.cc6
-rw-r--r--src/components/smart_objects/test/SmartObjectConvertionTime_test.cc4
17 files changed, 135 insertions, 97 deletions
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc
index 296f1c0e38..be84297b0e 100644
--- a/src/components/application_manager/src/application_manager_impl.cc
+++ b/src/components/application_manager/src/application_manager_impl.cc
@@ -1216,11 +1216,10 @@ void ApplicationManagerImpl::SendMessageToMobile(
app->protocol_version();
}
- mobile_so_factory().attachSchema(*message);
- LOG4CXX_INFO(
- logger_,
- "Attached schema to message, result if valid: " << message->isValid());
-
+ mobile_so_factory().attachSchema(*message, false);
+ LOG4CXX_INFO(logger_, "Attached schema to message, result if valid: "
+ << message->isValid());
+
// Messages to mobile are not yet prioritized so use default priority value
utils::SharedPtr<Message> message_to_send(new Message(
protocol_handler::MessagePriority::kDefault));
@@ -1350,7 +1349,7 @@ bool ApplicationManagerImpl::ManageMobileCommand(
}
// Message for "CheckPermission" must be with attached schema
- mobile_so_factory().attachSchema(*message);
+ mobile_so_factory().attachSchema(*message, false);
}
if (message_type ==
@@ -1468,10 +1467,9 @@ void ApplicationManagerImpl::SendMessageToHMI(
return;
}
- hmi_so_factory().attachSchema(*message);
- LOG4CXX_INFO(
- logger_,
- "Attached schema to message, result if valid: " << message->isValid());
+ hmi_so_factory().attachSchema(*message, false);
+ LOG4CXX_INFO(logger_, "Attached schema to message, result if valid: "
+ << message->isValid());
#ifdef HMI_DBUS_API
message_to_send->set_smart_object(*message);
@@ -1581,22 +1579,22 @@ bool ApplicationManagerImpl::ConvertMessageToSO(
case ProtocolVersion::kV4:
case ProtocolVersion::kV3:
case ProtocolVersion::kV2: {
- const bool conversion_result =
- formatters::CFormatterJsonSDLRPCv2::fromString(
- message.json_message(), output, message.function_id(),
- message.type(), message.correlation_id());
- if (!conversion_result
- || !mobile_so_factory().attachSchema(output)
- || ((output.validate() != smart_objects::Errors::OK)) ) {
- LOG4CXX_WARN(logger_, "Failed to parse string to smart object :"
- << message.json_message());
- utils::SharedPtr<smart_objects::SmartObject> response(
- MessageHelper::CreateNegativeResponse(
- message.connection_key(), message.function_id(),
- message.correlation_id(), mobile_apis::Result::INVALID_DATA));
- ManageMobileCommand(response);
- return false;
- }
+ const bool conversion_result =
+ formatters::CFormatterJsonSDLRPCv2::fromString(
+ message.json_message(), output, message.function_id(),
+ message.type(), message.correlation_id());
+ if (!conversion_result
+ || !mobile_so_factory().attachSchema(output, true)
+ || ((output.validate() != smart_objects::Errors::OK))) {
+ LOG4CXX_WARN(logger_, "Failed to parse string to smart object :"
+ << message.json_message());
+ utils::SharedPtr<smart_objects::SmartObject> response(
+ MessageHelper::CreateNegativeResponse(
+ message.connection_key(), message.function_id(),
+ message.correlation_id(), mobile_apis::Result::INVALID_DATA));
+ ManageMobileCommand(response, commands::Command::ORIGIN_SDL);
+ return false;
+ }
LOG4CXX_INFO(
logger_,
"Convertion result for sdl object is true" << " function_id "
@@ -1626,14 +1624,14 @@ bool ApplicationManagerImpl::ConvertMessageToSO(
#ifdef ENABLE_LOG
int32_t result =
#endif
- formatters::FormatterJsonRpc::FromString <
- hmi_apis::FunctionID::eType, hmi_apis::messageType::eType > (
- message.json_message(), output);
- LOG4CXX_INFO(
- logger_,
- "Convertion result: " << result << " function id "
- << output[jhs::S_PARAMS][jhs::S_FUNCTION_ID].asInt());
- if (!hmi_so_factory().attachSchema(output)) {
+ formatters::FormatterJsonRpc::FromString<
+ hmi_apis::FunctionID::eType, hmi_apis::messageType::eType>(
+ message.json_message(), output);
+ LOG4CXX_INFO(logger_,
+ "Convertion result: "
+ << result << " function id "
+ << output[jhs::S_PARAMS][jhs::S_FUNCTION_ID].asInt());
+ if (!hmi_so_factory().attachSchema(output, false)) {
LOG4CXX_WARN(logger_, "Failed to attach schema to object.");
return false;
}
@@ -1687,8 +1685,9 @@ bool ApplicationManagerImpl::ConvertMessageToSO(
output[strings::msg_params][strings::result_code] =
NsSmartDeviceLinkRPC::V1::Result::UNSUPPORTED_VERSION;
- smart_objects::SmartObjectSPtr msg_to_send = new smart_objects::SmartObject(output);
- v1_shema.attachSchema(*msg_to_send);
+ smart_objects::SmartObjectSPtr msg_to_send =
+ new smart_objects::SmartObject(output);
+ v1_shema.attachSchema(*msg_to_send, false);
SendMessageToMobile(msg_to_send);
return false;
}
@@ -2180,9 +2179,8 @@ void ApplicationManagerImpl::SendOnSDLClose() {
utils::SharedPtr<Message> message_to_send(
new Message(protocol_handler::MessagePriority::kDefault));
- hmi_so_factory().attachSchema(*msg);
- LOG4CXX_INFO(
- logger_,
+ hmi_so_factory().attachSchema(*msg, false);
+ LOG4CXX_DEBUG(logger_,
"Attached schema to message, result if valid: " << msg->isValid());
diff --git a/src/components/formatters/include/formatters/CSmartFactory.hpp b/src/components/formatters/include/formatters/CSmartFactory.hpp
index 7cefabaa74..55f9a30385 100644
--- a/src/components/formatters/include/formatters/CSmartFactory.hpp
+++ b/src/components/formatters/include/formatters/CSmartFactory.hpp
@@ -149,9 +149,13 @@ namespace NsSmartDeviceLink
*
* @param object SmartObject to attach schema for.
*
+ * @param RemoveFakeParameters contains true if need
+ * to remove fake parameters from smart object otherwise contains false.
+ *
* @return True if operation was successful or false otherwise.
*/
- bool attachSchema(NsSmartDeviceLink::NsSmartObjects::SmartObject& object);
+ bool attachSchema(NsSmartDeviceLink::NsSmartObjects::SmartObject& object,
+ const bool RemoveFakeParameters);
/**
* @brief Attach schema to the struct SmartObject.
@@ -275,7 +279,9 @@ namespace NsSmartDeviceLink
}
template <class FunctionIdEnum, class MessageTypeEnum, class StructIdEnum>
- bool CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>::attachSchema(NsSmartDeviceLink::NsSmartObjects::SmartObject &object)
+ bool CSmartFactory<FunctionIdEnum, MessageTypeEnum, StructIdEnum>::
+ attachSchema(NsSmartDeviceLink::NsSmartObjects::SmartObject &object,
+ const bool RemoveFakeParameters)
{
if(false == object.keyExists(strings::S_PARAMS)) return false;
if(false == object[strings::S_PARAMS].keyExists(strings::S_MESSAGE_TYPE)) return false;
@@ -295,7 +301,7 @@ namespace NsSmartDeviceLink
}
object.setSchema(schemaIterator->second);
- schemaIterator->second.applySchema(object);
+ schemaIterator->second.applySchema(object, RemoveFakeParameters);
return true;
}
@@ -315,7 +321,7 @@ namespace NsSmartDeviceLink
}
object.setSchema(structs_iterator->second);
- structs_iterator->second.applySchema(object);
+ structs_iterator->second.applySchema(object, false);
return true;
}
@@ -338,7 +344,7 @@ namespace NsSmartDeviceLink
NsSmartDeviceLink::NsSmartObjects::SmartObject function_object(
NsSmartDeviceLink::NsSmartObjects::SmartType_Map);
function_object.setSchema(schema_iterator->second);
- schema_iterator->second.applySchema(function_object);
+ schema_iterator->second.applySchema(function_object, false);
return function_object;
}
diff --git a/src/components/formatters/test/CSmartFactory_test.cc b/src/components/formatters/test/CSmartFactory_test.cc
index 39cf67b3fd..41a77f1f1e 100644
--- a/src/components/formatters/test/CSmartFactory_test.cc
+++ b/src/components/formatters/test/CSmartFactory_test.cc
@@ -145,7 +145,7 @@ TEST(CSmartFactoryTest, CreateSmartObj_AttachSchema1_ExpectCreatedObjectCorrespo
obj[S_PARAMS][S_FUNCTION_ID] = FunctionIdTest::Function1;
obj[S_PARAMS][S_MESSAGE_TYPE] = MessageTypeTest::request;
// Attach schema to object
- EXPECT_TRUE(test_factory.attachSchema(obj));
+ EXPECT_TRUE(test_factory.attachSchema(obj, false));
EXPECT_TRUE(SmartType::SmartType_Map == obj.getType());
// Adding necessary fileds to correspond schema
obj[S_PARAMS][S_CORRELATION_ID] = 444;
@@ -166,7 +166,7 @@ TEST(CSmartFactoryTest, CreateSmartObj_AttachSchema1_MissOneField_ExpectCreatedO
obj[S_PARAMS][S_FUNCTION_ID] = FunctionIdTest::Function1;
obj[S_PARAMS][S_MESSAGE_TYPE] = MessageTypeTest::request;
// Attach schema to object
- EXPECT_TRUE(test_factory.attachSchema(obj));
+ EXPECT_TRUE(test_factory.attachSchema(obj, false));
EXPECT_TRUE(SmartType::SmartType_Map == obj.getType());
// Adding necessary fileds to correspond schema but 1 field is missing
obj[S_PARAMS][S_PROTOCOL_VERSION] = 1;
@@ -186,7 +186,7 @@ TEST(CSmartFactoryTest, CreateSmartObj_AttachNotExistedSchema_ExpectSmSchemaNotA
obj[S_PARAMS][S_FUNCTION_ID] = FunctionIdTest::Function1;
obj[S_PARAMS][S_MESSAGE_TYPE] = 10;
// Attach schema to object
- EXPECT_FALSE(test_factory.attachSchema(obj));
+ EXPECT_FALSE(test_factory.attachSchema(obj, false));
EXPECT_TRUE(SmartType::SmartType_Map == obj.getType());
}
@@ -198,7 +198,7 @@ TEST(CSmartFactoryTest, CreateSmartObj_AttachSchema1_AddInvalidValue_ExpectCreat
obj[S_PARAMS][S_FUNCTION_ID] = FunctionIdTest::Function1;
obj[S_PARAMS][S_MESSAGE_TYPE] = MessageTypeTest::request;
// Attach schema to object
- EXPECT_TRUE(test_factory.attachSchema(obj));
+ EXPECT_TRUE(test_factory.attachSchema(obj, false));
EXPECT_TRUE(SmartType::SmartType_Map == obj.getType());
// Adding necessary fileds to correspond schema but 1 field is missing
obj[S_PARAMS][S_PROTOCOL_VERSION] = "string";
diff --git a/src/components/formatters/test/formatter_json_rpc_test.cc b/src/components/formatters/test/formatter_json_rpc_test.cc
index 24bdc2fa3f..9047d6790a 100644
--- a/src/components/formatters/test/formatter_json_rpc_test.cc
+++ b/src/components/formatters/test/formatter_json_rpc_test.cc
@@ -56,7 +56,7 @@ TEST(FormatterJsonRPCTest, CorrectRPCv1_request_SmartObjectToString_EXPECT_SUCCE
obj[S_MSG_PARAMS] = SmartObject(SmartType::SmartType_Map);
// Attach Schema
hmi_apis::HMI_API factory;
- EXPECT_TRUE(factory.attachSchema(obj));
+ EXPECT_TRUE(factory.attachSchema(obj, false));
std::string result;
// Convert SmrtObject to Json string
@@ -76,7 +76,7 @@ TEST(FormatterJsonRPCTest, CorrectRPCv2_request_SmartObjectToString_EXPECT_SUCCE
obj[S_MSG_PARAMS] = SmartObject(SmartType::SmartType_Map);
// Attach Schema
mobile_apis::MOBILE_API factory;
- EXPECT_TRUE(factory.attachSchema(obj));
+ EXPECT_TRUE(factory.attachSchema(obj, false));
std::string result;
// Convert SmrtObject to Json string
@@ -99,7 +99,7 @@ TEST(FormatterJsonRPCTest, CorrectRPCv1_notification_SmartObjectToString_EXPECT_
obj[S_MSG_PARAMS] = SmartObject(SmartType::SmartType_Map);
// Attach Schema
hmi_apis::HMI_API factory;
- EXPECT_TRUE(factory.attachSchema(obj));
+ EXPECT_TRUE(factory.attachSchema(obj, false));
// Convert SmrtObject to Json string
EXPECT_TRUE(FormatterJsonRpc::ToString(obj, result));
EXPECT_EQ(
@@ -121,7 +121,7 @@ TEST(FormatterJsonRPCTest, InvalidRPC_SmartObjectToString_EXPECT_FALSE) {
obj[S_MSG_PARAMS] = SmartObject(SmartType::SmartType_Map);
// Attach Schema
hmi_apis::HMI_API factory;
- EXPECT_FALSE(factory.attachSchema(obj));
+ EXPECT_FALSE(factory.attachSchema(obj, false));
// Convert SmrtObject to Json string
EXPECT_FALSE(FormatterJsonRpc::ToString(obj, result));
// Expect result with default value. No correct conversion was done
diff --git a/src/components/smart_objects/include/smart_objects/array_schema_item.h b/src/components/smart_objects/include/smart_objects/array_schema_item.h
index f8fa8e9462..6454693b38 100644
--- a/src/components/smart_objects/include/smart_objects/array_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/array_schema_item.h
@@ -73,8 +73,11 @@ class CArraySchemaItem : public ISchemaItem {
* @brief Apply schema.
*
* @param Object Object to apply schema.
+ *
+ * @param RemoveFakeParameters contains true if need to remove fake parameters
+ * from smart object otherwise contains false.
**/
- void applySchema(SmartObject& Object) OVERRIDE;
+ void applySchema(SmartObject& Object, const bool RemoveFakeParameters) OVERRIDE;
/**
* @brief Unapply schema.
diff --git a/src/components/smart_objects/include/smart_objects/enum_schema_item.h b/src/components/smart_objects/include/smart_objects/enum_schema_item.h
index b38b910452..c303061152 100644
--- a/src/components/smart_objects/include/smart_objects/enum_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/enum_schema_item.h
@@ -76,8 +76,10 @@ class TEnumSchemaItem : public CDefaultSchemaItem<EnumType> {
* and tries to convert it to integer according to element-to-string
* map.
* @param Object Object to apply schema.
+ * @param RemoveFakeParameters contains true if need to remove fake parameters
+ * from smart object otherwise contains false.
**/
- void applySchema(SmartObject& Object) OVERRIDE;
+ void applySchema(SmartObject& Object, const bool RemoveFakeParameters) OVERRIDE;
/**
* @brief Unapply schema.
* @param Object Object to unapply schema.
@@ -214,7 +216,7 @@ Errors::eType TEnumSchemaItem<EnumType>::validate(const SmartObject& Object) {
}
template<typename EnumType>
-void TEnumSchemaItem<EnumType>::applySchema(SmartObject& Object) {
+void TEnumSchemaItem<EnumType>::applySchema(SmartObject& Object, const bool RemoveFakeParameters) {
if (SmartType_String == Object.getType()) {
EnumType enum_val = static_cast<EnumType>(-1);
if (ConversionHelper::StringToEnum(Object.asString(), &enum_val)) {
diff --git a/src/components/smart_objects/include/smart_objects/object_schema_item.h b/src/components/smart_objects/include/smart_objects/object_schema_item.h
index b58414459d..6e16e6a2a2 100644
--- a/src/components/smart_objects/include/smart_objects/object_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/object_schema_item.h
@@ -93,8 +93,10 @@ class CObjectSchemaItem : public ISchemaItem {
/**
* @brief Apply schema.
* @param Object Object to apply schema.
+ * @param RemoveFakeParameters contains true if need to remove fake parameters
+ * from smart object otherwise contains false.
**/
- void applySchema(SmartObject& Object) OVERRIDE;
+ void applySchema(SmartObject& Object, const bool RemoveFakeParameters) OVERRIDE;
/**
* @brief Unapply schema.
* @param Object Object to unapply schema.
@@ -121,6 +123,13 @@ class CObjectSchemaItem : public ISchemaItem {
* describing the object member.
**/
CObjectSchemaItem(const Members& Members);
+
+ /**
+ * @brief Removes fake parameters from object.
+ * @param Object Object to remove fake parameters.
+ **/
+ void RemoveFakeParams(SmartObject& Object);
+
/**
* @brief Map of member name to SMember structure describing the object member.
**/
diff --git a/src/components/smart_objects/include/smart_objects/schema_item.h b/src/components/smart_objects/include/smart_objects/schema_item.h
index 83adb0022b..92b1495909 100644
--- a/src/components/smart_objects/include/smart_objects/schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/schema_item.h
@@ -77,9 +77,11 @@ class ISchemaItem {
* @brief Apply schema.
*
* @param Object Object to apply schema.
+ * @param RemoveFakeParameters contains true if need to remove fake parameters
+ * from smart object otherwise contains false.
**/
- virtual void applySchema(
- NsSmartDeviceLink::NsSmartObjects::SmartObject& Object);
+ virtual void applySchema(NsSmartDeviceLink::NsSmartObjects::SmartObject& Object,
+ const bool RemoveFakeParameters);
/**
* @brief Unapply schema.
diff --git a/src/components/smart_objects/include/smart_objects/smart_schema.h b/src/components/smart_objects/include/smart_objects/smart_schema.h
index 720bfc9012..52dfa12004 100644
--- a/src/components/smart_objects/include/smart_objects/smart_schema.h
+++ b/src/components/smart_objects/include/smart_objects/smart_schema.h
@@ -80,8 +80,11 @@ class CSmartSchema FINAL {
* @brief Apply schema.
*
* @param Object Object to apply schema.
+ *
+ * @param RemoveFakeParameters contains true if need to remove fake parameters
+ * from smart object otherwise contains false.
**/
- void applySchema(SmartObject& Object);
+ void applySchema(SmartObject& Object, const bool RemoveFakeParameters);
/**
* @brief The reverse SmartObject conversion using schema.
diff --git a/src/components/smart_objects/src/array_schema_item.cc b/src/components/smart_objects/src/array_schema_item.cc
index a7c44bba3b..d85454bd1a 100644
--- a/src/components/smart_objects/src/array_schema_item.cc
+++ b/src/components/smart_objects/src/array_schema_item.cc
@@ -65,10 +65,11 @@ Errors::eType CArraySchemaItem::validate(const SmartObject& Object) {
return Errors::OK;
}
-void CArraySchemaItem::applySchema(SmartObject& Object) {
+void CArraySchemaItem::applySchema(SmartObject& Object,
+ const bool RemoveFakeParameters) {
if (SmartType_Array == Object.getType()) {
for (size_t i = 0U; i < Object.length(); ++i) {
- mElementSchemaItem->applySchema(Object[i]);
+ mElementSchemaItem->applySchema(Object[i], RemoveFakeParameters);
}
}
}
diff --git a/src/components/smart_objects/src/object_schema_item.cc b/src/components/smart_objects/src/object_schema_item.cc
index 8f572e427d..f2cc3eac41 100644
--- a/src/components/smart_objects/src/object_schema_item.cc
+++ b/src/components/smart_objects/src/object_schema_item.cc
@@ -87,25 +87,14 @@ Errors::eType CObjectSchemaItem::validate(const SmartObject& object) {
return Errors::OK;
}
-void CObjectSchemaItem::applySchema(SmartObject& Object) {
+void CObjectSchemaItem::applySchema(SmartObject& Object,
+ const bool RemoveFakeParameters) {
if (SmartType_Map != Object.getType()) {
return;
}
- for (SmartMap::const_iterator it = Object.map_begin(); it != Object.map_end(); ) {
- const std::string& key = it->first;
- if (mMembers.end() == mMembers.find(key)
- // FIXME(EZamakhov): Remove illegal usage of filed in AM
- && key.compare(connection_key) != 0
- && key.compare(binary_data) != 0
- && key.compare(app_id) != 0
- ) {
- ++it;
- // FIXME(DK): remove fake params. There are error responses with params
- // Object.erase(key);
- } else {
- it++;
- }
+ if (RemoveFakeParameters) {
+ RemoveFakeParams(Object);
}
SmartObject default_value;
@@ -115,10 +104,10 @@ void CObjectSchemaItem::applySchema(SmartObject& Object) {
if (!Object.keyExists(key)) {
if (member.mSchemaItem->setDefaultValue(default_value)) {
Object[key] = default_value;
- member.mSchemaItem->applySchema(Object[key]);
+ member.mSchemaItem->applySchema(Object[key], RemoveFakeParameters);
}
} else {
- member.mSchemaItem->applySchema(Object[key]);
+ member.mSchemaItem->applySchema(Object[key], RemoveFakeParameters);
}
}
}
@@ -169,5 +158,22 @@ size_t CObjectSchemaItem::GetMemberSize() {
CObjectSchemaItem::CObjectSchemaItem(const Members& members)
: mMembers(members) {}
+void CObjectSchemaItem::RemoveFakeParams(SmartObject& Object) {
+ for (SmartMap::const_iterator it = Object.map_begin(); it != Object.map_end(); ) {
+ const std::string& key = it->first;
+ if (mMembers.end() == mMembers.find(key)
+ // FIXME(EZamakhov): Remove illegal usage of filed in AM
+ && key.compare(connection_key) != 0
+ && key.compare(binary_data) != 0
+ && key.compare(app_id) != 0
+ ) {
+ ++it;
+ Object.erase(key);
+ } else {
+ it++;
+ }
+ }
+}
+
} // namespace NsSmartObjects
} // namespace NsSmartDeviceLink
diff --git a/src/components/smart_objects/src/schema_item.cc b/src/components/smart_objects/src/schema_item.cc
index b75e5a35ea..a78afe1f2c 100644
--- a/src/components/smart_objects/src/schema_item.cc
+++ b/src/components/smart_objects/src/schema_item.cc
@@ -47,7 +47,7 @@ bool ISchemaItem::hasDefaultValue(SmartObject& Object) {
return false;
}
-void ISchemaItem::applySchema(SmartObject& Object) {
+void ISchemaItem::applySchema(SmartObject& Object, const bool RemoveFakeParameters) {
}
void ISchemaItem::unapplySchema(SmartObject& Object) {
diff --git a/src/components/smart_objects/src/smart_schema.cc b/src/components/smart_objects/src/smart_schema.cc
index 36c153332a..3a9cd22a0a 100644
--- a/src/components/smart_objects/src/smart_schema.cc
+++ b/src/components/smart_objects/src/smart_schema.cc
@@ -51,8 +51,8 @@ void CSmartSchema::setSchemaItem(const ISchemaItemPtr schemaItem) {
mSchemaItem = schemaItem;
}
-void CSmartSchema::applySchema(SmartObject& Object) {
- mSchemaItem->applySchema(Object);
+void CSmartSchema::applySchema(SmartObject& Object, const bool RemoveFakeParameters) {
+ mSchemaItem->applySchema(Object, RemoveFakeParameters);
}
void CSmartSchema::unapplySchema(SmartObject& Object) {
diff --git a/src/components/smart_objects/test/ArraySchemaItem_test.cc b/src/components/smart_objects/test/ArraySchemaItem_test.cc
index e8cad40126..f153a4c4a7 100644
--- a/src/components/smart_objects/test/ArraySchemaItem_test.cc
+++ b/src/components/smart_objects/test/ArraySchemaItem_test.cc
@@ -77,7 +77,7 @@ TEST(test_no_default_value, test_ArraySchemaItemTest) {
resultType = item->validate(obj[3]);
EXPECT_EQ(Errors::OK, resultType);
- item->applySchema(obj);
+ item->applySchema(obj, false);
resultType = item->validate(obj);
EXPECT_EQ(Errors::OK, resultType);
@@ -146,7 +146,7 @@ TEST(test_item_with_default_value, test_ArraySchemaItemTest) {
resultType = item->validate(obj[2]);
EXPECT_EQ(Errors::INVALID_VALUE, resultType);
- item->applySchema(obj);
+ item->applySchema(obj, false);
resultType = item->validate(obj);
EXPECT_EQ(Errors::OK, resultType);
diff --git a/src/components/smart_objects/test/CObjectSchemaItem_test.cc b/src/components/smart_objects/test/CObjectSchemaItem_test.cc
index 56f365e5c4..b5e1286ee1 100644
--- a/src/components/smart_objects/test/CObjectSchemaItem_test.cc
+++ b/src/components/smart_objects/test/CObjectSchemaItem_test.cc
@@ -292,28 +292,36 @@ TEST_F(ObjectSchemaItemTest, validation_unexpected_param_remove) {
obj[S_PARAMS][fake2] = SmartObject("123");
obj[S_MSG_PARAMS][fake3] = true;
- // Check apply schema
- schema_item->applySchema(obj);
+ // Check apply schema, does not remove fake parameter
+ schema_item->applySchema(obj, false);
EXPECT_TRUE(obj.keyExists(fake1));
EXPECT_TRUE(obj[S_PARAMS].keyExists(fake2));
EXPECT_TRUE(obj[S_MSG_PARAMS].keyExists(fake3));
EXPECT_EQ(Errors::OK, schema_item->validate(obj));
- // all fake parameters are removed on unapply schema
- schema_item->unapplySchema(obj);
-
+ // Check apply schema, remove fake parameter
+ schema_item->applySchema(obj, true);
EXPECT_FALSE(obj.keyExists(fake1));
EXPECT_FALSE(obj[S_PARAMS].keyExists(fake2));
EXPECT_FALSE(obj[S_MSG_PARAMS].keyExists(fake3));
+ EXPECT_TRUE(obj[S_PARAMS].keyExists(S_FUNCTION_ID));
+ EXPECT_TRUE(obj[S_PARAMS].keyExists(S_CORRELATION_ID));
+ EXPECT_TRUE(obj[S_PARAMS].keyExists(S_PROTOCOL_VERSION));
+ EXPECT_TRUE(obj[S_MSG_PARAMS].keyExists(Keys::RESULT_CODE));
+ EXPECT_TRUE(obj[S_MSG_PARAMS].keyExists(Keys::INFO));
+ EXPECT_TRUE(obj[S_MSG_PARAMS].keyExists(Keys::SUCCESS));
+ EXPECT_EQ(Errors::OK, schema_item->validate(obj));
+
obj[fake1] = SmartObject(static_cast<int64_t>(0));
obj[S_PARAMS][fake2] = SmartObject("123");
obj[S_MSG_PARAMS][fake3] = true;
- // Check unapply schema
+ // all fake parameters are removed on unapply schema
schema_item->unapplySchema(obj);
- // all fake parameters are removed on apply schema
+
+ // all fake parameters are removed on unapply schema
EXPECT_FALSE(obj.keyExists(fake1));
EXPECT_FALSE(obj[S_PARAMS].keyExists(fake2));
EXPECT_FALSE(obj[S_MSG_PARAMS].keyExists(fake3));
@@ -334,7 +342,7 @@ TEST_F(ObjectSchemaItemTest, validation_empty_params) {
EXPECT_EQ(Errors::OK, schema_item->validate(obj));
- schema_item->applySchema(obj);
+ schema_item->applySchema(obj, false);
EXPECT_EQ(Errors::OK, schema_item->validate(obj));
schema_item->unapplySchema(obj);
@@ -374,7 +382,7 @@ TEST_F(ObjectSchemaItemTest, test_strings_to_enum_conversion) {
// S_FUNCTION_ID and RESULT_CODE are not converted to int
EXPECT_NE(Errors::OK, schema_item->validate(object));
- schema_item->applySchema(object);
+ schema_item->applySchema(object, false);
EXPECT_EQ(Errors::OK, schema_item->validate(object));
// check conversion result
diff --git a/src/components/smart_objects/test/EnumSchemaItem_test.cc b/src/components/smart_objects/test/EnumSchemaItem_test.cc
index e99e2f4e66..6d007b74b6 100644
--- a/src/components/smart_objects/test/EnumSchemaItem_test.cc
+++ b/src/components/smart_objects/test/EnumSchemaItem_test.cc
@@ -209,19 +209,19 @@ TEST_F(EnumSchemaItemTest, test_apply_unapply_schema) {
EXPECT_EQ(Errors::INVALID_VALUE, resultType);
EXPECT_EQ(std::string("FACTORY_DEFAULTS"), obj.asString());
- item->applySchema(obj);
+ item->applySchema(obj, false);
resultType = item->validate(obj);
EXPECT_EQ(Errors::OK, resultType);
EXPECT_EQ(TestType::FACTORY_DEFAULTS, obj.asInt());
obj = "TOO_MANY_REQUESTS";
- item->applySchema(obj);
+ item->applySchema(obj, false);
resultType = item->validate(obj);
EXPECT_EQ(Errors::OK, resultType);
EXPECT_EQ(TestType::TOO_MANY_REQUESTS, obj.asInt());
obj = "ENOUGH_REQUESTS";
- item->applySchema(obj);
+ item->applySchema(obj, false);
resultType = item->validate(obj);
EXPECT_EQ(Errors::INVALID_VALUE, resultType);
EXPECT_EQ(std::string("ENOUGH_REQUESTS"), obj.asString());
diff --git a/src/components/smart_objects/test/SmartObjectConvertionTime_test.cc b/src/components/smart_objects/test/SmartObjectConvertionTime_test.cc
index 11a1ed3d2e..f1bf1df697 100644
--- a/src/components/smart_objects/test/SmartObjectConvertionTime_test.cc
+++ b/src/components/smart_objects/test/SmartObjectConvertionTime_test.cc
@@ -183,7 +183,7 @@ class SmartObjectConvertionTimeTest : public ::testing::Test {
srcObj[S_PARAMS][S_PROTOCOL_VERSION] = 1; // adjust protocol version
- srcObj.getSchema().applySchema(dstObj);
+ srcObj.getSchema().applySchema(dstObj, false);
// The objects are different after remove non-schemed fields
// EXPECT_TRUE(srcObj == dstObj);
@@ -200,7 +200,7 @@ class SmartObjectConvertionTimeTest : public ::testing::Test {
srcObj[S_PARAMS][S_PROTOCOL_VERSION] = 2; // adjust protocol version
- dstObj.getSchema().applySchema(dstObj);
+ dstObj.getSchema().applySchema(dstObj, false);
// The objects are different after remove non-schemed fields
// EXPECT_TRUE(srcObj == dstObj);
}