From 5a711fbf5f3b86543b26c030ca784ee468b5570a Mon Sep 17 00:00:00 2001 From: Cuiziyuan Date: Thu, 19 Jun 2025 12:01:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cuiziyuan --- .../service/test/BUILD.gn | 2 ++ .../test/data_share_service_impl_test.cpp | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index e4bc3ecaa..d4302e93f 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -994,6 +994,7 @@ ohos_unittest("DataShareServiceImplTest") { "data_share_subscriber_managers_test.cpp", "data_share_types_util_test.cpp", "kv_dalegate_test.cpp", + "mock/account_delegate_mock.cpp", ] configs = [ ":module_private_config" ] @@ -1027,6 +1028,7 @@ ohos_unittest("DataShareServiceImplTest") { "data_share:datashare_common_lite", "data_share:datashare_consumer", "device_manager:devicemanagersdk", + "googletest:gmock_main", "googletest:gtest_main", "hicollie:libhicollie", "hilog:libhilog", diff --git a/services/distributeddataservice/service/test/data_share_service_impl_test.cpp b/services/distributeddataservice/service/test/data_share_service_impl_test.cpp index a4c51e60c..394e3e54c 100644 --- a/services/distributeddataservice/service/test/data_share_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/data_share_service_impl_test.cpp @@ -20,6 +20,7 @@ #include #include "accesstoken_kit.h" +#include "account_delegate_mock.h" #include "data_share_service_stub.h" #include "dump/dump_manager.h" #include "hap_token_info.h" @@ -517,4 +518,27 @@ HWTEST_F(DataShareServiceImplTest, GetSilentProxyStatus001, TestSize.Level1) SetSelfTokenInfo(USER_TEST); ZLOGI("DataShareServiceImplTest GetSilentProxyStatus001 end"); } + +/** +* @tc.name: DataProviderConfig001 +* @tc.desc: test get provider info function +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(DataShareServiceImplTest, DataProviderConfig001, TestSize.Level1) +{ + ZLOGI("DataShareServiceImplTest DataProviderConfig001 start"); + SetSelfTokenInfo(NATIVE_USER_ID); + auto testTokenId = Security::AccessToken::AccessTokenKit::GetHapTokenID( + NATIVE_USER_ID, BUNDLE_NAME, 0); + EXPECT_CALL(AccountDelegateMock::Init(), QueryForegroundUserId(testing::_)) + .Times(1) + .WillOnce(testing::Return(false)); + DataProviderConfig config(SLIENT_ACCESS_URI, testTokenId); + EXPECT_EQ(config.providerInfo_.uri, SLIENT_ACCESS_URI); + EXPECT_EQ(config.providerInfo_.currentUserId, NATIVE_USER_ID); + EXPECT_EQ(config.providerInfo_.visitedUserId, NATIVE_USER_ID); + SetSelfTokenInfo(USER_TEST); + ZLOGI("DataShareServiceImplTest DataProviderConfig001 end"); +} } // namespace OHOS::Test \ No newline at end of file -- Gitee