From fc800cba7a13eb23c462f5db297f3606bbb97b52 Mon Sep 17 00:00:00 2001 From: xinxin13 Date: Thu, 29 Dec 2022 22:38:09 +0800 Subject: [PATCH 1/5] add data ability impl tdd test code Signed-off-by: xinxin13 --- .../BUILD.gn | 35 +- .../data_ability_impl_test.cpp | 1692 ++++++++++++++++- 2 files changed, 1722 insertions(+), 5 deletions(-) diff --git a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn index 714134cc6dd..01358920e3f 100644 --- a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn @@ -17,8 +17,10 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/ability_test" config("coverage_flags") { - cflags = [ "--coverage" ] - ldflags = [ "--coverage" ] + if (ability_runtime_feature_coverage) { + cflags = [ "--coverage" ] + ldflags = [ "--coverage" ] + } } ############################################################################### @@ -860,6 +862,16 @@ ohos_unittest("form_extension_provider_client_test") { ohos_unittest("data_ability_impl_test") { module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_services_path}/abilitymgr/include", + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_base_kits_path}/extractortool/include", + "//foundation/distributeddatamgr/relational_store/frameworks/js/napi/rdb/include", + "//foundation/distributeddatamgr/relational_store/frameworks/js/napi/common/include", + "//foundation/distributeddatamgr/relational_store/frameworks/js/napi/dataability/include", + ] + sources = [ "${ability_runtime_innerkits_path}/app_manager/src/appmgr/process_info.cpp", "${ability_runtime_native_path}/appkit/app/app_context.cpp", @@ -868,10 +880,14 @@ ohos_unittest("data_ability_impl_test") { "${ability_runtime_native_path}/appkit/app/context_deal.cpp", "${ability_runtime_native_path}/appkit/app/ohos_application.cpp", "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include/mock_replace_ability_impl.cpp", + "//foundation/ability/ability_runtime/frameworks/native/ability/native/data_ability_impl.cpp", "data_ability_impl_test.cpp", ] - configs = [ ":module_private_config" ] + configs = [ + ":module_private_config", + ":coverage_flags", + ] deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", @@ -884,19 +900,32 @@ ohos_unittest("data_ability_impl_test") { ] external_deps = [ + "ability_base:base", "ability_base:configuration", "ability_base:want", "ability_base:zuri", + "ability_runtime:ability_context_native", "ability_runtime:ability_deps_wrapper", + "ability_runtime:ability_manager", + "ability_runtime:napi_base_context", "ability_runtime:runtime", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_base", "c_utils:utils", + "data_share:datashare_common", + "data_share:datashare_consumer", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "relational_store:native_appdatafwk", "relational_store:native_dataability", "relational_store:native_rdb", + "relational_store:rdb_data_ability_adapter", + "relational_store:rdb_data_share_adapter", + "samgr:samgr_proxy", ] if (ability_runtime_graphics) { diff --git a/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp index b0945681708..a002acfe6a9 100644 --- a/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp @@ -14,12 +14,17 @@ */ #include +#define private public +#define protected public #include "ability_loader.h" #include "data_ability_impl.h" #include "hilog_wrapper.h" #include "mock_ability_token.h" #include "mock_data_ability.h" - +#include "base/account/os_account/services/accountmgr/test/mock/app_account/accesstoken_kit.h" +#include "foundation/ability/ability_runtime/interfaces/kits/native/ability/native/data_ability_operation.h" +#undef private +#undef protected namespace OHOS { namespace AppExecFwk { using namespace testing::ext; @@ -56,7 +61,6 @@ void DataAbilityImplTest::SetUp(void) void DataAbilityImplTest::TearDown(void) {} - /** * @tc.number: AaFwk_DataAbilityImplTest_Insert_0100 * @tc.name: Insert @@ -111,6 +115,42 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Insert_0200, Function | GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Insert_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityImplTest_Insert_0300 + * @tc.name: Insert + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Insert_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Insert_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->isNativeAbility = true; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + EXPECT_NE(dataabilityimpl, nullptr); + Uri uri("\nullptr"); + constexpr int32_t number = -1; + NativeRdb::ValuesBucket value; + auto result = dataabilityimpl->Insert(uri, value); + + EXPECT_EQ(number, result); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Insert_0300 end"; +} /** * @tc.number: AaFwk_DataAbilityImplTest_Update_0100 @@ -162,6 +202,41 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Update_0200, Function | GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Update_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityImplTest_Update_0300 + * @tc.name: Update + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Update_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Update_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + constexpr int32_t number = -1; + NativeRdb::ValuesBucket value; + NativeRdb::DataAbilityPredicates predicates; + + EXPECT_EQ(number, dataabilityimpl->Update(uri, value, predicates)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Update_0300 end"; +} + /** * @tc.number: AaFwk_DataAbilityImplTest_Delete_0100 * @tc.name: Delete @@ -211,6 +286,41 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Delete_0200, Function | GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Delete_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityImplTest_Delete_0300 + * @tc.name: Delete + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Delete_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Delete_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + constexpr int32_t number = -1; + + NativeRdb::DataAbilityPredicates predicates; + + EXPECT_EQ(number, dataabilityimpl->Delete(uri, predicates)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Delete_0300 end"; +} + /** * @tc.number: AaFwk_DataAbilityImplTest_Query_0100 * @tc.name: Query @@ -262,5 +372,1583 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Query_0200, Function | M sleep(1); GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Query_0200 end"; } + +/** + * @tc.number: AaFwk_DataAbilityImplTest_Query_0300 + * @tc.name: Query + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Query_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Query_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + std::vector columns; + columns.push_back("string1"); + NativeRdb::DataAbilityPredicates predicates; + std::shared_ptr set = dataabilityimpl->Query(uri, columns, predicates); + + EXPECT_TRUE(set == nullptr); + dataabilityimpl.reset(); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Query_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_OpenFile_0100 + * @tc.name: OpenFile + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_OpenFile_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_OpenFile_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + Uri uri("\nullptr"); + constexpr int32_t number = 1; + const std::string mode = "abc"; + + EXPECT_EQ(number, dataabilityimpl->OpenFile(uri, mode)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_OpenFile_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_OpenFile_0200 + * @tc.name: OpenFile + * @tc.desc: Validate when normally entering a string. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_OpenFile_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_OpenFile_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + Uri uri("\nullptr"); + constexpr int32_t number = -1; + const std::string mode = "abc"; + + EXPECT_EQ(number, dataabilityimpl->OpenFile(uri, mode)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_OpenFile_0200 end"; +} + + +/** + * @tc.number: AaFwk_DataAbilityImplTest_OpenFile_0300 + * @tc.name: OpenFile + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_OpenFile_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_OpenFile_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + Uri uri("\nullptr"); + constexpr int32_t number = -1; + const std::string mode = "r"; + + EXPECT_EQ(number, dataabilityimpl->OpenFile(uri, mode)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_OpenFile_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_OpenRawFile_0100 + * @tc.name: OpenRawFile + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_OpenRawFile_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_OpenRawFile_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + Uri uri("\nullptr"); + constexpr int32_t number = 1; + const std::string mode = "abc"; + + EXPECT_EQ(number, dataabilityimpl->OpenRawFile(uri, mode)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_OpenRawFile_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_OpenRawFile_0200 + * @tc.name: OpenRawFile + * @tc.desc: Validate when normally entering a string. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_OpenRawFile_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_OpenRawFile_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + Uri uri("\nullptr"); + constexpr int32_t number = -1; + const std::string mode = "abc"; + + EXPECT_EQ(number, dataabilityimpl->OpenRawFile(uri, mode)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_OpenRawFile_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_OpenRawFile_0300 + * @tc.name: OpenRawFile + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_OpenRawFile_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_OpenRawFile_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + Uri uri("\nullptr"); + constexpr int32_t number = -1; + const std::string mode = "r"; + + EXPECT_EQ(number, dataabilityimpl->OpenRawFile(uri, mode)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_OpenRawFile_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_Call_0100 + * @tc.name: Call + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Call_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Call_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + Uri uri("\nullptr"); + const std::string method = "abc"; + const std::string arg = "abc"; + AppExecFwk::PacMap pacMap; + std::shared_ptr set = dataabilityimpl->Call(uri, method, arg, pacMap); + + EXPECT_TRUE(set != nullptr); + dataabilityimpl.reset(); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Call_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_Call_0200 + * @tc.name: Call + * @tc.desc: Validate when normally entering a string. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Call_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Call_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + Uri uri("\nullptr"); + const std::string method = "abc"; + const std::string arg = "abc"; + AppExecFwk::PacMap pacMap; + + std::shared_ptr set = dataabilityimpl->Call(uri, method, arg, pacMap); + EXPECT_EQ(nullptr, set); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Call_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_GetFileTypes_0100 + * @tc.name: GetFileTypes + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetFileTypes_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetFileTypes_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + + Uri uri("\nullptr"); + std::vector value; + const std::string mimeTypeFilter = "abc"; + + value = dataabilityimpl->GetFileTypes(uri, mimeTypeFilter); + std::string ret = value.back(); + EXPECT_EQ(ret, mimeTypeFilter); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetFileTypes_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_GetFileTypes_0200 + * @tc.name: GetFileTypes + * @tc.desc: Validate when normally entering a string. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetFileTypes_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetFileTypes_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + Uri uri("\nullptr"); + std::vector value; + const std::string mimeTypeFilter = "abc"; + + dataabilityimpl->GetFileTypes(uri, mimeTypeFilter); + EXPECT_EQ(value,dataabilityimpl->GetFileTypes(uri, mimeTypeFilter)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetFileTypes_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_GetType_0100 + * @tc.name: GetType + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetType_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetType_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + + Uri uri("\nullptr"); + const std::string value("Type1"); + + EXPECT_EQ(value, dataabilityimpl->GetType(uri)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetType_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_GetType_0200 + * @tc.name: GetType + * @tc.desc: Validate when normally entering a string. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetType_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetType_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + Uri uri("\nullptr"); + const std::string value; + + EXPECT_EQ(value, dataabilityimpl->GetType(uri)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetType_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_Reload_0100 + * @tc.name: Reload + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Reload_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Reload_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + + Uri uri("\nullptr"); + PacMap extras; + + EXPECT_TRUE(dataabilityimpl->Reload(uri, extras)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Reload_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_Reload_0200 + * @tc.name: Reload + * @tc.desc: Validate when normally entering a string. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_Reload_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Reload_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + Uri uri("\nullptr"); + PacMap extras; + + EXPECT_FALSE(dataabilityimpl->Reload(uri, extras)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_Reload_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_BatchInsert_0100 + * @tc.name: BatchInsert + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_BatchInsert_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_BatchInsert_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + + Uri uri("\nullptr"); + std::vector values; + constexpr int32_t number = 1; + + EXPECT_EQ(number, dataabilityimpl->BatchInsert(uri, values)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_BatchInsert_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_BatchInsert_0200 + * @tc.name: BatchInsert + * @tc.desc: Validate when normally entering a string. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_BatchInsert_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_BatchInsert_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + Uri uri("\nullptr"); + std::vector values; + constexpr int32_t number = -1; + + EXPECT_EQ(number, dataabilityimpl->BatchInsert(uri, values)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_BatchInsert_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_BatchInsert_0300 + * @tc.name: BatchInsert + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_BatchInsert_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_BatchInsert_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + std::vector values; + constexpr int32_t number = -1; + + EXPECT_EQ(number, dataabilityimpl->BatchInsert(uri, values)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_BatchInsert_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_NormalizeUri_0100 + * @tc.name: NormalizeUri + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_NormalizeUri_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_NormalizeUri_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + + Uri uri("\nullptr"); + Uri urivalue("UriTest"); + + EXPECT_EQ(urivalue, dataabilityimpl->NormalizeUri(uri)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_NormalizeUri_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_NormalizeUri_0200 + * @tc.name: NormalizeUri + * @tc.desc: Validate when normally entering a string. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_NormalizeUri_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_NormalizeUri_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + Uri uri("\nullptr"); + Uri urivalue(""); + + EXPECT_EQ(urivalue, dataabilityimpl->NormalizeUri(uri)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_NormalizeUri_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_NormalizeUri_0300 + * @tc.name: NormalizeUri + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_NormalizeUri_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_NormalizeUri_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + Uri urivalue(""); + + EXPECT_EQ(urivalue, dataabilityimpl->NormalizeUri(uri)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_NormalizeUri_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_DenormalizeUri_0100 + * @tc.name: DenormalizeUri + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_DenormalizeUri_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_DenormalizeUri_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + + Uri uri("\nullptr"); + Uri urivalue("UriTest"); + + EXPECT_EQ(urivalue, dataabilityimpl->DenormalizeUri(uri)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_DenormalizeUri_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_DenormalizeUri_0200 + * @tc.name: DenormalizeUri + * @tc.desc: Validate when normally entering a string. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_DenormalizeUri_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_DenormalizeUri_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + Uri uri("\nullptr"); + Uri urivalue(""); + + EXPECT_EQ(urivalue, dataabilityimpl->DenormalizeUri(uri)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_DenormalizeUri_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_DenormalizeUri_0300 + * @tc.name: DenormalizeUri + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_DenormalizeUri_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_DenormalizeUri_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + Uri urivalue(""); + + EXPECT_EQ(urivalue, dataabilityimpl->DenormalizeUri(uri)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_DenormalizeUri_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_GetPermissionInfo_0100 + * @tc.name: GetPermissionInfo + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetPermissionInfo_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetPermissionInfo_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + const std::string permissionType = "r"; + + EXPECT_TRUE(abilityInfo->readPermission == dataabilityimpl->GetPermissionInfo(permissionType)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetPermissionInfo_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_GetPermissionInfo_0200 + * @tc.name: GetPermissionInfo + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetPermissionInfo_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetPermissionInfo_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + const std::string permissionType = "w"; + + EXPECT_TRUE(abilityInfo->writePermission == dataabilityimpl->GetPermissionInfo(permissionType)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetPermissionInfo_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_GetPermissionInfo_0300 + * @tc.name: GetPermissionInfo + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetPermissionInfo_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetPermissionInfo_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + const std::string permissionType = "a"; + + EXPECT_TRUE("" == dataabilityimpl->GetPermissionInfo(permissionType)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetPermissionInfo_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_GetPermissionInfo_0400 + * @tc.name: GetPermissionInfo + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetPermissionInfo_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetPermissionInfo_0400 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + + + Uri uri("\nullptr"); + const std::string permissionType = "r"; + + EXPECT_TRUE("" == dataabilityimpl->GetPermissionInfo(permissionType)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetPermissionInfo_0400 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_GetPermissionInfo_0500 + * @tc.name: GetPermissionInfo + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetPermissionInfo_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetPermissionInfo_0500 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + + Uri uri("\nullptr"); + const std::string permissionType = "w"; + + EXPECT_TRUE("" == dataabilityimpl->GetPermissionInfo(permissionType)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_GetPermissionInfo_0500 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0100 + * @tc.name: CheckReadAndWritePermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F( + DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + const std::string permissionType = "a"; + bool ret = false; + ret = dataabilityimpl->CheckReadAndWritePermission(permissionType); + + EXPECT_TRUE(ret); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0200 + * @tc.name: CheckReadAndWritePermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F( + DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + + Uri uri("\nullptr"); + const std::string permissionType = "r"; + bool ret = false; + ret = dataabilityimpl->CheckReadAndWritePermission(permissionType); + + EXPECT_TRUE(ret); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0300 + * @tc.name: CheckReadAndWritePermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F( + DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + + Uri uri("\nullptr"); + const std::string permissionType = "w"; + bool ret = false; + ret = dataabilityimpl->CheckReadAndWritePermission(permissionType); + + EXPECT_TRUE(ret); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0400 + * @tc.name: CheckReadAndWritePermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F( + DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0400 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + const std::string permissionType = "r"; + bool ret = true; + ret = dataabilityimpl->CheckReadAndWritePermission(permissionType); + + EXPECT_FALSE(ret); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0400 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0500 + * @tc.name: CheckReadAndWritePermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F( + DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0500 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + const std::string permissionType = "w"; + bool ret = true; + ret = dataabilityimpl->CheckReadAndWritePermission(permissionType); + + EXPECT_FALSE(ret); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckReadAndWritePermission_0500 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0100 + * @tc.name: CheckOpenFilePermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + const std::string mode = "r"; + bool ret = true; + ret = dataabilityimpl->CheckOpenFilePermission(mode); + + EXPECT_FALSE(ret); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0200 + * @tc.name: CheckOpenFilePermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + const std::string mode = "w"; + bool ret = true; + ret = dataabilityimpl->CheckOpenFilePermission(mode); + + EXPECT_FALSE(ret); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0300 + * @tc.name: CheckOpenFilePermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + const std::string mode = "ar"; + bool ret = true; + ret = dataabilityimpl->CheckOpenFilePermission(mode); + + EXPECT_FALSE(ret); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0400 + * @tc.name: CheckOpenFilePermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0400 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + const std::string mode = "aw"; + bool ret = true; + ret = dataabilityimpl->CheckOpenFilePermission(mode); + + EXPECT_FALSE(ret); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0400 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0500 + * @tc.name: CheckOpenFilePermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0500 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + Uri uri("\nullptr"); + const std::string mode = "abc"; + bool ret = false; + ret = dataabilityimpl->CheckOpenFilePermission(mode); + + EXPECT_TRUE(ret); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckOpenFilePermission_0500 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_ExecuteBatch_0100 + * @tc.name: ExecuteBatch + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_ExecuteBatch_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_ExecuteBatch_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + + std::vector> operations; + std::vector> results; + results.clear(); + + EXPECT_EQ(results, dataabilityimpl->ExecuteBatch(operations)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_ExecuteBatch_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_ExecuteBatch_0200 + * @tc.name: ExecuteBatch + * @tc.desc: Validate when normally entering a string. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_ExecuteBatch_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_ExecuteBatch_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::vector> operations; + std::vector> results; + results.clear(); + + EXPECT_EQ(results, dataabilityimpl->ExecuteBatch(operations)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_ExecuteBatch_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_ExecuteBatch_0300 + * @tc.name: ExecuteBatch + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_ExecuteBatch_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_ExecuteBatch_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + std::vector> operations; + std::shared_ptr operation = std::make_shared(); + operation->type_ = 1; + operations.push_back(operation); + std::vector> results; + results.clear(); + + EXPECT_EQ(results, dataabilityimpl->ExecuteBatch(operations)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_ExecuteBatch_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_ExecuteBatch_0400 + * @tc.name: ExecuteBatch + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_ExecuteBatch_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_ExecuteBatch_0400 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + std::vector> operations; + + EXPECT_TRUE(true); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_ExecuteBatch_0400 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0100 + * @tc.name: CheckExecuteBatchPermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F( + DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + + std::vector> operations; + + EXPECT_TRUE(dataabilityimpl->CheckExecuteBatchPermission(operations)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0200 + * @tc.name: CheckExecuteBatchPermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F( + DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + + std::vector> operations; + std::shared_ptr operation; + operations.push_back(operation); + + EXPECT_FALSE(dataabilityimpl->CheckExecuteBatchPermission(operations)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0300 + * @tc.name: CheckExecuteBatchPermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F( + DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + std::vector> operations; + std::shared_ptr operation = std::make_shared(); + operation->type_ = 1; + operations.push_back(operation); + + EXPECT_FALSE(dataabilityimpl->CheckExecuteBatchPermission(operations)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0400 + * @tc.name: CheckExecuteBatchPermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F( + DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0400 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + std::vector> operations; + std::shared_ptr operation = std::make_shared(); + operation->type_ = 2; + operations.push_back(operation); + + EXPECT_FALSE(dataabilityimpl->CheckExecuteBatchPermission(operations)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0400 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0500 + * @tc.name: CheckExecuteBatchPermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F( + DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0500 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + std::vector> operations; + std::shared_ptr operation = std::make_shared(); + operation->type_ = 3; + operations.push_back(operation); + + EXPECT_FALSE(dataabilityimpl->CheckExecuteBatchPermission(operations)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0500 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0600 + * @tc.name: CheckExecuteBatchPermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F( + DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0600 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + std::vector> operations; + std::shared_ptr operation = std::make_shared(); + operation->type_ = 4; + operations.push_back(operation); + + EXPECT_FALSE(dataabilityimpl->CheckExecuteBatchPermission(operations)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0600 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0700 + * @tc.name: CheckExecuteBatchPermission + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F( + DataAbilityImplTest, AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0700 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockDataAbility"; + abilityInfo->type = AbilityType::DATA; + abilityInfo->readPermission = "r"; + abilityInfo->writePermission = "w"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + + std::vector> operations; + std::shared_ptr operation1 = std::make_shared(); + std::shared_ptr operation2 = std::make_shared(); + operation1->type_ = 4; + operation2->type_ = 1; + operations.push_back(operation1); + operations.push_back(operation2); + + EXPECT_FALSE(dataabilityimpl->CheckExecuteBatchPermission(operations)); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_CheckExecuteBatchPermission_0700 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0100 + * @tc.name: HandleAbilityTransaction + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0100 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + Want want; + AAFwk::LifeCycleStateInfo targetState; + dataabilityimpl->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; + targetState.state = AbilityLifeCycleState::ABILITY_STATE_INITIAL; + targetState.isNewWant = false; + dataabilityimpl->HandleAbilityTransaction(want, targetState); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0200 + * @tc.name: HandleAbilityTransaction + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0200 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + Want want; + AAFwk::LifeCycleStateInfo targetState; + dataabilityimpl->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; + targetState.state = AAFwk::ABILITY_STATE_ACTIVE; + targetState.isNewWant = true; + dataabilityimpl->HandleAbilityTransaction(want, targetState); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0300 + * @tc.name: HandleAbilityTransaction + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0300 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + Want want; + AAFwk::LifeCycleStateInfo targetState; + dataabilityimpl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE; + targetState.state = AAFwk::ABILITY_STATE_ACTIVE; + targetState.isNewWant = true; + dataabilityimpl->HandleAbilityTransaction(want, targetState); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0400 + * @tc.name: HandleAbilityTransaction + * @tc.desc: Simulate successful test cases. + */ +HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0400 start"; + std::shared_ptr dataabilityimpl = std::make_shared(); + Want want; + AAFwk::LifeCycleStateInfo targetState; + dataabilityimpl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE; + targetState.state = AAFwk::ABILITY_STATE_BACKGROUND; + targetState.isNewWant = true; + dataabilityimpl->HandleAbilityTransaction(want, targetState); + sleep(1); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_HandleAbilityTransaction_0400 end"; +} } // namespace AppExecFwk } // namespace OHOS -- Gitee From 7b1d6f95eb3250d6fc0f392ac9e9e0fb2fc5fb91 Mon Sep 17 00:00:00 2001 From: xinxin13 Date: Fri, 30 Dec 2022 09:40:34 +0800 Subject: [PATCH 2/5] fix codeindex Signed-off-by: xinxin13 --- .../data_ability_impl_test.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp index a002acfe6a9..69378b9761b 100644 --- a/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp @@ -457,7 +457,6 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_OpenFile_0200, Function GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_OpenFile_0200 end"; } - /** * @tc.number: AaFwk_DataAbilityImplTest_OpenFile_0300 * @tc.name: OpenFile @@ -1128,7 +1127,6 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_GetPermissionInfo_0400, std::shared_ptr contextDeal = std::make_shared(); dataabilityimpl->Init(application, record, ability, handler, token, contextDeal); - Uri uri("\nullptr"); const std::string permissionType = "r"; -- Gitee From 779f65b06d8f84f5556506139fa7b7ec0332ca6e Mon Sep 17 00:00:00 2001 From: xinxin13 Date: Fri, 30 Dec 2022 19:02:57 +0800 Subject: [PATCH 3/5] fix tdd error Signed-off-by: xinxin13 --- .../include/mock_data_ability.h | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_data_ability.h b/test/mock/frameworks_kits_ability_native_test/include/mock_data_ability.h index 09fd65f6c87..18917a1d78b 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_data_ability.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_data_ability.h @@ -107,6 +107,36 @@ public: return value; } + virtual std::shared_ptr Call( + const Uri &uri, const std::string &method, const std::string &arg, const AppExecFwk::PacMap &pacMap) + { + GTEST_LOG_(INFO) << "MockDataAbility::Call called"; + std::shared_ptr set = std::make_shared(); + return set; + } + + virtual Uri NormalizeUri(const Uri &uri) + { + GTEST_LOG_(INFO) << "MockDataAbility::NormalizeUri called"; + Uri urivalue("UriTest"); + return urivalue; + } + + virtual Uri DenormalizeUri(const Uri &uri) + { + GTEST_LOG_(INFO) << "MockDataAbility::DenormalizeUri called"; + Uri urivalue("UriTest"); + return urivalue; + } + + virtual std::vector> ExecuteBatch( + const std::vector> &operations) + { + GTEST_LOG_(INFO) << "MockDataAbility::ExecuteBatch called"; + std::vector> results; + return results; + } + int datatest = 0; MockDataAbility::Event state_ = UNDEFINED; std::vector value; -- Gitee From 006dc1cc073f93d9063826e1a601046f35735ca5 Mon Sep 17 00:00:00 2001 From: xinxin13 Date: Fri, 30 Dec 2022 19:05:11 +0800 Subject: [PATCH 4/5] fix code Signed-off-by: xinxin13 --- .../include/mock_data_ability.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_data_ability.h b/test/mock/frameworks_kits_ability_native_test/include/mock_data_ability.h index 18917a1d78b..e5c7111368d 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_data_ability.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_data_ability.h @@ -130,7 +130,7 @@ public: } virtual std::vector> ExecuteBatch( - const std::vector> &operations) + const std::vector> &operations) { GTEST_LOG_(INFO) << "MockDataAbility::ExecuteBatch called"; std::vector> results; -- Gitee From acdf147213eca350a88cff9e3035e989b726504d Mon Sep 17 00:00:00 2001 From: xinxin13 Date: Fri, 30 Dec 2022 20:57:06 +0800 Subject: [PATCH 5/5] fix tdd code Signed-off-by: xinxin13 --- .../data_ability_impl_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp index 69378b9761b..d5de957b34b 100644 --- a/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/data_ability_impl_test.cpp @@ -1624,7 +1624,7 @@ HWTEST_F(DataAbilityImplTest, AaFwk_DataAbilityImplTest_ExecuteBatch_0400, Funct ability->AttachBaseContext(contextDeal); std::vector> operations; - + dataabilityimpl->ExecuteBatch(operations); EXPECT_TRUE(true); sleep(1); GTEST_LOG_(INFO) << "AaFwk_DataAbilityImplTest_ExecuteBatch_0400 end"; -- Gitee