summaryrefslogtreecommitdiff
path: root/src/components/rpc_base
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/rpc_base
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/rpc_base')
-rw-r--r--src/components/rpc_base/CMakeLists.txt53
-rw-r--r--src/components/rpc_base/include/rpc_base/gtest_support.h2
-rw-r--r--src/components/rpc_base/include/rpc_base/rpc_base.h6
-rw-r--r--src/components/rpc_base/include/rpc_base/rpc_base_dbus_inl.h2
-rw-r--r--src/components/rpc_base/include/rpc_base/rpc_base_inl.h81
-rw-r--r--src/components/rpc_base/include/rpc_base/rpc_base_json_inl.h8
-rw-r--r--src/components/rpc_base/include/rpc_base/rpc_message.h62
-rw-r--r--src/components/rpc_base/include/rpc_base/validation_report.h2
-rw-r--r--src/components/rpc_base/src/rpc_base/rpc_base.cc2
-rw-r--r--src/components/rpc_base/test/CMakeLists.txt62
-rw-r--r--src/components/rpc_base/test/main.cc7
-rw-r--r--src/components/rpc_base/test/rpc_base_dbus_test.cc690
-rw-r--r--src/components/rpc_base/test/rpc_base_json_test.cc377
-rw-r--r--src/components/rpc_base/test/rpc_base_test.cc437
14 files changed, 1715 insertions, 76 deletions
diff --git a/src/components/rpc_base/CMakeLists.txt b/src/components/rpc_base/CMakeLists.txt
index 2a14274145..94e67cc985 100644
--- a/src/components/rpc_base/CMakeLists.txt
+++ b/src/components/rpc_base/CMakeLists.txt
@@ -1,21 +1,58 @@
+# 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(RPC_BASE_INCLUDE_DIR ${COMPONENTS_DIR}/rpc_base/include)
+
include_directories(
include
${JSONCPP_INCLUDE_DIRECTORY}
)
set (SOURCES
- src/rpc_base/rpc_base.cc
+ ${COMPONENTS_DIR}/rpc_base/src/rpc_base/rpc_base.cc
)
set (HEADERS
- include/rpc_base/gtest_support.h
- include/rpc_base/rpc_base_dbus_inl.h
- include/rpc_base/rpc_base.h
- include/rpc_base/rpc_base_inl.h
- include/rpc_base/rpc_base_json_inl.h
- include/rpc_base/rpc_message.h
- include/rpc_base/validation_report.h
+ ${RPC_BASE_INCLUDE_DIR}/rpc_base/gtest_support.h
+ ${RPC_BASE_INCLUDE_DIR}/rpc_base/rpc_base_dbus_inl.h
+ ${RPC_BASE_INCLUDE_DIR}/rpc_base/rpc_base.h
+ ${RPC_BASE_INCLUDE_DIR}/rpc_base/rpc_base_inl.h
+ ${RPC_BASE_INCLUDE_DIR}/rpc_base/rpc_base_json_inl.h
+ ${RPC_BASE_INCLUDE_DIR}/rpc_base/rpc_message.h
+ ${RPC_BASE_INCLUDE_DIR}/rpc_base/validation_report.h
)
add_library(rpc_base ${HEADERS} ${SOURCES})
target_link_libraries(rpc_base jsoncpp)
+
+if(BUILD_TESTS)
+ add_subdirectory(test)
+endif() \ No newline at end of file
diff --git a/src/components/rpc_base/include/rpc_base/gtest_support.h b/src/components/rpc_base/include/rpc_base/gtest_support.h
index 68d1a83141..daea5d3884 100644
--- a/src/components/rpc_base/include/rpc_base/gtest_support.h
+++ b/src/components/rpc_base/include/rpc_base/gtest_support.h
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2014, Ford Motor Company
* All rights reserved.
*
diff --git a/src/components/rpc_base/include/rpc_base/rpc_base.h b/src/components/rpc_base/include/rpc_base/rpc_base.h
index 56b099d9e9..1792262a0f 100644
--- a/src/components/rpc_base/include/rpc_base/rpc_base.h
+++ b/src/components/rpc_base/include/rpc_base/rpc_base.h
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2014, Ford Motor Company
* All rights reserved.
*
@@ -183,10 +183,12 @@ class Integer : public PrimitiveType {
// Methods
Integer();
explicit Integer(IntType value);
+ Integer(const Integer& value);
explicit Integer(const Json::Value* value);
explicit Integer(dbus::MessageReader* reader);
Integer(const Json::Value* value, IntType def_value);
Integer& operator=(IntType new_val);
+ Integer& operator=(const Integer& new_val);
Integer& operator++();
Integer& operator+=(int value);
operator IntType() const;
@@ -229,6 +231,8 @@ class String : public PrimitiveType {
String(const Json::Value* value, const std::string& def_value);
bool operator<(String new_val);
String& operator=(const std::string& new_val);
+ String& operator=(const String& new_val);
+ bool operator==(const String& rhs);
operator const std::string& () const;
Json::Value ToJsonValue() const;
void ToDbusWriter(dbus::MessageWriter* writer) const;
diff --git a/src/components/rpc_base/include/rpc_base/rpc_base_dbus_inl.h b/src/components/rpc_base/include/rpc_base/rpc_base_dbus_inl.h
index 7d66950fc9..5f9c45a060 100644
--- a/src/components/rpc_base/include/rpc_base/rpc_base_dbus_inl.h
+++ b/src/components/rpc_base/include/rpc_base/rpc_base_dbus_inl.h
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2014, Ford Motor Company
* All rights reserved.
*
diff --git a/src/components/rpc_base/include/rpc_base/rpc_base_inl.h b/src/components/rpc_base/include/rpc_base/rpc_base_inl.h
index 4373f0ea26..9a59e169c2 100644
--- a/src/components/rpc_base/include/rpc_base/rpc_base_inl.h
+++ b/src/components/rpc_base/include/rpc_base/rpc_base_inl.h
@@ -1,34 +1,34 @@
-/**
-* 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.
-*/
+/*
+ * 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.
+ */
#ifndef VALIDATED_TYPES_INL_H_
#define VALIDATED_TYPES_INL_H_
@@ -185,6 +185,13 @@ Integer<T, minval, maxval>& Integer<T, minval, maxval>::operator=(IntType new_va
}
template<typename T, T minval, T maxval>
+Integer<T, minval, maxval>& Integer<T, minval, maxval>::operator=(const Integer& new_val) {
+ this->value_ = new_val.value_;
+ this->value_state_= range_.Includes(new_val.value_) ? kValid : kInvalid;
+ return *this;
+}
+
+template<typename T, T minval, T maxval>
Integer<T, minval, maxval>& Integer<T, minval, maxval>::operator++() {
++value_;
return *this;
@@ -271,6 +278,18 @@ String<minlen, maxlen>& String<minlen, maxlen>::operator=(const std::string& new
}
template<size_t minlen, size_t maxlen>
+String<minlen, maxlen>& String<minlen, maxlen>::operator=(const String& new_val) {
+ value_.assign(new_val.value_);
+ value_state_ = new_val.value_state_;
+ return *this;
+}
+
+template<size_t minlen, size_t maxlen>
+bool String<minlen, maxlen>::operator==(const String& rhs) {
+ return value_ == rhs.value_;
+}
+
+template<size_t minlen, size_t maxlen>
String<minlen, maxlen>::operator const std::string&() const {
return value_;
}
diff --git a/src/components/rpc_base/include/rpc_base/rpc_base_json_inl.h b/src/components/rpc_base/include/rpc_base/rpc_base_json_inl.h
index a581092340..b5fd9a567a 100644
--- a/src/components/rpc_base/include/rpc_base/rpc_base_json_inl.h
+++ b/src/components/rpc_base/include/rpc_base/rpc_base_json_inl.h
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2014, Ford Motor Company
* All rights reserved.
*
@@ -139,6 +139,12 @@ Integer<T, minval, maxval>::Integer(const Json::Value* value)
}
template<typename T, T minval, T maxval>
+Integer<T, minval, maxval>::Integer(const Integer& val)
+ : PrimitiveType(range_.Includes(val.value_) ? kValid : kInvalid),
+ value_(val.value_) {
+}
+
+template<typename T, T minval, T maxval>
Integer<T, minval, maxval>::Integer(const Json::Value* value, IntType def_value)
: PrimitiveType(InitHelper(value, &Json::Value::isInt)),
value_(def_value) {
diff --git a/src/components/rpc_base/include/rpc_base/rpc_message.h b/src/components/rpc_base/include/rpc_base/rpc_message.h
index 48ef5ff391..18ace4552a 100644
--- a/src/components/rpc_base/include/rpc_base/rpc_message.h
+++ b/src/components/rpc_base/include/rpc_base/rpc_message.h
@@ -1,34 +1,34 @@
-/**
-* 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.
-*/
+/*
+ * 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.
+ */
#ifndef TYPE_BASE_H_
#define TYPE_BASE_H_
diff --git a/src/components/rpc_base/include/rpc_base/validation_report.h b/src/components/rpc_base/include/rpc_base/validation_report.h
index eeadb35ee4..b8a9c4d1cd 100644
--- a/src/components/rpc_base/include/rpc_base/validation_report.h
+++ b/src/components/rpc_base/include/rpc_base/validation_report.h
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2014, Ford Motor Company
* All rights reserved.
*
diff --git a/src/components/rpc_base/src/rpc_base/rpc_base.cc b/src/components/rpc_base/src/rpc_base/rpc_base.cc
index 88f0f53740..f2290780ed 100644
--- a/src/components/rpc_base/src/rpc_base/rpc_base.cc
+++ b/src/components/rpc_base/src/rpc_base/rpc_base.cc
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 2014, Ford Motor Company
* All rights reserved.
*
diff --git a/src/components/rpc_base/test/CMakeLists.txt b/src/components/rpc_base/test/CMakeLists.txt
new file mode 100644
index 0000000000..6513cb55b7
--- /dev/null
+++ b/src/components/rpc_base/test/CMakeLists.txt
@@ -0,0 +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.
+
+if(BUILD_TESTS)
+include_directories (
+ ${COMPONENTS_DIR}/dbus/include
+ ${COMPONENTS_DIR}/dbus/src
+ ${COMPONENTS_DIR}/rpc_base/include
+ ${CMAKE_SOURCE_DIR}/src/3rd_party/dbus-1.7.8
+ ${GMOCK_INCLUDE_DIRECTORY}
+ ${JSONCPP_INCLUDE_DIRECTORY}
+)
+
+set(LIBRARIES
+ gmock
+ jsoncpp
+)
+
+set(SOURCES
+ rpc_base_json_test.cc
+ rpc_base_test.cc
+ main.cc
+)
+
+if (${HMI_DBUS_API})
+ # Build dbus tests
+ include_directories(${DBUS_INCLUDE_DIRS})
+ set (LIBRARIES ${LIBRARIES} DBus)
+ set (SOURCES ${SOURCES} rpc_base_dbus_test.cc)
+endif ()
+
+create_test("rpc_base_test" "${SOURCES}" "${LIBRARIES}")
+
+endif()
+
diff --git a/src/components/rpc_base/test/main.cc b/src/components/rpc_base/test/main.cc
new file mode 100644
index 0000000000..59fa20e8b5
--- /dev/null
+++ b/src/components/rpc_base/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();
+}
+
diff --git a/src/components/rpc_base/test/rpc_base_dbus_test.cc b/src/components/rpc_base/test/rpc_base_dbus_test.cc
new file mode 100644
index 0000000000..e217eff476
--- /dev/null
+++ b/src/components/rpc_base/test/rpc_base_dbus_test.cc
@@ -0,0 +1,690 @@
+/* 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 "dbus/dbus_message.h"
+#include "rpc_base/rpc_base.h"
+#include "rpc_base/rpc_base_dbus_inl.h"
+
+namespace test {
+using namespace rpc;
+using namespace dbus;
+
+enum TestEnum {
+ kValue0,
+ kValue1,
+ kInvalidValue
+};
+
+bool IsValidEnum(TestEnum val) {
+ return val == kValue0 || val == kValue1;
+}
+
+bool EnumFromJsonString(const std::string& value, TestEnum* enm) {
+ if (value == "kValue0") {
+ *enm = kValue0;
+ return true;
+ } else if (value == "kValue1") {
+ *enm = kValue1;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+const char* EnumToJsonString(TestEnum enm) {
+ switch (enm) {
+ case kValue0:
+ return "kValue0";
+ case kValue1:
+ return "kValue1";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+struct DbusDeserialization : public testing::Test {
+ dbus::MessageRef msgref;
+ DbusDeserialization()
+ : msgref(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)) {
+ }
+};
+
+TEST_F(DbusDeserialization, DeserializeBool) {
+ {
+ dbus::MessageWriter writer(msgref);
+ writer.PutBool(true);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Boolean booln(&reader);
+ ASSERT_TRUE(booln);
+ }
+}
+
+TEST_F(DbusDeserialization, DeserializeByte) {
+ {
+ dbus::MessageWriter writer(msgref);
+ writer.PutByte(200);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Integer < uint8_t, 1, 220 > byte(&reader);
+ ASSERT_TRUE(byte.is_initialized());
+ ASSERT_TRUE(byte.is_valid());
+ ASSERT_EQ(byte, 200);
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, DeserializeInt64) {
+ {
+ dbus::MessageWriter writer(msgref);
+ writer.PutInt64(-1);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Integer < int64_t, -5, 220 > int64(&reader);
+ ASSERT_TRUE(int64.is_initialized());
+ ASSERT_TRUE(int64.is_valid());
+ ASSERT_EQ(int64, -1);
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, DeserializeFloat) {
+ {
+ dbus::MessageWriter writer(msgref);
+ writer.PutDouble(3.14);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Float < 3, 4 > pi(&reader);
+ ASSERT_TRUE(pi.is_initialized());
+ ASSERT_TRUE(pi.is_valid());
+ ASSERT_DOUBLE_EQ(pi, 3.14);
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, DeserializeString) {
+ {
+ dbus::MessageWriter writer(msgref);
+ writer.PutString("Hello");
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ String < 3, 10 > hello(&reader);
+ ASSERT_TRUE(hello.is_initialized());
+ ASSERT_TRUE(hello.is_valid());
+ ASSERT_EQ(std::string(hello), "Hello");
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, DeserializeEnum) {
+ {
+ dbus::MessageWriter writer(msgref);
+ writer.PutInt32(kValue1);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Enum<TestEnum> enm(&reader);
+ ASSERT_TRUE(enm.is_initialized());
+ ASSERT_TRUE(enm.is_valid());
+ ASSERT_EQ(enm, kValue1);
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, DeserializeArray) {
+ {
+ dbus::MessageWriter writer(msgref);
+ std::string array_signature;
+ rpc::DbusSignature<Integer<int32_t, 1, 50> >(&array_signature);
+ dbus::MessageWriter array_writer(&writer, dbus::kArray,
+ array_signature.c_str());
+ array_writer.PutInt32(5);
+ array_writer.PutInt32(33);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Array<Integer<int32_t, 1, 50>, 1, 100> array(&reader);
+ ASSERT_TRUE(array.is_initialized());
+ ASSERT_TRUE(array.is_valid());
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ ASSERT_EQ(array.size(), 2u);
+ ASSERT_EQ(array[0], 5);
+ ASSERT_EQ(array[1], 33);
+
+ }
+}
+
+TEST_F(DbusDeserialization, DeserializeArrayOfArrays) {
+ {
+ dbus::MessageWriter writer(msgref);
+ std::string array_signature;
+ rpc::DbusSignature<Array<Integer<int32_t, 1, 50>, 1, 5> >(&array_signature);
+ dbus::MessageWriter array_writer(&writer, dbus::kArray,
+ array_signature.c_str());
+ int val = 5;
+ for (int i = 0; i < 2; ++i) {
+ std::string subarray_signature;
+ rpc::DbusSignature<Integer<int32_t, 1, 50> >(&subarray_signature);
+ dbus::MessageWriter subarray_wirter(&array_writer, dbus::kArray,
+ subarray_signature.c_str());
+
+ subarray_wirter.PutInt32(val++);
+ subarray_wirter.PutInt32(val++);
+ }
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Array<Array<Integer<int32_t, 1, 50>, 1, 5>, 1, 5> array(&reader);
+ ASSERT_TRUE(array.is_initialized());
+ ASSERT_TRUE(array.is_valid());
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ ASSERT_EQ(array.size(), 2u);
+ ASSERT_EQ(array[0].size(), 2u);
+ ASSERT_EQ(array[1].size(), 2u);
+ ASSERT_EQ(array[0][0], 5);
+ ASSERT_EQ(array[0][1], 6);
+ ASSERT_EQ(array[1][0], 7);
+ ASSERT_EQ(array[1][1], 8);
+
+ }
+}
+
+TEST_F(DbusDeserialization, DeserializeMap) {
+ {
+ dbus::MessageWriter writer(msgref);
+ std::string dict_signature;
+ rpc::DbusSignature<Map<Enum<TestEnum>, 1, 5>::value_type>(&dict_signature);
+ dbus::MessageWriter array_writer(&writer, dbus::kArray,
+ dict_signature.c_str());
+ const char* keys[] = { "Hello", "World" };
+ int val = 0;
+ for (int i = 0; i < 2; ++i) {
+ dbus::MessageWriter dictval_wirter(&array_writer, dbus::kDictEntry, NULL);
+ dictval_wirter.PutString(keys[val]);
+ dictval_wirter.PutInt32(val++);
+ }
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Map<Enum<TestEnum>, 1, 5> amap(&reader);
+ ASSERT_TRUE(amap.is_initialized());
+ ASSERT_TRUE(amap.is_valid());
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ ASSERT_EQ(amap.size(), 2u);
+ ASSERT_EQ(amap["Hello"], kValue0);
+ ASSERT_EQ(amap["World"], kValue1);
+
+ }
+}
+
+TEST_F(DbusDeserialization, InconsistentTypesTest) {
+ {
+ dbus::MessageWriter writer(msgref);
+ writer.PutString("Hello");
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Boolean badbool(&reader);
+ ASSERT_TRUE(badbool.is_initialized());
+ ASSERT_FALSE(badbool.is_valid());
+ ASSERT_TRUE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, DeserializeOptionalString) {
+ {
+ dbus::MessageWriter writer(msgref);
+ dbus::MessageWriter optwriter(&writer, dbus::kStruct, NULL);
+ optwriter.PutBool(true);
+ optwriter.PutString("Hello dear");
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Optional < String<1, 100> > readback(&reader);
+ ASSERT_TRUE(readback.is_initialized());
+ ASSERT_TRUE(readback.is_valid());
+ ASSERT_EQ(std::string(*readback), "Hello dear");
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, DeserializeOptionalInt) {
+ {
+ dbus::MessageWriter writer(msgref);
+ dbus::MessageWriter optwriter(&writer, dbus::kStruct, NULL);
+ optwriter.PutBool(false);
+ optwriter.PutInt32(42);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Optional < Integer<int32_t, 1, 90>> readback(&reader);
+ ASSERT_FALSE(readback.is_initialized());
+ ASSERT_TRUE(readback.is_valid());
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+
+ }
+}
+
+
+TEST_F(DbusDeserialization, SerializeDeserializeBool) {
+ {
+ Boolean true_bool(true);
+ dbus::MessageWriter writer(msgref);
+ true_bool.ToDbusWriter(&writer);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Boolean readback(&reader);
+ ASSERT_TRUE(readback.is_initialized());
+ ASSERT_TRUE(readback.is_valid());
+ ASSERT_EQ(readback, true);
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, SerializeDeserializeInt8t) {
+ {
+ Integer < int8_t, 1, 100 > int8(42);
+ dbus::MessageWriter writer(msgref);
+ int8.ToDbusWriter(&writer);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Integer < int8_t, 1, 100 > readback(&reader);
+ ASSERT_TRUE(readback.is_initialized());
+ ASSERT_TRUE(readback.is_valid());
+ ASSERT_EQ(readback, 42);
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, BadSerializeDeserializeInt8t) {
+ {
+ Integer < int8_t, 1, 12 > int8(42);
+ dbus::MessageWriter writer(msgref);
+ int8.ToDbusWriter(&writer);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Integer < int8_t, 1, 12 > readback(&reader);
+ ASSERT_TRUE(readback.is_initialized());
+ ASSERT_FALSE(readback.is_valid());
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, SerializeDeserializeInt64t) {
+ {
+ Integer < int64_t, 1, 0xFFFFFFFFFF > int64(0xFFFFFFFFF1);
+ dbus::MessageWriter writer(msgref);
+ int64.ToDbusWriter(&writer);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Integer < int64_t, 1, 0xFFFFFFFFFF > readback(&reader);
+ ASSERT_TRUE(readback.is_initialized());
+ ASSERT_TRUE(readback.is_valid());
+ ASSERT_EQ(readback, 0xFFFFFFFFF1);
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+
+TEST_F(DbusDeserialization, SerializeDeserializeDouble) {
+ {
+ Float < 1, 5 > flt(3.14);
+ dbus::MessageWriter writer(msgref);
+ flt.ToDbusWriter(&writer);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Float < 1, 5 > readback(&reader);
+ ASSERT_TRUE(readback.is_initialized());
+ ASSERT_TRUE(readback.is_valid());
+ ASSERT_DOUBLE_EQ(readback, 3.14);
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, SerializeDeserializeString) {
+ {
+ String < 1, 12 > hello("Hello");
+ dbus::MessageWriter writer(msgref);
+ hello.ToDbusWriter(&writer);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ String < 1, 12 > readback(&reader);
+ ASSERT_TRUE(readback.is_initialized());
+ ASSERT_TRUE(readback.is_valid());
+ ASSERT_EQ(std::string(readback), "Hello");
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, SerializeDeserializeEnum) {
+ {
+ Enum<TestEnum> te(kValue1);
+ dbus::MessageWriter writer(msgref);
+ te.ToDbusWriter(&writer);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Enum<TestEnum> readback(&reader);
+ ASSERT_TRUE(readback.is_initialized());
+ ASSERT_TRUE(readback.is_valid());
+ ASSERT_EQ(readback, kValue1);
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, SerializeDeserializeArray) {
+ {
+ Array<Integer<int32_t, 1, 100>, 1, 90> ints;
+ ints.push_back(42);
+ ints.push_back(17);
+ dbus::MessageWriter writer(msgref);
+ ints.ToDbusWriter(&writer);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Array<Integer<int32_t, 1, 100>, 1, 90> readback(&reader);
+ ASSERT_TRUE(readback.is_initialized());
+ ASSERT_TRUE(readback.is_valid());
+ ASSERT_EQ(readback[0], 42);
+ ASSERT_EQ(readback[1], 17);
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, SerializeDeserializeMap) {
+ {
+ Map<Integer<int32_t, 1, 100>, 1, 90> ints;
+ ints["first"] = 42;
+ ints["second"] = 17;
+ dbus::MessageWriter writer(msgref);
+ ints.ToDbusWriter(&writer);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Map<Integer<int32_t, 1, 100>, 1, 90> readback(&reader);
+ ASSERT_TRUE(readback.is_initialized());
+ ASSERT_TRUE(readback.is_valid());
+ ASSERT_EQ(readback["first"], 42);
+ ASSERT_EQ(readback["second"], 17);
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusDeserialization, SerializeDeserializeMapOfArrays) {
+ {
+ Map<Array<Integer<int32_t, 1, 100>, 1, 5>, 1, 90> ints;
+ ints["first"].push_back(1);
+ ints["first"].push_back(42);
+ ints["second"].push_back(17);
+ ints["second"].push_back(3);
+ dbus::MessageWriter writer(msgref);
+ ints.ToDbusWriter(&writer);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ Map<Array<Integer<int32_t, 1, 100>, 1, 5>, 1, 90> readback(&reader);
+ ASSERT_TRUE(readback.is_initialized());
+ ASSERT_TRUE(readback.is_valid());
+ ASSERT_EQ(readback.size(), 2u);
+ ASSERT_EQ(readback["first"].size(), 2u);
+ ASSERT_EQ(readback["second"].size(), 2u);
+ ASSERT_EQ(readback["first"][0], 1);
+ ASSERT_EQ(readback["first"][1], 42);
+ ASSERT_EQ(readback["second"][0], 17);
+ ASSERT_EQ(readback["second"][1], 3);
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST(ValidatedTypes, TestBooleanDbusSignature) {
+ std::string sign;
+ DbusSignature<Boolean>(&sign);
+ ASSERT_EQ(sign, "b");
+}
+
+TEST(ValidatedTypes, TestIntDbusSignature) {
+ std::string sign;
+ DbusSignature<Integer<int32_t, 1, 2> >(&sign);
+ ASSERT_EQ(sign, "i");
+}
+
+TEST(ValidatedTypes, TestFloatDbusSignature) {
+ std::string sign;
+ DbusSignature<Float<1, 2> >(&sign);
+ ASSERT_EQ(sign, "d");
+}
+
+TEST(ValidatedTypes, TestStringDbusSignature) {
+ std::string sign;
+ DbusSignature<String<1, 2> >(&sign);
+ ASSERT_EQ(sign, "s");
+}
+
+TEST(ValidatedTypes, TestEnumDbusSignature) {
+ std::string sign;
+ DbusSignature<Enum<TestEnum> >(&sign);
+ ASSERT_EQ(sign, "i");
+}
+
+TEST(ValidatedTypes, TestIntArrayDbusSignature) {
+ std::string sign;
+ DbusSignature<Array<Integer<int32_t, 1, 2>, 1, 3> >(&sign);
+ ASSERT_EQ(sign, "ai");
+}
+
+TEST(ValidatedTypes, TestIntArrayArrayDbusSignature) {
+ std::string sign;
+ DbusSignature<Array<Array<Integer<int32_t, 1, 2>, 1, 3>, 4, 5> >(&sign);
+ ASSERT_EQ(sign, "aai");
+}
+
+TEST(ValidatedTypes, TestMapDbusSignature) {
+ std::string sign;
+ DbusSignature<Map<Integer<int32_t, 1, 2>, 3, 4> >(&sign);
+ ASSERT_EQ(sign, "a{si}");
+}
+
+TEST(ValidatedTypes, TestMandatoryEnumDbusSignature) {
+ std::string sign;
+ DbusSignature<Enum<TestEnum> >(&sign);
+ ASSERT_EQ(sign, "i");
+}
+
+TEST(ValidatedTypes, TestOptionalEnumDbusSignature) {
+ std::string sign;
+ DbusSignature<Optional<Enum<TestEnum> > >(&sign);
+ ASSERT_EQ(sign, "(bi)");
+}
+
+TEST(ValidatedTypes, TestOptionalFloatArrayDbusSignature) {
+ std::string sign;
+ DbusSignature<Optional<Array<Float<1, 2>, 3, 4> > >(&sign);
+ ASSERT_EQ(sign, "(bad)");
+}
+
+TEST(DbusMessageConstructionTest, DbusMessageConstruction) {
+ DBusMessage* rawmsg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
+ dbus::MessageRef msgref(rawmsg);
+}
+
+class DbusTest : public testing::Test {
+ public:
+ dbus::MessageRef msgref;
+ DbusTest()
+ : msgref(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)) {
+ }
+};
+
+TEST_F(DbusTest, DbusWriterConstructionTest) {
+ dbus::MessageWriter writer(msgref);
+}
+
+TEST_F(DbusTest, DbusEmptyMessageReaderTest) {
+ dbus::MessageReader reader(msgref);
+ ASSERT_TRUE(reader.has_failed());
+}
+
+TEST_F(DbusTest, DbusMessageWriterBoolWriteRead) {
+ dbus::MessageWriter writer(msgref);
+ writer.PutBool(true);
+ dbus::MessageReader reader(msgref);
+ bool redback_value = reader.TakeBool();
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_TRUE(redback_value);
+}
+
+TEST_F(DbusTest, DbusMessageWriterInt32WriteRead) {
+ dbus::MessageWriter writer(msgref);
+ writer.PutInt32(42);
+ dbus::MessageReader reader(msgref);
+ int32_t readback_value = reader.TakeInt32();
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_EQ(readback_value, 42);
+}
+
+TEST_F(DbusTest, DbusMessageWriterStringWriteRead) {
+ dbus::MessageWriter writer(msgref);
+ writer.PutString("Hello DBus!");
+ dbus::MessageReader reader(msgref);
+ std::string readback_value = reader.TakeString();
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_EQ(readback_value, "Hello DBus!");
+}
+
+TEST_F(DbusTest, DbusMultipleParamsReadWrite) {
+ {
+ dbus::MessageWriter writer(msgref);
+ writer.PutString("Hello DBus!");
+ writer.PutInt16(42);
+ writer.PutDouble(3.14);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ std::string readback_string = reader.TakeString();
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_EQ(readback_string, "Hello DBus!");
+ int16_t readback_int = reader.TakeInt16();
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_EQ(readback_int, 42);
+ double readback_double = reader.TakeDouble();
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_DOUBLE_EQ(readback_double, 3.14);
+ ASSERT_FALSE(reader.HasNext());
+ }
+}
+
+TEST_F(DbusTest, DbusArrayTest) {
+ {
+ dbus::MessageWriter writer(msgref);
+ dbus::MessageWriter array_writer(&writer, dbus::kArray,
+ DBUS_TYPE_INT16_AS_STRING);
+ array_writer.PutInt16(3);
+ array_writer.PutInt16(4);
+ array_writer.PutInt16(5);
+ }
+ {
+ dbus::MessageReader reader(msgref);
+ dbus::MessageReader array_reader = reader.TakeArrayReader();
+ int16_t readback_val = array_reader.TakeInt16();
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_EQ(readback_val, 3);
+ readback_val = array_reader.TakeInt16();
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_EQ(readback_val, 4);
+ readback_val = array_reader.TakeInt16();
+ ASSERT_FALSE(reader.has_failed());
+ ASSERT_EQ(readback_val, 5);
+ ASSERT_FALSE(array_reader.HasNext());
+ }
+}
+
+class DbusFailuresTest : public testing::Test {
+ public:
+ dbus::MessageRef int_msg;
+ DbusFailuresTest()
+ : int_msg(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)) {
+ dbus::MessageWriter writer(int_msg);
+ writer.PutInt64(42);
+ }
+};
+
+TEST_F(DbusFailuresTest, DbusInconsistentTypeReadFailureTest) {
+ dbus::MessageReader reader(int_msg);
+ std::string str = reader.TakeString();
+ ASSERT_EQ(str, std::string(""));
+ ASSERT_TRUE(reader.has_failed());
+}
+
+TEST_F(DbusFailuresTest, DbusNonExistentArrayReadTest) {
+ dbus::MessageReader reader(int_msg);
+ ASSERT_FALSE(reader.has_failed());
+ dbus::MessageReader array_reader = reader.TakeArrayReader();
+ ASSERT_TRUE(array_reader.has_failed());
+ ASSERT_TRUE(reader.has_failed());
+ int64_t val = array_reader.TakeInt64();
+ ASSERT_TRUE(array_reader.has_failed());
+ ASSERT_EQ(val, 0);
+}
+
+} // namespace test
diff --git a/src/components/rpc_base/test/rpc_base_json_test.cc b/src/components/rpc_base/test/rpc_base_json_test.cc
new file mode 100644
index 0000000000..8c0bef930e
--- /dev/null
+++ b/src/components/rpc_base/test/rpc_base_json_test.cc
@@ -0,0 +1,377 @@
+/**
+ * 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 "json/value.h"
+#include "rpc_base/rpc_base.h"
+
+namespace test {
+using namespace rpc;
+using Json::Value;
+
+namespace {
+enum TestEnum {
+ kValue0,
+ kValue1,
+ kInvalidValue
+};
+
+bool IsValidEnum(TestEnum val) {
+ return val == kValue0 || val == kValue1;
+}
+
+bool EnumFromJsonString(const std::string& value, TestEnum* enm) {
+ if (value == "kValue0") {
+ *enm = kValue0;
+ return true;
+ } else if (value == "kValue1") {
+ *enm = kValue1;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+const char* EnumToJsonString(TestEnum enm) {
+ switch(enm) {
+ case kValue0: return "kValue0";
+ case kValue1: return "kValue1";
+ default: return "UNKNOWN";
+ }
+}
+
+} // namespace
+
+TEST(ValidatedTypesJson, BooleanFromJsonTest) {
+ Value val(true);
+ Boolean boolean(&val);
+ ASSERT_TRUE(boolean.is_initialized());
+ ASSERT_TRUE(boolean.is_valid());
+ ASSERT_EQ(boolean, true);
+ Value readback = boolean.ToJsonValue();
+ ASSERT_TRUE(readback.isBool());
+ ASSERT_EQ(readback.asBool(), true);
+}
+
+TEST(ValidatedTypesJson, BooleanNullTest) {
+ Boolean boolean(&Value::null);
+ ASSERT_TRUE(boolean.is_initialized());
+ ASSERT_FALSE(boolean.is_valid());
+}
+
+TEST(ValidatedTypesJson, BooleanAbsentValueTest) {
+ Value* novalue = NULL;
+ Boolean boolean(novalue);
+ ASSERT_FALSE(boolean.is_initialized());
+ ASSERT_FALSE(boolean.is_valid());
+}
+
+TEST(ValidatedTypesJson, BooleanFromInvalidJsonTest) {
+ Value inv(7);
+ Boolean boolean(&inv);
+ ASSERT_TRUE(boolean.is_initialized());
+ ASSERT_FALSE(boolean.is_valid());
+}
+
+TEST(ValidatedTypesJson, IntegerFromJsonTest) {
+ Value int_val(42);
+ Integer<int32_t, -5, 192> integer(&int_val);
+ ASSERT_TRUE(integer.is_initialized());
+ ASSERT_TRUE(integer.is_valid());
+ Value readback = integer.ToJsonValue();
+ ASSERT_TRUE(readback.isInt());
+ ASSERT_EQ(readback.asInt(), 42);
+}
+
+TEST(ValidatedTypesJson, IntegerNullTest) {
+ Integer<int32_t, -5, 192> integer(&Value::null);
+ ASSERT_TRUE(integer.is_initialized());
+ ASSERT_FALSE(integer.is_valid());
+}
+
+TEST(ValidatedTypesJson, IntegerAbsentValueTest) {
+ Value* novalue = NULL;
+ Integer<int32_t, -5, 192> integer(novalue);
+ ASSERT_FALSE(integer.is_initialized());
+ ASSERT_FALSE(integer.is_valid());
+}
+
+TEST(ValidatedTypesJson, IntegerFromOverflowingJsonTest) {
+ Value int_val(0xFFFFFFFFFFll);
+ Integer<int32_t, -5, 192> integer(&int_val);
+ ASSERT_TRUE(integer.is_initialized());
+ ASSERT_FALSE(integer.is_valid());
+}
+
+TEST(ValidatedTypesJson, IntegerFromInvalidJsonTest) {
+ Value str_val("Hello");
+ Integer<int8_t, -3, 15> integer(&str_val);
+ ASSERT_TRUE(integer.is_initialized());
+ ASSERT_FALSE(integer.is_valid());
+}
+
+TEST(ValidatedTypesJson, IntegerFromOutOfRangeValueTest) {
+ Value big_int_val(500);
+ Integer<int8_t, 0, 100> integer(&big_int_val);
+ ASSERT_TRUE(integer.is_initialized());
+ ASSERT_FALSE(integer.is_valid());
+}
+
+TEST(ValidatedTypesJson, FloatFromJsonTest) {
+ Value float_value(4.2);
+ Float<1, 7> flt(&float_value);
+ ASSERT_TRUE(flt.is_initialized());
+ ASSERT_TRUE(flt.is_valid());
+ Value readback = flt.ToJsonValue();
+ ASSERT_TRUE(readback.isDouble());
+ ASSERT_EQ(readback.asDouble(), 4.2);
+}
+
+TEST(ValidatedTypesJson, FloatNullTest) {
+ Float<1, 7> flt(&Value::null);
+ ASSERT_TRUE(flt.is_initialized());
+ ASSERT_FALSE(flt.is_valid());
+}
+
+TEST(ValidatedTypesJson, FloatAbsentValueTest) {
+ Value* novalue = NULL;
+ Float<1, 7> flt(novalue);
+ ASSERT_FALSE(flt.is_initialized());
+ ASSERT_FALSE(flt.is_valid());
+}
+
+TEST(ValidatedTypesJson, FloatFromInvalidJsonTest) {
+ Value str_val("Hello");
+ Float<-5, 3> flt(&str_val);
+ ASSERT_TRUE(flt.is_initialized());
+ ASSERT_FALSE(flt.is_valid());
+}
+
+TEST(ValidatedTypesJson, StringFromJsonTest) {
+ Value str_val("Hello");
+ String<1, 42> str(&str_val);
+ ASSERT_TRUE(str.is_initialized());
+ ASSERT_TRUE(str.is_valid());
+ Value readback = str.ToJsonValue();
+ ASSERT_TRUE(readback.isString());
+ ASSERT_STREQ(readback.asCString(), "Hello");
+}
+
+TEST(ValidatedTypesJson, StringNullTest) {
+ String<1, 42> str(&Value::null);
+ ASSERT_TRUE(str.is_initialized());
+ ASSERT_FALSE(str.is_valid());
+}
+
+TEST(ValidatedTypesJson, StringFromInvalidJsonTest) {
+ Value int_val(42);
+ String<1, 500> str(&int_val);
+ ASSERT_TRUE(str.is_initialized());
+ ASSERT_FALSE(str.is_valid());
+}
+
+TEST(ValidatedTypesJson, StringAbsentValueTest) {
+ Value* novalue = NULL;
+ String<1, 500> str(novalue);
+ ASSERT_FALSE(str.is_initialized());
+ ASSERT_FALSE(str.is_valid());
+}
+
+TEST(ValidatedTypesJson, StringFromToLongJsonString) {
+ Value str_val("Too long string");
+ String<1, 5> str(&str_val);
+ ASSERT_TRUE(str.is_initialized());
+ ASSERT_FALSE(str.is_valid());
+}
+
+TEST(ValidatedTypesJson, EnumFromJsonTest) {
+ Value str_enum("kValue1");
+ Enum<TestEnum> enm(&str_enum);
+ ASSERT_TRUE(enm.is_initialized());
+ ASSERT_TRUE(enm.is_valid());
+ Value readback = enm.ToJsonValue();
+ ASSERT_TRUE(readback.isString());
+ ASSERT_STREQ(readback.asCString(), "kValue1");
+}
+
+TEST(ValidatedTypesJson, EnumNullTest) {
+ Enum<TestEnum> enm(&Value::null);
+ ASSERT_TRUE(enm.is_initialized());
+ ASSERT_FALSE(enm.is_valid());
+}
+
+TEST(ValidatedTypesJson, EnumAbsentValueTest) {
+ Value* novalue = NULL;
+ Enum<TestEnum> enm(novalue);
+ ASSERT_FALSE(enm.is_initialized());
+ ASSERT_FALSE(enm.is_valid());
+}
+
+TEST(ValidatedTypesJson, EnumFromInvalidJsonTest) {
+ Value str_value("Random string");
+ Enum<TestEnum> enm(&str_value);
+ ASSERT_TRUE(enm.is_initialized());
+ ASSERT_FALSE(enm.is_valid());
+}
+
+TEST(ValidatedTypesJson, ArrayFromJsonTest) {
+ Value array_value;
+ array_value.append(Value("haha"));
+ array_value.append(Value("hoho"));
+ Array<String<1, 32>, 2, 5> arr(&array_value);
+ ASSERT_TRUE(arr.is_initialized());
+ ASSERT_TRUE(arr.is_valid());
+ Value readback = arr.ToJsonValue();
+ ASSERT_TRUE(readback.isArray());
+ ASSERT_EQ(readback.size(), array_value.size());
+}
+
+TEST(ValidatedTypesJson, MandatoryArrayNullTest) {
+ Array<String<1, 32>, 2, 5> arr(&Value::null);
+ ASSERT_TRUE(arr.is_initialized());
+ ASSERT_FALSE(arr.is_valid());
+}
+
+TEST(ValidatedTypesJson, ArrayAbsentValueTest) {
+ Value* novalue = NULL;
+ Array<String<1, 32>, 2, 5> arr(novalue);
+ ASSERT_FALSE(arr.is_initialized());
+ ASSERT_FALSE(arr.is_valid());
+}
+
+TEST(ValidatedTypesJson, MandatoryMapNullTest) {
+ Map<String<1, 32>, 2, 5> map(&Value::null);
+ ASSERT_TRUE(map.is_initialized());
+ ASSERT_FALSE(map.is_valid());
+}
+
+TEST(ValidatedTypesJson, OptionalMapAbsentValueTest) {
+ Value* novalue = NULL;
+ Optional< Map<String<1, 32>, 0, 5> > map(novalue);
+ ASSERT_FALSE(map.is_initialized());
+ ASSERT_TRUE(map.is_valid());
+}
+
+TEST(ValidatedTypesJson, ArrayJsonTest) {
+ Value array_value;
+ array_value.append(Value("Hello"));
+ array_value.append(Value("World"));
+ Array<Integer<int8_t, 0, 32>, 2, 4> int_array(&array_value);
+ ASSERT_TRUE(int_array.is_initialized());
+ ASSERT_TRUE(int_array.is_valid());
+ ASSERT_EQ(int_array.size(), array_value.size());
+}
+
+TEST(ValidatedTypesJson, ArrayFromNonArrayJsonTest) {
+ Value array_value = "Hello";
+ Array<Integer<int8_t, 0, 32>, 0, 4> int_array(&array_value);
+ ASSERT_TRUE(int_array.is_initialized());
+ ASSERT_FALSE(int_array.is_valid());
+ ASSERT_TRUE(int_array.empty());
+}
+
+TEST(ValidatedTypesJson, MapFromNonArrayJsonTest) {
+ Value array_value = "Hello";
+ Map<Integer<int8_t, 0, 32>, 0, 4> int_map(&array_value);
+ ASSERT_TRUE(int_map.is_initialized());
+ ASSERT_FALSE(int_map.is_valid());
+ ASSERT_TRUE(int_map.empty());
+}
+
+TEST(ValidatedTypesJson, OptionalBoolFromJsonTest) {
+ Value bool_value(true);
+ Optional< Boolean > optional_bool;
+ *optional_bool = Boolean(&bool_value);
+ ASSERT_TRUE(optional_bool.is_initialized());
+ ASSERT_TRUE(optional_bool.is_valid());
+ Value readback = optional_bool->ToJsonValue();
+ ASSERT_TRUE(readback.isBool());
+ ASSERT_EQ(readback.asBool(), true);
+}
+
+TEST(ValidatedTypesJson, OptionalBoolFromAbsentValueTest) {
+ Value* none = NULL;
+ Optional< Boolean > optional_bool;
+ *optional_bool = Boolean(none);
+ ASSERT_FALSE(optional_bool.is_initialized());
+ // It is ok for Optional value to be absent
+ ASSERT_TRUE(optional_bool.is_valid());
+}
+
+TEST(ValidatedTypesJson, OptionalBoolFromNullValueTest) {
+ Optional< Boolean > optional_bool;
+ *optional_bool = Boolean(&Value::null);
+ ASSERT_TRUE(optional_bool.is_initialized());
+ // Optional values should not be absent
+ ASSERT_FALSE(optional_bool.is_valid());
+}
+
+TEST(ValidatedTypesJson, NullableIntFromNullValueTest) {
+ Nullable< Integer<int8_t, 1, 15> > nullable_int(&Value::null);
+ ASSERT_TRUE(nullable_int.is_initialized());
+ ASSERT_TRUE(nullable_int.is_valid());
+ ASSERT_TRUE(nullable_int.is_null());
+}
+
+TEST(ValidatedTypesJson, NullableIntFromNonNullValueTest) {
+ Value json(3);
+ Nullable< Integer<int8_t, 1, 15> > nullable_int(&json);
+ ASSERT_TRUE(nullable_int.is_initialized());
+ ASSERT_TRUE(nullable_int.is_valid());
+ ASSERT_FALSE(nullable_int.is_null());
+ ASSERT_EQ(3, nullable_int);
+}
+
+TEST(ValidatedTypesJson, NullableIntFromAbsentValueTest) {
+ Value* noval = NULL;
+ Nullable< Integer<int8_t, 1, 15> > nullable_int(noval);
+ ASSERT_FALSE(nullable_int.is_initialized());
+ ASSERT_FALSE(nullable_int.is_valid());
+ ASSERT_FALSE(nullable_int.is_null());
+}
+
+TEST(ValidatedTypesJson, OptionalIntFromJsonTest) {
+ Value int_value(42);
+ Optional< Integer<int64_t, 42, 43> > optional_int;
+ *optional_int = Integer<int64_t, 42, 43> (&int_value);
+ ASSERT_TRUE(optional_int.is_initialized());
+ ASSERT_TRUE(optional_int.is_valid());
+ Value readback = optional_int->ToJsonValue();
+ ASSERT_TRUE(readback.isInt());
+ ASSERT_EQ(readback.asInt(), 42);
+}
+
+
+} // namespace test
+
+
+
diff --git a/src/components/rpc_base/test/rpc_base_test.cc b/src/components/rpc_base/test/rpc_base_test.cc
new file mode 100644
index 0000000000..553dacb85d
--- /dev/null
+++ b/src/components/rpc_base/test/rpc_base_test.cc
@@ -0,0 +1,437 @@
+/**
+ * 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 "json/writer.h"
+#include "rpc_base/gtest_support.h"
+#include "rpc_base/rpc_base.h"
+
+namespace test {
+using namespace rpc;
+
+namespace {
+
+enum TestEnum {
+ kValue0,
+ kValue1,
+ kInvalidValue
+};
+
+bool IsValidEnum(TestEnum val) {
+ return val == kValue0 || val == kValue1;
+}
+
+} // namespace
+
+TEST(ValidatedTypes, TestBooleanDefaultConstructor) {
+ Boolean boolean;
+ ASSERT_FALSE(boolean.is_valid());
+ ASSERT_FALSE(boolean.is_initialized());
+ boolean = true;
+ bool val = boolean;
+ ASSERT_TRUE(val);
+ ASSERT_TRUE(boolean.is_initialized());
+}
+
+TEST(ValidatedTypes, TestBooleanInitializingConstructor) {
+ Boolean true_boolean(true);
+ ASSERT_RPCTYPE_VALID(true_boolean);
+ ASSERT_TRUE(true_boolean.is_initialized());
+ ASSERT_EQ(true_boolean, true);
+
+ Boolean false_boolean(false);
+ ASSERT_RPCTYPE_VALID(false_boolean);
+ ASSERT_TRUE(false_boolean.is_initialized());
+ ASSERT_EQ(false_boolean, false);
+}
+
+TEST(ValidatedTypes, TestIntegerDefaultConstructor) {
+ Integer<int32_t, 4, 100> integer;
+ ASSERT_FALSE(integer.is_valid());
+ ASSERT_FALSE(integer.is_initialized());
+ ASSERT_EQ(integer, 4);
+ integer = 5;
+ ASSERT_RPCTYPE_VALID(integer);
+ ASSERT_TRUE(integer.is_initialized());
+ ASSERT_EQ(integer, 5);
+ integer = 700;
+ ASSERT_FALSE(integer.is_valid());
+ ASSERT_TRUE(integer.is_initialized());
+ ASSERT_EQ(integer, 700);
+}
+
+TEST(ValidatedTypes, TestIntegerInitializingConstructor) {
+ Integer<int32_t, 0, 100> invalid_integer(200);
+ ASSERT_FALSE(invalid_integer.is_valid());
+ ASSERT_TRUE(invalid_integer.is_initialized());
+ ASSERT_EQ(invalid_integer, 200);
+
+ Integer<int32_t, 0, 100> valid_integer(42);
+ ASSERT_RPCTYPE_VALID(valid_integer);
+ ASSERT_TRUE(valid_integer.is_initialized());
+ ASSERT_EQ(valid_integer, 42);
+}
+
+TEST(ValidatedTypes, TestFloatDefaultConstructor) {
+ Float<-5, 12> flt;
+ ASSERT_FALSE(flt.is_initialized());
+ ASSERT_FALSE(flt.is_valid());
+ ASSERT_EQ(flt, -5.);
+
+ flt = 12.3;
+ ASSERT_TRUE(flt.is_initialized());
+ ASSERT_FALSE(flt.is_valid());
+ ASSERT_EQ(flt, 12.3);
+}
+
+TEST(ValidatedTypes, TestFloatInitializingConstructor) {
+ Float<13, 999, 10, 10> flt(4);
+ ASSERT_TRUE(flt.is_initialized());
+ ASSERT_RPCTYPE_VALID(flt);
+ ASSERT_EQ(flt, 4.);
+
+ flt = 1.2;
+ ASSERT_FALSE(flt.is_valid());
+ ASSERT_EQ(flt, 1.2);
+}
+
+TEST(ValidatedTypes, TestStringDefaultConstructor) {
+ String<1, 6> str;
+ ASSERT_FALSE(str.is_initialized());
+ ASSERT_FALSE(str.is_valid());
+ std::string val = str;
+ ASSERT_EQ(val, "");
+ str = "Test";
+ ASSERT_TRUE(str.is_initialized());
+ ASSERT_RPCTYPE_VALID(str);
+ val = str;
+ ASSERT_EQ(val, "Test");
+ str = "Long string";
+ ASSERT_TRUE(str.is_initialized());
+ ASSERT_FALSE(str.is_valid());
+ val = str;
+ ASSERT_EQ(val, "Long string");
+}
+
+TEST(ValidatedTypes, TestStringLengthRange) {
+ String<4, 10> str;
+ ASSERT_FALSE(str.is_initialized());
+ ASSERT_FALSE(str.is_valid());
+ str = "Hello";
+ ASSERT_TRUE(str.is_initialized());
+ ASSERT_RPCTYPE_VALID(str);
+ str = "Sh";
+ ASSERT_TRUE(str.is_initialized());
+ ASSERT_FALSE(str.is_valid());
+}
+
+TEST(ValidatedTypes, TestStringInitializingConstructor) {
+ String<1, 4> invalid_str("A string");
+ ASSERT_TRUE(invalid_str.is_initialized());
+ ASSERT_FALSE(invalid_str.is_valid());
+}
+
+TEST(ValidatedTypes, TestStringAssignment) {
+ String<1, 5> short_str("Short");
+ String<1, 10> long_str("A long string");
+ short_str = long_str;
+ ASSERT_TRUE(short_str.is_initialized());
+ ASSERT_FALSE(short_str.is_valid());
+}
+
+TEST(ValidatedTypes, TestArray) {
+ Array<String<1, 5>, 2, 10> arr;
+ ASSERT_FALSE(arr.is_initialized());
+ ASSERT_FALSE(arr.is_valid());
+ arr.push_back("Text");
+ arr.push_back("Dext");
+ ASSERT_RPCTYPE_VALID(arr);
+ ASSERT_TRUE(arr.is_initialized());
+ arr.push_back("Too long");
+ ASSERT_FALSE(arr.is_valid());
+}
+
+TEST(ValidatedTypes, TestArrayInitializingConstructor) {
+ std::vector<std::string> strings;
+ strings.push_back("One");
+ strings.push_back("Two");
+ Array<String<1, 5>, 2, 10> arr(strings);
+ ASSERT_TRUE(arr.is_initialized());
+ ASSERT_RPCTYPE_VALID(arr);
+}
+
+TEST(ValidatedTypes, TestOptionalEmptyArray) {
+ Optional< Array<Integer<int8_t, 0, 10>, 0, 5> > ai;
+ ASSERT_RPCTYPE_VALID(ai);
+ ASSERT_FALSE(ai.is_initialized());
+ Json::FastWriter fw;
+ std::string serialized = fw.write(ai.ToJsonValue());
+ ASSERT_EQ(serialized, "[]\n");
+}
+
+TEST(ValidatedTypes, TestMandatoryEmptyArray) {
+ Array<Integer<int8_t, 0, 10>, 0, 5> ai;
+ ASSERT_FALSE(ai.is_valid());
+ ASSERT_FALSE(ai.is_initialized());
+ Json::FastWriter fw;
+ std::string serialized = fw.write(ai.ToJsonValue());
+ ASSERT_EQ(serialized, "[]\n");
+}
+
+TEST(ValidatedTypes, TestMap) {
+ Map<String<1, 6>, 2, 10> map;
+ ASSERT_FALSE(map.is_initialized());
+ ASSERT_FALSE(map.is_valid());
+ map["a"] = "Hello";
+ map["b"] = "World";
+ ASSERT_TRUE(map.is_initialized());
+ ASSERT_RPCTYPE_VALID(map);
+ map["c"] = "Too long";
+ ASSERT_FALSE(map.is_valid());
+}
+
+TEST(ValidatedTypes, TestMapInitializingConstructor) {
+ std::map< std::string, std::string > init_map;
+ init_map["a"] = "Hello";
+ init_map["b"] = "World";
+ Map<String<1, 6>, 2, 10 > map(init_map);
+ ASSERT_TRUE(map.is_initialized());
+ ASSERT_RPCTYPE_VALID(map);
+}
+
+TEST(ValidatedTypes, TestEmptyMandatoryMap) {
+ Map<Integer<int8_t, 0, 10>, 0, 5> im;
+ ASSERT_FALSE(im.is_valid());
+ ASSERT_FALSE(im.is_initialized());
+ Json::FastWriter fw;
+ std::string serialized = fw.write(im.ToJsonValue());
+ ASSERT_EQ(serialized, "{}\n");
+}
+
+TEST(ValidatedTypes, TestEnumConstructor) {
+ Enum<TestEnum> te;
+ ASSERT_FALSE(te.is_initialized());
+ ASSERT_FALSE(te.is_valid());
+ te = kValue1;
+ ASSERT_TRUE(te.is_initialized());
+ ASSERT_RPCTYPE_VALID(te);
+ ASSERT_EQ(te, kValue1);
+ te = TestEnum(42);
+ ASSERT_TRUE(te.is_initialized());
+ ASSERT_FALSE(te.is_valid());
+}
+
+TEST(ValidatedTypes, TestNullableConstructor) {
+ Nullable< Integer<int8_t, 2, 10> >nullable_int;
+ ASSERT_FALSE(nullable_int.is_initialized());
+ ASSERT_FALSE(nullable_int.is_null());
+ ASSERT_FALSE(nullable_int.is_valid());
+ nullable_int = 5;
+ ASSERT_TRUE(nullable_int.is_initialized());
+ ASSERT_FALSE(nullable_int.is_null());
+ ASSERT_RPCTYPE_VALID(nullable_int);
+ nullable_int.set_to_null();
+ ASSERT_TRUE(nullable_int.is_initialized());
+ ASSERT_TRUE(nullable_int.is_null());
+ ASSERT_RPCTYPE_VALID(nullable_int);
+}
+
+TEST(ValidatedTypes, TestOptionalNullableConstructor) {
+ Optional< Nullable< Integer<int8_t, 2, 10> > > optional_nullable_int;
+ ASSERT_FALSE(optional_nullable_int.is_initialized());
+ ASSERT_FALSE(optional_nullable_int->is_null());
+ ASSERT_RPCTYPE_VALID(optional_nullable_int);
+ ASSERT_FALSE(optional_nullable_int);
+
+ *optional_nullable_int = 9;
+ ASSERT_TRUE(optional_nullable_int.is_initialized());
+ ASSERT_FALSE(optional_nullable_int->is_null());
+ ASSERT_RPCTYPE_VALID(optional_nullable_int);
+ ASSERT_EQ(9, *optional_nullable_int);
+ ASSERT_TRUE(optional_nullable_int);
+
+ optional_nullable_int->set_to_null();
+ ASSERT_TRUE(optional_nullable_int.is_initialized());
+ ASSERT_TRUE(optional_nullable_int->is_null());
+ ASSERT_RPCTYPE_VALID(optional_nullable_int);
+}
+
+TEST(ValidatedTypes, TestOptionalConstructor) {
+ Optional< Integer<int16_t, 3, 15> > optional_int;
+ ASSERT_FALSE(optional_int.is_initialized());
+ ASSERT_RPCTYPE_VALID(optional_int);
+ *optional_int = 42;
+ ASSERT_TRUE(optional_int.is_initialized());
+ ASSERT_FALSE(optional_int.is_valid());
+ *optional_int = 12;
+ ASSERT_TRUE(optional_int.is_initialized());
+ ASSERT_RPCTYPE_VALID(optional_int);
+ int readback = *optional_int;
+ ASSERT_EQ(readback, 12);
+}
+
+TEST(ValidatedTypes, TestOptionalInitializingConstructor) {
+ Optional< String<1, 12> > optional_string("Hello world");
+ ASSERT_TRUE(optional_string.is_initialized());
+ ASSERT_RPCTYPE_VALID(optional_string);
+ std::string value = *optional_string;
+ ASSERT_EQ(value, "Hello world");
+}
+
+TEST(ValidatedTypes, TestDifferentTypesAssignment) {
+ Integer<int8_t, 1, 3> val;
+ Integer<int32_t, 5, 90> val2(45);
+ val = val2;
+ ASSERT_TRUE(val2.is_initialized());
+ ASSERT_RPCTYPE_VALID(val2);
+ ASSERT_TRUE(val.is_initialized());
+ ASSERT_FALSE(val.is_valid());
+}
+
+TEST(ValidatedTypes, ReportUninitializedIntType) {
+ Integer<int8_t, 1, 3> val;
+ ASSERT_FALSE(val.is_valid());
+ ValidationReport report("val");
+ val.ReportErrors(&report);
+ ASSERT_EQ("val: value is not initialized\n", PrettyFormat(report));
+}
+
+TEST(ValidatedTypes, ReportIncorrectInitializedIntType) {
+ Integer<int8_t, 1, 3> val(5);
+ ASSERT_FALSE(val.is_valid());
+ ValidationReport report("val");
+ val.ReportErrors(&report);
+ ASSERT_EQ("val: value initialized incorrectly\n", PrettyFormat(report));
+}
+
+TEST(ValidatedTypes, ReportUninitializedOptionalType) {
+ Optional< Integer<int8_t, 1, 3> > val;
+ ASSERT_RPCTYPE_VALID(val);
+ ValidationReport report("val");
+ val.ReportErrors(&report);
+ ASSERT_EQ("", PrettyFormat(report));
+}
+
+TEST(ValidatedTypes, ReportIncorrectInitializedOptionalType) {
+ Optional< Integer<int8_t, 1, 3> > val(5);
+ ASSERT_FALSE(val.is_valid());
+ ValidationReport report("val");
+ val.ReportErrors(&report);
+ ASSERT_EQ("val: value initialized incorrectly\n", PrettyFormat(report));
+}
+
+TEST(ValidatedTypes, ReportUninitializedNullableIntType) {
+ Nullable< Integer<int8_t, 1, 3> > val;
+ ASSERT_FALSE(val.is_valid());
+ ValidationReport report("val");
+ val.ReportErrors(&report);
+ ASSERT_EQ("val: value is not initialized\n", PrettyFormat(report));
+}
+
+TEST(ValidatedTypes, ReportNullInitializedNullableIntType) {
+ Nullable< Integer<int8_t, 1, 3> > val;
+ val.set_to_null();
+ ASSERT_RPCTYPE_VALID(val);
+ ValidationReport report("val");
+ val.ReportErrors(&report);
+ ASSERT_EQ("", PrettyFormat(report));
+}
+
+TEST(ValidatedTypes, ReportNoninitializedIntArray) {
+ Array< Enum<TestEnum>, 1, 3 > array;
+ ASSERT_FALSE(array.is_valid());
+ ValidationReport report("array");
+ array.ReportErrors(&report);
+ ASSERT_EQ("array: object is not initialized\n", PrettyFormat(report));
+}
+
+TEST(ValidatedTypes, ReportIncorrectlyInitializedIntArray1) {
+ Array< Integer<int8_t, 1, 10>, 1, 3 > array;
+ array.push_back(11);
+ ASSERT_FALSE(array.is_valid());
+ ValidationReport report("array");
+ array.ReportErrors(&report);
+ ASSERT_EQ("array[0]: value initialized incorrectly\n", PrettyFormat(report));
+}
+
+TEST(ValidatedTypes, ReportIncorrectlyInitializedIntArray2) {
+ Array< Integer<int8_t, 1, 10>, 1, 3 > array;
+ array.push_back(1);
+ array.push_back(2);
+ array.push_back(3);
+ array.push_back(4);
+ ASSERT_FALSE(array.is_valid());
+ ValidationReport report("array");
+ array.ReportErrors(&report);
+ ASSERT_EQ("array: array has invalid size\n", PrettyFormat(report));
+}
+
+TEST(ValidatedTypes, ReportIncorrectlyInitializedArray3) {
+ Array< Integer<int8_t, 1, 10>, 1, 3 > array;
+ array.push_back(1);
+ array.push_back(2);
+ array.push_back(42);
+ array.push_back(4);
+ ValidationReport report("array");
+ array.ReportErrors(&report);
+ ASSERT_EQ("array: array has invalid size\n"
+ "array[2]: value initialized incorrectly\n", PrettyFormat(report));
+}
+
+TEST(ValidatedTypes, ReportUninitializedMap) {
+ Map< Integer<int8_t, 1, 10>, 1, 3 > map;
+ ValidationReport report("map");
+ map.ReportErrors(&report);
+ ASSERT_EQ("map: object is not initialized\n", PrettyFormat(report));
+}
+
+TEST(ValidatedTypes, ReportIncorrectlyInitializedMap1) {
+ Map< Integer<int8_t, 1, 10>, 1, 3 > map;
+ map["aha"] = 42;
+ ValidationReport report("map");
+ map.ReportErrors(&report);
+ ASSERT_EQ("map[\"aha\"]: value initialized incorrectly\n", PrettyFormat(report));
+}
+
+TEST(ValidatedTypes, ReportIncorrectlyInitializedMap2) {
+ Map< Integer<int8_t, 1, 10>, 1, 3 > map;
+ map["aha"] = 3;
+ map["haha"] = 12;
+ map["muhahaha"] = 17;
+ map["muhahaha"] = 22;
+ ValidationReport report("map");
+ map.ReportErrors(&report);
+ ASSERT_EQ("map[\"haha\"]: value initialized incorrectly\n"
+ "map[\"muhahaha\"]: value initialized incorrectly\n", PrettyFormat(report));
+}
+
+} // namespace codegen