summaryrefslogtreecommitdiff
path: root/src/components/formatters
diff options
context:
space:
mode:
authorJustin Dickow <jjdickow@gmail.com>2015-02-20 09:11:18 -0500
committerJustin Dickow <jjdickow@gmail.com>2015-02-20 09:11:18 -0500
commita7c5d752cb75485baa0ded5226335d0f8eb10321 (patch)
treefbfd9251ada2cdcd5cf6a03a79887d08f6b496d7 /src/components/formatters
parentb2b2233d866f102d3de339afa8ccaf37d3cf2570 (diff)
downloadsdl_core-a7c5d752cb75485baa0ded5226335d0f8eb10321.tar.gz
Bug Fixes and ImprovementsSynchronizationCommit
Fix Empty perform iteration request Fix type of name from string to enum SendLocation implemented on HTML5 HMI Fixed PI response on VR rejection due to high priority. Fix Apps not responsive/not able to start app/apps remain listed on SYNC even after USB disconnect Mobile API change and processing capabilities Change perform interaction request conditions. Fix SDL must always start 3sec timer before resuming the HMILevel of the app Remove redundant StartSavePersistentDataTimer() call. Change wrong predicate name to right. Added stream request handling feature Made streaming timeout in media manager configurable Put navi app in LIMITED in case of phone call Handling of audio state for applications Add stop streaming timeout into ini file Implement HMILevel resumption for job-1 Fix result code ABORTED when interrupts it by Voice recognition activation Fix incorrect value parameter unexpectedDisconnect in BCOnAppUnregistered Fix SDL send BC.OnAppUnregistered with "unexpectedDisconnect" set to "true" in case received from HMI OnExitAllApplications {"reason":"MASTER_RESET"} Fix Update ini file for iAP1 support Current working directory added to image path Fix helpers to make it workable with more then 2 parameters DCHECK() for ManageMobileCommand() replaced with log message because the latter returns false in some regular situations (e.g. TOO_MANY_PENDING_REQUESTS, see SDLAQ-CRS-10) Remove connection after closing. Signed-off-by: Justin Dickow <jjdickow@gmail.com>
Diffstat (limited to 'src/components/formatters')
-rw-r--r--src/components/formatters/CMakeLists.txt59
-rw-r--r--src/components/formatters/include/formatters/formatter_json_rpc.h2
-rw-r--r--src/components/formatters/include/formatters/generic_json_formatter.h2
-rw-r--r--src/components/formatters/include/formatters/meta_formatter.h2
-rw-r--r--src/components/formatters/src/formatter_json_rpc.cc2
-rw-r--r--src/components/formatters/src/generic_json_formatter.cc2
-rw-r--r--src/components/formatters/src/meta_formatter.cc2
-rw-r--r--src/components/formatters/test/CMakeLists.txt54
-rw-r--r--src/components/formatters/test/generic_json_formatter_test.cc162
-rw-r--r--src/components/formatters/test/main.cc7
10 files changed, 277 insertions, 17 deletions
diff --git a/src/components/formatters/CMakeLists.txt b/src/components/formatters/CMakeLists.txt
index 3f53cf0b7f..3dd7dc9366 100644
--- a/src/components/formatters/CMakeLists.txt
+++ b/src/components/formatters/CMakeLists.txt
@@ -1,25 +1,62 @@
+# Copyright (c) 2014, Ford Motor Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+#
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following
+# disclaimer in the documentation and/or other materials provided with the
+# distribution.
+#
+# Neither the name of the Ford Motor Company nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+
+set(FORMATTERS_SRC_DIR ${COMPONENTS_DIR}/formatters/src)
+
include_directories (
- ./include/
- ../protocol_handler/include/
- ../utils/include/
+ include/
+ ${COMPONENTS_DIR}/protocol_handler/include/
+ ${COMPONENTS_DIR}/utils/include/
${JSONCPP_INCLUDE_DIRECTORY}
${MESSAGE_BROKER_INCLUDE_DIRECTORY}
- ../../../src/components/smart_objects/include
+ ${COMPONENTS_DIR}/smart_objects/include
)
set (SOURCES
- ./src/CSmartFactory.cpp
+ ${FORMATTERS_SRC_DIR}/CSmartFactory.cpp
)
set (FORMATTER_SOURCES
- ./src/CFormatterJsonBase.cpp
- ./src/CFormatterJsonSDLRPCv1.cpp
- ./src/CFormatterJsonSDLRPCv2.cpp
- ./src/formatter_json_rpc.cc
- ./src/meta_formatter.cc
- ./src/generic_json_formatter.cc
+ ${FORMATTERS_SRC_DIR}/CFormatterJsonBase.cpp
+ ${FORMATTERS_SRC_DIR}/CFormatterJsonSDLRPCv1.cpp
+ ${FORMATTERS_SRC_DIR}/CFormatterJsonSDLRPCv2.cpp
+ ${FORMATTERS_SRC_DIR}/formatter_json_rpc.cc
+ ${FORMATTERS_SRC_DIR}/meta_formatter.cc
+ ${FORMATTERS_SRC_DIR}/generic_json_formatter.cc
)
add_library("formatters" ${SOURCES}
${FORMATTER_SOURCES}
)
+
+if(BUILD_TESTS)
+ add_subdirectory(test)
+endif()
diff --git a/src/components/formatters/include/formatters/formatter_json_rpc.h b/src/components/formatters/include/formatters/formatter_json_rpc.h
index 26636f4a2b..d4653ef565 100644
--- a/src/components/formatters/include/formatters/formatter_json_rpc.h
+++ b/src/components/formatters/include/formatters/formatter_json_rpc.h
@@ -1,4 +1,4 @@
-/**
+/*
* @file formatter_json_rpc.h
* @brief FormatterJsonRpc header file.
*/
diff --git a/src/components/formatters/include/formatters/generic_json_formatter.h b/src/components/formatters/include/formatters/generic_json_formatter.h
index 3eaee0b36e..a4b3f3f712 100644
--- a/src/components/formatters/include/formatters/generic_json_formatter.h
+++ b/src/components/formatters/include/formatters/generic_json_formatter.h
@@ -1,4 +1,4 @@
-/**
+/*
* @file generic_json_formatter.h
* @brief Generic JSON formatter header file.
*/
diff --git a/src/components/formatters/include/formatters/meta_formatter.h b/src/components/formatters/include/formatters/meta_formatter.h
index c1b767d7cf..f9fd6fad72 100644
--- a/src/components/formatters/include/formatters/meta_formatter.h
+++ b/src/components/formatters/include/formatters/meta_formatter.h
@@ -1,4 +1,4 @@
-/**
+/*
* @file meta_fromatter.h
* @brief file describes class CMetaFormatter which is designed to format
* the smart object against given schema for given formatter
diff --git a/src/components/formatters/src/formatter_json_rpc.cc b/src/components/formatters/src/formatter_json_rpc.cc
index 8722df46df..012962bbb2 100644
--- a/src/components/formatters/src/formatter_json_rpc.cc
+++ b/src/components/formatters/src/formatter_json_rpc.cc
@@ -1,4 +1,4 @@
-/**
+/*
* @file formatter_json_rpc.cc
* @brief formatter_json_rpc source file.
*/
diff --git a/src/components/formatters/src/generic_json_formatter.cc b/src/components/formatters/src/generic_json_formatter.cc
index ce1aa03807..6cc2266193 100644
--- a/src/components/formatters/src/generic_json_formatter.cc
+++ b/src/components/formatters/src/generic_json_formatter.cc
@@ -1,4 +1,4 @@
-/**
+/*
* @file generic_json_formatter.cc
* @brief Generic JSON formatter source file.
*/
diff --git a/src/components/formatters/src/meta_formatter.cc b/src/components/formatters/src/meta_formatter.cc
index 145020a5e2..8b24fd4b0e 100644
--- a/src/components/formatters/src/meta_formatter.cc
+++ b/src/components/formatters/src/meta_formatter.cc
@@ -1,4 +1,4 @@
-/**
+/*
* @file meta_fromatter.cc
* @brief implementation of class CMetaFormatter which is designed to format
* the smart object against given schema for given formatter
diff --git a/src/components/formatters/test/CMakeLists.txt b/src/components/formatters/test/CMakeLists.txt
new file mode 100644
index 0000000000..8188e8104b
--- /dev/null
+++ b/src/components/formatters/test/CMakeLists.txt
@@ -0,0 +1,54 @@
+# Copyright (c) 2014, Ford Motor Company
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+#
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following
+# disclaimer in the documentation and/or other materials provided with the
+# distribution.
+#
+# Neither the name of the Ford Motor Company nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+
+if(BUILD_TESTS)
+
+include_directories(
+ ${GMOCK_INCLUDE_DIRECTORY}
+ ${COMPONENTS_DIR}/smart_objects/include
+ ${COMPONENTS_DIR}/formatters/include
+)
+
+set(LIBRARIES
+ gmock
+ SmartObjects
+ formatters
+ jsoncpp
+)
+
+set(SOURCES
+${COMPONENTS_DIR}/formatters/test/generic_json_formatter_test.cc
+${COMPONENTS_DIR}/formatters/test/main.cc
+)
+
+create_test("generic_json_formatter_test" "${SOURCES}" "${LIBRARIES}")
+
+endif()
diff --git a/src/components/formatters/test/generic_json_formatter_test.cc b/src/components/formatters/test/generic_json_formatter_test.cc
new file mode 100644
index 0000000000..51da8c91ff
--- /dev/null
+++ b/src/components/formatters/test/generic_json_formatter_test.cc
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "gtest/gtest.h"
+#include "formatters/generic_json_formatter.h"
+
+namespace test {
+namespace components {
+namespace formatters {
+
+TEST(GenericJsonFormatter, ToString) {
+ namespace smartobj = NsSmartDeviceLink::NsSmartObjects;
+ namespace formatters = NsSmartDeviceLink::NsJSONHandler::Formatters;
+
+ smartobj::SmartObject obj;
+ std::string result;
+
+ formatters::GenericJsonFormatter::ToString(obj, result);
+ ASSERT_STREQ("null\n", result.c_str());
+
+ obj = true;
+ formatters::GenericJsonFormatter::ToString(obj, result);
+ ASSERT_STREQ("true\n", result.c_str());
+
+ obj = 10;
+ formatters::GenericJsonFormatter::ToString(obj, result);
+ ASSERT_STREQ("10\n", result.c_str());
+
+ obj = 15.2;
+ formatters::GenericJsonFormatter::ToString(obj, result);
+ ASSERT_STREQ("15.20\n", result.c_str());
+
+ obj = 'c';
+ formatters::GenericJsonFormatter::ToString(obj, result);
+ ASSERT_STREQ("\"c\"\n", result.c_str());
+
+ obj[0] = 1;
+ obj[1] = true;
+ obj[2] = "string";
+ formatters::GenericJsonFormatter::ToString(obj, result);
+ ASSERT_STREQ("[ 1, true, \"string\" ]\n", result.c_str());
+
+ obj["intField"] = 100500;
+ obj["stringField"] = "s";
+ obj["subobject"]["boolField"] = false;
+ obj["subobject"]["arrayField"][0] = 0;
+ obj["subobject"]["arrayField"][1] = 'c';
+ obj["subobject"]["arrayField"][2][0] = 10.0;
+ formatters::GenericJsonFormatter::ToString(obj, result);
+ ASSERT_STREQ("{\n"
+ " \"intField\" : 100500,\n"
+ " \"stringField\" : \"s\",\n"
+ " \"subobject\" : {\n"
+ " \"arrayField\" : [\n"
+ " 0,\n"
+ " \"c\",\n"
+ " [ 10.0 ]\n"
+ " ],\n"
+ " \"boolField\" : false\n"
+ " }\n"
+ "}\n", result.c_str());
+}
+
+TEST(GenericJsonFormatter, FromString) {
+ namespace smartobj = NsSmartDeviceLink::NsSmartObjects;
+ namespace formatters = NsSmartDeviceLink::NsJSONHandler::Formatters;
+
+ smartobj::SmartObject result;
+
+ ASSERT_FALSE(formatters::GenericJsonFormatter::FromString("", result));
+ ASSERT_FALSE(formatters::GenericJsonFormatter::FromString("\"str", result));
+ ASSERT_FALSE(formatters::GenericJsonFormatter::FromString("[10", result));
+ ASSERT_FALSE(formatters::GenericJsonFormatter::FromString("{10}", result));
+
+ ASSERT_TRUE(formatters::GenericJsonFormatter::FromString("null", result));
+ ASSERT_EQ(smartobj::SmartType_Null, result.getType());
+
+ ASSERT_TRUE(formatters::GenericJsonFormatter::FromString("true", result));
+ ASSERT_EQ(smartobj::SmartType_Boolean, result.getType());
+ ASSERT_EQ(true, result.asBool());
+
+ ASSERT_TRUE(formatters::GenericJsonFormatter::FromString("1", result));
+ ASSERT_EQ(smartobj::SmartType_Integer, result.getType());
+ ASSERT_EQ(1, result.asInt());
+
+ ASSERT_TRUE(formatters::GenericJsonFormatter::FromString("0.5", result));
+ ASSERT_EQ(smartobj::SmartType_Double, result.getType());
+ ASSERT_DOUBLE_EQ(0.5, result.asDouble());
+
+ ASSERT_TRUE(formatters::GenericJsonFormatter::FromString("\"str\"", result));
+ ASSERT_EQ(smartobj::SmartType_String, result.getType());
+ ASSERT_STREQ("str", result.asString().c_str());
+
+ ASSERT_TRUE(formatters::GenericJsonFormatter::FromString("[true, null, 10]",
+ result));
+ ASSERT_EQ(smartobj::SmartType_Array, result.getType());
+ ASSERT_EQ(smartobj::SmartType_Boolean, result.getElement(0U).getType());
+ ASSERT_EQ(true, result.getElement(0U).asBool());
+ ASSERT_EQ(smartobj::SmartType_Null, result.getElement(1U).getType());
+ ASSERT_EQ(smartobj::SmartType_Integer, result.getElement(2U).getType());
+ ASSERT_EQ(10, result.getElement(2U).asInt());
+
+ ASSERT_TRUE(
+ formatters::GenericJsonFormatter::FromString("{"
+ " \"intField\": 100500,"
+ " \"subobject\": {"
+ " \"arrayField\": [1, null],"
+ " \"strField\": \"str\""
+ " }"
+ "}",
+ result));
+ ASSERT_EQ(smartobj::SmartType_Map, result.getType());
+ ASSERT_EQ(smartobj::SmartType_Integer,
+ result.getElement("intField").getType());
+ ASSERT_EQ(100500, result.getElement("intField").asInt());
+ ASSERT_EQ(smartobj::SmartType_Map, result.getElement("subobject").getType());
+ ASSERT_EQ(smartobj::SmartType_Array,
+ result.getElement("subobject").getElement("arrayField").getType());
+ ASSERT_EQ(smartobj::SmartType_Integer,
+ result.getElement("subobject").getElement("arrayField").getElement(0U).getType());
+ ASSERT_EQ(1, result.getElement("subobject").getElement("arrayField").getElement(0U).asInt());
+ ASSERT_EQ(smartobj::SmartType_Null,
+ result.getElement("subobject").getElement("arrayField").getElement(1U).getType());
+ ASSERT_EQ(smartobj::SmartType_String,
+ result.getElement("subobject").getElement("strField").getType());
+ ASSERT_STREQ(
+ "str",
+ result.getElement("subobject").getElement("strField").asString().c_str());
+}
+
+} // formatters
+} // components
+} // test
diff --git a/src/components/formatters/test/main.cc b/src/components/formatters/test/main.cc
new file mode 100644
index 0000000000..59fa20e8b5
--- /dev/null
+++ b/src/components/formatters/test/main.cc
@@ -0,0 +1,7 @@
+#include "gmock/gmock.h"
+
+int main(int argc, char** argv) {
+ testing::InitGoogleMock(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+