summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2019-03-17 14:30:57 -0400
committerGitHub <noreply@github.com>2019-03-17 14:30:57 -0400
commit6c6e363dc72338893dc8c577e9b59867a3215aa2 (patch)
treebf5c89f4d6fb41af8b1c30c6c81382043a590f1e
parent499cc74f2b633ed5a070507d81413af3432a0279 (diff)
parentd309b03fcb3240bea005132682400f4c5444e61b (diff)
downloadsdl_core-6c6e363dc72338893dc8c577e9b59867a3215aa2.tar.gz
Merge pull request #2838 from smartdevicelink/feature/app_service_policies_unit_tests
App service policies unit tests
-rw-r--r--src/components/application_manager/test/policy_handler_test.cc64
-rw-r--r--src/components/application_manager/test/sdl_pt_update.json8
-rw-r--r--src/components/policy/policy_external/test/json/valid_sdl_pt_update.json8
-rw-r--r--src/components/policy/policy_external/test/policy_manager_impl_test.cc31
-rw-r--r--src/components/policy/policy_regular/test/policy_manager_impl_test.cc31
-rw-r--r--src/components/policy/policy_regular/test/sql_pt_representation_test.cc39
-rw-r--r--src/components/policy/policy_regular/test/valid_sdl_pt_update.json8
7 files changed, 186 insertions, 3 deletions
diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc
index 25024ff50d..af21a705bf 100644
--- a/src/components/application_manager/test/policy_handler_test.cc
+++ b/src/components/application_manager/test/policy_handler_test.cc
@@ -378,6 +378,70 @@ TEST_F(PolicyHandlerTest, ClearUserConsent) {
policy_handler_.ClearUserConsent();
}
+TEST_F(PolicyHandlerTest, AppServiceUpdate_CheckAppService) {
+ // Arrange
+ EnablePolicy();
+ EXPECT_TRUE(policy_handler_.LoadPolicyLibrary());
+ // Check
+ EXPECT_TRUE(policy_handler_.InitPolicyTable());
+ ChangePolicyManagerToMock();
+ std::string file_name("sdl_pt_update.json");
+ std::ifstream ifile(file_name);
+ Json::Reader reader;
+ std::string json;
+ Json::Value root(Json::objectValue);
+ if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ json = root.toStyledString();
+ }
+ ifile.close();
+ BinaryMessage msg(json.begin(), json.end());
+ // Checks
+ EXPECT_CALL(*mock_policy_manager_, LoadPT("", msg)).WillOnce(Return(true));
+ policy_handler_.ReceiveMessageFromSDK("", msg);
+
+ policy_table::AppServiceParameters app_service_params =
+ policy_table::AppServiceParameters();
+ std::string kServiceType = "MEDIA";
+ std::string as_app_id = "1010101010";
+ std::string service_name1 = "SDL Music";
+ std::string service_name2 = "SDL App";
+ (app_service_params)[kServiceType] = policy_table::AppServiceInfo();
+ (app_service_params)[kServiceType].service_names->push_back(service_name2);
+ (app_service_params)[kServiceType].service_names->push_back(service_name1);
+ (app_service_params)[kServiceType].service_names->mark_initialized();
+ policy_table::AppServiceHandledRpc handled_rpc;
+ handled_rpc.function_id = 41;
+ (app_service_params)[kServiceType].handled_rpcs.push_back(handled_rpc);
+ EXPECT_CALL(*mock_policy_manager_, GetAppServiceParameters(_, _))
+ .WillRepeatedly(SetArgPointee<1>(app_service_params));
+
+ ns_smart_device_link::ns_smart_objects::SmartArray requested_handled_rpcs;
+ ns_smart_device_link::ns_smart_objects::SmartObject rpc_id(41);
+ requested_handled_rpcs.push_back(rpc_id);
+
+ ns_smart_device_link::ns_smart_objects::SmartArray fake_handled_rpcs;
+ ns_smart_device_link::ns_smart_objects::SmartObject fake_rpc_id(40);
+ fake_handled_rpcs.push_back(fake_rpc_id);
+
+ EXPECT_TRUE(policy_handler_.CheckAppServiceParameters(
+ as_app_id, service_name1, kServiceType, &requested_handled_rpcs));
+ EXPECT_TRUE(policy_handler_.CheckAppServiceParameters(
+ as_app_id, service_name2, kServiceType, &requested_handled_rpcs));
+ EXPECT_TRUE(policy_handler_.CheckAppServiceParameters(
+ as_app_id, service_name2, kServiceType, NULL));
+ EXPECT_TRUE(policy_handler_.CheckAppServiceParameters(
+ as_app_id, "", kServiceType, NULL));
+
+ EXPECT_FALSE(
+ policy_handler_.CheckAppServiceParameters(as_app_id, "", "", NULL));
+ EXPECT_FALSE(policy_handler_.CheckAppServiceParameters(
+ as_app_id, service_name2, "NAVIGATION", &requested_handled_rpcs));
+ EXPECT_FALSE(policy_handler_.CheckAppServiceParameters(
+ as_app_id, "MUSIC", kServiceType, &requested_handled_rpcs));
+ EXPECT_FALSE(policy_handler_.CheckAppServiceParameters(
+ as_app_id, service_name2, kServiceType, &fake_handled_rpcs));
+}
+
TEST_F(PolicyHandlerTest, ReceiveMessageFromSDK) {
// Arrange
EnablePolicy();
diff --git a/src/components/application_manager/test/sdl_pt_update.json b/src/components/application_manager/test/sdl_pt_update.json
index 17b07f797f..aea3f7700b 100644
--- a/src/components/application_manager/test/sdl_pt_update.json
+++ b/src/components/application_manager/test/sdl_pt_update.json
@@ -20,7 +20,13 @@
"nicknames" : [ "SyncProxyTester" ],
"priority" : "EMERGENCY",
"steal_focus" : true,
- "watchdog_timer_ms" : 20000
+ "watchdog_timer_ms" : 20000,
+ "app_services": {
+ "MEDIA": {
+ "service_names" : ["SDL App", "SDL Music"],
+ "handled_rpcs" : [{"function_id": 41}]
+ }
+ }
},
"default" : {
"default_hmi" : "NONE",
diff --git a/src/components/policy/policy_external/test/json/valid_sdl_pt_update.json b/src/components/policy/policy_external/test/json/valid_sdl_pt_update.json
index 35e6b1d1a6..acf18c5706 100644
--- a/src/components/policy/policy_external/test/json/valid_sdl_pt_update.json
+++ b/src/components/policy/policy_external/test/json/valid_sdl_pt_update.json
@@ -20,7 +20,13 @@
"nicknames" : [ "SyncProxyTester" ],
"priority" : "EMERGENCY",
"steal_focus" : true,
- "heart_beat_timeout_ms": 5000
+ "heart_beat_timeout_ms": 5000,
+ "app_services": {
+ "MEDIA": {
+ "service_names" : ["SDL App", "SDL Music"],
+ "handled_rpcs" : [{"function_id": 41}]
+ }
+ }
},
"default" : {
"default_hmi" : "NONE",
diff --git a/src/components/policy/policy_external/test/policy_manager_impl_test.cc b/src/components/policy/policy_external/test/policy_manager_impl_test.cc
index 6521db7c36..1916e09efc 100644
--- a/src/components/policy/policy_external/test/policy_manager_impl_test.cc
+++ b/src/components/policy/policy_external/test/policy_manager_impl_test.cc
@@ -345,6 +345,37 @@ TEST_F(PolicyManagerImplTest2, GetCurrentDeviceId) {
EXPECT_EQ("", policy_manager_->GetCurrentDeviceId(app_id_2_));
}
+TEST_F(PolicyManagerImplTest2, UpdateApplication_AppServices) {
+ // Arrange
+ std::string kServiceType = "MEDIA";
+ CreateLocalPT(preloaded_pt_filename_);
+ EXPECT_EQ("UP_TO_DATE", policy_manager_->GetPolicyTableStatus());
+ GetPTU("json/valid_sdl_pt_update.json");
+ EXPECT_EQ("UP_TO_DATE", policy_manager_->GetPolicyTableStatus());
+ // Try to add existing app
+ policy_table::AppServiceParameters app_service_parameters =
+ policy_table::AppServiceParameters();
+ policy_manager_->GetAppServiceParameters(app_id_2_, &app_service_parameters);
+
+ ASSERT_FALSE(app_service_parameters.find(kServiceType) ==
+ app_service_parameters.end());
+
+ auto service_names = *(app_service_parameters[kServiceType].service_names);
+
+ ASSERT_TRUE(service_names.is_initialized());
+ ASSERT_EQ(service_names.size(), 2u);
+ EXPECT_EQ(static_cast<std::string>(service_names[0]), "SDL App");
+ EXPECT_EQ(static_cast<std::string>(service_names[1]), "SDL Music");
+
+ auto handled_rpcs = app_service_parameters[kServiceType].handled_rpcs;
+
+ ASSERT_TRUE(handled_rpcs.is_initialized());
+ EXPECT_EQ(handled_rpcs[0].function_id, 41);
+
+ // Check no update required
+ EXPECT_EQ("UP_TO_DATE", policy_manager_->GetPolicyTableStatus());
+}
+
TEST_F(
PolicyManagerImplTest_ExternalConsent,
ExternalConsent_SetExternalConsentStatusWhileAppExists_ExpectUserConsentsUpdateForApp) {
diff --git a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc
index ff054b3cc4..97b1768666 100644
--- a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc
+++ b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc
@@ -834,6 +834,37 @@ TEST_F(
EXPECT_EQ("UP_TO_DATE", manager->GetPolicyTableStatus());
}
+TEST_F(PolicyManagerImplTest2, UpdateApplication_AppServices) {
+ std::string kServiceType = "MEDIA";
+ // Arrange
+ CreateLocalPT("sdl_preloaded_pt.json");
+ EXPECT_EQ("UP_TO_DATE", manager->GetPolicyTableStatus());
+ GetPTU("valid_sdl_pt_update.json");
+ EXPECT_EQ("UP_TO_DATE", manager->GetPolicyTableStatus());
+ // Try to add existing app
+ policy_table::AppServiceParameters app_service_parameters =
+ policy_table::AppServiceParameters();
+ manager->GetAppServiceParameters(app_id2, &app_service_parameters);
+
+ ASSERT_FALSE(app_service_parameters.find(kServiceType) ==
+ app_service_parameters.end());
+
+ auto service_names = *(app_service_parameters[kServiceType].service_names);
+
+ ASSERT_TRUE(service_names.is_initialized());
+ ASSERT_EQ(service_names.size(), 2u);
+ EXPECT_EQ(static_cast<std::string>(service_names[0]), "SDL App");
+ EXPECT_EQ(static_cast<std::string>(service_names[1]), "SDL Music");
+
+ auto handled_rpcs = app_service_parameters[kServiceType].handled_rpcs;
+
+ ASSERT_TRUE(handled_rpcs.is_initialized());
+ EXPECT_EQ(handled_rpcs[0].function_id, 41);
+
+ // Check no update required
+ EXPECT_EQ("UP_TO_DATE", manager->GetPolicyTableStatus());
+}
+
TEST_F(PolicyManagerImplTest2,
PTUpdatedAt_DaysNotExceedLimit_ExpectNoUpdateRequired) {
// Arrange
diff --git a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc
index 6448a47b42..675d708843 100644
--- a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc
+++ b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc
@@ -124,6 +124,13 @@ class SQLPTRepresentationTest : public SQLPTRepresentation,
policy_table::ApplicationPoliciesSection* policies) const {
return ::SQLPTRepresentation::GatherApplicationPoliciesSection(policies);
}
+
+ bool GatherAppServiceParameters(
+ const std::string& app_id,
+ policy_table::AppServiceParameters* policies) const {
+ return ::SQLPTRepresentation::GatherAppServiceParameters(app_id, policies);
+ }
+
virtual void GatherDeviceData(policy_table::DeviceData* data) const {
::SQLPTRepresentation::GatherDeviceData(data);
}
@@ -314,6 +321,21 @@ class SQLPTRepresentationTest : public SQLPTRepresentation,
app_policies["1234"]["keep_context"] = Json::Value(false);
app_policies["1234"]["steal_focus"] = Json::Value(false);
app_policies["1234"]["RequestType"] = Json::Value(Json::arrayValue);
+ app_policies["1234"]["app_services"] = Json::Value(Json::objectValue);
+ app_policies["1234"]["app_services"]["MEDIA"] =
+ Json::Value(Json::objectValue);
+ app_policies["1234"]["app_services"]["MEDIA"]["service_names"] =
+ Json::Value(Json::arrayValue);
+ app_policies["1234"]["app_services"]["MEDIA"]["service_names"][0] =
+ Json::Value("SDL App");
+ app_policies["1234"]["app_services"]["MEDIA"]["service_names"][1] =
+ Json::Value("SDL Music");
+ app_policies["1234"]["app_services"]["MEDIA"]["handled_rpcs"] =
+ Json::Value(Json::arrayValue);
+ app_policies["1234"]["app_services"]["MEDIA"]["handled_rpcs"][0] =
+ Json::Value(Json::objectValue);
+ app_policies["1234"]["app_services"]["MEDIA"]["handled_rpcs"][0]
+ ["function_id"] = Json::Value(41);
app_policies["device"] = Json::Value(Json::objectValue);
app_policies["device"]["groups"] = Json::Value(Json::arrayValue);
@@ -1706,6 +1728,23 @@ TEST_F(SQLPTRepresentationTest, Save_SetPolicyTableThenSave_ExpectSavedToPT) {
GatherDeviceData(&devices);
EXPECT_EQ(3u, devices.size());
+
+ const std::string kAppId = "1234";
+ const std::string kServiceType = "MEDIA";
+ policy_table::AppServiceParameters app_service_parameters;
+ GatherAppServiceParameters(kAppId, &app_service_parameters);
+ ASSERT_FALSE(app_service_parameters.find(kServiceType) ==
+ app_service_parameters.end());
+ auto service_names = *(app_service_parameters[kServiceType].service_names);
+ EXPECT_TRUE(service_names.is_initialized());
+ ASSERT_EQ(service_names.size(), 2u);
+ EXPECT_EQ(static_cast<std::string>(service_names[0]), "SDL App");
+ EXPECT_EQ(static_cast<std::string>(service_names[1]), "SDL Music");
+
+ auto handled_rpcs = app_service_parameters[kServiceType].handled_rpcs;
+
+ EXPECT_TRUE(handled_rpcs.is_initialized());
+ EXPECT_EQ(handled_rpcs[0].function_id, 41);
}
} // namespace policy_test
diff --git a/src/components/policy/policy_regular/test/valid_sdl_pt_update.json b/src/components/policy/policy_regular/test/valid_sdl_pt_update.json
index 35e6b1d1a6..acf18c5706 100644
--- a/src/components/policy/policy_regular/test/valid_sdl_pt_update.json
+++ b/src/components/policy/policy_regular/test/valid_sdl_pt_update.json
@@ -20,7 +20,13 @@
"nicknames" : [ "SyncProxyTester" ],
"priority" : "EMERGENCY",
"steal_focus" : true,
- "heart_beat_timeout_ms": 5000
+ "heart_beat_timeout_ms": 5000,
+ "app_services": {
+ "MEDIA": {
+ "service_names" : ["SDL App", "SDL Music"],
+ "handled_rpcs" : [{"function_id": 41}]
+ }
+ }
},
"default" : {
"default_hmi" : "NONE",