summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacobkeeler <jacob.keeler@livioradio.com>2019-03-14 11:11:44 -0400
committerjacobkeeler <jacob.keeler@livioradio.com>2019-03-14 11:11:44 -0400
commitb84c348facd194ec0f94348af1621534549320b0 (patch)
tree2ecd4db7346e95d4e0ad76f4438bb4855e021f7a
parent089aefaf5862dbccd2b24ebf4074d6f7c29471d2 (diff)
downloadsdl_core-b84c348facd194ec0f94348af1621534549320b0.tar.gz
Add mock app service manager
-rw-r--r--src/components/application_manager/include/application_manager/app_service_manager.h22
-rw-r--r--src/components/application_manager/include/application_manager/application_manager_impl.h4
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_app_extension.cc8
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_records_request.cc2
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification.cc2
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_system_capability_request.cc2
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_capability_updated_notification.cc2
-rw-r--r--src/components/application_manager/src/app_service_manager.cc32
-rw-r--r--src/components/application_manager/test/application_manager_impl_test.cc12
-rw-r--r--src/components/application_manager/test/include/application_manager/mock_app_service_manager.h95
10 files changed, 142 insertions, 39 deletions
diff --git a/src/components/application_manager/include/application_manager/app_service_manager.h b/src/components/application_manager/include/application_manager/app_service_manager.h
index f7c46178c5..7f8d305edd 100644
--- a/src/components/application_manager/include/application_manager/app_service_manager.h
+++ b/src/components/application_manager/include/application_manager/app_service_manager.h
@@ -123,28 +123,28 @@ class AppServiceManager {
* @brief TODO
* @param manifest
*/
- std::vector<smart_objects::SmartObject> GetAllServices();
+ std::vector<smart_objects::SmartObject> GetAllServiceRecords();
std::vector<std::pair<std::string, AppService> > GetActiveServices();
void GetProviderByType(const std::string& service_type,
- bool mobile_consumer,
+ const bool mobile_consumer,
ApplicationSharedPtr& app,
bool& hmi_service);
void GetProviderByID(const std::string& service_id,
- bool mobile_consumer,
+ const bool mobile_consumer,
ApplicationSharedPtr& app,
bool& hmi_service);
- AppService* ActiveServiceByType(std::string service_type);
+ AppService* ActiveServiceForType(const std::string service_type);
- AppService* EmbeddedServiceForType(std::string service_type);
+ AppService* EmbeddedServiceForType(const std::string service_type);
- AppService* FindServiceByName(std::string name);
+ AppService* FindServiceByName(const std::string name);
- AppService* FindServiceByID(std::string service_id);
+ AppService* FindServiceByID(const std::string service_id);
- std::string DefaultServiceByType(std::string service_type);
+ std::string DefaultServiceByType(const std::string service_type);
/**
* @brief TODO
@@ -175,11 +175,11 @@ class AppServiceManager {
const mobile_apis::ServiceUpdateReason::eType update_reason,
smart_objects::SmartObject& msg_params);
void GetProviderFromService(const AppService& service,
- bool mobile_consumer,
+ const bool mobile_consumer,
ApplicationSharedPtr& app,
bool& hmi_service);
- AppService* FindServiceByPolicyAppID(std::string policy_app_id,
- std::string type);
+ AppService* FindServiceByPolicyAppID(const std::string policy_app_id,
+ const std::string type);
std::string GetPolicyAppID(AppService service);
};
diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h
index 007b3433f0..2d2eff7bd3 100644
--- a/src/components/application_manager/include/application_manager/application_manager_impl.h
+++ b/src/components/application_manager/include/application_manager/application_manager_impl.h
@@ -1587,8 +1587,8 @@ class ApplicationManagerImpl
}
virtual void SetAppServiceManager(
- std::unique_ptr<AppServiceManager>& app_service_manager) {
- app_service_manager_.reset(app_service_manager.release());
+ AppServiceManager* app_service_manager) {
+ app_service_manager_.reset(app_service_manager);
}
private:
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_app_extension.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_app_extension.cc
index 63812056f1..6d8b0c08cc 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_app_extension.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_app_extension.cc
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2018, Ford Motor Company
+ Copyright (c) 2019, Ford Motor Company, Livio
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -13,9 +13,9 @@
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.
+ Neither the name of the the copyright holders nor the names of their
+ 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
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_records_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_records_request.cc
index 1131448d2f..6123843704 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_records_request.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_records_request.cc
@@ -61,7 +61,7 @@ void ASGetAppServiceRecordsRequest::Run() {
smart_objects::SmartObject records =
smart_objects::SmartObject(smart_objects::SmartType_Array);
std::vector<smart_objects::SmartObject> service_records =
- application_manager_.GetAppServiceManager().GetAllServices();
+ application_manager_.GetAppServiceManager().GetAllServiceRecords();
int index = 0;
for (auto& record : service_records) {
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification.cc
index 73ec1137a8..494651379f 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification.cc
@@ -120,7 +120,7 @@ void OnBCSystemCapabilityUpdatedNotification::Run() {
break;
case hmi_apis::Common_SystemCapabilityType::APP_SERVICES: {
auto all_services =
- application_manager_.GetAppServiceManager().GetAllServices();
+ application_manager_.GetAppServiceManager().GetAllServiceRecords();
auto app_service_caps =
MessageHelper::CreateAppServiceCapabilities(all_services);
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_system_capability_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_system_capability_request.cc
index 63a4416139..a90c51f48a 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_system_capability_request.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_system_capability_request.cc
@@ -143,7 +143,7 @@ void GetSystemCapabilityRequest::Run() {
break;
case mobile_apis::SystemCapabilityType::APP_SERVICES: {
auto all_services =
- application_manager_.GetAppServiceManager().GetAllServices();
+ application_manager_.GetAppServiceManager().GetAllServiceRecords();
response_params
[strings::system_capability][strings::app_services_capabilities] =
MessageHelper::CreateAppServiceCapabilities(all_services);
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_capability_updated_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_capability_updated_notification.cc
index b5e3a73ee4..6ab560f56c 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_capability_updated_notification.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_capability_updated_notification.cc
@@ -86,7 +86,7 @@ void OnSystemCapabilityUpdatedNotification::Run() {
break;
case mobile_apis::SystemCapabilityType::APP_SERVICES: {
auto all_services =
- application_manager_.GetAppServiceManager().GetAllServices();
+ application_manager_.GetAppServiceManager().GetAllServiceRecords();
auto app_service_caps =
MessageHelper::CreateAppServiceCapabilities(all_services);
diff --git a/src/components/application_manager/src/app_service_manager.cc b/src/components/application_manager/src/app_service_manager.cc
index d148e4ef61..c2f647f567 100644
--- a/src/components/application_manager/src/app_service_manager.cc
+++ b/src/components/application_manager/src/app_service_manager.cc
@@ -120,7 +120,7 @@ smart_objects::SmartObject AppServiceManager::PublishAppService(
// Activate the new service if it is the default for its service type, or if
// no service is active of its service type
- AppService* active_service = ActiveServiceByType(service_type);
+ AppService* active_service = ActiveServiceForType(service_type);
if (!active_service || app_service.default_service) {
ActivateAppService(service_id);
}
@@ -189,7 +189,7 @@ void AppServiceManager::OnAppActivated(ApplicationConstSharedPtr app) {
}
}
-std::vector<smart_objects::SmartObject> AppServiceManager::GetAllServices() {
+std::vector<smart_objects::SmartObject> AppServiceManager::GetAllServiceRecords() {
LOG4CXX_AUTO_TRACE(logger_);
std::vector<smart_objects::SmartObject> services;
sync_primitives::AutoLock lock(published_services_lock_);
@@ -201,11 +201,11 @@ std::vector<smart_objects::SmartObject> AppServiceManager::GetAllServices() {
}
void AppServiceManager::GetProviderByType(const std::string& service_type,
- bool mobile_consumer,
+ const bool mobile_consumer,
ApplicationSharedPtr& app,
bool& hmi_service) {
LOG4CXX_AUTO_TRACE(logger_);
- auto active_service = ActiveServiceByType(service_type);
+ auto active_service = ActiveServiceForType(service_type);
if (!active_service) {
LOG4CXX_ERROR(logger_,
"There is no active service for the given service type: "
@@ -218,7 +218,7 @@ void AppServiceManager::GetProviderByType(const std::string& service_type,
}
void AppServiceManager::GetProviderByID(const std::string& service_id,
- bool mobile_consumer,
+ const bool mobile_consumer,
ApplicationSharedPtr& app,
bool& hmi_service) {
LOG4CXX_AUTO_TRACE(logger_);
@@ -234,7 +234,7 @@ void AppServiceManager::GetProviderByID(const std::string& service_id,
}
void AppServiceManager::GetProviderFromService(const AppService& service,
- bool mobile_consumer,
+ const bool mobile_consumer,
ApplicationSharedPtr& app,
bool& hmi_service) {
LOG4CXX_AUTO_TRACE(logger_);
@@ -327,7 +327,7 @@ bool AppServiceManager::ActivateAppService(const std::string service_id) {
const std::string service_type =
service[strings::service_manifest][strings::service_type].asString();
- auto active_service = ActiveServiceByType(service_type);
+ auto active_service = ActiveServiceForType(service_type);
if (active_service) {
active_service->record[strings::service_active] = false;
AppServiceUpdated(active_service->record,
@@ -391,7 +391,8 @@ bool AppServiceManager::DeactivateAppService(const std::string service_id) {
return true;
}
-AppService* AppServiceManager::ActiveServiceByType(std::string service_type) {
+AppService* AppServiceManager::ActiveServiceForType(
+ const std::string service_type) {
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock lock(published_services_lock_);
for (auto it = published_services_.begin(); it != published_services_.end();
@@ -407,7 +408,7 @@ AppService* AppServiceManager::ActiveServiceByType(std::string service_type) {
}
AppService* AppServiceManager::EmbeddedServiceForType(
- std::string service_type) {
+ const std::string service_type) {
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock lock(published_services_lock_);
for (auto it = published_services_.begin(); it != published_services_.end();
@@ -421,7 +422,7 @@ AppService* AppServiceManager::EmbeddedServiceForType(
return NULL;
}
-AppService* AppServiceManager::FindServiceByName(std::string name) {
+AppService* AppServiceManager::FindServiceByName(const std::string name) {
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock lock(published_services_lock_);
for (auto it = published_services_.begin(); it != published_services_.end();
@@ -435,7 +436,7 @@ AppService* AppServiceManager::FindServiceByName(std::string name) {
}
AppService* AppServiceManager::FindServiceByPolicyAppID(
- std::string policy_app_id, std::string type) {
+ const std::string policy_app_id, const std::string type) {
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock lock(published_services_lock_);
for (auto it = published_services_.begin(); it != published_services_.end();
@@ -452,7 +453,7 @@ AppService* AppServiceManager::FindServiceByPolicyAppID(
return NULL;
}
-AppService* AppServiceManager::FindServiceByID(std::string service_id) {
+AppService* AppServiceManager::FindServiceByID(const std::string service_id) {
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock lock(published_services_lock_);
@@ -464,7 +465,8 @@ AppService* AppServiceManager::FindServiceByID(std::string service_id) {
return &(it->second);
}
-std::string AppServiceManager::DefaultServiceByType(std::string service_type) {
+std::string AppServiceManager::DefaultServiceByType(
+ const std::string service_type) {
LOG4CXX_AUTO_TRACE(logger_);
Json::Value& dictionary = last_state_.get_dictionary();
if (dictionary[kAppServiceSection][kDefaults].isMember(service_type)) {
@@ -474,7 +476,7 @@ std::string AppServiceManager::DefaultServiceByType(std::string service_type) {
}
void AppServiceManager::SetServicePublished(const std::string service_id,
- bool service_published) {
+ const bool service_published) {
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock lock(published_services_lock_);
auto it = published_services_.find(service_id);
@@ -500,7 +502,7 @@ bool AppServiceManager::UpdateNavigationCapabilities(
ns_smart_device_link::ns_smart_objects::
EnumConversionHelper<mobile_apis::AppServiceType::eType>::EnumToString(
mobile_apis::AppServiceType::NAVIGATION, &navi_service_type);
- auto service = ActiveServiceByType(navi_service_type);
+ auto service = ActiveServiceForType(navi_service_type);
if (!service) {
return false;
}
diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc
index f27e252142..e88d10d3e0 100644
--- a/src/components/application_manager/test/application_manager_impl_test.cc
+++ b/src/components/application_manager/test/application_manager_impl_test.cc
@@ -42,6 +42,7 @@
#include "application_manager/mock_application.h"
#include "application_manager/mock_application_manager_settings.h"
#include "application_manager/mock_resumption_data.h"
+#include "application_manager/mock_app_service_manager.h"
#include "application_manager/mock_rpc_plugin_manager.h"
#include "application_manager/mock_rpc_service.h"
#include "application_manager/resumption/resume_ctrl_impl.h"
@@ -115,6 +116,8 @@ class ApplicationManagerImplTest : public ::testing::Test {
std::make_shared<NiceMock<resumption_test::MockResumptionData> >(
mock_app_mngr_))
, mock_rpc_service_(new MockRPCService)
+ , mock_app_service_manager_(
+ new MockAppServiceManager(mock_app_mngr_, mock_last_state_))
, mock_message_helper_(
application_manager::MockMessageHelper::message_helper_mock())
@@ -139,11 +142,13 @@ class ApplicationManagerImplTest : public ::testing::Test {
app_manager_impl_->resume_controller().set_resumption_storage(
mock_storage_);
app_manager_impl_->set_connection_handler(&mock_connection_handler_);
+ ON_CALL(*mock_app_service_manager_, UnpublishServices(_))
+ .WillByDefault(Return());
+ ON_CALL(*mock_app_service_manager_, OnAppActivated(_))
+ .WillByDefault(Return());
+ app_manager_impl_->SetAppServiceManager(mock_app_service_manager_);
Json::Value empty;
ON_CALL(mock_last_state_, get_dictionary()).WillByDefault(ReturnRef(empty));
- std::unique_ptr<AppServiceManager> app_service_manager_ptr(
- new AppServiceManager(*app_manager_impl_, mock_last_state_));
- app_manager_impl_->SetAppServiceManager(app_service_manager_ptr);
}
void CreateAppManager() {
@@ -221,6 +226,7 @@ class ApplicationManagerImplTest : public ::testing::Test {
NiceMock<MockApplicationManagerSettings> mock_application_manager_settings_;
application_manager_test::MockApplicationManager mock_app_mngr_;
std::unique_ptr<am::ApplicationManagerImpl> app_manager_impl_;
+ MockAppServiceManager* mock_app_service_manager_;
application_manager::MockMessageHelper* mock_message_helper_;
std::shared_ptr<MockApplication> mock_app_ptr_;
diff --git a/src/components/application_manager/test/include/application_manager/mock_app_service_manager.h b/src/components/application_manager/test/include/application_manager/mock_app_service_manager.h
new file mode 100644
index 0000000000..030c130cbc
--- /dev/null
+++ b/src/components/application_manager/test/include/application_manager/mock_app_service_manager.h
@@ -0,0 +1,95 @@
+/*
+ Copyright (c) 2019, Ford Motor Company, Livio
+ 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 the copyright holders nor the names of their
+ 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 SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_APP_SERVICE_MANAGER_H_
+#define SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_APP_SERVICE_MANAGER_H_
+
+#include <gmock/gmock.h>
+#include "application_manager/app_service_manager.h"
+
+namespace test {
+namespace components {
+namespace application_manager_test {
+
+class MockAppServiceManager : public application_manager::AppServiceManager {
+ public:
+ MockAppServiceManager(application_manager::ApplicationManager& app_manager,
+ resumption::LastState& last_state)
+ : application_manager::AppServiceManager(app_manager, last_state) {}
+ MOCK_METHOD3(PublishAppService, smart_objects::SmartObject(
+ const smart_objects::SmartObject& manifest,
+ const bool mobile_service,
+ const uint32_t connection_key));
+ MOCK_METHOD1(UnpublishAppService, bool(const std::string service_id));
+ MOCK_METHOD1(UnpublishServices, void(const uint32_t connection_key));
+ MOCK_METHOD1(OnAppActivated,
+ void(application_manager::ApplicationConstSharedPtr app));
+ MOCK_METHOD1(SetDefaultService, bool(const std::string service_id));
+ MOCK_METHOD1(RemoveDefaultService, bool(const std::string service_id));
+ MOCK_METHOD1(ActivateAppService, bool(const std::string service_id));
+ MOCK_METHOD1(DeactivateAppService, bool(const std::string service_id));
+ MOCK_METHOD0(GetAllServiceRecords, std::vector<smart_objects::SmartObject>());
+ MOCK_METHOD0(
+ GetActiveServices,
+ std::vector<std::pair<std::string, application_manager::AppService> >());
+ MOCK_METHOD4(GetProviderByType,
+ void(const std::string& service_type,
+ const bool mobile_consumer,
+ application_manager::ApplicationSharedPtr& app,
+ bool& hmi_service));
+ MOCK_METHOD4(GetProviderByID,
+ void(const std::string& service_id,
+ const bool mobile_consumer,
+ application_manager::ApplicationSharedPtr& app,
+ bool& hmi_service));
+ MOCK_METHOD1(
+ ActiveServiceForType,
+ application_manager::AppService*(const std::string service_type));
+ MOCK_METHOD1(
+ EmbeddedServiceForType,
+ application_manager::AppService*(const std::string service_type));
+ MOCK_METHOD1(FindServiceByID,
+ application_manager::AppService*(const std::string service_id));
+ MOCK_METHOD1(DefaultServiceByType,
+ std::string(const std::string service_type));
+ MOCK_METHOD2(SetServicePublished,
+ void(const std::string service_id,
+ const bool service_published));
+ MOCK_METHOD1(UpdateNavigationCapabilities,
+ bool(smart_objects::SmartObject& out_params));
+};
+
+} // namespace application_manager_test
+} // namespace components
+} // namespace test
+
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_APP_SERVICE_MANAGER_H_