diff options
4 files changed, 31 insertions, 13 deletions
diff --git a/src/components/formatters/src/CFormatterJsonBase.cpp b/src/components/formatters/src/CFormatterJsonBase.cpp index 64a60e4f8f..c3f89cdf83 100644 --- a/src/components/formatters/src/CFormatterJsonBase.cpp +++ b/src/components/formatters/src/CFormatterJsonBase.cpp @@ -55,9 +55,10 @@ void NsSmartDeviceLink::NsJSONHandler::Formatters::CFormatterJsonBase::jsonValue for (uint32_t i = 0; i < value.size(); i++) { jsonValueToObj(value[i], obj[i]); } - } else if (value.type() == Json::intValue - || value.type() == Json::uintValue) { + } else if (value.type() == Json::intValue) { obj = value.asInt(); + } else if (value.type() == Json::uintValue) { + obj = value.asUInt(); } else if (value.type() == Json::realValue) { obj = value.asDouble(); } else if (value.type() == Json::booleanValue) { @@ -104,6 +105,9 @@ void NsSmartDeviceLink::NsJSONHandler::Formatters::CFormatterJsonBase::objToJson } else if (NsSmartDeviceLink::NsSmartObjects::SmartType_Integer == obj.getType()) { item = obj.asInt(); + } else if (NsSmartDeviceLink::NsSmartObjects::SmartType_UInteger + == obj.getType()) { + item = obj.asUInt(); } else if (NsSmartDeviceLink::NsSmartObjects::SmartType_Double == obj.getType()) { item = obj.asDouble(); diff --git a/src/components/formatters/test/CFormatterJsonBase_test.cc b/src/components/formatters/test/CFormatterJsonBase_test.cc index 3765da29d4..d617c21a67 100644 --- a/src/components/formatters/test/CFormatterJsonBase_test.cc +++ b/src/components/formatters/test/CFormatterJsonBase_test.cc @@ -102,13 +102,13 @@ TEST(CFormatterJsonBaseTest, JSonSignedMaxIntValueToSmartObj_ExpectSuccessful) { TEST(CFormatterJsonBaseTest, JSonUnsignedMaxIntValueToSmartObj_ExpectSuccessful) { // Arrange value - Json::Int ui_val = Json::Value::maxInt; + Json::UInt ui_val = Json::Value::maxUInt; Json::Value json_value(ui_val); // Json value from maximum possible unsigned int SmartObject object; // Convert json to smart object CFormatterJsonBase::jsonValueToObj(json_value, object); // Check conversion was successful - EXPECT_EQ(ui_val, object.asInt()); + EXPECT_EQ(ui_val, object.asUInt()); } TEST(CFormatterJsonBaseTest, JSonSignedMaxInt64ValueToSmartObj_ExpectFailed) { @@ -242,13 +242,13 @@ TEST(CFormatterJsonBaseTest, MinIntSmartObjectToJSon_ExpectSuccessful) { TEST(CFormatterJsonBaseTest, UnsignedMaxIntSmartObjectToJSon_ExpectSuccessful) { // Arrange value - Json::Int ui_val = Json::Value::maxInt; + Json::UInt ui_val = Json::Value::maxUInt; Json::Value json_value; // Json value from maximum unsigned int SmartObject object(ui_val); // Convert json to smart object CFormatterJsonBase::objToJsonValue(object, json_value); // Check conversion was successful - EXPECT_EQ(ui_val, json_value.asInt()); + EXPECT_EQ(ui_val, json_value.asUInt()); } TEST(CFormatterJsonBaseTest, BoolSmartObjectToJSon_ExpectSuccessful) { diff --git a/src/components/smart_objects/include/smart_objects/smart_object.h b/src/components/smart_objects/include/smart_objects/smart_object.h index bd70b7ea11..eca1199cec 100644 --- a/src/components/smart_objects/include/smart_objects/smart_object.h +++ b/src/components/smart_objects/include/smart_objects/smart_object.h @@ -94,6 +94,11 @@ enum SmartType { SmartType_Binary = 8, /** + * @brief Unsigned Integer value. + **/ + SmartType_UInteger = 9, + + /** * @brief Invalid value. Represents invalid object that cannot change his type. **/ SmartType_Invalid = -1 diff --git a/src/components/smart_objects/src/smart_object.cc b/src/components/smart_objects/src/smart_object.cc index 264652e448..599141f087 100644 --- a/src/components/smart_objects/src/smart_object.cc +++ b/src/components/smart_objects/src/smart_object.cc @@ -72,6 +72,9 @@ SmartObject::SmartObject(SmartType Type) case SmartType_Integer: set_value_integer(0); break; + case SmartType_UInteger: + set_value_integer(0); + break; case SmartType_Double: set_value_double(0); break; @@ -121,6 +124,8 @@ bool SmartObject::operator==(const SmartObject& Other) const { switch (m_type) { case SmartType_Integer: return m_data.int_value == Other.m_data.int_value; + case SmartType_UInteger: + return m_data.int_value == Other.m_data.int_value; case SmartType_Double: return m_data.double_value == Other.m_data.double_value; case SmartType_Boolean: @@ -201,7 +206,12 @@ bool SmartObject::operator==(const int32_t Value) const { } void SmartObject::set_value_integer(int64_t NewValue) { - set_new_type(SmartType_Integer); + if (NewValue > std::numeric_limits<int32_t>::max() + && NewValue <= std::numeric_limits<uint32_t>::max()) { + set_new_type(SmartType_UInteger); + } else { + set_new_type(SmartType_Integer); + } m_data.int_value = NewValue; } @@ -213,6 +223,8 @@ int64_t SmartObject::convert_int() const { return (m_data.bool_value == true) ? 1 : 0; case SmartType_Integer: return m_data.int_value; + case SmartType_UInteger: + return m_data.int_value; case SmartType_Double: return static_cast<int64_t>(m_data.double_value); default: @@ -836,12 +848,9 @@ std::set<std::string> SmartObject::enumerate() const { std::set<std::string> keys; if (m_type == SmartType_Map) { - std::transform( - m_data.map_value->begin(), - m_data.map_value->end(), - std::inserter(keys, keys.end()), - &SmartObject::OperatorToTransform - ); + std::transform(m_data.map_value->begin(), m_data.map_value->end(), + std::inserter(keys, keys.end()), + &SmartObject::OperatorToTransform); } return keys; } |