diff options
Diffstat (limited to 'src/components/policy/policy_external/test')
7 files changed, 56 insertions, 40 deletions
diff --git a/src/components/policy/policy_external/test/generated_code_test.cc b/src/components/policy/policy_external/test/generated_code_test.cc index 15d14e3e3b..03cfae511b 100644 --- a/src/components/policy/policy_external/test/generated_code_test.cc +++ b/src/components/policy/policy_external/test/generated_code_test.cc @@ -51,8 +51,9 @@ TEST(PolicyGeneratedCodeTest, TestValidPTPreloadJsonIsValid) { std::ifstream json_file("json/sdl_preloaded_pt.json"); ASSERT_TRUE(json_file.is_open()); Json::Value valid_table; - Json::Reader reader; - ASSERT_TRUE(reader.parse(json_file, valid_table)); + Json::CharReaderBuilder reader_builder; + ASSERT_TRUE( + Json::parseFromStream(reader_builder, json_file, &valid_table, nullptr)); Table table(&valid_table); table.SetPolicyTableType(rpc::policy_table_interface_base::PT_PRELOADED); ASSERT_RPCTYPE_VALID(table); @@ -62,8 +63,9 @@ TEST(PolicyGeneratedCodeTest, TestValidPTUpdateJsonIsValid) { std::ifstream json_file("json/valid_sdl_pt_update.json"); ASSERT_TRUE(json_file.is_open()); Json::Value valid_table; - Json::Reader reader; - ASSERT_TRUE(reader.parse(json_file, valid_table)); + Json::CharReaderBuilder reader_builder; + ASSERT_TRUE( + Json::parseFromStream(reader_builder, json_file, &valid_table, nullptr)); Table table(&valid_table); table.SetPolicyTableType(rpc::policy_table_interface_base::PT_UPDATE); ASSERT_RPCTYPE_VALID(table); diff --git a/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc b/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc index 333f4e8f84..4fbbeaa6aa 100644 --- a/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc +++ b/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc @@ -153,11 +153,11 @@ TEST_F(PolicyManagerImplTest2, IsAppRevoked_SetRevokedAppID_ExpectAppRevoked) { device_id_1_, app_id_1_, HmiTypes(policy_table::AHT_DEFAULT)); std::ifstream ifile(kValidSdlPtUpdateJson); - Json::Reader reader; + Json::CharReaderBuilder reader_builder; std::string json; Json::Value root(Json::objectValue); if (ifile.is_open()) { - if (reader.parse(ifile, root, true)) { + if (Json::parseFromStream(reader_builder, ifile, &root, nullptr)) { root["policy_table"]["app_policies"][app_id_1_] = Json::nullValue; json = root.toStyledString(); } @@ -249,11 +249,11 @@ TEST_F(PolicyManagerImplTest2, ASSERT_TRUE(output.list_of_allowed_params.empty()); // Act std::ifstream ifile(kValidSdlPtUpdateJson); - Json::Reader reader; + Json::CharReaderBuilder reader_builder; std::string json; Json::Value root(Json::objectValue); EXPECT_TRUE(ifile.is_open()); - EXPECT_TRUE(reader.parse(ifile, root, true)); + EXPECT_TRUE(Json::parseFromStream(reader_builder, ifile, &root, nullptr)); root["policy_table"]["app_policies"][app_id_1_] = Json::nullValue; json = root.toStyledString(); ifile.close(); @@ -297,10 +297,11 @@ TEST_F(PolicyManagerImplTest2, device_id_1_, application_id_, HmiTypes(policy_table::AHT_MEDIA)); // Emulate PTU with new policies for app added above std::ifstream ifile(kValidSdlPtUpdateJson); - Json::Reader reader; + Json::CharReaderBuilder reader_builder; std::string json; Json::Value root(Json::objectValue); - if (ifile.is_open() && reader.parse(ifile, root, true)) { + if (ifile.is_open() && + Json::parseFromStream(reader_builder, ifile, &root, nullptr)) { // Add AppID with policies root["policy_table"]["app_policies"][application_id_] = Json::Value(Json::objectValue); @@ -801,11 +802,11 @@ TEST_F(PolicyManagerImplTest2, device_id_1_, application_id_, HmiTypes(policy_table::AHT_DEFAULT)); std::ifstream ifile("json/sdl_update_pt_2_groups_no_params_in1.json"); - Json::Reader reader; + Json::CharReaderBuilder reader_builder; std::string json; Json::Value root(Json::objectValue); if (ifile.is_open()) { - reader.parse(ifile, root, true); + Json::parseFromStream(reader_builder, ifile, &root, nullptr); } json = root.toStyledString(); ifile.close(); @@ -903,11 +904,11 @@ TEST_F(PolicyManagerImplTest2, std::ifstream ifile( "json/sdl_update_pt_2_groups_no_params_in1_omitted_in2.json"); - Json::Reader reader; + Json::CharReaderBuilder reader_builder; std::string json; Json::Value root(Json::objectValue); if (ifile.is_open()) { - reader.parse(ifile, root, true); + Json::parseFromStream(reader_builder, ifile, &root, nullptr); } json = root.toStyledString(); ifile.close(); diff --git a/src/components/policy/policy_external/test/policy_manager_impl_snapshot_test.cc b/src/components/policy/policy_external/test/policy_manager_impl_snapshot_test.cc index ddb5474df3..f89a2ce0c7 100644 --- a/src/components/policy/policy_external/test/policy_manager_impl_snapshot_test.cc +++ b/src/components/policy/policy_external/test/policy_manager_impl_snapshot_test.cc @@ -53,10 +53,11 @@ TEST_F(PolicyManagerImplTest2, UpdatedPreloadedPT_ExpectLPT_IsUpdated) { CreateLocalPT(preloaded_pt_filename_); // Update preloadedPT std::ifstream ifile(preloaded_pt_filename_); - Json::Reader reader; + Json::CharReaderBuilder reader_builder; Json::Value root(Json::objectValue); - if (ifile.is_open() && reader.parse(ifile, root, true)) { + if (ifile.is_open() && + Json::parseFromStream(reader_builder, ifile, &root, nullptr)) { root["policy_table"]["module_config"]["preloaded_date"] = new_data.new_date_; Json::Value val(Json::objectValue); @@ -70,9 +71,8 @@ TEST_F(PolicyManagerImplTest2, UpdatedPreloadedPT_ExpectLPT_IsUpdated) { } ifile.close(); - Json::StyledStreamWriter writer; std::ofstream ofile(preloaded_pt_filename_); - writer.write(ofile, root); + ofile << root; ofile.flush(); ofile.close(); 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 809c0b5599..f824d37dfb 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 @@ -265,9 +265,10 @@ TEST_F(PolicyManagerImplTest2, RetrySequenceDelaysSeconds_Expect_CorrectValues) { // Arrange std::ifstream ifile(preloaded_pt_filename_); - Json::Reader reader; + Json::CharReaderBuilder reader_builder; Json::Value root(Json::objectValue); - if (ifile.is_open() && reader.parse(ifile, root, true)) { + if (ifile.is_open() && + Json::parseFromStream(reader_builder, ifile, &root, nullptr)) { Json::Value seconds_between_retries = Json::Value(Json::arrayValue); seconds_between_retries = root["policy_table"]["module_config"]["seconds_between_retries"]; diff --git a/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc b/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc index b3c85df65b..9f363a223a 100644 --- a/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc +++ b/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc @@ -39,8 +39,8 @@ #include "utils/file_system.h" -#include "json/reader.h" #include "utils/gen_hash.h" +#include "utils/jsoncpp_reader_wrapper.h" #include "policy/mock_pt_ext_representation.h" @@ -175,8 +175,8 @@ Json::Value createPTforLoad() { "}"); Json::Value table(Json::objectValue); - Json::Reader reader; - EXPECT_TRUE(reader.parse(load_table, table)); + utils::JsonReader reader; + EXPECT_TRUE(reader.parse(load_table, &table)); return table; } @@ -282,10 +282,11 @@ void PolicyManagerImplTest2::SetUp() { const Json::Value PolicyManagerImplTest2::GetPTU(const std::string& file_name) { // Get PTU std::ifstream ifile(file_name); - Json::Reader reader; + Json::CharReaderBuilder reader_builder; std::string json; Json::Value root(Json::objectValue); - if (ifile.is_open() && reader.parse(ifile, root, true)) { + if (ifile.is_open() && + Json::parseFromStream(reader_builder, ifile, &root, nullptr)) { json = root.toStyledString(); } ifile.close(); @@ -471,11 +472,11 @@ void PolicyManagerImplTest2:: // Expect all parameters are allowed std::ifstream ifile(update_file); - Json::Reader reader; + Json::CharReaderBuilder reader_builder; std::string json; Json::Value root(Json::objectValue); if (ifile.is_open()) { - reader.parse(ifile, root, true); + Json::parseFromStream(reader_builder, ifile, &root, nullptr); } json = root.toStyledString(); ifile.close(); @@ -578,10 +579,11 @@ void PolicyManagerImplTest2::CheckRpcPermissions( void PolicyManagerImplTest2::EmulatePTAppRevoked(const std::string& ptu_name) { std::ifstream ifile(ptu_name); - Json::Reader reader; + Json::CharReaderBuilder reader_builder; std::string json; Json::Value root(Json::objectValue); - if (ifile.is_open() && reader.parse(ifile, root, true)) { + if (ifile.is_open() && + Json::parseFromStream(reader_builder, ifile, &root, nullptr)) { // Emulate application is revoked root["policy_table"]["app_policies"]["1234"]["is_revoked"] = 1; json = root.toStyledString(); @@ -620,11 +622,11 @@ void PolicyManagerImplTest2::LoadPTUFromJsonFile( const std::string& update_file) { // Load Json to cache std::ifstream ifile(update_file); - Json::Reader reader; + Json::CharReaderBuilder reader_builder; std::string json; Json::Value root(Json::objectValue); if (ifile.is_open()) { - reader.parse(ifile, root, true); + Json::parseFromStream(reader_builder, ifile, &root, nullptr); } json = root.toStyledString(); ifile.close(); @@ -684,10 +686,11 @@ const Json::Value PolicyManagerImplTest_RequestTypes::GetPTU( const std::string& file_name) { // Get PTU std::ifstream ifile(file_name); - Json::Reader reader; + Json::CharReaderBuilder reader_builder; std::string json; Json::Value root(Json::objectValue); - if (ifile.is_open() && reader.parse(ifile, root, true)) { + if (ifile.is_open() && + Json::parseFromStream(reader_builder, ifile, &root, nullptr)) { json = root.toStyledString(); } ifile.close(); @@ -905,10 +908,11 @@ std::string PolicyManagerImplTest_ExternalConsent::PreparePTUWithNewGroup( using namespace rpc; std::ifstream ifile(preloaded_pt_filename_); - Json::Reader reader; + Json::CharReaderBuilder reader_builder; std::string json; Json::Value root(Json::objectValue); - if (ifile.is_open() && reader.parse(ifile, root, true)) { + if (ifile.is_open() && + Json::parseFromStream(reader_builder, ifile, &root, nullptr)) { Table t = PreparePTWithGroupsHavingExternalConsent(); ExternalConsentEntity entity_4(type, id); diff --git a/src/components/policy/policy_external/test/sql_pt_representation_test.cc b/src/components/policy/policy_external/test/sql_pt_representation_test.cc index 67702ab4d2..2f85f8dc0a 100644 --- a/src/components/policy/policy_external/test/sql_pt_representation_test.cc +++ b/src/components/policy/policy_external/test/sql_pt_representation_test.cc @@ -1682,13 +1682,15 @@ TEST_F(SQLPTRepresentationTest, table["policy_table"]["module_meta"] = Json::Value(Json::objectValue); table["policy_table"]["module_config"]["preloaded_pt"] = Json::Value(false); policy_table::Table expected(&table); - Json::StyledWriter writer; + Json::StreamWriterBuilder writer_builder; // Checks - EXPECT_EQ(writer.write(expected.ToJsonValue()), - writer.write(snapshot->ToJsonValue())); - std::cout << writer.write(snapshot->ToJsonValue()) << std::endl; + Json::Value snapshot_json_value = snapshot->ToJsonValue(); + EXPECT_EQ(Json::writeString(writer_builder, expected.ToJsonValue()), + Json::writeString(writer_builder, snapshot_json_value)); + std::cout << Json::writeString(writer_builder, snapshot_json_value) + << std::endl; EXPECT_EQ(expected.ToJsonValue().toStyledString(), - snapshot->ToJsonValue().toStyledString()); + snapshot_json_value.toStyledString()); } TEST_F(SQLPTRepresentationTest, diff --git a/src/components/policy/policy_external/test/update_status_manager_test.cc b/src/components/policy/policy_external/test/update_status_manager_test.cc index 9f68456750..29952bd18e 100644 --- a/src/components/policy/policy_external/test/update_status_manager_test.cc +++ b/src/components/policy/policy_external/test/update_status_manager_test.cc @@ -340,6 +340,12 @@ TEST_F(UpdateStatusManagerTest, EXPECT_FALSE(manager_->IsAppsSearchInProgress()); } +TEST_F(UpdateStatusManagerTest, OnAppRegistered) { + manager_->ScheduleUpdate(); + ASSERT_EQ(policy::kUpdateNeeded, manager_->StringifiedUpdateStatus()); + manager_->ProcessEvent(policy::UpdateEvent::kOnNewAppRegistered); + EXPECT_EQ(policy::kUpdateNeeded, manager_->StringifiedUpdateStatus()); +} } // namespace policy_test } // namespace components } // namespace test |