find_package(Gstreamer-1.0 REQUIRED)
find_package(Glib-2.0 REQUIRED)
+
+if (BUILD_TESTS_WITH_HMI)
find_package(LibXML2 REQUIRED)
+endif(BUILD_TESTS_WITH_HMI)
# --- GoogleTest example
#add_subdirectory(./gtest-example)
add_subdirectory(./tools)
-include_directories (
+set (INCLUDE_DIR
../src/thirdPartyLibs/gmock-1.7.0/include
../src/thirdPartyLibs/jsoncpp/include/
../src/thirdPartyLibs/gmock-1.7.0/gtest/include
../src/components/request_watchdog/include
../src/components/media_manager/include
../src/components/config_profile/include
+ ../src/components/policy/src/policy/include
+ ../src/components/policy/src/policy/usage_statistics/include
../src/components/protocol_handler/include
../src/components/transport_manager/include
../src/components/connection_handler/include
../test/components/application_manager/rpc/include
${CMAKE_BINARY_DIR}/src/components/
${CMAKE_BINARY_DIR}
- ${LibXML2_INCLUDE_DIR}
# /usr/lib/i386-linux-gnu/glib-2.0/include
# /usr/lib/x86_64-linux-gnu/glib-2.0/include/
# ${GSTREAMER_gst_INCLUDE_DIR}
# ${GLIB_glib_2_INCLUDE_DIR}
)
- set(LIBRARIES
+set(LIBRARIES
MediaManager
ApplicationManager
gtest
MessageBrokerClient
MessageBrokerServer
encryption
- bluetooth
- pthread
- avahi-client
- avahi-common
- ${LibXML2_LIBRARIES} -lxml2
# rt
# ${GSTREAMER_gstreamer_LIBRARY}
Resumption
add_executable("test_suit" "./test_suit.cc")
if (BUILD_TESTS_WITH_HMI)
- target_link_libraries("test_suit" test_App_Manager ${LIBRARIES})
+include_directories(${INCLUDE_DIR} ${LibXML2_INCLUDE_DIR})
+target_link_libraries("test_suit"
+ test_App_Manager
+ ${LIBRARIES}
+ ${LibXML2_LIBRARIES} -lxml2
+ avahi-client
+ )
else (BUILD_TESTS_WITH_HMI)
+include_directories(${INCLUDE_DIR})
target_link_libraries("test_suit" ${LIBRARIES})
endif (BUILD_TESTS_WITH_HMI)
add_subdirectory(./protocol_handler)
# --- ProtocolHandler
-add_subdirectory(./connection_handler)
+#add_subdirectory(./connection_handler)
add_subdirectory(./hmi_message_handler)
../../../../src/components/media_manager/include
../../../../src/components/formatters/include
../../../../src/components/config_profile/include
- ../../../../src/components/policies/include
+ ../../../../src/components/policy/src/policy/include
+ ../../../../src/components/policy/src/policy/usage_statistics/include
${GSTREAMER_gst_INCLUDE_DIR}
${GLIB_glib_2_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/src/components/
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/XmlTests/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/XmlTests/)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/SyncProxyTester/ DESTINATION ${CMAKE_BINARY_DIR}/test/SyncProxyTester/)
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/SyncProxyTester/icon.png DESTINATION ${CMAKE_BINARY_DIR}/test/AppManagerImplTest/)
add_library("test_App_Manager"
"./src/admin_app_test.cc"
* POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef TEST_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_APPLICATION_MANAGER_IMPL_TEST_H_
-#define TEST_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_APPLICATION_MANAGER_IMPL_TEST_H_
+#ifndef TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_APPLICATION_MANAGER_IMPL_TEST_H_
+#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_APPLICATION_MANAGER_IMPL_TEST_H_
#include "gtest/gtest.h"
#include "gmock/gmock.h"
-#include <cstdint>
+#include <stdint.h>
#include <string>
#include <list>
#include <vector>
#include "application_manager/application_manager.h"
#include "application_manager/hmi_capabilities.h"
#include "application_manager/message.h"
-#include "application_manager/policies_manager/policies_manager.h"
#include "application_manager/request_controller.h"
#include "application_manager/resume_ctrl.h"
#include "protocol_handler/protocol_observer.h"
#include "formatters/CFormatterJsonSDLRPCv2.hpp"
#include "application_manager/mobile_message_handler.h"
#include "connection_handler/connection_handler_impl.h"
+#include "hmi_message_handler/hmi_message_handler_impl.h"
+#include "protocol_handler/protocol_handler_impl.h"
namespace application_manager {
class ApplicationManagerImpl;
namespace test {
- class ApplicationManagerImplTest {
- public:
- ApplicationManagerImplTest();
+class ApplicationManagerImplTest {
+ public:
+ ApplicationManagerImplTest();
- ~ApplicationManagerImplTest();
+ ~ApplicationManagerImplTest();
- const std::map<int32_t, am::ApplicationSharedPtr>& GetApplications();
+ const std::set<am::ApplicationSharedPtr>& GetApplications();
- const std::set<am::ApplicationSharedPtr>& GetApplicationList();
+ const std::list<am::CommandSharedPtr>& GetNotificationList();
- const std::list<am::CommandSharedPtr>& GetNotificationList();
+ const std::map<const int32_t, const uint32_t>& GetAppIDList();
- const std::map<const int32_t, const uint32_t>& GetAppIDList();
+ bool GetAudioPassThruActive();
- bool GetAudioPassThruActive();
+ bool GetIsDistractingDriver();
- bool GetIsDistractingDriver();
+ bool GetIsVrSessionStrated();
- bool GetIsVrSessionStrated();
+ bool GetHMICooperating();
- bool GetHMICooperating();
+ bool GetIsAllAppsAllowed();
- bool GetIsAllAppsAllowed();
+ const media_manager::MediaManager* GetMediaManager();
- const media_manager::MediaManager* GetMediaManager();
+ const hmi_message_handler::HMIMessageHandler* GetHmiHandler();
- const hmi_message_handler::HMIMessageHandler* GetHmiHandler();
+ const connection_handler::ConnectionHandler* GetConnectionHandler();
- const connection_handler::ConnectionHandler* GetConnectionHandler();
+ const protocol_handler::ProtocolHandler* GetProtocolHandler();
- const protocol_handler::ProtocolHandler* GetProtocolHandler();
+ const policy::PolicyManager* GetPolicyManager();
- const policies::PolicyManager* GetPolicyManager();
+ const am::HMICapabilities& GetHmiCapabilities();
- const am::HMICapabilities& GetHmiCapabilities();
+ const hmi_apis::HMI_API* GetHmiSoFactory();
- const am::policies_manager::PoliciesManager& GetPoliciesManager();
+ const mobile_apis::MOBILE_API* GetMobileSoFactory();
- const hmi_apis::HMI_API* GetHmiSoFactory();
+ am::mobile_api::AppInterfaceUnregisteredReason::eType
+ GetUnregisterReason();
- const mobile_apis::MOBILE_API* GetMobileSoFactory();
+ const am::impl::FromMobileQueue& GetMessagesFromMobile();
- //uint32_t GetCorelationId();
+ const am::impl::ToMobileQueue& GetMessagesToMobile();
- //uint32_t GetMaxCorelationId();
+ const am::impl::FromHmiQueue& GetMessagesFromHmi();
- am::mobile_api::AppInterfaceUnregisteredReason::eType
- GetUnregisterReason();
+ const am::impl::ToHmiQueue& GetMessagesToHmi();
- const am::impl::FromMobileQueue& GetMessagesFromMobile();
+ private:
+ am::ApplicationManagerImpl* app_;
+};
- const am::impl::ToMobileQueue& GetMessagesToMobile();
+class HMIMessageHandlerInterceptor :
+ public hmi_message_handler::HMIMessageHandler {
+ public:
+ HMIMessageHandlerInterceptor();
- const am::impl::FromHmiQueue& GetMessagesFromHmi();
+ ~HMIMessageHandlerInterceptor();
- const am::impl::ToHmiQueue& GetMessagesToHmi();
+ virtual void SendMessageToHMI(
+ hmi_message_handler::MessageSharedPointer message);
+ virtual void OnMessageReceived(
+ utils::SharedPtr<application_manager::Message> message);
+ virtual void OnErrorSending(
+ utils::SharedPtr<application_manager::Message> message);
+ virtual void AddHMIMessageAdapter(
+ hmi_message_handler::HMIMessageAdapter* adapter);
+ virtual void RemoveHMIMessageAdapter(
+ hmi_message_handler::HMIMessageAdapter* adapter);
+ std::list<hmi_message_handler::MessageSharedPointer>* GetMasMessage();
- /*
- const std::map<int32_t, am::ApplicationSharedPtr>& GetApplications() {
- return applications_;
- }
+ private:
+ std::list<hmi_message_handler::MessageSharedPointer> mas_mess;
- const std::set<am::ApplicationSharedPtr>& GetApplicationList() {
- return application_list_;
- }
+ DISALLOW_COPY_AND_ASSIGN(HMIMessageHandlerInterceptor);
+};
- const std::list<am::CommandSharedPtr>& GetNotificationList() {
- return notification_list_;
- }
+class ProtocolHandlerInterceptor : public protocol_handler::ProtocolHandlerImpl {
+ public:
+ ProtocolHandlerInterceptor(
+ transport_manager::TransportManager* transport_manager_param);
- const std::map<const int32_t, const uint32_t>& GetAppIDList() {
- return appID_list_;
- }
+ ~ProtocolHandlerInterceptor();
- bool GetAudioPassThruActive() {
- return audio_pass_thru_active_;
- }
+ void SendMessageToMobileApp(const protocol_handler::RawMessagePtr& message,
+ bool final_message) OVERRIDE;
- bool GetIsDistractingDriver() {
- return is_distracting_driver_;
- }
+ std::list<protocol_handler::RawMessagePtr>* GetMasRawMessage();
- bool GetIsVrSessionStrated() {
- return is_vr_session_strated_;
- }
+ private:
+ ProtocolHandlerInterceptor* operator=(const ProtocolHandlerInterceptor&);
+ ProtocolHandlerInterceptor(const ProtocolHandlerInterceptor&);
- bool GetHMICooperating() {
- return hmi_cooperating_;
- }
+ std::list<protocol_handler::RawMessagePtr> mas_mess;
+};
- bool GetIsAllAppsAllowed() {
- return is_all_apps_allowed_;
- }
+void RegistrSO(utils::SharedPtr<smart::SmartObject> AppRegRequest);
- const media_manager::MediaManager* GetMediaManager() {
- return media_manager_;
- }
+utils::SharedPtr<protocol_handler::RawMessage>
+ConvertSOToRawMess(utils::SharedPtr<smart::SmartObject> so);
- const hmi_message_handler::HMIMessageHandler* GetHmiHandler() {
- return hmi_handler_;
- }
+void AddDevice(uint32_t);
- const connection_handler::ConnectionHandler* GetConnectionHandler() {
- return connection_handler_;
- }
-
- const protocol_handler::ProtocolHandler* GetProtocolHandler() {
- return protocol_handler_;
- }
-
- const policies::PolicyManager* GetPolicyManager() {
- return policy_manager_;
- }
-
- const am::HMICapabilities& GetHmiCapabilities() {
- return hmi_capabilities_;
- }
-
- const am::policies_manager::PoliciesManager& GetPoliciesManager() {
- return policies_manager_;
- }
-
- const hmi_apis::HMI_API* GetHmiSoFactory() {
- return hmi_so_factory_;
- }
-
- const mobile_apis::MOBILE_API* GetMobileSoFactory() {
- return mobile_so_factory_;
- }
-
- const uint32_t& GetCorelationId() {
- return corelation_id_;
- }
-
- const uint32_t& GetMaxCorelationId() {
- return max_corelation_id_;
- }
-
- am::mobile_api::AppInterfaceUnregisteredReason::eType
- GetUnregisterReason() {
- return unregister_reason_;
- }
-
- const am::impl::FromMobileQueue& GetMessagesFromMobile() {
- return messages_from_mobile_;
- }
-
- const am::impl::ToMobileQueue& GetMessagesToMobile() {
- return messages_to_mobile_;
- }
-
- const am::impl::FromHmiQueue& GetMessagesFromHmi() {
- return messages_from_hmi_;
- }
-
- const am::impl::ToHmiQueue& GetMessagesToHmi() {
- return messages_to_hmi_;
- }
- */
- private:
- am::ApplicationManagerImpl* app_;
- };
-
- void RegistrSO(utils::SharedPtr<smart::SmartObject> AppRegRequest);
-
- utils::SharedPtr<protocol_handler::RawMessage>
- ConvertSOToRawMess(utils::SharedPtr<smart::SmartObject> so);
-
- void AddDevice(uint32_t);
+void RemovedDevice(uint32_t);
} // namespace test
-#endif // TEST_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_APPLICATION_MANAGER_IMPL_TEST_H_
+#endif // TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_APPLICATION_MANAGER_IMPL_TEST_H_
#include <fstream>
#include "utils/macro.h"
-#include "utils/logger.h"
#include "utils/signals.h"
#include "config_profile/profile.h"
#include "networking.h"
namespace smart = NsSmartDeviceLink::NsSmartObjects;
namespace jsn = NsSmartDeviceLink::NsJSONHandler::strings;
+namespace test {
/**
* @brief Initialize TransportManager, ProtocolHandlerImpl, ConnectionHandlerImpl
* ApplicationManagerImpl, MessageBrokerAdapter
*/
void RegApp();
+/**
+ * @brief Activate application
+ */
+void ActivateApp();
+
+} // namespace test
+
#endif // TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_INIT_START_DATA_H_
namespace smart = NsSmartDeviceLink::NsSmartObjects;
namespace test {
+
/**
* @brief Function read test from xml files and create Gtest to verify Mobile
* response and HMI request
*
*/
bool CheckNotTestedHMIRequest();
+
+ /**
+ * @brief Function init params smoke test
+ *
+ * @return true if all init
+ *
+ */
+ bool InitSmokeTestExpMedia();
+
} // namespace test
#endif // TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_SMOKE_TEST_EXP_MEDIA_H_
#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_TEST_APP_MANAGER_H_
#include <string>
+#include <list>
+#include <vector>
#include "rpc/application_manager_impl_test.h"
#include "rpc/init_hmi.h"
#include "connection_handler/connection_handler_impl.h"
#include "formatters/CFormatterJsonSDLRPCv2.hpp"
#include "application_manager/mobile_message_handler.h"
+#include "application_manager/commands/command_impl.h"
#include "life_cycle.h"
namespace smart = NsSmartDeviceLink::NsSmartObjects;
namespace jsn = NsSmartDeviceLink::NsJSONHandler::strings;
-// void RegistrSO(utils::SharedPtr<smart::SmartObject> AppRegRequest);
+namespace test {
-// utils::SharedPtr<protocol_handler::RawMessage>
-// ConvertSOToRawMess(utils::SharedPtr<smart::SmartObject> so);
+namespace connect_key {
+
+enum eType {
+ FIRST_CONNECTION_KEY = 65546,
+ SECOND_CONNECTION_KEY = 65547
+};
+}
+
+namespace device_id {
+
+enum eType {
+ FIRST_DEVICE_ID = 10,
+ SECOND_DEVICE_ID = 11
+};
+}
+
+TEST(TestApplicationManager, application) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+
+ if (!sh_app_first.valid()) {
+ AddDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_first.valid());
+ }
+ /****************************************************************************/
+ /**
+ * Check app
+ */
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ EXPECT_TRUE(sh_app_first.valid());
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, active_application) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+
+ if (!sh_app_first.valid()) {
+ AddDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_first.valid());
+ }
+
+ /****************************************************************************/
+ /**
+ * Check active_application
+ */
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ (*sh_app_first).set_hmi_level(am::mobile_api::HMILevel::HMI_FULL);
+
+ am::ApplicationSharedPtr sh_app_second(app_manager->active_application());
+
+ EXPECT_EQ(sh_app_first, sh_app_second);
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, applications_by_button) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+
+ if (!sh_app_first.valid()) {
+ AddDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_first.valid());
+ }
+ /****************************************************************************/
+ /**
+ * Check applications_by_button
+ */
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ (*sh_app_first).SubscribeToButton(mobile_apis::ButtonName::SEEKLEFT);
+
+ std::vector<am::ApplicationSharedPtr> vect_app =
+ app_manager->applications_by_button(
+ mobile_apis::ButtonName::SEEKLEFT);
+
+ EXPECT_EQ(vect_app[0], sh_app_first);
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, IviInfoUpdated) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+
+ if (!sh_app_first.valid()) {
+ AddDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_first.valid());
+ }
+ /****************************************************************************/
+ /**
+ * Check IviInfoUpdated
+ */
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ (*sh_app_first).SubscribeToIVI(
+ mobile_apis::VehicleDataType::VEHICLEDATA_FUELLEVEL);
+
+ std::vector<am::ApplicationSharedPtr> vect_app = app_manager->IviInfoUpdated(
+ am::VehicleDataType::FUELLEVEL, 0);
+
+ EXPECT_EQ(vect_app[0], sh_app_first);
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, applications_with_navi) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+
+ if (!sh_app_first.valid()) {
+ AddDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_first.valid());
+ }
+ /****************************************************************************/
+ /**
+ * Check applications_with_navi
+ */
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ (*sh_app_first).set_allowed_support_navigation(true);
+
+ std::vector<am::ApplicationSharedPtr> vect_app =
+ app_manager->applications_with_navi();
+
+ EXPECT_EQ(vect_app[0], sh_app_first);
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
-namespace test {
TEST(TestApplicationManager, RegApp) {
/****************************************************************************/
/**
- * Test without ConnectionHandle Device
+ * Init params
*/
utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
utils::SharedPtr<protocol_handler::RawMessage> raw_mes;
am::ApplicationManagerImpl* app_manager =
am::ApplicationManagerImpl::instance();
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor =
+ new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+ sleep(1);
+
+ /****************************************************************************/
+ /**
+ * Test without ConnectionHandle Device
+ */
RegistrSO(so_reg);
raw_mes = ConvertSOToRawMess(so_reg);
app_manager->OnMessageReceived(raw_mes);
sleep(3);
- sh_app = app_manager->application(65546);
+ sh_app = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
EXPECT_FALSE(sh_app.valid());
/**
* Valid add app
*/
- AddDevice(10);
+ AddDevice(device_id::FIRST_DEVICE_ID);
app_manager->OnMessageReceived(raw_mes);
sleep(3);
- sh_app = app_manager->application(65546);
+ sh_app = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
EXPECT_TRUE(sh_app.valid());
RegistrSO(so_reg2);
(*so_reg2)[jsn::S_MSG_PARAMS][am::strings::app_id] = "65547";
- (*so_reg2)[jsn::S_PARAMS][am::strings::connection_key] = 65547;
+ (*so_reg2)[jsn::S_PARAMS][am::strings::connection_key] =
+ connect_key::SECOND_CONNECTION_KEY;
(*so_reg2)[jsn::S_MSG_PARAMS][am::strings::app_name] = "SyncProxyTester";
(*so_reg2)[jsn::S_MSG_PARAMS][am::strings::vr_synonyms][0] =
- "VR SyncProxyTester2";
+ "VR SyncProxyTester2";
raw_mes2 = ConvertSOToRawMess(so_reg2);
- AddDevice(11);
+ AddDevice(device_id::SECOND_DEVICE_ID);
sleep(1);
app_manager->OnMessageReceived(raw_mes2);
sleep(3);
- sh_app = app_manager->application(65547);
+ sh_app = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
EXPECT_FALSE(sh_app.valid());
app_manager->OnMessageReceived(raw_mes2);
sleep(3);
- sh_app = app_manager->application(65547);
+ sh_app = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
EXPECT_FALSE(sh_app.valid());
app_manager->OnMessageReceived(raw_mes2);
sleep(3);
- sh_app = app_manager->application(65547);
+ sh_app = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
EXPECT_FALSE(sh_app.valid());
app_manager->OnMessageReceived(raw_mes2);
sleep(3);
- sh_app = app_manager->application(65547);
+ sh_app = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
EXPECT_FALSE(sh_app.valid());
*/
(*so_reg2)[jsn::S_MSG_PARAMS][am::strings::tts_name][0]["text"] = "\n";
-
raw_mes2 = ConvertSOToRawMess(so_reg2);
app_manager->OnMessageReceived(raw_mes2);
sleep(3);
- sh_app = app_manager->application(65547);
+ sh_app = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
EXPECT_FALSE(sh_app.valid());
* Test tts_name is INVALID_DATA -Failed to parse string to smart object
*/
(*so_reg2)[jsn::S_MSG_PARAMS][am::strings::tts_name][0]["text"] =
- "SyncProxyTesterTTS2";
+ "SyncProxyTesterTTS2";
(*so_reg2)[jsn::S_MSG_PARAMS][am::strings::tts_name][1]["text"] = "";
(*so_reg2)[jsn::S_MSG_PARAMS][am::strings::tts_name][1]["type"] = "TEXT";
app_manager->OnMessageReceived(raw_mes2);
sleep(3);
- sh_app = app_manager->application(65547);
+ sh_app = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
EXPECT_FALSE(sh_app.valid());
* Test tts_name is INVALID_DATA - Param names restrictions check failed
*/
(*so_reg2)[jsn::S_MSG_PARAMS][am::strings::tts_name][1]["text"] =
- "\n";
+ "\n";
raw_mes2 = ConvertSOToRawMess(so_reg2);
app_manager->OnMessageReceived(raw_mes2);
sleep(3);
- sh_app = app_manager->application(65547);
+ sh_app = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
EXPECT_FALSE(sh_app.valid());
* Test vr_synonyms is DUPLICATE_NAME - Some VR synonyms are known already
*/
(*so_reg2)[jsn::S_MSG_PARAMS][am::strings::tts_name][1]["text"] =
- "TTSName";
+ "TTSName";
(*so_reg2)[jsn::S_MSG_PARAMS][am::strings::vr_synonyms][0] =
- "VR SyncProxyTester";
+ "VR SyncProxyTester";
raw_mes2 = ConvertSOToRawMess(so_reg2);
app_manager->OnMessageReceived(raw_mes2);
sleep(3);
- sh_app = app_manager->application(65547);
+ sh_app = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
EXPECT_FALSE(sh_app.valid());
* Test app_id is INVALID_DATA - duplicate
*/
(*so_reg2)[jsn::S_MSG_PARAMS][am::strings::vr_synonyms][0] =
- "VR SyncProxyTester2";
- (*so_reg2)[jsn::S_MSG_PARAMS][am::strings::app_id] = "65537";
+ "VR SyncProxyTester2";
+ (*so_reg2)[jsn::S_MSG_PARAMS][am::strings::app_id] = "65546";
raw_mes2 = ConvertSOToRawMess(so_reg2);
app_manager->OnMessageReceived(raw_mes2);
sleep(3);
- sh_app = app_manager->application(65547);
+ sh_app = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
EXPECT_FALSE(sh_app.valid());
/**
* Valid add app
*/
-
(*so_reg2)[jsn::S_MSG_PARAMS][am::strings::app_id] = "65547";
raw_mes2 = ConvertSOToRawMess(so_reg2);
app_manager->OnMessageReceived(raw_mes2);
sleep(3);
- sh_app = app_manager->application(65547);
+ sh_app = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
EXPECT_TRUE(sh_app.valid());
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ app_manager->UnregisterApplication(connect_key::SECOND_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ RemovedDevice(device_id::SECOND_DEVICE_ID);
+ sleep(2);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, RemoveAppDataFromHMI) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+ am::ApplicationSharedPtr app;
+
+ EXPECT_TRUE(app_manager->RemoveAppDataFromHMI(app));
+}
+
+TEST(TestApplicationManager, LoadAppDataToHMI) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+ am::ApplicationSharedPtr app;
+
+ EXPECT_TRUE(app_manager->LoadAppDataToHMI(app));
+}
+
+TEST(TestApplicationManager, ActivateApplication) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ utils::SharedPtr<protocol_handler::RawMessage> raw_mes;
+ am::ApplicationSharedPtr sh_app_first;
+ am::ApplicationSharedPtr sh_app_second;
+
+ std::list<hmi_message_handler::MessageSharedPointer>* array_message;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ array_message = hmi_message_handler_interceptor->GetMasMessage();
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ sleep(2);
+ if (!sh_app_first.valid()) {
+ AddDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_first.valid());
+ }
+
+ (*so_reg)[jsn::S_MSG_PARAMS][am::strings::app_id] = "65547";
+ (*so_reg)[jsn::S_PARAMS][am::strings::connection_key] =
+ connect_key::SECOND_CONNECTION_KEY;
+ (*so_reg)[jsn::S_MSG_PARAMS][am::strings::app_name] = "SyncProxyTester2";
+ (*so_reg)[jsn::S_MSG_PARAMS][am::strings::vr_synonyms][0] =
+ "VR SyncProxyTester2";
+
+ sh_app_second = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
+
+ if (sh_app_second.valid()) {
+ app_manager->UnregisterApplication(connect_key::SECOND_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+ sh_app_second = app_manager->RegisterApplication(so_reg);
+
+ if (!sh_app_second.valid()) {
+ AddDevice(device_id::SECOND_DEVICE_ID);
+ sleep(1);
+ sh_app_second = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_second.valid());
+ }
+
+ am::mobile_api::HMILevel::eType hmi_limit =
+ am::mobile_api::HMILevel::HMI_LIMITED;
+
+ am::mobile_api::HMILevel::eType hmi_full = am::mobile_api::HMILevel::HMI_FULL;
+
+ am::mobile_api::HMILevel::eType hmi_background =
+ am::mobile_api::HMILevel::HMI_BACKGROUND;
+
+ array_message->clear();
+ /****************************************************************************/
+ /**
+ * app->app_id() == curr_app->app_id() - true
+ * curr_app->IsFullscreen() - true
+ */
+ (*sh_app_first).MakeFullscreen();
+
+ EXPECT_FALSE(app_manager->ActivateApplication(sh_app_first));
+
+ /****************************************************************************/
+ /**
+ * curr_app->hmi_level() != HMI_LIMITED - true
+ * curr_app->has_been_activated() - true
+ */
+
+ (*sh_app_first).set_hmi_level(hmi_background);
+
+ app_manager->ActivateApplication(sh_app_first);
+ sleep(2);
+
+ EXPECT_EQ(array_message->size(), 1);
+
+ /****************************************************************************/
+ /**
+ * is_new_app_media - true
+ * curr_app->IsAudible() - true
+ */
+
+ (*sh_app_first).set_is_media_application(true);
+ (*sh_app_first).set_hmi_level(hmi_background);
+
+ (*sh_app_second).set_hmi_level(hmi_limit);
+
+ app_manager->ActivateApplication(sh_app_first);
+ sleep(2);
+
+ EXPECT_EQ(array_message->size(), 2);
+
+ /****************************************************************************/
+ /**
+ * curr_app->IsFullscreen() - true
+ */
+
+ (*sh_app_first).set_is_media_application(false);
+ (*sh_app_first).set_hmi_level(hmi_background);
+
+ (*sh_app_second).set_hmi_level(hmi_full);
+
+ app_manager->ActivateApplication(sh_app_first);
+ sleep(2);
+
+ EXPECT_EQ(array_message->size(), 5);
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+ app_manager->UnregisterApplication(connect_key::SECOND_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ RemovedDevice(11);
+ sleep(2);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
}
+
+TEST(TestApplicationManager, PutApplicationInLimited) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ utils::SharedPtr<protocol_handler::RawMessage> raw_mes;
+ am::ApplicationSharedPtr sh_app_first;
+ am::ApplicationSharedPtr sh_app_second;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor =
+ new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ }
+
+ AddDevice(device_id::FIRST_DEVICE_ID);
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ sleep(3);
+
+ (*so_reg)[jsn::S_MSG_PARAMS][am::strings::app_id] = "65547";
+ (*so_reg)[jsn::S_PARAMS][am::strings::connection_key] =
+ connect_key::SECOND_CONNECTION_KEY;
+ (*so_reg)[jsn::S_MSG_PARAMS][am::strings::app_name] = "SyncProxyTester2";
+ (*so_reg)[jsn::S_MSG_PARAMS][am::strings::vr_synonyms][0] =
+ "VR SyncProxyTester2";
+
+ sh_app_first = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::SECOND_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ }
+
+ AddDevice(device_id::SECOND_DEVICE_ID);
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ sleep(3);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ sh_app_second = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
+
+ am::mobile_api::HMILevel::eType hmi_limit =
+ am::mobile_api::HMILevel::HMI_LIMITED;
+ am::mobile_api::HMILevel::eType hmi_full = am::mobile_api::HMILevel::HMI_FULL;
+ am::mobile_api::HMILevel::eType return_put;
+ /****************************************************************************/
+ /**
+ * curr_app->hmi_level() - mobile_api::HMILevel::HMI_LIMITED
+ */
+ (*sh_app_first).set_is_media_application(true);
+ (*sh_app_first).set_hmi_level(hmi_limit);
+
+ return_put = app_manager->PutApplicationInLimited(sh_app_second);
+
+ EXPECT_EQ(return_put, am::mobile_api::HMILevel::HMI_BACKGROUND);
+
+ /****************************************************************************/
+ /**
+ * curr_app->hmi_level() - mobile_api::HMILevel::HMI_FULL
+ * curr_app->is_media_application() - true
+ */
+ (*sh_app_first).set_hmi_level(hmi_full);
+
+ return_put = app_manager->PutApplicationInLimited(sh_app_second);
+
+ EXPECT_EQ(return_put, am::mobile_api::HMILevel::HMI_BACKGROUND);
+
+ /****************************************************************************/
+ /**
+ * curr_app->hmi_level() - mobile_api::HMILevel::HMI_FULL
+ * curr_app->is_media_application() - false
+ */
+ (*sh_app_first).set_is_media_application(false);
+
+ return_put = app_manager->PutApplicationInLimited(sh_app_second);
+
+ EXPECT_EQ(return_put, am::mobile_api::HMILevel::HMI_LIMITED);
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+ app_manager->UnregisterApplication(connect_key::SECOND_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ RemovedDevice(device_id::SECOND_DEVICE_ID);
+ sleep(2);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, PutApplicationInFull) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ utils::SharedPtr<protocol_handler::RawMessage> raw_mes;
+ am::ApplicationSharedPtr sh_app_first;
+ am::ApplicationSharedPtr sh_app_second;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor =
+ new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ }
+
+ AddDevice(device_id::FIRST_DEVICE_ID);
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ sleep(3);
+
+ (*so_reg)[jsn::S_MSG_PARAMS][am::strings::app_id] = "65547";
+ (*so_reg)[jsn::S_PARAMS][am::strings::connection_key] = 65547;
+ (*so_reg)[jsn::S_MSG_PARAMS][am::strings::app_name] = "SyncProxyTester2";
+ (*so_reg)[jsn::S_MSG_PARAMS][am::strings::vr_synonyms][0] =
+ "VR SyncProxyTester2";
+
+ sh_app_first = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::SECOND_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ }
+
+ AddDevice(device_id::SECOND_DEVICE_ID);
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ sleep(3);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ sh_app_second = app_manager->application(connect_key::SECOND_CONNECTION_KEY);
+
+ am::mobile_api::HMILevel::eType hmi_limit =
+ am::mobile_api::HMILevel::HMI_LIMITED;
+ am::mobile_api::HMILevel::eType hmi_full = am::mobile_api::HMILevel::HMI_FULL;
+ am::mobile_api::HMILevel::eType return_put;
+
+ /****************************************************************************/
+ /**
+ * is_new_app_media - true
+ * curr_app->is_media_application() - true
+ * curr_app->hmi_level() -mobile_api::HMILevel::HMI_FULL
+ */
+ (*sh_app_first).set_is_media_application(true);
+ (*sh_app_first).set_hmi_level(hmi_full);
+
+ (*sh_app_second).set_is_media_application(true);
+ return_put = app_manager->PutApplicationInFull(sh_app_second);
+
+ EXPECT_EQ(return_put, am::mobile_api::HMILevel::HMI_BACKGROUND);
+
+ /****************************************************************************/
+ /**
+ * is_new_app_media - true
+ * curr_app->is_media_application() - false
+ * curr_app->hmi_level() -mobile_api::HMILevel::HMI_FULL
+ */
+ (*sh_app_first).set_is_media_application(false);
+
+ return_put = app_manager->PutApplicationInFull(sh_app_second);
+
+ EXPECT_EQ(return_put, am::mobile_api::HMILevel::HMI_LIMITED);
+
+ /****************************************************************************/
+ /**
+ * is_new_app_media - true
+ * curr_app->is_media_application() - false
+ * curr_app->hmi_level() -mobile_api::HMILevel::HMI_LIMITED
+ */
+ (*sh_app_first).set_hmi_level(hmi_limit);
+
+ return_put = app_manager->PutApplicationInFull(sh_app_second);
+
+ EXPECT_EQ(return_put, am::mobile_api::HMILevel::HMI_BACKGROUND);
+
+ /****************************************************************************/
+ /**
+ * is_new_app_media - false
+ * curr_app->hmi_level() -mobile_api::HMILevel::HMI_FULL
+ */
+ (*sh_app_second).set_is_media_application(false);
+
+ (*sh_app_first).set_hmi_level(hmi_full);
+
+ return_put = app_manager->PutApplicationInFull(sh_app_second);
+
+ EXPECT_EQ(return_put, am::mobile_api::HMILevel::HMI_BACKGROUND);
+
+ /****************************************************************************/
+ /**
+ * is_new_app_media - false
+ * curr_app->hmi_level() -mobile_api::HMILevel::HMI_LIMITED
+ */
+ (*sh_app_first).set_hmi_level(hmi_limit);
+
+ return_put = app_manager->PutApplicationInFull(sh_app_second);
+
+ EXPECT_EQ(return_put, am::mobile_api::HMILevel::HMI_FULL);
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+ app_manager->UnregisterApplication(65547, mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ RemovedDevice(device_id::SECOND_DEVICE_ID);
+ sleep(2);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, OnHMIStartedCooperation) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ std::list<hmi_message_handler::MessageSharedPointer>* array_message;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ array_message = hmi_message_handler_interceptor->GetMasMessage();
+
+ /****************************************************************************/
+
+ app_manager->OnHMIStartedCooperation();
+ sleep(3);
+ EXPECT_EQ(array_message->size(), 6);
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, begin_end_audio_pass_thru) {
+ /**
+ * Init params
+ */
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ /****************************************************************************/
+
+ EXPECT_TRUE(app_manager->begin_audio_pass_thru());
+
+ EXPECT_FALSE(app_manager->begin_audio_pass_thru());
+
+ EXPECT_TRUE(app_manager->end_audio_pass_thru());
+
+ EXPECT_FALSE(app_manager->end_audio_pass_thru());
+}
+
+TEST(TestApplicationManager, SendAudioPassThroughNotification) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ std::list<hmi_message_handler::MessageSharedPointer>* array_message;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ array_message = hmi_message_handler_interceptor->GetMasMessage();
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+
+ if (!sh_app_first.valid()) {
+ AddDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_first.valid());
+ }
+
+ /****************************************************************************/
+
+ uint32_t session_key = connect_key::FIRST_CONNECTION_KEY;
+ std::vector<uint8_t> binaryData;
+ app_manager->SendAudioPassThroughNotification(session_key, binaryData);
+
+ EXPECT_EQ(array_message->size(), 1);
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, GetDeviceName) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ AddDevice(device_id::FIRST_DEVICE_ID);
+
+ /****************************************************************************/
+ /**
+ * nonexistent device
+ */
+ std::string str = app_manager->GetDeviceName(100500);
+
+ EXPECT_TRUE(str.empty());
+
+ /****************************************************************************/
+ /**
+ * existent device
+ */
+ str = app_manager->GetDeviceName(device_id::FIRST_DEVICE_ID);
+
+ EXPECT_FALSE(str.empty());
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, OnMobileMessageSent) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+ protocol_handler::RawMessagePtr raw_message;
+
+ app_manager->OnMobileMessageSent(raw_message);
+}
+
+TEST(TestApplicationManager, OnErrorSending) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+ hmi_message_handler::MessageSharedPointer hmi_message;
+
+ app_manager->OnErrorSending(hmi_message);
+}
+
+TEST(TestApplicationManager, OnDeviceListUpdated) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ std::list<hmi_message_handler::MessageSharedPointer>* array_message;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+ //sleep(1);
+ array_message = hmi_message_handler_interceptor->GetMasMessage();
+
+ connection_handler::DeviceList device_list;
+
+ transport_manager::DeviceHandle device_handler_test = 10;
+ std::string mac_address_test = "255.255.255.0";
+ std::string name_test = "test_DeviceInfo";
+
+ transport_manager::ConnectionUID connection_id_test = 10;
+
+ transport_manager::DeviceInfo device_info(
+ device_handler_test,
+ mac_address_test,
+ name_test);
+
+ device_list.insert(connection_handler::DeviceList::value_type(
+ device_info.device_handle(),
+ connection_handler::Device(
+ device_info.device_handle(),
+ device_info.name(),
+ device_info.mac_address())));
+ sleep(1);
+
+ /****************************************************************************/
+
+ app_manager->OnDeviceListUpdated(device_list);
+ sleep(2);
+
+ EXPECT_EQ(array_message->size(), 1);
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, RemoveDevice) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ app_manager->RemoveDevice(0);
+}
+
+TEST(TestApplicationManager, IsAudioStreamingAllowed) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+
+ if (!sh_app_first.valid()) {
+ AddDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_first.valid());
+ }
+
+ am::mobile_api::HMILevel::eType hmi_limit =
+ am::mobile_api::HMILevel::HMI_LIMITED;
+
+ am::mobile_api::HMILevel::eType hmi_full = am::mobile_api::HMILevel::HMI_FULL;
+ am::mobile_api::HMILevel::eType hmi_background =
+ am::mobile_api::HMILevel::HMI_BACKGROUND;
+
+ /****************************************************************************/
+ /**
+ * hmi_level - HMI_FULL
+ */
+ (*sh_app_first).set_hmi_level(hmi_full);
+
+ EXPECT_TRUE(app_manager->IsAudioStreamingAllowed(
+ connect_key::FIRST_CONNECTION_KEY));
+
+ /****************************************************************************/
+ /**
+ * hmi_level - HMI_LIMITED
+ */
+ (*sh_app_first).set_hmi_level(hmi_limit);
+
+ EXPECT_TRUE(app_manager->IsAudioStreamingAllowed(
+ connect_key::FIRST_CONNECTION_KEY));
+
+ /****************************************************************************/
+ /**
+ * hmi_level - HMI_BACKGROUND
+ */
+ (*sh_app_first).set_hmi_level(hmi_background);
+
+ EXPECT_FALSE(app_manager->IsAudioStreamingAllowed(
+ connect_key::FIRST_CONNECTION_KEY));
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, IsVideoStreamingAllowed) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+
+ if (!sh_app_first.valid()) {
+ AddDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_first.valid());
+ }
+
+ am::mobile_api::HMILevel::eType hmi_limit =
+ am::mobile_api::HMILevel::HMI_LIMITED;
+
+ am::mobile_api::HMILevel::eType hmi_full = am::mobile_api::HMILevel::HMI_FULL;
+ am::mobile_api::HMILevel::eType hmi_background =
+ am::mobile_api::HMILevel::HMI_BACKGROUND;
+
+ /****************************************************************************/
+ /**
+ * hmi_level - HMI_FULL
+ * hmi_supports_navi_streaming - true
+ */
+ (*sh_app_first).set_hmi_level(hmi_full);
+ (*sh_app_first).set_hmi_supports_navi_streaming(true);
+
+ EXPECT_TRUE(app_manager->IsVideoStreamingAllowed(
+ connect_key::FIRST_CONNECTION_KEY));
+
+ /****************************************************************************/
+ /**
+ * hmi_level - HMI_LIMITED
+ */
+ (*sh_app_first).set_hmi_level(hmi_limit);
+
+ EXPECT_FALSE(app_manager->IsVideoStreamingAllowed(
+ connect_key::FIRST_CONNECTION_KEY));
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, GenerateGrammarID) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ EXPECT_TRUE((app_manager->GenerateGrammarID() >= 0));
+}
+
+TEST(TestApplicationManager, OnServiceStartedCallback) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ connection_handler::DeviceHandle device_handle = 11;
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+
+ if (!sh_app_first.valid()) {
+ AddDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_first.valid());
+ }
+
+ /****************************************************************************/
+ /**
+ * protocol_handler::ServiceType = kRpc
+ */
+ EXPECT_TRUE(app_manager->OnServiceStartedCallback(
+ device_handle,
+ connect_key::FIRST_CONNECTION_KEY,
+ protocol_handler::kRpc));
+
+ /****************************************************************************/
+ /**
+ * protocol_handler::ServiceType = kMobileNav
+ * set_allowed_support_navigation - true
+ */
+ (*sh_app_first).set_allowed_support_navigation(true);
+
+ EXPECT_TRUE(app_manager->OnServiceStartedCallback(
+ device_handle,
+ connect_key::FIRST_CONNECTION_KEY,
+ protocol_handler::kMobileNav));
+
+ /****************************************************************************/
+ /**
+ * protocol_handler::ServiceType = kMobileNav
+ * set_allowed_support_navigation - false
+ */
+ (*sh_app_first).set_allowed_support_navigation(false);
+
+ EXPECT_FALSE(app_manager->OnServiceStartedCallback(
+ device_handle, connect_key::FIRST_CONNECTION_KEY,
+ protocol_handler::kMobileNav));
+
+ /****************************************************************************/
+ /**
+ * protocol_handler::ServiceType = kAudio
+ * set_allowed_support_navigation - true
+ */
+ (*sh_app_first).set_allowed_support_navigation(true);
+
+ EXPECT_TRUE(app_manager->OnServiceStartedCallback(
+ device_handle, connect_key::FIRST_CONNECTION_KEY,
+ protocol_handler::kAudio));
+
+ /****************************************************************************/
+ /**
+ * protocol_handler::ServiceType = kAudio
+ * set_allowed_support_navigation - false
+ */
+ (*sh_app_first).set_allowed_support_navigation(false);
+
+ EXPECT_FALSE(app_manager->OnServiceStartedCallback(
+ device_handle,
+ connect_key::FIRST_CONNECTION_KEY,
+ protocol_handler::kAudio));
+
+ /****************************************************************************/
+ /**
+ * type kInvalidServiceType
+ *
+ */
+ (*sh_app_first).set_allowed_support_navigation(false);
+
+ EXPECT_TRUE(app_manager->OnServiceStartedCallback(
+ device_handle, connect_key::FIRST_CONNECTION_KEY,
+ protocol_handler::kInvalidServiceType));
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, OnServiceEndedCallback) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ std::list<hmi_message_handler::MessageSharedPointer>* array_message;
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ array_message = hmi_message_handler_interceptor->GetMasMessage();
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+
+ if (!sh_app_first.valid()) {
+ AddDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_first.valid());
+ }
+ array_message->clear();
+
+ /****************************************************************************/
+ /**
+ * protocol_handler::kRpc
+ */
+ app_manager->OnServiceEndedCallback(connect_key::FIRST_CONNECTION_KEY,
+ protocol_handler::kRpc);
+ sleep(1);
+ EXPECT_FALSE(app_manager->application(connect_key::FIRST_CONNECTION_KEY));
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, SendMessageToMobile) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ std::list<protocol_handler::RawMessagePtr>* array_message;
+
+ transport_manager::TransportManager* transport_manager_;
+ transport_manager_ = transport_manager::TransportManagerDefault::instance();
+
+ protocol_handler::ProtocolHandlerImpl* protocol_handler_ =
+ new protocol_handler::ProtocolHandlerImpl(transport_manager_);
+
+ ProtocolHandlerInterceptor* protocol_handler_interceptor =
+ new ProtocolHandlerInterceptor(transport_manager_);
+
+ app_manager->set_protocol_handler(protocol_handler_interceptor);
+
+ array_message = protocol_handler_interceptor->GetMasRawMessage();
+
+ utils::SharedPtr<smart::SmartObject> so_message(new smart::SmartObject);
+
+ (*so_message)[am::strings::params][am::strings::function_id] =
+ (am::mobile_api::FunctionID::OnHMIStatusID);
+
+ (*so_message)[am::strings::params][am::strings::message_type] =
+ mobile_apis::messageType::request;
+
+ (*so_message)[jsn::S_PARAMS][am::strings::protocol_version] =
+ am::commands::CommandImpl::protocol_version_;
+
+ (*so_message)[jsn::S_PARAMS][am::strings::protocol_type] =
+ am::commands::CommandImpl::hmi_protocol_type_;
+
+ (*so_message)[am::strings::params][am::strings::connection_key] = 100500;
+
+ (*so_message)[am::strings::msg_params][am::strings::hmi_level] =
+ mobile_apis::HMILevel::HMI_BACKGROUND;
+
+ (*so_message)[am::strings::msg_params][am::strings::audio_streaming_state] =
+ 1;
+
+ (*so_message)[am::strings::msg_params][am::strings::system_context] = 1;
+
+ /****************************************************************************/
+ /**
+ *protocol_handler_ - NULL;
+ */
+
+ app_manager->set_protocol_handler(NULL);
+
+ app_manager->SendMessageToMobile(so_message);
+ sleep(1);
+ EXPECT_EQ(array_message->size(), 0);
+
+ /****************************************************************************/
+ /**
+ * Can't send msg to Mobile: failed to create string
+ */
+
+ app_manager->set_protocol_handler(protocol_handler_interceptor);
+
+ app_manager->SendMessageToMobile(so_message);
+ sleep(1);
+ EXPECT_EQ(array_message->size(), 0);
+
+ /****************************************************************************/
+ /**
+ * No application associated with connection key
+ */
+
+ (*so_message)[jsn::S_PARAMS][am::strings::protocol_version] =
+ am::kV2;
+ (*so_message)[jsn::S_PARAMS][am::strings::protocol_type] =
+ 0;
+
+ (*so_message)[am::strings::params][am::strings::message_type] =
+ application_manager::MessageType::kNotification;
+
+ app_manager->SendMessageToMobile(so_message);
+ sleep(1);
+ EXPECT_EQ(array_message->size(), 1);
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->set_protocol_handler(protocol_handler_);
+
+ delete protocol_handler_interceptor;
+}
+
+TEST(TestApplicationManager, ManageMobileCommand) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ utils::SharedPtr<smart::SmartObject> so_manage(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ /****************************************************************************/
+ /**
+ * APPLICATION_NOT_REGISTERED
+ */
+
+ (*so_reg)[jsn::S_PARAMS][am::strings::function_id] =
+ hmi_apis::FunctionID::BasicCommunication_UpdateDeviceList;
+
+ (*so_reg)[am::strings::params][am::strings::protocol_type] =
+ am::commands::CommandImpl::mobile_protocol_type_;
+
+ EXPECT_FALSE(app_manager->ManageMobileCommand(so_reg));
+}
+
+TEST(TestApplicationManager, SendMessageToHMI) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ std::list<hmi_message_handler::MessageSharedPointer>* array_message;
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor
+ = new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ array_message = hmi_message_handler_interceptor->GetMasMessage();
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+
+ if (!sh_app_first.valid()) {
+ AddDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_first.valid());
+ }
+ array_message->clear();
+
+ /****************************************************************************/
+ /**
+ * Send message to HMI
+ */
+ utils::SharedPtr<smart::SmartObject> so_to_hmi(new smart::SmartObject);
+ (*so_to_hmi)[jsn::S_PARAMS][am::strings::function_id] =
+ hmi_apis::FunctionID::UI_Show;
+ (*so_to_hmi)[jsn::S_PARAMS][am::strings::message_type] =
+ mobile_apis::messageType::request;
+ (*so_to_hmi)[jsn::S_PARAMS][am::strings::protocol_version] =
+ am::commands::CommandImpl::protocol_version_;
+ (*so_to_hmi)[jsn::S_PARAMS][am::strings::protocol_type] =
+ am::commands::CommandImpl::hmi_protocol_type_;
+ (*so_to_hmi)[jsn::S_PARAMS][am::strings::correlation_id] =
+ app_manager->GetNextHMICorrelationID();
+
+ app_manager->SendMessageToHMI(so_to_hmi);
+ sleep(1);
+
+ EXPECT_EQ(array_message->size(), 1);
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, ManageHMICommand) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ utils::SharedPtr<smart::SmartObject> so_reg(new smart::SmartObject);
+ am::ApplicationSharedPtr sh_app_first;
+
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ std::list<hmi_message_handler::MessageSharedPointer>* array_message;
+
+ hmi_message_handler::HMIMessageHandlerImpl* hmi_handler =
+ hmi_message_handler::HMIMessageHandlerImpl::instance();
+
+ HMIMessageHandlerInterceptor* hmi_message_handler_interceptor =
+ new HMIMessageHandlerInterceptor;
+
+ app_manager->set_hmi_message_handler(hmi_message_handler_interceptor);
+
+ array_message = hmi_message_handler_interceptor->GetMasMessage();
+
+ RegistrSO(so_reg);
+
+ sh_app_first = app_manager->application(connect_key::FIRST_CONNECTION_KEY);
+
+ if (sh_app_first.valid()) {
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(2);
+ }
+
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+
+ if (!sh_app_first.valid()) {
+ AddDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ sh_app_first = app_manager->RegisterApplication(so_reg);
+ ASSERT_TRUE(sh_app_first.valid());
+ }
+ array_message->clear();
+
+ /****************************************************************************/
+ /**
+ * Send message to HMI
+ */
+ utils::SharedPtr<smart::SmartObject> so_to_hmi(new smart::SmartObject);
+
+ (*so_to_hmi)[jsn::S_PARAMS][am::strings::function_id] =
+ hmi_apis::FunctionID::UI_Show;
+ (*so_to_hmi)[jsn::S_PARAMS][am::strings::message_type] =
+ mobile_apis::messageType::request;
+ (*so_to_hmi)[jsn::S_PARAMS][am::strings::protocol_version] =
+ am::commands::CommandImpl::protocol_version_;
+ (*so_to_hmi)[jsn::S_PARAMS][am::strings::protocol_type] =
+ am::commands::CommandImpl::hmi_protocol_type_;
+ (*so_to_hmi)[jsn::S_PARAMS][am::strings::correlation_id] = app_manager
+ ->GetNextHMICorrelationID();
+
+ app_manager->SendMessageToHMI(so_to_hmi);
+ sleep(1);
+
+ EXPECT_EQ(array_message->size(), 1);
+
+ /****************************************************************************/
+ /**
+ * Finish test
+ */
+ app_manager->UnregisterApplication(connect_key::FIRST_CONNECTION_KEY,
+ mobile_apis::Result::SUCCESS);
+ sleep(1);
+
+ RemovedDevice(device_id::FIRST_DEVICE_ID);
+ sleep(1);
+ app_manager->set_hmi_message_handler(hmi_handler);
+
+ delete hmi_message_handler_interceptor;
+}
+
+TEST(TestApplicationManager, set_application_id) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+ bool bool_value = true;
+
+ /****************************************************************************/
+ /**
+ * application_id - true
+ */
+ int32_t correlation_id = 5;
+ int32_t app_id = 6;
+
+ app_manager->set_application_id(correlation_id, app_id);
+
+ bool_value = (app_manager->application_id(correlation_id) == app_id);
+ EXPECT_TRUE(bool_value);
+
+ /****************************************************************************/
+ /**
+ * application_id - false
+ */
+
+ bool_value = (app_manager->application_id(correlation_id) == app_id);
+ EXPECT_FALSE(bool_value);
+}
+
+TEST(TestApplicationManager, SaveBinary) {
+ /****************************************************************************/
+ /**
+ * Init params
+ */
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ std::vector<uint8_t> binary_data;
+ std::string file_path = "";
+ std::string file_name = "";
+ uint32_t offset = 0;
+
+ /****************************************************************************/
+ /**
+ * offset != 0
+ * file_size != offset
+ */
+ offset = 1;
+
+ EXPECT_EQ(app_manager->SaveBinary(binary_data, file_path, file_name, offset),
+ mobile_apis::Result::INVALID_DATA);
+
+ /****************************************************************************/
+ /**
+ * offset = 0
+ */
+ file_path = "./AppManagerImplTest/";
+ file_name = "temp.jpg";
+ offset = 0;
+ binary_data.clear();
+
+ file_system::ReadBinaryFile("./AppManagerImplTest/icon.png", binary_data);
+
+ EXPECT_EQ(app_manager->SaveBinary(binary_data, file_path, file_name, offset),
+ mobile_apis::Result::SUCCESS);
+
+}
+
} // namespace test
#endif // TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_TEST_APP_MANAGER_H_
printf("\n\n\n after init in Admin \n\n\n");
- //////////////////////////////////////////////
+ /**************************************************************************/
// Smoke test
- SmokeTestExpMedia("./components/application_manager/rpc/XmlTests");
+ // SmokeTestExpMedia("./components/application_manager/rpc/XmlTests");
sleep(5);
}
} // namespace test
ApplicationManagerImplTest::ApplicationManagerImplTest()
: app_(NULL) {
- app_ = am::ApplicationManagerImpl::instance();
- //app_ = new application_manager::ApplicationManagerImpl;
- app_->application_list_;
}
ApplicationManagerImplTest::~ApplicationManagerImplTest() {
}
-const std::map<int32_t, am::ApplicationSharedPtr>&
-ApplicationManagerImplTest::GetApplications() {
- return app_->applications_;
-}
-
const std::set<am::ApplicationSharedPtr>&
-ApplicationManagerImplTest::GetApplicationList() {
+ApplicationManagerImplTest::GetApplications() {
return app_->application_list_;
}
return app_->protocol_handler_;
}
-const policies::PolicyManager* ApplicationManagerImplTest::GetPolicyManager() {
+const policy::PolicyManager* ApplicationManagerImplTest::GetPolicyManager() {
return app_->policy_manager_;
}
return app_->hmi_capabilities_;
}
-const am::policies_manager::PoliciesManager&
-ApplicationManagerImplTest::GetPoliciesManager() {
- return app_->policies_manager_;
-}
-
const hmi_apis::HMI_API* ApplicationManagerImplTest::GetHmiSoFactory() {
return app_->hmi_so_factory_;
}
return app_->messages_to_hmi_;
}
+HMIMessageHandlerInterceptor::HMIMessageHandlerInterceptor() {
+}
+
+HMIMessageHandlerInterceptor::~HMIMessageHandlerInterceptor() {
+}
+
+void HMIMessageHandlerInterceptor::SendMessageToHMI(
+ hmi_message_handler::MessageSharedPointer message) {
+ mas_mess.push_back(message);
+ printf("\n\n message.json = %s\n\n",(*message).json_message().data());
+}
+
+void HMIMessageHandlerInterceptor::OnMessageReceived(
+ utils::SharedPtr<application_manager::Message> message) {
+}
+
+void HMIMessageHandlerInterceptor::OnErrorSending(
+ utils::SharedPtr<application_manager::Message> message) {
+}
+
+void HMIMessageHandlerInterceptor::AddHMIMessageAdapter(
+ hmi_message_handler::HMIMessageAdapter* adapter) {
+}
+
+void HMIMessageHandlerInterceptor::RemoveHMIMessageAdapter(
+ hmi_message_handler::HMIMessageAdapter* adapter) {
+}
+
+std::list<hmi_message_handler::MessageSharedPointer>*
+HMIMessageHandlerInterceptor::GetMasMessage() {
+ return &mas_mess;
+}
+
+ProtocolHandlerInterceptor::ProtocolHandlerInterceptor(
+ transport_manager::TransportManager* transport_manager_param)
+ : ProtocolHandlerImpl(transport_manager_param) {
+}
+
+ProtocolHandlerInterceptor::~ProtocolHandlerInterceptor() {
+}
+
+void ProtocolHandlerInterceptor::SendMessageToMobileApp(
+ const protocol_handler::RawMessagePtr& message,
+ bool final_message) {
+ printf("\n\n in SendMessageToMobileApp \n\n");
+ mas_mess.push_back(message);
+}
+
+std::list<protocol_handler::RawMessagePtr>*
+ProtocolHandlerInterceptor::GetMasRawMessage() {
+ return &mas_mess;
+}
+
+ProtocolHandlerInterceptor::ProtocolHandlerInterceptor(
+ const ProtocolHandlerInterceptor&)
+ : ProtocolHandlerImpl(NULL) {
+}
+
+ProtocolHandlerInterceptor* ProtocolHandlerInterceptor::operator=(
+ const ProtocolHandlerInterceptor&) {
+ return this;
+}
+
void RegistrSO(utils::SharedPtr<smart::SmartObject> AppRegRequest) {
(*AppRegRequest)[jsn::S_PARAMS][am::strings::function_id] =
mobile_apis::FunctionID::RegisterAppInterfaceID;
mobile_apis::messageType::request;
(*AppRegRequest)[jsn::S_PARAMS][am::strings::connection_key] = 65546;
+ (*AppRegRequest)[jsn::S_PARAMS][am::strings::protocol_version] = 2;
(*AppRegRequest)[jsn::S_MSG_PARAMS][am::strings::app_name] =
"SyncProxyTester";
[am::strings::hmi_display_language_desired] =
hmi_apis::Common_Language::EN_US;
- (*AppRegRequest)[jsn::S_MSG_PARAMS][am::strings::app_id] = "65537";
+ (*AppRegRequest)[jsn::S_MSG_PARAMS][am::strings::app_id] = "65546";
(*AppRegRequest)[jsn::S_MSG_PARAMS]
[am::strings::sync_msg_version]["majorVersion"] = 2;
(*AppRegRequest)[jsn::S_MSG_PARAMS]
(*message_to_app).set_connection_key(
(*so)[jsn::S_PARAMS][am::strings::connection_key].asInt());
(*message_to_app).set_message_type(application_manager::kRequest);
+ (*message_to_app).set_protocol_version(static_cast<am::ProtocolVersion>(
+ (*so)[jsn::S_PARAMS][am::strings::protocol_version].asUInt()));
NsSmartDeviceLink::NsJSONHandler::Formatters::CFormatterJsonSDLRPCv2::
toString((*so), str);
connection_id_test);
}
+void RemovedDevice(uint32_t value) {
+ connection_handler::ConnectionHandlerImpl* connection_handle =
+ connection_handler::ConnectionHandlerImpl::instance();
+
+ transport_manager::DeviceHandle device_handler_test = value;
+ std::string mac_address_test = "255.255.255.0";
+ std::string name_test = "test_DeviceInfo";
+
+ transport_manager::ConnectionUID connection_id_test = value;
+
+ transport_manager::DeviceInfo device_info_test(
+ device_handler_test,
+ mac_address_test,
+ name_test);
+
+ connection_handle->OnDeviceRemoved(device_info_test);
+}
+
/*
am::ApplicationSharedPtr RegistrApp() {
connection_handler::ConnectionHandlerImpl* connection_handler_ =
*/
#include "rpc/init_hmi.h"
+#include "utils/logger.h"
namespace InitializeHMI {
+
+CREATE_LOGGERPTR_GLOBAL(logger_, "appMain")
+
#ifdef __QNX__
bool Execute(std::string command, const char * const *) {
- log4cxx::LoggerPtr logger = log4cxx::LoggerPtr(
- log4cxx::Logger::getLogger("appMain"));
if (system(command.c_str()) == -1) {
LOG4CXX_INFO(logger, "Can't start HMI!");
return false;
}
#else
bool Execute(std::string file, const char * const * argv) {
- log4cxx::LoggerPtr logger = log4cxx::LoggerPtr(
- log4cxx::Logger::getLogger("appMain"));
// Create a child process.
pid_t pid_hmi = fork();
* @return true if success otherwise false.
*/
bool InitHmi() {
- log4cxx::LoggerPtr logger = log4cxx::LoggerPtr(
- log4cxx::Logger::getLogger("appMain"));
struct stat sb;
if (stat("../src/appMain/hmi_link", &sb) == -1) {
LOG4CXX_INFO(logger, "File with HMI link doesn't exist!");
* @return true if success otherwise false.
*/
bool InitHmi() {
- log4cxx::LoggerPtr logger = log4cxx::LoggerPtr(
- log4cxx::Logger::getLogger("appMain"));
std::string kStartHmi = "./start_hmi.sh";
struct stat sb;
if (stat(kStartHmi.c_str(), &sb) == -1) {
- LOG4CXX_INFO(logger, "HMI start script doesn't exist!");
+ LOG4CXX_FATAL(logger, "HMI start script doesn't exist!");
return false;
}
}
#endif // QT_HMI
- log4cxx::LoggerPtr loggerInitHmi = log4cxx::LoggerPtr(
- log4cxx::Logger::getLogger("test_InitHMI"));
-
InitHMI::InitHMI()
: ThreadDelegate() {
}
#include "rpc/init_start_data.h"
#include "life_cycle.h"
+#include "application_manager/commands/command_impl.h"
+
+namespace test {
+
+const int CONNECT_KEY = 65537;
void InitStartData() {
printf("\n\n\n in initStartData\n\n\n");
- log4cxx::LoggerPtr logger_ = log4cxx::LoggerPtr(
- log4cxx::Logger::getLogger("initStartData"));
+ CREATE_LOGGERPTR_LOCAL(logger_, "initStartData")
LOG4CXX_INFO(logger_, " Application started!");
if (!main_namespace::LifeCycle::instance()->InitMessageSystem()) {
main_namespace::LifeCycle::instance()->StopComponents();
- // without this line log4cxx threads continue using some
- // instances destroyed by exit()
+ // without this line log4cxx threads continue using some
+ // instances destroyed by exit()
log4cxx::Logger::getRootLogger()->closeNestedAppenders();
exit(EXIT_FAILURE);
- }
- LOG4CXX_INFO(logger_, "InitMessageBroker successful");
+ } LOG4CXX_INFO(logger_, "InitMessageBroker successful");
if (profile::Profile::instance()->launch_hmi()) {
- if (profile::Profile::instance()->server_address() ==
- std::string(InitializeHMI::kLocalHostAddress)) {
+ if (profile::Profile::instance()->server_address()
+ == std::string(InitializeHMI::kLocalHostAddress)) {
LOG4CXX_INFO(logger_, "Start HMI on localhost");
sleep(1);
/*
- threads::ThreadOptions threadOption(16384);
- InitializeHMI::InitHMI* initHMI = new InitializeHMI::InitHMI;
- threads::Thread threadInitializeHMI("InitializeHMI", initHMI);
- //initHMI->threadMain();
- //threadInitializeHMI.startWithOptions(threadOption);
- threadInitializeHMI.start();
- threadInitializeHMI.join();
- */
+ threads::ThreadOptions threadOption(16384);
+ InitializeHMI::InitHMI* initHMI = new InitializeHMI::InitHMI;
+ threads::Thread threadInitializeHMI("InitializeHMI", initHMI);
+ //initHMI->threadMain();
+ //threadInitializeHMI.startWithOptions(threadOption);
+ threadInitializeHMI.start();
+ threadInitializeHMI.join();
+ */
if (!InitializeHMI::InitHmi()) {
main_namespace::LifeCycle::instance()->StopComponents();
// instances destroyed by exit()
log4cxx::Logger::getRootLogger()->closeNestedAppenders();
exit(EXIT_FAILURE);
- }
- LOG4CXX_INFO(logger_, "InitHmi successful");
+ } LOG4CXX_INFO(logger_, "InitHmi successful");
}
}
utils::SubscribeToTerminateSignal(
- &main_namespace::LifeCycle::StopComponentsOnSignal);
+ &main_namespace::LifeCycle::StopComponentsOnSignal);
}
-
void RegApp() {
connection_handler::ConnectionHandlerImpl* connection_handler_ =
connection_handler::ConnectionHandlerImpl::instance();
transport_manager::ConnectionUID connection_id_test = 1;
- transport_manager::DeviceInfo device_info_test(
- device_handler_test,
- mac_address_test,
- name_test);
+ transport_manager::DeviceInfo device_info_test(device_handler_test,
+ mac_address_test, name_test);
- // std::vector<transport_manager::DeviceInfo> device_list_test;
- // device_list_test.push_back(device_info_test);
- // connection_handler_->OnDeviceListUpdated(device_list_test);
connection_handler_->OnDeviceAdded(device_info_test);
- connection_handler_->OnConnectionEstablished(
- device_info_test,
- connection_id_test);
+ connection_handler_->OnConnectionEstablished(device_info_test,
+ connection_id_test);
sleep(5);
utils::SharedPtr<smart::SmartObject> AppRegRequest(new smart::SmartObject);
mobile_apis::FunctionID::RegisterAppInterfaceID;
(*AppRegRequest)[jsn::S_PARAMS][am::strings::message_type] =
mobile_apis::messageType::request;
-
- (*AppRegRequest)[jsn::S_PARAMS][am::strings::connection_key] = 65537;
+ (*AppRegRequest)[jsn::S_PARAMS][am::strings::protocol_version] =
+ am::commands::CommandImpl::protocol_version_;
+ (*AppRegRequest)[jsn::S_PARAMS][am::strings::connection_key] = CONNECT_KEY;
(*AppRegRequest)[jsn::S_MSG_PARAMS][am::strings::app_name] =
"SyncProxyTester";
= hmi_apis::Common_Language::EN_US;
(*AppRegRequest)[jsn::S_MSG_PARAMS][am::strings::app_id] = "65537";
- (*AppRegRequest)[jsn::S_MSG_PARAMS]
- [am::strings::sync_msg_version]["majorVersion"] = 2;
- (*AppRegRequest)[jsn::S_MSG_PARAMS]
- [am::strings::sync_msg_version]["minorVersion"] = 2;
- (*AppRegRequest)[jsn::S_MSG_PARAMS]
- [am::strings::is_media_application] = true;
- (*AppRegRequest)[jsn::S_MSG_PARAMS]
- [am::strings::app_hmi_type][0] = "NAVIGATION";
- (*AppRegRequest)[jsn::S_MSG_PARAMS]
- [am::strings::ngn_media_screen_app_name] = "SyncP";
- (*AppRegRequest)[jsn::S_MSG_PARAMS]
- [am::strings::vr_synonyms][0] = "VR SyncProxyTester";
+ (*AppRegRequest)[jsn::S_MSG_PARAMS][am::strings::sync_msg_version]
+ ["majorVersion"] = 2;
+ (*AppRegRequest)[jsn::S_MSG_PARAMS][am::strings::sync_msg_version]
+ ["minorVersion"] = 2;
+ (*AppRegRequest)[jsn::S_MSG_PARAMS][am::strings::is_media_application] = true;
+ (*AppRegRequest)[jsn::S_MSG_PARAMS][am::strings::app_hmi_type][0] =
+ "NAVIGATION";
+ (*AppRegRequest)[jsn::S_MSG_PARAMS][am::strings::ngn_media_screen_app_name] =
+ "SyncP";
+ (*AppRegRequest)[jsn::S_MSG_PARAMS][am::strings::vr_synonyms][0] =
+ "VR SyncProxyTester";
app_manager_->ManageMobileCommand(AppRegRequest);
-
- // -------------------------------------------------------------------------
- // Activate App
sleep(2);
+}
+
+void ActivateApp() {
+ am::ApplicationManagerImpl* app_manager_ =
+ am::ApplicationManagerImpl::instance();
+
utils::SharedPtr<smart::SmartObject> ActivateApp(new smart::SmartObject);
(*ActivateApp)[jsn::S_PARAMS][am::strings::function_id] =
hmi_apis::FunctionID::BasicCommunication_OnAppActivated;
app_manager_->ManageHMICommand(ActivateApp);
}
+} // namespace test
(*message_to_app).set_connection_key(
(*request_)[jsn::S_PARAMS][am::strings::connection_key].asInt());
(*message_to_app).set_message_type(application_manager::kRequest);
-
+ (*message_to_app).set_protocol_version(
+ static_cast<application_manager::ProtocolVersion>
+ ((*request_)[jsn::S_PARAMS][am::strings::protocol_version].asInt()));
NsSmartDeviceLink::NsJSONHandler::Formatters::CFormatterJsonSDLRPCv2::
toString((*request_), str);
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "application_manager/commands/command_impl.h"
+
#include "rpc/smoke_test_exp_media.h"
+
namespace test {
- void SmokeTestExpMedia(const char* patch) {
- am::ApplicationManagerImpl* app_manager_ =
- am::ApplicationManagerImpl::instance();
+ void SmokeTestExpMedia(const char* patch) {
ProtocolHandlerMockup* protocol_handler_test_ =
ProtocolHandlerMockup::instance();
HMIMessageHandlerTester* hmi_handler_test =
HMIMessageHandlerTester::instance();
+ am::ApplicationManagerImpl* app_manager_ =
+ am::ApplicationManagerImpl::instance();
+
utils::SharedPtr<am::Application> appl(app_manager_->application(65537));
- if (!(appl.valid())) {
+ if (!appl.valid()) {
RegApp();
sleep(3);
appl = app_manager_->application(65537);
}
}
- app_manager_->set_hmi_message_handler(hmi_handler_test);
- app_manager_->set_protocol_handler(protocol_handler_test_);
+ addTest("smoke_test_exp_media",
+ "init_smoke_test_exp_media",
+ &InitSmokeTestExpMedia,
+ true);
XmlParser* xmlp = XmlParser::instance();
new smart::SmartObject);
if (xmlp->GetRequestFromTest(&(*soForParser))) {
+ //application_manager::MessageHelper::PrintSmartObject((*soForParser));
*soRequest = (*soForParser)["request"];
*soResponse = (*soForParser)["response"];
-
-
(*soRequest)[jsn::S_PARAMS][am::strings::connection_key] = 65537;
(*soRequest)[jsn::S_PARAMS][am::strings::message_type] =
mobile_apis::messageType::request;
+ (*soRequest)[jsn::S_PARAMS][am::strings::protocol_version] = 3;
+ //am::commands::CommandImpl::protocol_version_;
addTest<ProtocolHandlerMockup*,
utils::SharedPtr<smart::SmartObject>,
return hmi_handler_test->CheckUntestableRequest();
}
+
+ bool InitSmokeTestExpMedia() {
+ am::ApplicationManagerImpl* app_manager_ =
+ am::ApplicationManagerImpl::instance();
+
+ ProtocolHandlerMockup* protocol_handler_test_ =
+ ProtocolHandlerMockup::instance();
+
+ HMIMessageHandlerTester* hmi_handler_test =
+ HMIMessageHandlerTester::instance();
+
+ utils::SharedPtr<am::Application> appl(app_manager_->application(65537));
+
+ if (!appl.valid()) {
+ RegApp();
+ sleep(3);
+ appl = app_manager_->application(65537);
+
+ if (!appl.valid()) {
+ return false;
+ }
+ }
+
+ ActivateApp();
+ sleep(2);
+ app_manager_->set_hmi_message_handler(hmi_handler_test);
+ app_manager_->set_protocol_handler(protocol_handler_test_);
+
+ return true;
+ }
} // namespace test
*/
#include "rpc/xml_parser.h"
+#include "config_profile/ini_file.h"
+#include "config_profile/profile.h"
+
namespace test {
std::vector<uint8_t> binStr;
- std::string fullPatch = "SyncProxyTester/" + msgValue;
- std::string full_file_path = file_system::FullPath(fullPatch);
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ am::ApplicationSharedPtr active_app = app_manager->active_application();
+ if (!active_app.valid()) {
+ return;
+ }
+ std::string app_name = (*active_app).name();
+
+ std::string fullPatch = profile::Profile::instance()->app_storage_folder();
+ std::string full_file_path = fullPatch + app_name + "/" + msgValue;
if (file_system::ReadBinaryFile(full_file_path, binStr)) {
(*so)[am::strings::binary_data] = binStr;
std::string msgValue(ToString(xmlParam->children->content));
if (!VerifyString(msgParam)) return;
- std::string fullPatch = "SyncProxyTester/" + msgValue;
- std::string full_file_path = file_system::FullPath(fullPatch);
+ am::ApplicationManagerImpl* app_manager =
+ am::ApplicationManagerImpl::instance();
+
+ am::ApplicationSharedPtr active_app = app_manager->active_application();
+ if (!active_app.valid()) {
+ return;
+ }
+ std::string app_name = (*active_app).name();
+
+ std::string fullPatch = profile::Profile::instance()->app_storage_folder();
+ std::string full_file_path = fullPatch + app_name+ "/" + msgValue;
(*so)[msgParam] = full_file_path;
}
ConfigProfile
formatters
jsoncpp
- log4cxx
)
if (EXTENDED_MEDIA_MODE)
create_test("test_MediaManager" "${SOURCES}" "${LIBRARIES}")
+if(ENABLE_LOG)
+ target_link_libraries("test_MediaManager" log4cxx)
+endif()
# vim: set ts=2 sw=2 et:
#include "media_manager/media_manager_impl.h"
#include "utils/threads/thread.h"
#include "utils/threads/thread_delegate.h"
+#include "utils/logger.h"
namespace test {
namespace components {
namespace media_manager_test {
-log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("media_manager_impl"));
+CREATE_LOGGERPTR_GLOBAL(logger_, "MediaManagerImplTest")
class MediaManagerTest : public ::testing::Test {
protected:
mediaManager->PlayA2DPSource(1);
// mediaManager->playA2DPSource(1);
- LOG4CXX_INFO(logger, ".Playing stream");
+ LOG4CXX_INFO(logger_, ".Playing stream");
//LOG4CXX_TRACE(logger, );
//while (true) {
usleep(10000000);
"./src/mobile_message_handler_test.cc"
"${LIBRARIES}")
-target_link_libraries ("test_mobile_message_handler"
- log4cxx)
+if(ENABLE_LOG)
+ target_link_libraries("test_mobile_message_handler" log4cxx)
+endif()
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/log4cxx.properties DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
#include "mobile_message_handler/mobile_message_handler_impl.h"
#include "protocol_handler/protocol_handler_impl.h"
-#include "utils/logger.h"
-
#include "utils/lock.h"
#include "utils/conditional_variable.h"
#include "utils/threads/thread.h"
//! ---------------------------------------------------------------------------
-log4cxx::LoggerPtr logger = log4cxx::LoggerPtr(
- log4cxx::Logger::getLogger("mobile_message_handler_test"));
-
sync_primitives::Lock lock;
sync_primitives::ConditionalVariable cond_var;
const unsigned int kTimeout = 2;
#include "request_watchdog/request_watchdog.h"
#include "utils/threads/thread.h"
#include "utils/threads/thread_delegate.h"
+#include "utils/logger.h"
namespace test {
namespace components {
namespace request_watchdog_test {
-log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("request_watchdog_test"));
+CREATE_LOGGERPTR_GLOBAL(logger_, "RequestWatchdogTest")
class RequestWatchdogTest : public ::testing::Test {
protected:
}
void RequestWatchdogSubscriber::onTimeoutExpired(request_watchdog::RequestInfo requestInfo) {
- LOG4CXX_TRACE_ENTER(logger);
- LOG4CXX_INFO(logger, this << "::onTimeoutExpired\n"
+ LOG4CXX_TRACE_ENTER(logger_);
+ LOG4CXX_INFO(logger_, this << "::onTimeoutExpired\n"
<< "for the following request: "
<< "\n ConnectionID : " << requestInfo.connectionID_
<< "\n CorrelationID : " << requestInfo.correlationID_
-find_package(DBus)
-
include_directories (
${CMAKE_SOURCE_DIR}/src/components/dbus/include
${CMAKE_SOURCE_DIR}/src/components/rpc_base/include
${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/gmock-1.7.0/gtest/include
${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/gmock-1.7.0/include
${CMAKE_SOURCE_DIR}/src/thirdPartyLibs/jsoncpp/include
- ${DBUS_INCLUDE_DIRS}
)
set (LIBRARIES
TEST(ValidatedTypes, TestMandatoryEnumDbusSignature) {
std::string sign;
- DbusSignature< Mandatory<Enum<TestEnum> > >(&sign);
+ DbusSignature< Enum<TestEnum> >(&sign);
ASSERT_EQ(sign, "i");
}
ASSERT_EQ(readback.size(), array_value.size());
}
-TEST(ValidatedTypesJson, ArrayNullTest) {
+TEST(ValidatedTypesJson, MandatoryArrayNullTest) {
Array<String<1, 32>, 2, 5> arr(&Value::null);
ASSERT_TRUE(arr.is_initialized());
- ASSERT_TRUE(arr.is_null());
ASSERT_FALSE(arr.is_valid());
}
Value* novalue = NULL;
Array<String<1, 32>, 2, 5> arr(novalue);
ASSERT_FALSE(arr.is_initialized());
- ASSERT_FALSE(arr.is_null());
ASSERT_FALSE(arr.is_valid());
}
-TEST(ValidatedTypesJson, MapNullTest) {
+TEST(ValidatedTypesJson, MandatoryMapNullTest) {
Map<String<1, 32>, 2, 5> map(&Value::null);
ASSERT_TRUE(map.is_initialized());
- ASSERT_TRUE(map.is_null());
ASSERT_FALSE(map.is_valid());
}
-TEST(ValidatedTypesJson, MapAbsentValueTest) {
+TEST(ValidatedTypesJson, OptionalMapAbsentValueTest) {
Value* novalue = NULL;
- Map<String<1, 32>, 0, 5> map(novalue);
+ Optional< Map<String<1, 32>, 0, 5> > map(novalue);
ASSERT_FALSE(map.is_initialized());
- ASSERT_FALSE(map.is_null());
ASSERT_TRUE(map.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;
#include "gtest/gtest.h"
#include "json/writer.h"
+#include "rpc_base/gtest_support.h"
#include "rpc_base/rpc_base.h"
#include "rpc_base/rpc_base_json_inl.h"
TEST(ValidatedTypes, TestBooleanInitializingConstructor) {
Boolean true_boolean(true);
- ASSERT_TRUE(true_boolean.is_valid());
+ ASSERT_RPCTYPE_VALID(true_boolean);
ASSERT_TRUE(true_boolean.is_initialized());
ASSERT_EQ(true_boolean, true);
Boolean false_boolean(false);
- ASSERT_TRUE(false_boolean.is_valid());
+ ASSERT_RPCTYPE_VALID(false_boolean);
ASSERT_TRUE(false_boolean.is_initialized());
ASSERT_EQ(false_boolean, false);
}
ASSERT_FALSE(integer.is_initialized());
ASSERT_EQ(integer, 4);
integer = 5;
- ASSERT_TRUE(integer.is_valid());
+ ASSERT_RPCTYPE_VALID(integer);
ASSERT_TRUE(integer.is_initialized());
ASSERT_EQ(integer, 5);
integer = 700;
ASSERT_EQ(invalid_integer, 200);
Integer<int32_t, 0, 100> valid_integer(42);
- ASSERT_TRUE(valid_integer.is_valid());
+ ASSERT_RPCTYPE_VALID(valid_integer);
ASSERT_TRUE(valid_integer.is_initialized());
ASSERT_EQ(valid_integer, 42);
}
TEST(ValidatedTypes, TestFloatInitializingConstructor) {
Float<13, 999, 10, 10> flt(4);
ASSERT_TRUE(flt.is_initialized());
- ASSERT_TRUE(flt.is_valid());
+ ASSERT_RPCTYPE_VALID(flt);
ASSERT_EQ(flt, 4.);
flt = 1.2;
ASSERT_EQ(val, "");
str = "Test";
ASSERT_TRUE(str.is_initialized());
- ASSERT_TRUE(str.is_valid());
+ ASSERT_RPCTYPE_VALID(str);
val = str;
ASSERT_EQ(val, "Test");
str = "Long string";
ASSERT_FALSE(str.is_valid());
str = "Hello";
ASSERT_TRUE(str.is_initialized());
- ASSERT_TRUE(str.is_valid());
+ ASSERT_RPCTYPE_VALID(str);
str = "Sh";
ASSERT_TRUE(str.is_initialized());
ASSERT_FALSE(str.is_valid());
ASSERT_FALSE(arr.is_valid());
arr.push_back("Text");
arr.push_back("Dext");
- ASSERT_TRUE(arr.is_valid());
+ ASSERT_RPCTYPE_VALID(arr);
ASSERT_TRUE(arr.is_initialized());
arr.push_back("Too long");
ASSERT_FALSE(arr.is_valid());
strings.push_back("Two");
Array<String<1, 5>, 2, 10> arr(strings);
ASSERT_TRUE(arr.is_initialized());
- ASSERT_TRUE(arr.is_valid());
+ ASSERT_RPCTYPE_VALID(arr);
}
-TEST(ValidatedTypes, TestEmptyArray) {
+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_TRUE(ai.is_valid());
+ ASSERT_FALSE(ai.is_valid());
ASSERT_FALSE(ai.is_initialized());
Json::FastWriter fw;
std::string serialized = fw.write(ai.ToJsonValue());
map["a"] = "Hello";
map["b"] = "World";
ASSERT_TRUE(map.is_initialized());
- ASSERT_TRUE(map.is_valid());
+ ASSERT_RPCTYPE_VALID(map);
map["c"] = "Too long";
ASSERT_FALSE(map.is_valid());
}
init_map["b"] = "World";
Map<String<1, 6>, 2, 10 > map(init_map);
ASSERT_TRUE(map.is_initialized());
- ASSERT_TRUE(map.is_valid());
+ ASSERT_RPCTYPE_VALID(map);
}
-TEST(ValidatedTypes, TestEmptyMap) {
+TEST(ValidatedTypes, TestEmptyMandatoryMap) {
Map<Integer<int8_t, 0, 10>, 0, 5> im;
- ASSERT_TRUE(im.is_valid());
+ ASSERT_FALSE(im.is_valid());
ASSERT_FALSE(im.is_initialized());
Json::FastWriter fw;
std::string serialized = fw.write(im.ToJsonValue());
ASSERT_FALSE(te.is_valid());
te = kValue1;
ASSERT_TRUE(te.is_initialized());
- ASSERT_TRUE(te.is_valid());
+ ASSERT_RPCTYPE_VALID(te);
ASSERT_EQ(te, kValue1);
te = TestEnum(42);
ASSERT_TRUE(te.is_initialized());
nullable_int = 5;
ASSERT_TRUE(nullable_int.is_initialized());
ASSERT_FALSE(nullable_int.is_null());
- ASSERT_TRUE(nullable_int.is_valid());
+ ASSERT_RPCTYPE_VALID(nullable_int);
nullable_int.set_to_null();
ASSERT_TRUE(nullable_int.is_initialized());
ASSERT_TRUE(nullable_int.is_null());
- ASSERT_TRUE(nullable_int.is_valid());
+ 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_TRUE(optional_nullable_int.is_valid());
+ 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_TRUE(optional_nullable_int.is_valid());
+ 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_TRUE(optional_nullable_int.is_valid());
+ ASSERT_RPCTYPE_VALID(optional_nullable_int);
}
TEST(ValidatedTypes, TestOptionalConstructor) {
Optional< Integer<int16_t, 3, 15> > optional_int;
ASSERT_FALSE(optional_int.is_initialized());
- ASSERT_TRUE(optional_int.is_valid());
+ 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_TRUE(optional_int.is_valid());
+ 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_TRUE(optional_string.is_valid());
+ ASSERT_RPCTYPE_VALID(optional_string);
std::string value = *optional_string;
ASSERT_EQ(value, "Hello world");
}
Integer<int32_t, 5, 90> val2(45);
val = val2;
ASSERT_TRUE(val2.is_initialized());
- ASSERT_TRUE(val2.is_valid());
+ 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
MockTransportAdapter(ITransportAdapterListener & Listener, IHandleGenerator & HandleGenerator)
: mListener(Listener)
, mHandleGenerator(HandleGenerator)
- , logger_(log4cxx::LoggerPtr(log4cxx::Logger::getLogger("TransportManagerTest")))
{
}
protected:
ITransportAdapterListener & mListener;
IHandleGenerator & mHandleGenerator;
-#ifdef ENABLE_LOG
- static log4cxx::LoggerPtr logger_;
-#endif // ENABLE_LOG
};
/**
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include <cstring>
+
#include <sys/socket.h>
#include <sys/un.h>
#include <sstream>
ConfigProfile
)
-set (SOURCES
-# ./src/file_system_tests.cc
+set(SOURCES
+ ./src/file_system_tests.cc
+ ./src/data_time_tests.cc
./src/prioritized_queue_tests.cc
)
create_test("test_Utils" "${SOURCES}" "${LIBRARIES}")
-add_library("test_UtilsTest" "${SOURCES}")
+add_library("test_UtilsTest" ${SOURCES})
--- /dev/null
+/*
+* 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 DATA_TIME_TESTS_H
+#define DATA_TIME_TESTS_H
+
+#include <unistd.h>
+
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+#include "utils/date_time.h"
+
+namespace test {
+namespace components {
+namespace utils {
+ TEST(DateTimeTest, GetCurrentTime) {
+ const TimevalStruct time1 = date_time::DateTime::getCurrentTime();
+ ASSERT_NE(0, time1.tv_sec);
+ ASSERT_GE(time1.tv_usec, 0);
+
+ const TimevalStruct time2 = date_time::DateTime::getCurrentTime();
+ ASSERT_NE(0, time2.tv_sec);
+ ASSERT_GE(time2.tv_usec, 0);
+ ASSERT_GE(time2.tv_sec, time1.tv_sec);
+ }
+
+ TEST(DateTimeTest, GetmSecs) {
+ TimevalStruct time;
+ time.tv_sec = 1;
+ time.tv_usec = 2 * date_time::DateTime::MICROSECONDS_IN_MILLISECONDS;
+
+ ASSERT_EQ(time.tv_sec * date_time::DateTime::MILLISECONDS_IN_SECOND +
+ time.tv_usec / date_time::DateTime::MICROSECONDS_IN_MILLISECONDS,
+ date_time::DateTime::getmSecs(time));
+ }
+ TEST(DateTimeTest, GetuSecs) {
+ TimevalStruct time;
+ time.tv_sec = 3;
+ time.tv_usec = 4;
+
+ ASSERT_EQ(time.tv_sec * date_time::DateTime::MILLISECONDS_IN_SECOND *
+ date_time::DateTime::MICROSECONDS_IN_MILLISECONDS + time.tv_usec,
+ date_time::DateTime::getuSecs(time));
+ }
+ TEST(DateTimeTest, GetuSecsmSecs) {
+ TimevalStruct time;
+ time.tv_sec = 5;
+ time.tv_usec = 6;
+
+ ASSERT_EQ( date_time::DateTime::getmSecs(time),
+ date_time::DateTime::getuSecs(time) / date_time::DateTime::MICROSECONDS_IN_MILLISECONDS);
+ }
+
+ TEST(DateTimeTest, CalculateTimeSpan) {
+ const TimevalStruct time = date_time::DateTime::getCurrentTime();
+
+ const uint32_t sleep_time_mSec = 10;
+ usleep(sleep_time_mSec * date_time::DateTime::MICROSECONDS_IN_MILLISECONDS);
+
+ ASSERT_GE(date_time::DateTime::calculateTimeSpan(time),
+ sleep_time_mSec);
+ }
+
+ TEST(DateTimeTest, CalculateTimeDiff) {
+ TimevalStruct time1;
+ time1.tv_sec = 1;
+ time1.tv_usec = 2 * date_time::DateTime::MICROSECONDS_IN_MILLISECONDS;
+
+ TimevalStruct time2;
+ time2.tv_sec = 3;
+ time2.tv_usec = 4 * date_time::DateTime::MICROSECONDS_IN_MILLISECONDS;
+
+ //time2 to time1
+ TimevalStruct diff1;
+ diff1.tv_sec = time2.tv_sec - time1.tv_sec;
+ diff1.tv_usec = time2.tv_usec - time1.tv_usec;
+
+ const int64_t mSecDiff = static_cast<int64_t>(diff1.tv_sec) * 1000
+ + diff1.tv_usec / 1000;
+
+ ASSERT_EQ(mSecDiff,
+ date_time::DateTime::calculateTimeDiff(time2, time1));
+
+ //time1 to time2
+ TimevalStruct diff2;
+ diff2.tv_sec = time1.tv_sec - time2.tv_sec;
+ diff2.tv_usec = time1.tv_usec - time2.tv_usec;
+
+ const int64_t mSecDiff2 = static_cast<int64_t>(diff2.tv_sec) * 1000
+ + diff2.tv_usec / 1000;
+
+ ASSERT_EQ(mSecDiff2,
+ date_time::DateTime::calculateTimeDiff(time1, time2));
+ }
+} // namespace utils
+} // namespace components
+} // namespace test
+#endif // DATA_TIME_TESTS_H
--- /dev/null
+/*
+* 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 "utils/data_time_tests.h"
#include "gmock/gmock.h"
#include "config_profile/profile.h"
+#include "utils/logger.h"
+
#include "utils/file_system_tests.h"
+#include "utils/data_time_tests.h"
#include "utils/prioritized_queue_tests.h"
#include "protocol_handler/protocol_handler_tm_test.h"
#include "application_manager/formatters_commands.h"
-#include "media_manager/media_manager_impl_test.h"
#include "SmartObjectDraftTest.h"
#include "SmartObjectInvalidTest.h"
#include "SmartObjectStressTest.h"
#include "SmartObjectUnitTest.h"
#include "TSharedPtrTest.h"
+//#include "media_manager/media_manager_impl_test.h"
//#include "jsoncpp/json_reader_test.h"
// #include "json_handler/smart_schema_draft_test.h"
int main(int argc, char **argv) {
::testing::InitGoogleMock(&argc, argv);
- profile::Profile::instance()->config_file_name("log4cxx.properties");
- log4cxx::PropertyConfigurator::configure("log4cxx.properties");
-
+ profile::Profile::instance()->config_file_name("smartDeviceLink.ini");
+ INIT_LOGGER("log4cxx.properties");
#ifdef TESTS_WITH_HMI
test::AdminAppTest app;
#endif
int result = RUN_ALL_TESTS();
-#ifdef __cplusplus
+#if defined(__cplusplus) and defined(GCOV_ENABLED)
__gcov_flush();
#endif
sleep(2);
return result;
}
-
notification::DummyNotification dn;
TdStruct tds;
tds.resArrMap["Hello"].push_back(R_SUCCESS);
- tds.optionalResArrMap["World"].push_back(R_INVALID_DATA);
+ (*tds.optionalResArrMap)["World"].push_back(R_INVALID_DATA);
dn.tds.push_back(tds);
ASSERT_TRUE(dn.is_valid());
dn.ToDbusWriter(&writer);
ASSERT_FALSE(reader.has_failed());
ASSERT_FALSE(reader.HasNext());
ASSERT_EQ(dn.tds[0].resArrMap["Hello"][0], R_SUCCESS);
- ASSERT_EQ(dn.tds[0].optionalResArrMap["World"][0], R_INVALID_DATA);
+ ASSERT_EQ((*dn.tds[0].optionalResArrMap)["World"][0], R_INVALID_DATA);
}
}
#include <test_rpc_interface/interface.h>
#include <test_rpc_interface/functions.h>
+
#include "json/reader.h"
#include "json/writer.h"
+#include "rpc_base/gtest_support.h"
namespace test {
using namespace rpc::test_rpc_interface;
Value json_value = JsonValue(org_json);
notification::OnAppInterfaceUnregistered oaiu(&json_value);
ASSERT_TRUE(oaiu.is_initialized());
- ASSERT_TRUE(oaiu.is_valid());
+ ASSERT_RPCTYPE_VALID(oaiu);
std::string serialized = writer.write(oaiu.ToJsonValue());
ASSERT_EQ(org_json, serialized);
TEST_F(GeneratedInterfaceTests, FunctionWithoutParams) {
notification::OnAudioPassThru oapt;
ASSERT_FALSE(oapt.is_initialized());
- ASSERT_TRUE(oapt.is_valid());
+ ASSERT_FALSE(oapt.is_valid());
+ oapt.mark_initialized();
+ ASSERT_TRUE(oapt.is_initialized());
+ ASSERT_RPCTYPE_VALID(oapt);
std::string serialized = writer.write(oapt.ToJsonValue());
ASSERT_EQ("{}\n", serialized);
}
Value json_value = JsonValue(org_json);
request::AddSubMenu aasm(&json_value);
ASSERT_TRUE(aasm.is_initialized());
- ASSERT_TRUE(aasm.is_valid());
+ ASSERT_RPCTYPE_VALID(aasm);
ASSERT_EQ(aasm.position, 1000);
std::string serialized = writer.write(aasm.ToJsonValue());
init_map.insert(std::make_pair("two", "Second value"));
choice = Choice(1, "Menu name", init_map);
ASSERT_TRUE(choice.is_initialized());
- ASSERT_TRUE(choice.is_valid());
+ ASSERT_RPCTYPE_VALID(choice);
std::string serialized = writer.write(choice.ToJsonValue());
ASSERT_EQ(expected_json, serialized);
TdStruct ts;
ts.resArrMap["Hello"].push_back(R_SUCCESS);
- ts.optionalResArrMap["World"].push_back(R_INVALID_DATA);
+ (*ts.optionalResArrMap)["World"].push_back(R_INVALID_DATA);
ASSERT_TRUE(ts.is_initialized());
- ASSERT_TRUE(ts.is_valid());
+ ASSERT_RPCTYPE_VALID(ts);
std::string serialized = writer.write(ts.ToJsonValue());
ASSERT_EQ(expected_json, serialized);
}
ASSERT_FALSE(with_nullable.nullableInt.is_valid());
ASSERT_FALSE(with_nullable.nullableInt.is_null());
with_nullable.nullableInt.set_to_null();
- ASSERT_TRUE(with_nullable.is_valid());
+ ASSERT_RPCTYPE_VALID(with_nullable);
ASSERT_TRUE(with_nullable.is_initialized());
ASSERT_TRUE(with_nullable.nullableInt.is_null());
- ASSERT_TRUE(with_nullable.nullableInt.is_valid());
+ ASSERT_RPCTYPE_VALID(with_nullable.nullableInt);
ASSERT_TRUE(with_nullable.nullableInt.is_initialized());
}
Value json_value = JsonValue(input_json);
TestStructWithNullableParam with_nullable(&json_value);
ASSERT_TRUE(with_nullable.is_initialized());
- ASSERT_TRUE(with_nullable.is_valid());
+ ASSERT_RPCTYPE_VALID(with_nullable);
ASSERT_TRUE(with_nullable.nullableInt.is_null());
std::string result = writer.write(with_nullable.ToJsonValue());
ASSERT_EQ(input_json, result);
Value json_value = JsonValue(input_json);
TestStructWithNullableParam with_nullable(&json_value);
ASSERT_TRUE(with_nullable.is_initialized());
- ASSERT_TRUE(with_nullable.is_valid());
+ ASSERT_RPCTYPE_VALID(with_nullable);
ASSERT_FALSE(with_nullable.nullableInt.is_null());
ASSERT_EQ(3, with_nullable.nullableInt);
std::string result = writer.write(with_nullable.ToJsonValue());
strct_with_nullable.nullableEnum = IT_DYNAMIC;
strct_with_nullable.nonNullableEnum = IT_STATIC;
ASSERT_TRUE(strct_with_nullable.is_initialized());
- ASSERT_TRUE(strct_with_nullable.is_valid());
+ ASSERT_RPCTYPE_VALID(strct_with_nullable);
std::string result = writer.write(strct_with_nullable.ToJsonValue());
const char* awaited_json1 = "{\"nonNullableEnum\":\"STATIC\",\"nullableEnum\":\"DYNAMIC\"}\n";
ASSERT_EQ(awaited_json1, result);
strct_with_nullable.nullableEnum.set_to_null();
ASSERT_TRUE(strct_with_nullable.is_initialized());
- ASSERT_TRUE(strct_with_nullable.is_valid());
+ ASSERT_RPCTYPE_VALID(strct_with_nullable);
result = writer.write(strct_with_nullable.ToJsonValue());
const char* awaited_json2 = "{\"nonNullableEnum\":\"STATIC\",\"nullableEnum\":null}\n";
ASSERT_EQ(awaited_json2, result);
ASSERT_FALSE(swntd.is_valid());
swntd.nullableTdResult = R_SUCCESS;
ASSERT_TRUE(swntd.is_initialized());
- ASSERT_TRUE(swntd.is_valid());
+ ASSERT_RPCTYPE_VALID(swntd);
ASSERT_EQ(R_SUCCESS, swntd.nullableTdResult);
swntd.nullableTdResult.set_to_null();
ASSERT_FALSE(nmoni.nullableMap.is_null());
nmoni.nullableMap.set_to_null();
ASSERT_TRUE(nmoni.is_initialized());
- ASSERT_TRUE(nmoni.is_valid());
+ ASSERT_RPCTYPE_VALID(nmoni);
ASSERT_TRUE(nmoni.nullableMap.is_null());
const char* awaited_json = "{\"nullableMap\":null}\n";
std::string result = writer.write(nmoni.ToJsonValue());
nmoni.nullableMap["Hello"].set_to_null();
ASSERT_TRUE(nmoni.is_initialized());
- ASSERT_TRUE(nmoni.is_valid());
+ ASSERT_RPCTYPE_VALID(nmoni);
ASSERT_FALSE(nmoni.nullableMap.is_null());
ASSERT_TRUE(nmoni.nullableMap["Hello"].is_null());
const char* awaited_json = "{\"nullableMap\":{\"Hello\":null}}\n";
TEST_F(GeneratedInterfaceTests, EmptyStructTests) {
EmptyStruct e;
- ASSERT_TRUE(e.is_valid());
+ ASSERT_TRUE(e.struct_empty());
+ ASSERT_FALSE(e.is_valid());
ASSERT_FALSE(e.is_initialized());
+ e.mark_initialized();
+ ASSERT_TRUE(e.struct_empty());
+ ASSERT_RPCTYPE_VALID(e);
+ ASSERT_TRUE(e.is_initialized());
}
TEST_F(GeneratedInterfaceTests, StructWithOptionalEmptyStructFieldTest) {
StructWithOptionalEmptyStructField oe;
- ASSERT_TRUE(oe.is_valid());
+ ASSERT_FALSE(oe.is_valid());
ASSERT_FALSE(oe.is_initialized());
+ oe.emptyOne->mark_initialized();
+ ASSERT_RPCTYPE_VALID(oe);
+ ASSERT_TRUE(oe.is_initialized());
+ ASSERT_FALSE(oe.struct_empty());
+ ASSERT_TRUE(oe.emptyOne->struct_empty());
}
TEST_F(GeneratedInterfaceTests, StructWithMandatoryEmptyStructFieldTest) {
StructWithMandatoryEmptyStructField me;
- ASSERT_TRUE(me.is_valid());
+ ASSERT_FALSE(me.is_valid());
ASSERT_FALSE(me.is_initialized());
}
TEST_F(GeneratedInterfaceTests, EmptyStructJsonTests) {
EmptyStruct e;
- ASSERT_TRUE(e.is_valid());
+ ASSERT_FALSE(e.is_valid());
ASSERT_FALSE(e.is_initialized());
-
+ e.mark_initialized();
+ ASSERT_RPCTYPE_VALID(e);
+ ASSERT_TRUE(e.is_initialized());
const char* expected_json = "{}\n";
ASSERT_EQ(expected_json, writer.write(e.ToJsonValue()));
}
TEST_F(GeneratedInterfaceTests, StructWithOptionalEmptyStructFieldJsonTest) {
StructWithOptionalEmptyStructField oe;
- ASSERT_TRUE(oe.is_valid());
+ ASSERT_FALSE(oe.is_valid());
ASSERT_FALSE(oe.is_initialized());
+ oe.mark_initialized();
+ ASSERT_RPCTYPE_VALID(oe);
+ ASSERT_TRUE(oe.is_initialized());
const char* expected_json = "{}\n";
ASSERT_EQ(expected_json, writer.write(oe.ToJsonValue()));
}
TEST_F(GeneratedInterfaceTests, StructWithMandatoryEmptyStructFieldJsonTest) {
StructWithMandatoryEmptyStructField me;
- ASSERT_TRUE(me.is_valid());
+ ASSERT_FALSE(me.is_valid());
ASSERT_FALSE(me.is_initialized());
+ me.emptyOne.mark_initialized();
+ ASSERT_RPCTYPE_VALID(me);
+ ASSERT_TRUE(me.is_initialized());
const char* expected_json = "{\"emptyOne\":{}}\n";
ASSERT_EQ(expected_json, writer.write(me.ToJsonValue()));
}
TEST_F(GeneratedInterfaceTests, StructWithOneOptionalIntFieldTest) {
StructWithOneOptionalIntField soo;
- ASSERT_TRUE(soo.is_valid());
+ ASSERT_FALSE(soo.is_valid());
ASSERT_FALSE(soo.is_initialized());
+ soo.mark_initialized();
+ ASSERT_TRUE(soo.is_initialized());
+ ASSERT_RPCTYPE_VALID(soo);
}
TEST_F(GeneratedInterfaceTests, StructWithOneOptionalInitializedIntFieldTest) {
StructWithOneOptionalIntField soo;
*soo.optionalInt = 13;
- ASSERT_TRUE(soo.is_valid());
+ ASSERT_RPCTYPE_VALID(soo);
ASSERT_TRUE(soo.is_initialized());
}
TEST_F(GeneratedInterfaceTests, StructWithOneOptionalIntFieldJsonTest) {
StructWithOneOptionalIntField soo;
- ASSERT_TRUE(soo.is_valid());
+ ASSERT_FALSE(soo.is_valid());
ASSERT_FALSE(soo.is_initialized());
+ soo.mark_initialized();
const char* expected_json = "{}\n";
ASSERT_EQ(expected_json, writer.write(soo.ToJsonValue()));
}
const char* input_json = "{\"optionalInt\":11}\n";
Json::Value json_value = JsonValue(input_json);
StructWithOneOptionalIntField soo(&json_value);
- ASSERT_TRUE(soo.is_valid());
+ ASSERT_RPCTYPE_VALID(soo);
ASSERT_TRUE(soo.is_initialized());
ASSERT_EQ(11, *soo.optionalInt);
ASSERT_EQ(input_json, writer.write(soo.ToJsonValue()));
TEST_F(GeneratedInterfaceTests, StructWithFieldOfStructThatMightBeEmptyTest) {
StructWithFieldOfStructThatMightBeEmpty sfme;
- ASSERT_TRUE(sfme.is_valid());
+ ASSERT_FALSE(sfme.is_valid());
ASSERT_FALSE(sfme.is_initialized());
+ ASSERT_TRUE(sfme.struct_empty());
*sfme.fieldThatMightBeEmpty.optionalInt = 5;
- ASSERT_TRUE(sfme.is_valid());
+ ASSERT_FALSE(sfme.struct_empty());
+ ASSERT_RPCTYPE_VALID(sfme);
ASSERT_TRUE(sfme.is_initialized());
}
TEST_F(GeneratedInterfaceTests, StructWithFieldOfStructThatMightBeEmptyJsonNoValueTest) {
StructWithFieldOfStructThatMightBeEmpty sfme;
- ASSERT_TRUE(sfme.is_valid());
+ ASSERT_TRUE(sfme.struct_empty());
+ ASSERT_FALSE(sfme.is_valid());
ASSERT_FALSE(sfme.is_initialized());
+ sfme.fieldThatMightBeEmpty.mark_initialized();
+ ASSERT_FALSE(sfme.struct_empty());
+ ASSERT_RPCTYPE_VALID(sfme);
+ ASSERT_TRUE(sfme.is_initialized());
const char* expcected_json = "{\"fieldThatMightBeEmpty\":{}}\n";
ASSERT_EQ(expcected_json, writer.write(sfme.ToJsonValue()));
}
const char* input_json = "{\"fieldThatMightBeEmpty\":{\"optionalInt\":12}}\n";
Json::Value json_value = JsonValue(input_json);
StructWithFieldOfStructThatMightBeEmpty sfme(&json_value);
- ASSERT_TRUE(sfme.is_valid());
+ ASSERT_RPCTYPE_VALID(sfme);
ASSERT_TRUE(sfme.is_initialized());
ASSERT_EQ(12, *sfme.fieldThatMightBeEmpty.optionalInt);
ASSERT_EQ(input_json, writer.write(sfme.ToJsonValue()));
TEST_F(GeneratedInterfaceTests, StructWithFieldOfOptionalMapTest) {
StructWithNullableOptionalMap snom;
- ASSERT_TRUE(snom.is_valid());
+ ASSERT_TRUE(snom.struct_empty());
+ ASSERT_FALSE(snom.is_valid());
ASSERT_FALSE(snom.is_initialized());
- snom.nullableOptionalIntMap["a"] = 5;
- ASSERT_TRUE(snom.is_valid());
+ (*snom.nullableOptionalIntMap)["a"] = 5;
+ ASSERT_FALSE(snom.struct_empty());
+ ASSERT_RPCTYPE_VALID(snom);
ASSERT_TRUE(snom.is_initialized());
}
TEST_F(GeneratedInterfaceTests, StructWithFieldOfOptionalMapToJsonTest) {
StructWithNullableOptionalMap snom;
- ASSERT_TRUE(snom.is_valid());
+ ASSERT_TRUE(snom.struct_empty());
+ ASSERT_FALSE(snom.is_valid());
ASSERT_FALSE(snom.is_initialized());
+ snom.mark_initialized();
+ ASSERT_TRUE(snom.struct_empty());
+ ASSERT_RPCTYPE_VALID(snom);
+ ASSERT_TRUE(snom.is_initialized());
const char* expected_json = "{}\n";
ASSERT_EQ(expected_json, writer.write(snom.ToJsonValue()));
}
TEST_F(GeneratedInterfaceTests, StructWithFieldOfOptionalMapNulledToJsonTest) {
StructWithNullableOptionalMap snom;
- ASSERT_TRUE(snom.is_valid());
+ ASSERT_TRUE(snom.struct_empty());
+ ASSERT_FALSE(snom.is_valid());
ASSERT_FALSE(snom.is_initialized());
- snom.nullableOptionalIntMap.set_to_null();
+ snom.nullableOptionalIntMap->set_to_null();
+ ASSERT_FALSE(snom.struct_empty());
+ ASSERT_RPCTYPE_VALID(snom);
+ ASSERT_TRUE(snom.is_initialized());
const char* expected_json = "{\"nullableOptionalIntMap\":null}\n";
ASSERT_EQ(expected_json, writer.write(snom.ToJsonValue()));
}
const char* input_json = "{\"nullableOptionalIntMap\":null}\n";
Json::Value json_value = JsonValue(input_json);
StructWithNullableOptionalMap snom(&json_value);
- ASSERT_TRUE(snom.is_valid());
+ ASSERT_RPCTYPE_VALID(snom);
ASSERT_TRUE(snom.is_initialized());
- ASSERT_TRUE(snom.nullableOptionalIntMap.is_null());
+ ASSERT_TRUE(snom.nullableOptionalIntMap->is_null());
ASSERT_EQ(input_json, writer.write(snom.ToJsonValue()));
}
const char* input_json = "{\"nullableOptionalIntMap\":{\"Hello\":2}}\n";
Json::Value json_value = JsonValue(input_json);
StructWithNullableOptionalMap snom(&json_value);
- ASSERT_TRUE(snom.is_valid());
+ ASSERT_RPCTYPE_VALID(snom);
ASSERT_TRUE(snom.is_initialized());
- ASSERT_FALSE(snom.nullableOptionalIntMap.is_null());
+ ASSERT_FALSE(snom.nullableOptionalIntMap->is_null());
ASSERT_EQ(input_json, writer.write(snom.ToJsonValue()));
}
+TEST_F(GeneratedInterfaceTests, StructWithOptionalArrayTest) {
+ const char* expected_json = "{}\n";
+ StructWithOptionalIntArray soia;
+ ASSERT_TRUE(soia.struct_empty());
+ ASSERT_FALSE(soia.is_valid());
+ ASSERT_FALSE(soia.is_initialized());
+ soia.mark_initialized();
+ ASSERT_EQ(expected_json, writer.write(soia.ToJsonValue()));
+ (*soia.optionalIntArray).push_back(2);
+ ASSERT_RPCTYPE_VALID(soia);
+ ASSERT_TRUE(soia.is_initialized());
+ const char* expected_json2 = "{\"optionalIntArray\":[2]}\n";
+ ASSERT_EQ(expected_json2, writer.write(soia.ToJsonValue()));
+}
+
+TEST_F(GeneratedInterfaceTests, StructWithMandatoryArrayTest) {
+ const char* expected_json = "{\"mandatoryIntArray\":[]}\n";
+ StructWithMandatoryIntArray smia;
+ ASSERT_FALSE(smia.is_valid());
+ ASSERT_FALSE(smia.is_initialized());
+ smia.mandatoryIntArray.mark_initialized();
+ ASSERT_RPCTYPE_VALID(smia);
+ ASSERT_TRUE(smia.is_initialized());
+ ASSERT_EQ(expected_json, writer.write(smia.ToJsonValue()));
+
+ smia.mandatoryIntArray.push_back(3);
+ ASSERT_RPCTYPE_VALID(smia);
+ ASSERT_TRUE(smia.is_initialized());
+ const char* expected_json2 = "{\"mandatoryIntArray\":[3]}\n";
+ ASSERT_EQ(expected_json2, writer.write(smia.ToJsonValue()));
+}
+
+TEST_F(GeneratedInterfaceTests, StructWithOptionalMapTest) {
+ const char* expected_json = "{}\n";
+ StructWithOptionalIntMap soim;
+ ASSERT_TRUE(soim.struct_empty());
+ ASSERT_FALSE(soim.is_valid());
+ ASSERT_FALSE(soim.is_initialized());
+ soim.mark_initialized();
+ ASSERT_TRUE(soim.struct_empty());
+ ASSERT_RPCTYPE_VALID(soim);
+ ASSERT_TRUE(soim.is_initialized());
+ ASSERT_EQ(expected_json, writer.write(soim.ToJsonValue()));
+ (*soim.optionalIntMap)["Yay"] = 2;
+ ASSERT_RPCTYPE_VALID(soim);
+ ASSERT_TRUE(soim.is_initialized());
+ const char* expected_json2 = "{\"optionalIntMap\":{\"Yay\":2}}\n";
+ ASSERT_EQ(expected_json2, writer.write(soim.ToJsonValue()));
+}
+
+TEST_F(GeneratedInterfaceTests, StructWithMandatoryMapTest) {
+ const char* expected_json = "{\"mandatoryIntMap\":{}}\n";
+ StructWithMandatoryIntMap smim;
+ ASSERT_FALSE(smim.is_valid());
+ ASSERT_FALSE(smim.is_initialized());
+ smim.mandatoryIntMap.mark_initialized();
+ ASSERT_RPCTYPE_VALID(smim);
+ ASSERT_TRUE(smim.is_initialized());
+ ASSERT_EQ(expected_json, writer.write(smim.ToJsonValue()));
+ smim.mandatoryIntMap["Yay"] = 2;
+ ASSERT_RPCTYPE_VALID(smim);
+ ASSERT_TRUE(smim.is_initialized());
+ const char* expected_json2 = "{\"mandatoryIntMap\":{\"Yay\":2}}\n";
+ ASSERT_EQ(expected_json2, writer.write(smim.ToJsonValue()));
+}
+
+TEST_F(GeneratedInterfaceTests, StructWithMandatoryMapInitFromWrongJsonTest) {
+ const char* empty_json = "{}\n";
+ Json::Value json_value = JsonValue(empty_json);
+
+ StructWithMandatoryIntMap smim(&json_value);
+
+ ASSERT_TRUE(smim.struct_empty());
+ ASSERT_FALSE(smim.is_valid());
+ ASSERT_TRUE(smim.is_initialized());
+
+ smim.mandatoryIntMap["Yay"] = 2;
+ ASSERT_FALSE(smim.struct_empty());
+ ASSERT_RPCTYPE_VALID(smim);
+ ASSERT_TRUE(smim.is_initialized());
+ const char* expected_json = "{\"mandatoryIntMap\":{\"Yay\":2}}\n";
+ ASSERT_EQ(expected_json, writer.write(smim.ToJsonValue()));
+}
+
+TEST_F(GeneratedInterfaceTests, ReportIncorrectlyInitializedMap1) {
+ StructWithMandatoryIntMap smim;
+ smim.mark_initialized();
+ ASSERT_FALSE(smim.is_valid());
+ rpc::ValidationReport report("smim");
+ smim.ReportErrors(&report);
+ ASSERT_EQ("smim.mandatoryIntMap: object is not initialized\n", PrettyFormat(report));
+}
+
+TEST_F(GeneratedInterfaceTests, ReportIncorrectlyInitializedMap2) {
+ Choice c;
+ ASSERT_FALSE(c.is_valid());
+ rpc::ValidationReport report("c");
+ c.ReportErrors(&report);
+ ASSERT_EQ("c: object is not initialized\n"
+ "c.choiceID: value is not initialized\n"
+ "c.menuName: value is not initialized\n"
+ "c.vrCommands: object is not initialized\n", PrettyFormat(report));
+}
+
+TEST_F(GeneratedInterfaceTests, TestFrankenstructCreation) {
+ FrankenstructOfEmptyStringWithMandatoryInt fbmi;
+ ASSERT_FALSE(fbmi.is_valid());
+ ASSERT_FALSE(fbmi.is_initialized());
+ ASSERT_TRUE(fbmi.empty());
+ ASSERT_TRUE(fbmi.struct_empty());
+ fbmi.mandatoryInt = 5;
+ ASSERT_FALSE(fbmi.struct_empty());
+ ASSERT_TRUE(fbmi.empty());
+ ASSERT_TRUE(fbmi.is_initialized());
+
+ // Ok known bug: frankenstructs must be explicitly marked initialized
+ // or has values in map
+ ASSERT_FALSE(fbmi.is_valid());
+ fbmi.mark_initialized();
+ ASSERT_RPCTYPE_VALID(fbmi);
+
+ ASSERT_TRUE(fbmi.is_initialized());
+
+ rpc::ValidationReport report("fbmi");
+ fbmi.ReportErrors(&report);
+ ASSERT_EQ("", PrettyFormat(report));
+}
+
+TEST_F(GeneratedInterfaceTests, FrankenstructToJson) {
+ const char* expected_json = "{\"hello\":\"str\",\"mandatoryInt\":2}\n";
+ FrankenstructOfEmptyStringWithMandatoryInt fbmi;
+ fbmi.mandatoryInt = 2;
+ fbmi["hello"] = "str";
+ ASSERT_TRUE(fbmi.is_initialized());
+ ASSERT_RPCTYPE_VALID(fbmi);
+ ASSERT_FALSE(fbmi.empty());
+ ASSERT_FALSE(fbmi.struct_empty());
+ ASSERT_EQ(expected_json,
+ writer.write(fbmi.ToJsonValue()));
+}
+
+TEST_F(GeneratedInterfaceTests, FrankenstructFromJson) {
+ const char* input_json = "{\"hello\":\"str\",\"mandatoryInt\":2}\n";
+ Json::Value json_value = JsonValue(input_json);
+ FrankenstructOfEmptyStringWithMandatoryInt fbmi(&json_value);
+ ASSERT_TRUE(fbmi.is_initialized());
+ ASSERT_RPCTYPE_VALID(fbmi);
+ ASSERT_FALSE(fbmi.empty());
+ ASSERT_FALSE(fbmi.struct_empty());
+ ASSERT_EQ(1, fbmi.size());
+ ASSERT_EQ(2, fbmi.mandatoryInt);
+ ASSERT_EQ("str", std::string(fbmi["hello"]));
+}
+
+TEST_F(GeneratedInterfaceTests, FrankenstructFromInvalidJson) {
+ const char* input_json = "{\"hello\":true,\"mandatoryInt\":2}\n";
+ Json::Value json_value = JsonValue(input_json);
+ FrankenstructOfEmptyStringWithMandatoryInt fbmi(&json_value);
+ ASSERT_TRUE(fbmi.is_initialized());
+ ASSERT_FALSE(fbmi.is_valid());
+ ASSERT_FALSE(fbmi.empty());
+ ASSERT_FALSE(fbmi.struct_empty());
+ ASSERT_EQ(1, fbmi.size());
+ ASSERT_EQ(2, fbmi.mandatoryInt);
+ rpc::ValidationReport report("fbmi");
+ fbmi.ReportErrors(&report);
+ ASSERT_EQ("fbmi[\"hello\"]: value initialized incorrectly\n", PrettyFormat(report));
+}
+
} // namespace test
</struct>
<struct name="StructWithNullableOptionalMap">
- <param name="nullableOptionalIntMap" type="Integer" map="true" nullable="true" manadatory="false" minsize="0" maxsize="5" minvalue="2" maxvalue="10" />
+ <param name="nullableOptionalIntMap" type="Integer" map="true" nullable="true" mandatory="false" minsize="0" maxsize="5" minvalue="2" maxvalue="10" />
</struct>
<struct name="StructWithNullableMapOfNullableInts">
<param name="nullableMap" type="Integer" minvalue="0" maxvalue="42" map="true" minsize="1" maxsize="5" nullable="true" null_values_allowed="true" />
</struct>
+ <struct name="StructWithOptionalIntArray">
+ <param name="optionalIntArray" type="Integer" minvalue="0" maxvalue="42" array="true" minsize="0" maxsize="5" mandatory="false" />
+ </struct>
+
+ <struct name="StructWithMandatoryIntArray">
+ <param name="mandatoryIntArray" type="Integer" minvalue="0" maxvalue="42" array="true" minsize="0" maxsize="5" />
+ </struct>
+
+ <struct name="StructWithOptionalIntMap">
+ <param name="optionalIntMap" type="Integer" minvalue="0" maxvalue="42" map="true" minsize="0" maxsize="5" mandatory="false" />
+ </struct>
+
+ <struct name="StructWithMandatoryIntMap">
+ <param name="mandatoryIntMap" type="Integer" minvalue="0" maxvalue="42" map="true" minsize="0" maxsize="5" />
+ </struct>
+
+ <struct name="FrankenstructOfEmptyStringWithMandatoryInt" type="String" maxlength="15" minsize="0" maxsize="3">
+ <param name="mandatoryInt" type="Integer" minvalue="0" maxvalue="42" />
+ </struct>
+
<typedef name="TdResultArray" type="TdResult" array="true" minsize="1" maxsize="10">
<description>
Test typedef over array