diff --git a/framework/innerkitsimpl/test/unittest/BUILD.gn b/framework/innerkitsimpl/test/unittest/BUILD.gn index 974e0568cad5d4eb458dbebab1ddf12bc47eeda5..ef0f1265c2f644bfed22142c477fb70978c5cf88 100644 --- a/framework/innerkitsimpl/test/unittest/BUILD.gn +++ b/framework/innerkitsimpl/test/unittest/BUILD.gn @@ -97,6 +97,27 @@ ohos_unittest("UdmfClientSystemHapTest") { external_deps = common_external_deps } +ohos_unittest("UdmfClientHapPermissionTest") { + module_out_path = module_output_path + + sources = [ "udmf_client_hap_permission_test.cpp" ] + + include_dirs = [ + "${udmf_interfaces_path}/innerkits/client", + "${udmf_interfaces_path}/innerkits/common", + "${udmf_interfaces_path}/innerkits/data", + "${udmf_interfaces_path}/innerkits/convert", + "${udmf_framework_path}/common", + "${udmf_framework_path}/innerkits/service", + "${udmf_framework_path}/innerkitsimpl/client/", + "${udmf_framework_path}/innerkitsimpl/test/unittest/mock/include", + ] + + deps = common_deps + + external_deps = common_external_deps +} + ohos_unittest("UtdClientTest") { module_out_path = module_output_path @@ -493,6 +514,7 @@ group("unittest") { ":SystemDefinedRecordTest", ":TextTest", ":UdmfClientAbnormalTest", + ":UdmfClientHapPermissionTest", ":UdmfClientSystemHapTest", ":UdmfClientTest", ":UnifiedDataHelperTest", diff --git a/framework/innerkitsimpl/test/unittest/udmf_client_hap_permission_test.cpp b/framework/innerkitsimpl/test/unittest/udmf_client_hap_permission_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0d0cfc71e9a85ef02c5d1d2cf8d8ad0a8cf0edb3 --- /dev/null +++ b/framework/innerkitsimpl/test/unittest/udmf_client_hap_permission_test.cpp @@ -0,0 +1,357 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define LOG_TAG "UdmfClientHapPermissionTest" +#include + +#include +#include +#include + +#include "token_setproc.h" +#include "accesstoken_kit.h" +#include "directory_ex.h" +#include "nativetoken_kit.h" + +#include "logger.h" +#include "udmf_client.h" +#include "application_defined_record.h" +#include "audio.h" +#include "file.h" +#include "folder.h" +#include "html.h" +#include "image.h" +#include "link.h" +#include "plain_text.h" +#include "system_defined_appitem.h" +#include "system_defined_form.h" +#include "system_defined_pixelmap.h" +#include "system_defined_record.h" +#include "text.h" +#include "unified_data_helper.h" +#include "video.h" + +using namespace testing::ext; +using namespace OHOS::Security::AccessToken; +using namespace OHOS::UDMF; +using namespace OHOS; +namespace OHOS::Test { +static constexpr int USER_ID = 100; +static constexpr int INST_INDEX = 0; +class UdmfClientHapPermissionTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + void SetNativeToken(const std::string &processName); + static void AllocHapToken1(); + static void AllocHapToken2(); + void SetHapToken1(); + void SetHapToken2(); + void AddPrivilege(QueryOption &option); +}; + +void UdmfClientHapPermissionTest::SetUpTestCase() +{ + AllocHapToken1(); + AllocHapToken2(); +} + +void UdmfClientHapPermissionTest::TearDownTestCase() +{ + auto tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo11", INST_INDEX); + AccessTokenKit::DeleteToken(tokenId); + tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo22", INST_INDEX); + AccessTokenKit::DeleteToken(tokenId); +} + +void UdmfClientHapPermissionTest::SetUp() +{ + SetHapToken1(); +} + +void UdmfClientHapPermissionTest::TearDown() +{ +} + +void UdmfClientHapPermissionTest::SetNativeToken(const std::string &processName) +{ + auto tokenId = AccessTokenKit::GetNativeTokenId(processName); + SetSelfTokenID(tokenId); +} + +void UdmfClientHapPermissionTest::AllocHapToken1() +{ + HapInfoParams info = { + .userID = USER_ID, + .bundleName = "ohos.test.demo11", + .instIndex = INST_INDEX, + .appIDDesc = "ohos.test.demo11", + .isSystemApp = false, + }; + + HapPolicyParams policy = { + .apl = APL_SYSTEM_BASIC, + .domain = "test.domain", + .permList = { + { + .permissionName = "ohos.permission.test", + .bundleName = "ohos.test.demo11", + .grantMode = 1, + .availableLevel = APL_SYSTEM_BASIC, + .label = "label", + .labelId = 1, + .description = "test1", + .descriptionId = 1 + } + }, + .permStateList = { + { + .permissionName = "ohos.permission.test", + .isGeneral = true, + .resDeviceID = { "local" }, + .grantStatus = { PermissionState::PERMISSION_GRANTED }, + .grantFlags = { 1 } + } + } + }; + auto tokenID = AccessTokenKit::AllocHapToken(info, policy); + SetSelfTokenID(tokenID.tokenIDEx); +} + +void UdmfClientHapPermissionTest::AllocHapToken2() +{ + HapInfoParams info = { + .userID = USER_ID, + .bundleName = "ohos.test.demo22", + .instIndex = 0, + .isSystemApp = false, + .appIDDesc = "ohos.test.demo22" + }; + HapPolicyParams policy = { + .apl = APL_SYSTEM_BASIC, + .domain = "test.domain", + .permList = { + { + .permissionName = "ohos.permission.MANAGE_UDMF_APP_SHARE_OPTION", + .bundleName = "ohos.test.demo22", + .grantMode = 1, + .availableLevel = APL_SYSTEM_BASIC, + .label = "label", + .labelId = 1, + .description = "test2", + .descriptionId = 1 + } + }, + .permStateList = { + { + .permissionName = "ohos.permission.MANAGE_UDMF_APP_SHARE_OPTION", + .isGeneral = true, + .resDeviceID = { "local" }, + .grantStatus = { PermissionState::PERMISSION_GRANTED }, + .grantFlags = { 1 } + } + } + }; + auto tokenID = AccessTokenKit::AllocHapToken(info, policy); + SetSelfTokenID(tokenID.tokenIDEx); +} + +void UdmfClientHapPermissionTest::SetHapToken1() +{ + auto tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo11", INST_INDEX); + SetSelfTokenID(tokenId); +} + +void UdmfClientHapPermissionTest::SetHapToken2() +{ + auto tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo22", INST_INDEX); + SetSelfTokenID(tokenId); +} + +void UdmfClientHapPermissionTest::AddPrivilege(QueryOption &option) +{ + Privilege privilege; + privilege.tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo22", INST_INDEX); + privilege.readPermission = "readPermission"; + privilege.writePermission = "writePermission"; + SetNativeToken("msdp_sa"); + auto status = UdmfClient::GetInstance().AddPrivilege(option, privilege); + ASSERT_EQ(status, E_OK); +} + +/** +* @tc.name: SetAppShareOption001 +* @tc.desc: abnormal test, no permission +* @tc.type: FUNC +*/ +HWTEST_F(UdmfClientHapPermissionTest, SetAppShareOption001, TestSize.Level1) +{ + SetHapToken1(); + LOG_INFO(UDMF_TEST, "SetAppShareOption001 begin."); + auto status = UdmfClient::GetInstance().SetAppShareOption("drag", ShareOptions::IN_APP); + EXPECT_EQ(status, E_NO_PERMISSION); + LOG_INFO(UDMF_TEST, "SetAppShareOption001 end."); +} + +/** +* @tc.name: SetAppShareOption002 +* @tc.desc: normal test, has permission +* @tc.type: FUNC +*/ +HWTEST_F(UdmfClientHapPermissionTest, SetAppShareOption002, TestSize.Level1) +{ + SetHapToken2(); + LOG_INFO(UDMF_TEST, "SetAppShareOption002 begin."); + auto status = UdmfClient::GetInstance().SetAppShareOption("drag", ShareOptions::IN_APP); + EXPECT_EQ(status, E_OK); + + ShareOptions appShareOptions; + status = UdmfClient::GetInstance().GetAppShareOption("drag", appShareOptions); + EXPECT_EQ(status, E_OK); + EXPECT_EQ(appShareOptions, ShareOptions::IN_APP); + + status = UdmfClient::GetInstance().RemoveAppShareOption("drag"); + EXPECT_EQ(status, E_OK); + + status = UdmfClient::GetInstance().SetAppShareOption("drag", ShareOptions::CROSS_APP); + EXPECT_EQ(status, E_OK); + + status = UdmfClient::GetInstance().GetAppShareOption("drag", appShareOptions); + EXPECT_EQ(status, E_OK); + EXPECT_EQ(appShareOptions, ShareOptions::CROSS_APP); + + status = UdmfClient::GetInstance().RemoveAppShareOption("drag"); + EXPECT_EQ(status, E_OK); + + status = UdmfClient::GetInstance().GetAppShareOption("drag", appShareOptions); + EXPECT_EQ(status, E_NOT_FOUND); + LOG_INFO(UDMF_TEST, "SetAppShareOption002 end."); +} + +/** +* @tc.name: SetAppShareOption003 +* @tc.desc: SetAppShareOption IN_APP, get data success when IN_APP +* @tc.type: FUNC +*/ +HWTEST_F(UdmfClientHapPermissionTest, SetAppShareOption003, TestSize.Level1) +{ + LOG_INFO(UDMF_TEST, "SetAppShareOption003 begin."); + SetHapToken2(); + auto status = UdmfClient::GetInstance().SetAppShareOption("drag", ShareOptions::IN_APP); + EXPECT_EQ(status, E_OK); + + CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG }; + UnifiedData data1; + Text text1; + std::shared_ptr record1 = std::make_shared(text1); + data1.AddRecord(record1); + std::string key; + status = UdmfClient::GetInstance().SetData(option1, data1, key); + ASSERT_EQ(status, E_OK); + + QueryOption option2 = { .key = key }; + SetHapToken2(); + UnifiedData data2; + status = UdmfClient::GetInstance().GetData(option2, data2); + ASSERT_EQ(status, E_OK); + + std::shared_ptr record2 = data2.GetRecordAt(0); + ASSERT_NE(record2, nullptr); + auto type = record2->GetType(); + EXPECT_EQ(type, UDType::TEXT); + + auto text2 = static_cast(record2.get()); + ASSERT_NE(text2, nullptr); + + status = UdmfClient::GetInstance().RemoveAppShareOption("drag"); + EXPECT_EQ(status, E_OK); + LOG_INFO(UDMF_TEST, "SetAppShareOption003 end."); +} + +/** +* @tc.name: SetAppShareOption004 +* @tc.desc: SetAppShareOption CROSS_APP, get data success when CROSS_APP +* @tc.type: FUNC +*/ +HWTEST_F(UdmfClientHapPermissionTest, SetAppShareOption004, TestSize.Level1) +{ + LOG_INFO(UDMF_TEST, "SetAppShareOption004 begin."); + SetHapToken2(); + auto status = UdmfClient::GetInstance().SetAppShareOption("drag", ShareOptions::CROSS_APP); + EXPECT_EQ(status, E_OK); + + CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG }; + UnifiedData data1; + Text text1; + std::shared_ptr record1 = std::make_shared(text1); + data1.AddRecord(record1); + std::string key; + status = UdmfClient::GetInstance().SetData(option1, data1, key); + ASSERT_EQ(status, E_OK); + + QueryOption option2 = { .key = key }; + AddPrivilege(option2); + + SetHapToken2(); + UnifiedData data2; + status = UdmfClient::GetInstance().GetData(option2, data2); + ASSERT_EQ(status, E_OK); + std::shared_ptr record2 = data2.GetRecordAt(0); + ASSERT_NE(record2, nullptr); + auto type = record2->GetType(); + EXPECT_EQ(type, UDType::TEXT); + auto text2 = static_cast(record2.get()); + ASSERT_NE(text2, nullptr); + + SetHapToken2(); + status = UdmfClient::GetInstance().RemoveAppShareOption("drag"); + EXPECT_EQ(status, E_OK); + LOG_INFO(UDMF_TEST, "SetAppShareOption004 end."); +} + +/** +* @tc.name: RemoveAppShareOption001 +* @tc.desc: abnormal test, no permission +* @tc.type: FUNC +*/ +HWTEST_F(UdmfClientHapPermissionTest, RemoveAppShareOption001, TestSize.Level1) +{ + SetHapToken1(); + LOG_INFO(UDMF_TEST, "RemoveAppShareOption001 begin."); + auto status = UdmfClient::GetInstance().RemoveAppShareOption("drag"); + EXPECT_EQ(status, E_NO_PERMISSION); + LOG_INFO(UDMF_TEST, "RemoveAppShareOption001 end."); +} + +/** +* @tc.name: RemoveAppShareOption002 +* @tc.desc: normal test, has permission +* @tc.type: FUNC +*/ +HWTEST_F(UdmfClientHapPermissionTest, RemoveAppShareOption002, TestSize.Level1) +{ + SetHapToken2(); + LOG_INFO(UDMF_TEST, "RemoveAppShareOption002 begin."); + auto status = UdmfClient::GetInstance().RemoveAppShareOption("drag"); + EXPECT_EQ(status, E_OK); + + ShareOptions appShareOptions; + status = UdmfClient::GetInstance().GetAppShareOption("drag", appShareOptions); + EXPECT_EQ(status, E_NOT_FOUND); + LOG_INFO(UDMF_TEST, "RemoveAppShareOption002 end."); +} +} // OHOS::Test \ No newline at end of file diff --git a/framework/jskitsimpl/data/unified_data_channel_napi.cpp b/framework/jskitsimpl/data/unified_data_channel_napi.cpp index 8daaaeaf8f2515d4705fd4614ecf9a09606b4f58..d1c4bab0b7f37a17b527bbc1419473a943adaf36 100644 --- a/framework/jskitsimpl/data/unified_data_channel_napi.cpp +++ b/framework/jskitsimpl/data/unified_data_channel_napi.cpp @@ -16,7 +16,6 @@ #include "unified_data_channel_napi.h" #include "napi_data_utils.h" -#include "udmf_client.h" #include "unified_data_napi.h" namespace OHOS { @@ -84,6 +83,8 @@ napi_value UnifiedDataChannelNapi::InsertData(napi_env env, napi_callback_info i ASSERT_BUSINESS_ERR(ctxt, argc >= 2, E_INVALID_PARAMETERS, "Parameter error: Mandatory parameters are left unspecified"); ctxt->status = GetNamedProperty(env, argv[0], "intention", intention); + ASSERT_BUSINESS_ERR(ctxt, UnifiedDataUtils::GetIntentionByString(intention) != UD_INTENTION_DRAG, + E_INVALID_PARAMETERS, "Parameter error: The intention parameter is invalid"); ASSERT_BUSINESS_ERR(ctxt, ctxt->status == napi_ok && UnifiedDataUtils::IsPersist(intention), E_INVALID_PARAMETERS, "Parameter error: parameter options intention type must correspond to Intention"); ctxt->status = napi_unwrap(env, argv[1], reinterpret_cast(&unifiedDataNapi)); @@ -160,6 +161,8 @@ napi_value UnifiedDataChannelNapi::QueryData(napi_env env, napi_callback_info in auto options = argv[0]; keyStatus = GetNamedProperty(env, options, "key", ctxt->key); intentionStatus = GetNamedProperty(env, options, "intention", intention); + ASSERT_BUSINESS_ERR(ctxt, UnifiedDataUtils::GetIntentionByString(intention) != UD_INTENTION_DRAG, + E_INVALID_PARAMETERS, "Parameter error: The intention parameter is invalid"); ASSERT_BUSINESS_ERR(ctxt, (keyStatus == napi_ok || intentionStatus == napi_ok) && UnifiedDataUtils::IsValidOptions(ctxt->key, intention), E_INVALID_PARAMETERS, "Parameter error: parameter options intention type must correspond to Intention"); @@ -178,18 +181,8 @@ napi_value UnifiedDataChannelNapi::QueryData(napi_env env, napi_callback_info in }; auto output = [env, ctxt](napi_value &result) { ASSERT_WITH_ERRCODE(ctxt, !ctxt->unifiedDataSet.empty(), E_ERROR, "unifiedDataSet is empty!"); - ctxt->status = napi_create_array_with_length(env, ctxt->unifiedDataSet.size(), &ctxt->output); - ASSERT_WITH_ERRCODE(ctxt, ctxt->status == napi_ok, E_ERROR, "napi_create_array_with_length failed!"); - int index = 0; - for (const UnifiedData &data : ctxt->unifiedDataSet) { - std::shared_ptr unifiedData = std::make_shared(); - unifiedData->SetRecords(data.GetRecords()); - napi_value dataNapi = nullptr; - UnifiedDataNapi::NewInstance(env, unifiedData, dataNapi); - ctxt->status = napi_set_element(env, ctxt->output, index++, dataNapi); - ASSERT_WITH_ERRCODE(ctxt, ctxt->status == napi_ok, E_ERROR, "napi_set_element failed!"); - } - result = ctxt->output; + ctxt->status = ConvertUnifiedDataSetToNapi(env, ctxt->unifiedDataSet, result); + ASSERT_WITH_ERRCODE(ctxt, ctxt->status == napi_ok, E_ERROR, "ConvertUnifiedDataSetToNapi failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output); } @@ -213,6 +206,9 @@ napi_value UnifiedDataChannelNapi::DeleteData(napi_env env, napi_callback_info i napi_value options = argv[0]; keyStatus = GetNamedProperty(env, options, "key", ctxt->key); intentionStatus = GetNamedProperty(env, options, "intention", intention); + ASSERT_BUSINESS_ERR(ctxt, intention.empty() || + UnifiedDataUtils::GetIntentionByString(intention) == UD_INTENTION_DATA_HUB, + E_INVALID_PARAMETERS, "Parameter error: The intention parameter is invalid"); ASSERT_BUSINESS_ERR(ctxt, (keyStatus == napi_ok || intentionStatus == napi_ok) && UnifiedDataUtils::IsValidOptions(ctxt->key, intention), @@ -231,18 +227,8 @@ napi_value UnifiedDataChannelNapi::DeleteData(napi_env env, napi_callback_info i }; auto output = [env, ctxt](napi_value &result) { - ctxt->status = napi_create_array_with_length(env, ctxt->unifiedDataSet.size(), &ctxt->output); - ASSERT_WITH_ERRCODE(ctxt, ctxt->status == napi_ok, E_ERROR, "napi_create_array_with_length failed!"); - int index = 0; - for (const UnifiedData &data : ctxt->unifiedDataSet) { - std::shared_ptr unifiedData = std::make_shared(); - unifiedData->SetRecords(data.GetRecords()); - napi_value dataNapi = nullptr; - UnifiedDataNapi::NewInstance(env, unifiedData, dataNapi); - ctxt->status = napi_set_element(env, ctxt->output, index++, dataNapi); - ASSERT_WITH_ERRCODE(ctxt, ctxt->status == napi_ok, E_ERROR, "napi_set_element failed!"); - } - result = ctxt->output; + ctxt->status = ConvertUnifiedDataSetToNapi(env, ctxt->unifiedDataSet, result); + ASSERT_WITH_ERRCODE(ctxt, ctxt->status == napi_ok, E_ERROR, "ConvertUnifiedDataSetToNapi failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output); } @@ -322,7 +308,7 @@ napi_value UnifiedDataChannelNapi::SetAppShareOptions(napi_env env, napi_callbac std::transform(intention.begin(), intention.end(), intention.begin(), ::tolower); // js : Drag --> drag status = UdmfClient::GetInstance().SetAppShareOption(intention, static_cast(shareOptionValue)); ASSERT_BUSINESS_ERR_VOID(ctxt, !(status == E_SETTINGS_EXISTED), E_SETTINGS_EXISTED, "Settings already exist!"); - ASSERT_BUSINESS_ERR_VOID(ctxt, !(status == E_NO_PERMISSION), E_NO_SYSTEM_PERMISSION, "Permission denied!"); + ASSERT_BUSINESS_ERR_VOID(ctxt, status != E_NO_PERMISSION, E_NO_PERMISSION, "Permission denied!"); ASSERT_ERR(ctxt->env, status == E_OK, status, "invalid arguments!"); return nullptr; } @@ -348,9 +334,32 @@ napi_value UnifiedDataChannelNapi::RemoveAppShareOptions(napi_env env, napi_call std::transform(intention.begin(), intention.end(), intention.begin(), ::tolower); // js : Drag --> drag auto status = E_OK; status = UdmfClient::GetInstance().RemoveAppShareOption(intention); - ASSERT_BUSINESS_ERR_VOID(ctxt, !(status == E_NO_PERMISSION), E_NO_SYSTEM_PERMISSION, "Permission denied!"); + ASSERT_BUSINESS_ERR_VOID(ctxt, status != E_NO_PERMISSION, E_NO_PERMISSION, "Permission denied!"); ASSERT_ERR(ctxt->env, status == E_OK, status, "invalid arguments!"); return nullptr; } + +napi_status UnifiedDataChannelNapi::ConvertUnifiedDataSetToNapi( + napi_env env, const std::vector &dataSet, napi_value &output) +{ + auto status = napi_create_array_with_length(env, dataSet.size(), &output); + if (status != napi_ok) { + LOG_ERROR(UDMF_KITS_NAPI, "napi_create_array_with_length failed!"); + return napi_generic_failure; + } + int index = 0; + for (const UnifiedData &data : dataSet) { + std::shared_ptr unifiedData = std::make_shared(); + unifiedData->SetRecords(data.GetRecords()); + napi_value dataNapi = nullptr; + UnifiedDataNapi::NewInstance(env, unifiedData, dataNapi); + status = napi_set_element(env, output, index++, dataNapi); + if (status != napi_ok) { + LOG_ERROR(UDMF_KITS_NAPI, "napi_set_element failed!"); + return napi_generic_failure; + } + } + return napi_ok; +} } // namespace UDMF } // namespace OHOS \ No newline at end of file diff --git a/framework/jskitsimpl/unittest/UdmfJsTest.js b/framework/jskitsimpl/unittest/UdmfJsTest.js index 9999cf81b384b48c86de3fdd0a973416a375fa35..1061f78b68303040a5156c2e67a5dc98573ad24b 100644 --- a/framework/jskitsimpl/unittest/UdmfJsTest.js +++ b/framework/jskitsimpl/unittest/UdmfJsTest.js @@ -30,6 +30,8 @@ const LONG_TEST2M = 'a'.repeat(NUM_2M); const LONG_TESTOVER2M = 'a'.repeat((NUM_2M + 1)); let U8_ARRAY = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); +const ERROR_PARAMETER = '401'; +const NO_PERMISSION = '201'; describe('UdmfJSTest', function () { @@ -1691,4 +1693,44 @@ describe('UdmfJSTest', function () { done(); } }); + + /** + * @tc.name UdmfSetAppShareOptionsTest001 + * @tc.desc Test Js Api setAppShareOptions, error intention + * @tc.type: FUNC + * @tc.require: + */ + it('UdmfSetAppShareOptionsTest001', 0, function () { + const TAG = 'UdmfSetAppShareOptionsTest001:'; + console.info(TAG, 'start'); + try { + UDC.setAppShareOptions(UDC.Intention.DATA_HUB, UDC.ShareOptions.IN_APP); + console.error(TAG, 'Unreachable code!'); + expect(null).assertFail(); + } catch (e) { + console.error(TAG, `get e. code is ${e.code},message is ${e.message} `); + expect(e.code === ERROR_PARAMETER).assertTrue(); + } + console.info(TAG, 'end'); + }); + + /** + * @tc.name UdmfRemoveAppShareOptionsTest001 + * @tc.desc Test Js Api removeAppShareOptions, error intention + * @tc.type: FUNC + * @tc.require: + */ + it('UdmfRemoveAppShareOptionsTest001', 0, function () { + const TAG = 'UdmfRemoveAppShareOptionsTest001:'; + console.info(TAG, 'start'); + try { + UDC.removeAppShareOptions(UDC.Intention.DATA_HUB); + console.error(TAG, 'Unreachable code!'); + expect(null).assertFail(); + } catch (e) { + console.error(TAG, `get e. code is ${e.code},message is ${e.message} `); + expect(e.code === ERROR_PARAMETER).assertTrue(); + } + console.info(TAG, 'end'); + }); }); \ No newline at end of file diff --git a/interfaces/jskits/data/unified_data_channel_napi.h b/interfaces/jskits/data/unified_data_channel_napi.h index 9077bacce4cd4230933f53f29784fc9c10b1772e..a1168bd767cc3e2ba58eec157c40ae4faf87b05e 100644 --- a/interfaces/jskits/data/unified_data_channel_napi.h +++ b/interfaces/jskits/data/unified_data_channel_napi.h @@ -20,6 +20,7 @@ #include "napi/native_api.h" #include "napi/native_node_api.h" +#include "udmf_client.h" namespace OHOS { namespace UDMF { @@ -39,6 +40,8 @@ private: static napi_value CreateShareOptions(napi_env env, napi_callback_info info); static napi_value SetAppShareOptions(napi_env env, napi_callback_info info); static napi_value RemoveAppShareOptions(napi_env env, napi_callback_info info); + static napi_status ConvertUnifiedDataSetToNapi( + napi_env env, const std::vector &dataSet, napi_value &output); }; } // namespace UDMF } // namespace OHOS