summaryrefslogtreecommitdiff
path: root/src/components/application_manager/test/application_manager_impl_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/test/application_manager_impl_test.cc')
-rw-r--r--src/components/application_manager/test/application_manager_impl_test.cc444
1 files changed, 444 insertions, 0 deletions
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 5b232e1dfc..d19d3cd8ed 100644
--- a/src/components/application_manager/test/application_manager_impl_test.cc
+++ b/src/components/application_manager/test/application_manager_impl_test.cc
@@ -32,11 +32,13 @@
#include <stdint.h>
#include <memory>
#include <set>
+#include <bson_object.h>
#include "gtest/gtest.h"
#include "application_manager/application.h"
#include "application_manager/application_impl.h"
#include "application_manager/application_manager_impl.h"
+#include "application_manager/mock_application.h"
#include "application_manager/mock_application_manager_settings.h"
#include "application_manager/mock_resumption_data.h"
#include "application_manager/resumption/resume_ctrl_impl.h"
@@ -45,6 +47,7 @@
#include "hmi_message_handler/mock_hmi_message_handler.h"
#include "policy/mock_policy_settings.h"
#include "policy/usage_statistics/mock_statistics_manager.h"
+#include "protocol/bson_object_keys.h"
#include "protocol_handler/mock_session_observer.h"
#include "utils/custom_string.h"
#include "utils/file_system.h"
@@ -61,14 +64,22 @@ namespace policy_test = test::components::policy_handler_test;
namespace con_test = connection_handler_test;
using testing::_;
+using ::testing::ByRef;
+using ::testing::DoAll;
using ::testing::Mock;
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::NiceMock;
+using ::testing::SaveArg;
using ::testing::SetArgPointee;
using namespace application_manager;
+// custom action to call a member function with 4 arguments
+ACTION_P6(InvokeMemberFuncWithArg4, ptr, memberFunc, a, b, c, d) {
+ (ptr->*memberFunc)(a, b, c, d);
+}
+
namespace {
const std::string kDirectoryName = "./test_storage";
const uint32_t kTimeout = 10000u;
@@ -124,8 +135,14 @@ class ApplicationManagerImplTest : public ::testing::Test {
.WillByDefault(ReturnRef(kTimeout));
app_manager_impl_.reset(new am::ApplicationManagerImpl(
mock_application_manager_settings_, mock_policy_settings_));
+ mock_app_ptr_ = utils::SharedPtr<MockApplication>(new MockApplication());
ASSERT_TRUE(app_manager_impl_.get());
+ ASSERT_TRUE(mock_app_ptr_.get());
+ }
+
+ void AddMockApplication() {
+ app_manager_impl_->AddMockApplication(mock_app_ptr_);
}
NiceMock<policy_test::MockPolicySettings> mock_policy_settings_;
@@ -139,6 +156,7 @@ class ApplicationManagerImplTest : public ::testing::Test {
application_manager::MockMessageHelper* mock_message_helper_;
uint32_t app_id_;
application_manager::MessageHelper* message_helper_;
+ utils::SharedPtr<MockApplication> mock_app_ptr_;
};
TEST_F(ApplicationManagerImplTest, ProcessQueryApp_ExpectSuccess) {
@@ -195,6 +213,432 @@ TEST_F(
EXPECT_TRUE(result.find(app_id_) != result.end());
}
+TEST_F(ApplicationManagerImplTest, OnServiceStartedCallback_RpcService) {
+ AddMockApplication();
+
+ const connection_handler::DeviceHandle device_handle = 0;
+ const protocol_handler::ServiceType service_type =
+ protocol_handler::ServiceType::kRpc;
+ const int32_t session_key = 123;
+ EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key));
+
+ bool result = false;
+ std::vector<std::string> rejected_params;
+ EXPECT_CALL(mock_connection_handler_, NotifyServiceStartedResult(_, _, _))
+ .WillOnce(DoAll(SaveArg<1>(&result), SaveArg<2>(&rejected_params)));
+
+ app_manager_impl_->OnServiceStartedCallback(
+ device_handle, session_key, service_type, NULL);
+
+ // check: return value is true and list is empty
+ EXPECT_TRUE(result);
+ EXPECT_TRUE(rejected_params.empty());
+}
+
+TEST_F(ApplicationManagerImplTest, OnServiceStartedCallback_UnknownApp) {
+ AddMockApplication();
+
+ const connection_handler::DeviceHandle device_handle = 0;
+ const protocol_handler::ServiceType service_type =
+ protocol_handler::ServiceType::kInvalidServiceType;
+ const int32_t session_key = 123;
+ EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(456));
+
+ bool result = false;
+ std::vector<std::string> rejected_params;
+ EXPECT_CALL(mock_connection_handler_, NotifyServiceStartedResult(_, _, _))
+ .WillOnce(DoAll(SaveArg<1>(&result), SaveArg<2>(&rejected_params)));
+
+ app_manager_impl_->OnServiceStartedCallback(
+ device_handle, session_key, service_type, NULL);
+
+ // check: return value is false and list is empty
+ EXPECT_FALSE(result);
+ EXPECT_TRUE(rejected_params.empty());
+}
+
+TEST_F(ApplicationManagerImplTest, OnServiceStartedCallback_UnknownService) {
+ AddMockApplication();
+
+ const connection_handler::DeviceHandle device_handle = 0;
+ const protocol_handler::ServiceType service_type =
+ protocol_handler::ServiceType::kInvalidServiceType;
+ const int32_t session_key = 123;
+ EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key));
+
+ bool result = false;
+ std::vector<std::string> rejected_params;
+ EXPECT_CALL(mock_connection_handler_, NotifyServiceStartedResult(_, _, _))
+ .WillOnce(DoAll(SaveArg<1>(&result), SaveArg<2>(&rejected_params)));
+
+ app_manager_impl_->OnServiceStartedCallback(
+ device_handle, session_key, service_type, NULL);
+
+ // check: return value is false and list is empty
+ EXPECT_FALSE(result);
+ EXPECT_TRUE(rejected_params.empty());
+}
+
+TEST_F(ApplicationManagerImplTest, OnServiceStartedCallback_VideoServiceStart) {
+ AddMockApplication();
+
+ const connection_handler::DeviceHandle device_handle = 0;
+ const protocol_handler::ServiceType service_type =
+ protocol_handler::ServiceType::kMobileNav;
+ const int32_t session_key = 123;
+ EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key));
+ EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true));
+ EXPECT_CALL(*mock_app_ptr_, hmi_level())
+ .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL));
+
+ bool result = false;
+ std::vector<std::string> rejected_params;
+ EXPECT_CALL(mock_connection_handler_, NotifyServiceStartedResult(_, _, _))
+ .WillOnce(DoAll(SaveArg<1>(&result), SaveArg<2>(&rejected_params)));
+
+ // check: SetVideoConfig() should not be called, StartStreaming() is called
+ EXPECT_CALL(*mock_app_ptr_, SetVideoConfig(_, _)).Times(0);
+ EXPECT_CALL(*mock_app_ptr_, StartStreaming(service_type)).WillOnce(Return());
+
+ app_manager_impl_->OnServiceStartedCallback(
+ device_handle, session_key, service_type, NULL);
+
+ // check: return value is true and list is empty
+ EXPECT_TRUE(result);
+ EXPECT_TRUE(rejected_params.empty());
+}
+
+TEST_F(ApplicationManagerImplTest,
+ OnServiceStartedCallback_VideoServiceNotStart1) {
+ AddMockApplication();
+
+ const connection_handler::DeviceHandle device_handle = 0;
+ const protocol_handler::ServiceType service_type =
+ protocol_handler::ServiceType::kMobileNav;
+ const int32_t session_key = 123;
+ EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key));
+ // is_navi() is false
+ EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(false));
+ EXPECT_CALL(*mock_app_ptr_, hmi_level())
+ .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL));
+
+ bool result = false;
+ std::vector<std::string> rejected_params;
+ EXPECT_CALL(mock_connection_handler_, NotifyServiceStartedResult(_, _, _))
+ .WillOnce(DoAll(SaveArg<1>(&result), SaveArg<2>(&rejected_params)));
+
+ // check: SetVideoConfig() and StartStreaming() should not be called
+ EXPECT_CALL(*mock_app_ptr_, SetVideoConfig(_, _)).Times(0);
+ EXPECT_CALL(*mock_app_ptr_, StartStreaming(service_type)).Times(0);
+
+ app_manager_impl_->OnServiceStartedCallback(
+ device_handle, session_key, service_type, NULL);
+
+ // check: return value is false and list is empty
+ EXPECT_FALSE(result);
+ EXPECT_TRUE(rejected_params.empty());
+}
+
+TEST_F(ApplicationManagerImplTest,
+ OnServiceStartedCallback_VideoServiceNotStart2) {
+ AddMockApplication();
+
+ const connection_handler::DeviceHandle device_handle = 0;
+ const protocol_handler::ServiceType service_type =
+ protocol_handler::ServiceType::kMobileNav;
+ const int32_t session_key = 123;
+ EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key));
+ EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true));
+ // HMI level is not FULL nor LIMITED
+ EXPECT_CALL(*mock_app_ptr_, hmi_level())
+ .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_BACKGROUND));
+
+ bool result = false;
+ std::vector<std::string> rejected_params;
+ EXPECT_CALL(mock_connection_handler_, NotifyServiceStartedResult(_, _, _))
+ .WillOnce(DoAll(SaveArg<1>(&result), SaveArg<2>(&rejected_params)));
+
+ // check: SetVideoConfig() and StartStreaming() should not be called
+ EXPECT_CALL(*mock_app_ptr_, SetVideoConfig(_, _)).Times(0);
+ EXPECT_CALL(*mock_app_ptr_, StartStreaming(service_type)).Times(0);
+
+ app_manager_impl_->OnServiceStartedCallback(
+ device_handle, session_key, service_type, NULL);
+
+ // check: return value is false and list is empty
+ EXPECT_FALSE(result);
+ EXPECT_TRUE(rejected_params.empty());
+}
+
+TEST_F(ApplicationManagerImplTest,
+ OnServiceStartedCallback_VideoSetConfig_SUCCESS) {
+ AddMockApplication();
+
+ const connection_handler::DeviceHandle device_handle = 0;
+ const protocol_handler::ServiceType service_type =
+ protocol_handler::ServiceType::kMobileNav;
+ const int32_t session_key = 123;
+ EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key));
+ EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true));
+ EXPECT_CALL(*mock_app_ptr_, hmi_level())
+ .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_LIMITED));
+
+ bool result = false;
+ std::vector<std::string> rejected_params;
+ EXPECT_CALL(mock_connection_handler_, NotifyServiceStartedResult(_, _, _))
+ .WillOnce(DoAll(SaveArg<1>(&result), SaveArg<2>(&rejected_params)));
+
+ BsonObject input_params;
+ bson_object_initialize_default(&input_params);
+ char protocol_version[] = "1.0.0";
+ bson_object_put_string(&input_params,
+ protocol_handler::strings::protocol_version,
+ protocol_version);
+ bson_object_put_int64(&input_params, protocol_handler::strings::mtu, 100);
+ char protocol_name[] = "RTP";
+ bson_object_put_string(
+ &input_params, protocol_handler::strings::video_protocol, protocol_name);
+ char codec_name[] = "VP9";
+ bson_object_put_string(
+ &input_params, protocol_handler::strings::video_codec, codec_name);
+ bson_object_put_int32(&input_params, protocol_handler::strings::height, 640);
+ bson_object_put_int32(&input_params, protocol_handler::strings::width, 480);
+
+ smart_objects::SmartObject converted_params(smart_objects::SmartType_Map);
+ converted_params[strings::protocol] =
+ hmi_apis::Common_VideoStreamingProtocol::RTP;
+ converted_params[strings::codec] = hmi_apis::Common_VideoStreamingCodec::VP9;
+ converted_params[strings::height] = 640;
+ converted_params[strings::width] = 480;
+
+ std::vector<std::string> empty;
+
+ // check: SetVideoConfig() and StartStreaming() are called
+ EXPECT_CALL(*mock_app_ptr_, SetVideoConfig(service_type, converted_params))
+ .WillOnce(DoAll(InvokeMemberFuncWithArg4(
+ app_manager_impl_.get(),
+ &ApplicationManagerImpl::OnStreamingConfigured,
+ session_key,
+ service_type,
+ true,
+ ByRef(empty)),
+ Return(true)));
+ EXPECT_CALL(*mock_app_ptr_, StartStreaming(service_type)).WillOnce(Return());
+
+ app_manager_impl_->OnServiceStartedCallback(
+ device_handle, session_key, service_type, &input_params);
+
+ // check: return value is true and list is empty
+ EXPECT_TRUE(result);
+ EXPECT_TRUE(rejected_params.empty());
+}
+
+static bool ValidateList(std::vector<std::string>& expected,
+ std::vector<std::string>& actual) {
+ if (expected.size() != actual.size()) {
+ return false;
+ }
+ for (unsigned int i = 0; i < expected.size(); i++) {
+ std::string& param = expected[i];
+ unsigned int j;
+ for (j = 0; j < actual.size(); j++) {
+ if (param == actual[j]) {
+ break;
+ }
+ }
+ if (j == actual.size()) {
+ // not found
+ return false;
+ }
+ }
+ return true;
+}
+
+TEST_F(ApplicationManagerImplTest,
+ OnServiceStartedCallback_VideoSetConfig_FAILURE) {
+ AddMockApplication();
+
+ const connection_handler::DeviceHandle device_handle = 0;
+ const protocol_handler::ServiceType service_type =
+ protocol_handler::ServiceType::kMobileNav;
+ const int32_t session_key = 123;
+ EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key));
+ EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true));
+ EXPECT_CALL(*mock_app_ptr_, hmi_level())
+ .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL));
+
+ bool result = false;
+ std::vector<std::string> rejected_params;
+ EXPECT_CALL(mock_connection_handler_, NotifyServiceStartedResult(_, _, _))
+ .WillOnce(DoAll(SaveArg<1>(&result), SaveArg<2>(&rejected_params)));
+
+ BsonObject input_params;
+ bson_object_initialize_default(&input_params);
+ char protocol_version[] = "1.0.0";
+ bson_object_put_string(&input_params,
+ protocol_handler::strings::protocol_version,
+ protocol_version);
+ bson_object_put_int64(&input_params, protocol_handler::strings::mtu, 100);
+ char protocol_name[] = "RTP";
+ bson_object_put_string(
+ &input_params, protocol_handler::strings::video_protocol, protocol_name);
+ char codec_name[] = "VP9";
+ bson_object_put_string(
+ &input_params, protocol_handler::strings::video_codec, codec_name);
+ bson_object_put_int32(&input_params, protocol_handler::strings::height, 640);
+ bson_object_put_int32(&input_params, protocol_handler::strings::width, 480);
+
+ smart_objects::SmartObject converted_params(smart_objects::SmartType_Map);
+ converted_params[strings::protocol] =
+ hmi_apis::Common_VideoStreamingProtocol::RTP;
+ converted_params[strings::codec] = hmi_apis::Common_VideoStreamingCodec::VP9;
+ converted_params[strings::height] = 640;
+ converted_params[strings::width] = 480;
+
+ std::vector<std::string> rejected_list;
+ rejected_list.push_back(std::string("protocol"));
+ rejected_list.push_back(std::string("codec"));
+
+ // simulate HMI returning negative response
+ EXPECT_CALL(*mock_app_ptr_, SetVideoConfig(service_type, converted_params))
+ .WillOnce(DoAll(InvokeMemberFuncWithArg4(
+ app_manager_impl_.get(),
+ &ApplicationManagerImpl::OnStreamingConfigured,
+ session_key,
+ service_type,
+ false,
+ ByRef(rejected_list)),
+ Return(true)));
+
+ // check: StartStreaming() should not be called
+ EXPECT_CALL(*mock_app_ptr_, StartStreaming(service_type)).Times(0);
+
+ app_manager_impl_->OnServiceStartedCallback(
+ device_handle, session_key, service_type, &input_params);
+
+ // check: return value is false
+ EXPECT_FALSE(result);
+
+ // check: rejected param list contains "videoProtocol" and "videoCodec"
+ ASSERT_EQ(2u, rejected_params.size());
+ std::vector<std::string> expected_list;
+ expected_list.push_back(
+ std::string(protocol_handler::strings::video_protocol));
+ expected_list.push_back(std::string(protocol_handler::strings::video_codec));
+ ASSERT_TRUE(ValidateList(expected_list, rejected_params));
+}
+
+TEST_F(ApplicationManagerImplTest,
+ OnServiceStartedCallback_VideoServiceWithoutVideoParams) {
+ AddMockApplication();
+
+ const connection_handler::DeviceHandle device_handle = 0;
+ const protocol_handler::ServiceType service_type =
+ protocol_handler::ServiceType::kMobileNav;
+ const int32_t session_key = 123;
+ EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key));
+ EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true));
+ EXPECT_CALL(*mock_app_ptr_, hmi_level())
+ .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL));
+
+ bool result = false;
+ std::vector<std::string> rejected_params;
+ EXPECT_CALL(mock_connection_handler_, NotifyServiceStartedResult(_, _, _))
+ .WillOnce(DoAll(SaveArg<1>(&result), SaveArg<2>(&rejected_params)));
+
+ BsonObject input_params;
+ bson_object_initialize_default(&input_params);
+ char protocol_version[] = "1.0.0";
+ bson_object_put_string(&input_params, "protocolVersion", protocol_version);
+ bson_object_put_int64(&input_params, "mtu", 100);
+
+ // check: SetVideoConfig() should not be called, StartStreaming() is called
+ EXPECT_CALL(*mock_app_ptr_, SetVideoConfig(_, _)).Times(0);
+ EXPECT_CALL(*mock_app_ptr_, StartStreaming(service_type)).WillOnce(Return());
+
+ app_manager_impl_->OnServiceStartedCallback(
+ device_handle, session_key, service_type, &input_params);
+
+ // check: return value is true and list is empty
+ EXPECT_TRUE(result);
+ EXPECT_TRUE(rejected_params.empty());
+}
+
+TEST_F(ApplicationManagerImplTest, OnServiceStartedCallback_AudioServiceStart) {
+ AddMockApplication();
+
+ const connection_handler::DeviceHandle device_handle = 0;
+ const protocol_handler::ServiceType service_type =
+ protocol_handler::ServiceType::kAudio;
+ const int32_t session_key = 123;
+ EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key));
+ EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true));
+ EXPECT_CALL(*mock_app_ptr_, hmi_level())
+ .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL));
+
+ bool result = false;
+ std::vector<std::string> rejected_params;
+ EXPECT_CALL(mock_connection_handler_, NotifyServiceStartedResult(_, _, _))
+ .WillOnce(DoAll(SaveArg<1>(&result), SaveArg<2>(&rejected_params)));
+
+ // check: SetVideoConfig() should not be called, StartStreaming() is called
+ EXPECT_CALL(*mock_app_ptr_, SetVideoConfig(_, _)).Times(0);
+ EXPECT_CALL(*mock_app_ptr_, StartStreaming(service_type)).WillOnce(Return());
+
+ app_manager_impl_->OnServiceStartedCallback(
+ device_handle, session_key, service_type, NULL);
+
+ // check: return value is true and list is empty
+ EXPECT_TRUE(result);
+ EXPECT_TRUE(rejected_params.empty());
+}
+
+TEST_F(ApplicationManagerImplTest,
+ OnServiceStartedCallback_AudioServiceWithParams) {
+ AddMockApplication();
+
+ const connection_handler::DeviceHandle device_handle = 0;
+ const protocol_handler::ServiceType service_type =
+ protocol_handler::ServiceType::kAudio;
+ const int32_t session_key = 123;
+ EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key));
+ EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true));
+ EXPECT_CALL(*mock_app_ptr_, hmi_level())
+ .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL));
+
+ bool result = false;
+ std::vector<std::string> rejected_params;
+ EXPECT_CALL(mock_connection_handler_, NotifyServiceStartedResult(_, _, _))
+ .WillOnce(DoAll(SaveArg<1>(&result), SaveArg<2>(&rejected_params)));
+
+ BsonObject input_params;
+ bson_object_initialize_default(&input_params);
+ char protocol_version[] = "1.0.0";
+ bson_object_put_string(&input_params,
+ protocol_handler::strings::protocol_version,
+ protocol_version);
+ bson_object_put_int64(&input_params, protocol_handler::strings::mtu, 100);
+ char protocol_name[] = "RTP";
+ bson_object_put_string(
+ &input_params, protocol_handler::strings::video_protocol, protocol_name);
+ char codec_name[] = "VP9";
+ bson_object_put_string(
+ &input_params, protocol_handler::strings::video_codec, codec_name);
+ bson_object_put_int32(&input_params, protocol_handler::strings::height, 640);
+ bson_object_put_int32(&input_params, protocol_handler::strings::width, 480);
+
+ // check: SetVideoConfig() should not be called, StartStreaming() is called
+ EXPECT_CALL(*mock_app_ptr_, SetVideoConfig(_, _)).Times(0);
+ EXPECT_CALL(*mock_app_ptr_, StartStreaming(service_type)).WillOnce(Return());
+
+ app_manager_impl_->OnServiceStartedCallback(
+ device_handle, session_key, service_type, &input_params);
+
+ // check: return value is true and list is empty
+ EXPECT_TRUE(result);
+ EXPECT_TRUE(rejected_params.empty());
+}
+
} // application_manager_test
} // namespace components
} // namespace test