diff options
Diffstat (limited to 'src/components/rpc_base')
13 files changed, 89 insertions, 78 deletions
diff --git a/src/components/rpc_base/CMakeLists.txt b/src/components/rpc_base/CMakeLists.txt index 94e67cc985..d9bf821b67 100644 --- a/src/components/rpc_base/CMakeLists.txt +++ b/src/components/rpc_base/CMakeLists.txt @@ -28,31 +28,28 @@ # 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(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/sources.cmake) include_directories( - include + ${COMPONENTS_DIR}/rpc_base/include + ${COMPONENTS_DIR}/utils/include ${JSONCPP_INCLUDE_DIRECTORY} ) -set (SOURCES - ${COMPONENTS_DIR}/rpc_base/src/rpc_base/rpc_base.cc +set(PATHS + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/src ) +collect_sources(SOURCES "${PATHS}") -set (HEADERS - ${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 +set(LIBRARIES + jsoncpp + Utils ) -add_library(rpc_base ${HEADERS} ${SOURCES}) -target_link_libraries(rpc_base jsoncpp) +add_library(rpc_base ${SOURCES}) +target_link_libraries(rpc_base ${LIBRARIES}) if(BUILD_TESTS) add_subdirectory(test) -endif()
\ No newline at end of file +endif() 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 04ad1219b5..64930f7259 100644 --- a/src/components/rpc_base/include/rpc_base/gtest_support.h +++ b/src/components/rpc_base/include/rpc_base/gtest_support.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef RPC_BASE_GTEST_SUPPORT_H_ -#define RPC_BASE_GTEST_SUPPORT_H_ +#ifndef SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_GTEST_SUPPORT_H_ +#define SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_GTEST_SUPPORT_H_ #include <gtest/gtest.h> @@ -59,4 +59,4 @@ template <typename T> #define EXPECT_RPCTYPE_VALID(object) \ EXPECT_PRED_FORMAT1(AssertRpcObjValid, object) -#endif /* RPC_BASE_GTEST_SUPPORT_H_ */ +#endif // SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_GTEST_SUPPORT_H_ 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 883c2ec4bf..6792f47732 100644 --- a/src/components/rpc_base/include/rpc_base/rpc_base.h +++ b/src/components/rpc_base/include/rpc_base/rpc_base.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef VALIDATED_TYPES_H_ -#define VALIDATED_TYPES_H_ +#ifndef SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_BASE_H_ +#define SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_BASE_H_ #include <stdint.h> #include <map> @@ -58,7 +58,7 @@ enum PolicyTableType { PT_UPDATE, PT_SNAPSHOT }; -const std::string ommited_validation_info = "should be ommited in "; +const std::string omitted_validation_info = "should be omitted in "; const std::string required_validation_info = "is required in "; std::string PolicyTableTypeToString(const PolicyTableType pt_type); @@ -300,7 +300,7 @@ class Array : public std::vector<T>, public CompositeType { Json::Value ToJsonValue() const; void ToDbusWriter(dbus::MessageWriter* writer) const; - bool is_valid() const; + virtual bool is_valid() const; bool is_initialized() const; void ReportErrors(ValidationReport* report) const; virtual void SetPolicyTableType( @@ -439,4 +439,4 @@ class Optional { #include "rpc_base_inl.h" #include "rpc_base_json_inl.h" -#endif /* VALIDATED_TYPES_H_ */ +#endif // SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_BASE_H_ 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 2b968dd034..aae1a34ac2 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 @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef RPC_BASE_DBUS_INL_H_ -#define RPC_BASE_DBUS_INL_H_ +#ifndef SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_BASE_DBUS_INL_H_ +#define SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_BASE_DBUS_INL_H_ #include "dbus/dbus_message.h" #include "json/value.h" @@ -498,4 +498,4 @@ inline void Optional<T>::ToDbusWriter(dbus::MessageWriter* writer) const { } // namespace rpc -#endif // RPC_BASE_DBUS_INL_H_ +#endif // SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_BASE_DBUS_INL_H_ 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 cf14526541..b6b47c2ed8 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 @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef VALIDATED_TYPES_INL_H_ -#define VALIDATED_TYPES_INL_H_ +#ifndef SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_BASE_INL_H_ +#define SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_BASE_INL_H_ #include "rpc_base.h" @@ -177,7 +177,7 @@ Integer<T, minval, maxval>& Integer<T, minval, maxval>::operator=( const Integer& new_val) { this->value_ = new_val.value_; if (new_val.is_initialized()) { - this->value_state_ = range_.Includes(new_val.value_) ? kValid : kInvalid; + this->value_state_ = new_val.value_state_; } return *this; @@ -674,4 +674,4 @@ void Stringifyable<T>::ReportErrors(ValidationReport* report) const { } // namespace rpc -#endif /* VALIDATED_TYPES_INL_H_ */ +#endif // SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_BASE_INL_H_ 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 31f8c90872..6c8bb359af 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 @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef VALIDATED_TYPES_JSON_INL_H_ -#define VALIDATED_TYPES_JSON_INL_H_ +#ifndef SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_BASE_JSON_INL_H_ +#define SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_BASE_JSON_INL_H_ #include "rpc_base/rpc_base.h" #include "json/value.h" @@ -140,8 +140,7 @@ 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_) {} + : PrimitiveType(val.value_state_), value_(val.value_) {} template <typename T, T minval, T maxval> Integer<T, minval, maxval>::Integer(const Json::Value* value, IntType def_value) @@ -385,4 +384,4 @@ inline Json::Value Stringifyable<T>::ToJsonValue() const { } // namespace rpc -#endif /* VALIDATED_TYPES_JSON_INL_H_ */ +#endif // SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_BASE_JSON_INL_H_ 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 7b5ed2e375..5d1958157f 100644 --- a/src/components/rpc_base/include/rpc_base/rpc_message.h +++ b/src/components/rpc_base/include/rpc_base/rpc_message.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TYPE_BASE_H_ -#define TYPE_BASE_H_ +#ifndef SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_MESSAGE_H_ +#define SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_MESSAGE_H_ #include "rpc_base.h" @@ -99,4 +99,4 @@ class NotificationBase : public Message, public CompositeType { } // namespace rpc -#endif /* TYPE_BASE_H_ */ +#endif // SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_RPC_MESSAGE_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 941c8f61cc..4397112d54 100644 --- a/src/components/rpc_base/include/rpc_base/validation_report.h +++ b/src/components/rpc_base/include/rpc_base/validation_report.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef RPC_BASE_VALIDATION_REPORT_H_ -#define RPC_BASE_VALIDATION_REPORT_H_ +#ifndef SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_VALIDATION_REPORT_H_ +#define SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_VALIDATION_REPORT_H_ #include <string> #include <list> @@ -119,4 +119,4 @@ inline std::string PrettyFormat(const ValidationReport& report) { } // namespace rpc -#endif /* RPC_BASE_VALIDATION_REPORT_H_ */ +#endif // SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_VALIDATION_REPORT_H_ diff --git a/src/components/rpc_base/test/CMakeLists.txt b/src/components/rpc_base/test/CMakeLists.txt index 76cf738f46..566f0ddcde 100644 --- a/src/components/rpc_base/test/CMakeLists.txt +++ b/src/components/rpc_base/test/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2015, Ford Motor Company +# Copyright (c) 2016, Ford Motor Company # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -28,8 +28,9 @@ # 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 ( +include(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/sources.cmake) + +include_directories( ${COMPONENTS_DIR}/dbus/include ${COMPONENTS_DIR}/dbus/src ${COMPONENTS_DIR}/rpc_base/include @@ -43,20 +44,16 @@ set(LIBRARIES jsoncpp ) -set(SOURCES - rpc_base_json_test.cc - rpc_base_test.cc - validation_report_test.cc -) - -if (${HMI_DBUS_API}) - # Build dbus tests +if(${HMI_DBUS_API}) 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}") - + list(APPEND LIBRARIES + DBus + ) +else() + set(EXCLUDE_PATHS + rpc_base_dbus_test.cc + ) endif() +collect_sources(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}" "${EXCLUDE_PATHS}") +create_test(rpc_base_test "${SOURCES}" "${LIBRARIES}") diff --git a/src/components/rpc_base/test/rpc_base_dbus_test.cc b/src/components/rpc_base/test/rpc_base_dbus_test.cc index f26ce25c5d..4a22e111a3 100644 --- a/src/components/rpc_base/test/rpc_base_dbus_test.cc +++ b/src/components/rpc_base/test/rpc_base_dbus_test.cc @@ -35,6 +35,9 @@ #include "rpc_base/rpc_base_dbus_inl.h" namespace test { +namespace components { +namespace rpc_base_test { + using namespace rpc; using namespace dbus; @@ -169,7 +172,7 @@ TEST_F(DbusDeserialization, DeserializeArray) { { dbus::MessageWriter writer(msgref); std::string array_signature; - rpc::DbusSignature<Integer<int32_t, 1, 50>>(&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); @@ -192,13 +195,13 @@ TEST_F(DbusDeserialization, DeserializeArrayOfArrays) { { dbus::MessageWriter writer(msgref); std::string array_signature; - rpc::DbusSignature<Array<Integer<int32_t, 1, 50>, 1, 5>>(&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); + rpc::DbusSignature<Integer<int32_t, 1, 50> >(&subarray_signature); dbus::MessageWriter subarray_wirter( &array_writer, dbus::kArray, subarray_signature.c_str()); @@ -275,7 +278,7 @@ TEST_F(DbusDeserialization, DeserializeOptionalString) { } { dbus::MessageReader reader(msgref); - Optional<String<1, 100>> readback(&reader); + Optional<String<1, 100> > readback(&reader); ASSERT_TRUE(readback.is_initialized()); ASSERT_TRUE(readback.is_valid()); ASSERT_EQ(std::string(*readback), "Hello dear"); @@ -293,7 +296,7 @@ TEST_F(DbusDeserialization, DeserializeOptionalInt) { } { dbus::MessageReader reader(msgref); - Optional<Integer<int32_t, 1, 90>> readback(&reader); + Optional<Integer<int32_t, 1, 90> > readback(&reader); ASSERT_FALSE(readback.is_initialized()); ASSERT_TRUE(readback.is_valid()); ASSERT_FALSE(reader.has_failed()); @@ -494,61 +497,61 @@ TEST(ValidatedTypes, TestBooleanDbusSignature) { TEST(ValidatedTypes, TestIntDbusSignature) { std::string sign; - DbusSignature<Integer<int32_t, 1, 2>>(&sign); + DbusSignature<Integer<int32_t, 1, 2> >(&sign); ASSERT_EQ(sign, "i"); } TEST(ValidatedTypes, TestFloatDbusSignature) { std::string sign; - DbusSignature<Float<1, 2>>(&sign); + DbusSignature<Float<1, 2> >(&sign); ASSERT_EQ(sign, "d"); } TEST(ValidatedTypes, TestStringDbusSignature) { std::string sign; - DbusSignature<String<1, 2>>(&sign); + DbusSignature<String<1, 2> >(&sign); ASSERT_EQ(sign, "s"); } TEST(ValidatedTypes, TestEnumDbusSignature) { std::string sign; - DbusSignature<Enum<TestEnum>>(&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); + 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); + 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); + 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); + DbusSignature<Enum<TestEnum> >(&sign); ASSERT_EQ(sign, "i"); } TEST(ValidatedTypes, TestOptionalEnumDbusSignature) { std::string sign; - DbusSignature<Optional<Enum<TestEnum>>>(&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); + DbusSignature<Optional<Array<Float<1, 2>, 3, 4> > >(&sign); ASSERT_EQ(sign, "(bad)"); } @@ -674,4 +677,6 @@ TEST_F(DbusFailuresTest, DbusNonExistentArrayReadTest) { ASSERT_EQ(val, 0); } +} // namespace rpc_base_test +} // namespace components } // 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 index 07ac0418e0..cad9dd3a65 100644 --- a/src/components/rpc_base/test/rpc_base_json_test.cc +++ b/src/components/rpc_base/test/rpc_base_json_test.cc @@ -35,6 +35,9 @@ #include "rpc_base/rpc_base.h" namespace test { +namespace components { +namespace rpc_base_test { + using namespace rpc; using Json::Value; @@ -278,8 +281,8 @@ TEST(ValidatedTypesJson, OptionalMapAbsentValueTest) { TEST(ValidatedTypesJson, ArrayJsonTest) { Value array_value; - array_value.append(Value("Hello")); - array_value.append(Value("World")); + array_value.append(Value(10)); + array_value.append(Value(20)); Array<Integer<int8_t, 0, 32>, 2, 4> int_array(&array_value); ASSERT_TRUE(int_array.is_initialized()); ASSERT_TRUE(int_array.is_valid()); @@ -365,4 +368,6 @@ TEST(ValidatedTypesJson, OptionalIntFromJsonTest) { ASSERT_EQ(readback.asInt(), 42); } +} // namespace rpc_base_test +} // namespace components } // namespace test diff --git a/src/components/rpc_base/test/rpc_base_test.cc b/src/components/rpc_base/test/rpc_base_test.cc index 37a64b319e..c4ffbc321e 100644 --- a/src/components/rpc_base/test/rpc_base_test.cc +++ b/src/components/rpc_base/test/rpc_base_test.cc @@ -36,6 +36,8 @@ #include "rpc_base/rpc_base.h" namespace test { +namespace components { +namespace rpc_base_test { using namespace rpc; namespace { @@ -435,4 +437,6 @@ TEST(ValidatedTypes, ReportIncorrectlyInitializedMap2) { PrettyFormat(report)); } -} // namespace codegen +} // namespace rpc_base_test +} // namespace components +} // namespace test diff --git a/src/components/rpc_base/test/validation_report_test.cc b/src/components/rpc_base/test/validation_report_test.cc index e7dded342c..596bfdb20d 100644 --- a/src/components/rpc_base/test/validation_report_test.cc +++ b/src/components/rpc_base/test/validation_report_test.cc @@ -35,6 +35,8 @@ #include "rpc_base/validation_report.h" namespace test { +namespace components { +namespace rpc_base_test { using namespace rpc; class ValidationReportTest : public testing::Test { @@ -157,4 +159,6 @@ TEST_F(ValidationReportTest, PrettyFormat_ExpectDataCorrect) { EXPECT_EQ(temp2, result2); } -} // namespace rpc +} // namespace rpc_base_test +} // namespace components +} // namespace test |