代码拉取完成,页面将自动刷新
同步操作将从 OpenHarmony/filemanagement_app_file_service 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
* Copyright (c) 2024 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.
*/
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <string>
#include "b_error/b_error.h"
#include "b_radar/b_radar.h"
#include "b_sa/b_sa_utils.h"
#include "b_jsonutil/b_jsonutil.h"
#include "filemgmt_libhilog.h"
#include "message_parcel.h"
#include "bms_adapter_mock.h"
#include "module_app_gallery/app_gallery_dispose_proxy.h"
#include "module_app_gallery/app_gallery_service_connection.h"
#include "want.h"
namespace OHOS::FileManagement::Backup {
using namespace std;
using namespace testing;
using namespace testing::ext;
class AppGalleryTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase();
void SetUp() {};
void TearDown() {};
static inline shared_ptr<BundleMgrAdapterMock> bms = nullptr;
};
void AppGalleryTest::SetUpTestCase(void)
{
bms = make_shared<BundleMgrAdapterMock>();
BundleMgrAdapterMock::bms = bms;
}
void AppGalleryTest::TearDownTestCase()
{
BundleMgrAdapterMock::bms = nullptr;
bms = nullptr;
}
/**
* @tc.number: App_Gallery_GetInstance_0100
* @tc.name: App_Gallery_GetInstance_0100
* @tc.desc: 测试 GetInstance
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: issueIAKC3I
*/
HWTEST_F(AppGalleryTest, App_Gallery_GetInstance_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "ServiceTest-begin App_Gallery_GetInstance_0100";
try {
auto instance = AppGalleryDisposeProxy::GetInstance();
bool result = instance != nullptr;
EXPECT_TRUE(result);
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by App_Gallery_GetInstance_0100.";
}
GTEST_LOG_(INFO) << "ServiceTest-end App_Gallery_GetInstance_0100";
}
/**
* @tc.number: App_Gallery_GetInstance_0200
* @tc.name: App_Gallery_GetInstance_0200
* @tc.desc: 测试 GetInstance
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: issueIAKC3I
*/
HWTEST_F(AppGalleryTest, App_Gallery_GetInstance_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "ServiceTest-begin App_Gallery_GetInstance_0200";
try {
auto instance1 = AppGalleryDisposeProxy::GetInstance();
auto instance2 = AppGalleryDisposeProxy::GetInstance();
bool result = instance1 == instance2;
EXPECT_TRUE(result);
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by App_Gallery_GetInstance_0200.";
}
GTEST_LOG_(INFO) << "ServiceTest-end App_Gallery_GetInstance_0200";
}
/**
* @tc.number: App_Gallery_GetAppGalleryConnection_0100
* @tc.name: App_Gallery_GetAppGalleryConnection_0100
* @tc.desc: 测试 GetAppGalleryConnection
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: issueIAKC3I
*/
HWTEST_F(AppGalleryTest, App_Gallery_GetAppGalleryConnection_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "ServiceTest-begin App_Gallery_GetAppGalleryConnection_0100";
try {
auto instance = AppGalleryDisposeProxy::GetInstance();
EXPECT_TRUE(instance != nullptr);
int32_t userId = 100;
auto result = instance->GetAppGalleryConnection(userId);
EXPECT_TRUE(result == nullptr);
instance->appGalleryConnectionMap_[userId] = sptr(new AppGalleryConnection(userId));
result = instance->GetAppGalleryConnection(userId);
EXPECT_TRUE(result != nullptr);
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by App_Gallery_GetAppGalleryConnection_0100.";
}
GTEST_LOG_(INFO) << "ServiceTest-end App_Gallery_GetAppGalleryConnection_0100";
}
/**
* @tc.number: App_Gallery_ConnectAppGallery_0100
* @tc.name: App_Gallery_ConnectAppGallery_0100
* @tc.desc: 测试 ConnectAppGallery
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: issueIAKC3I
*/
HWTEST_F(AppGalleryTest, App_Gallery_ConnectAppGallery_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "ServiceTest-begin App_Gallery_ConnectAppGallery_0100";
try {
auto instance = AppGalleryDisposeProxy::GetInstance();
EXPECT_TRUE(instance != nullptr);
int32_t userId = 101;
EXPECT_CALL(*bms, GetAppGalleryBundleName()).WillOnce(Return(""));
auto result = instance->ConnectAppGallery(userId);
EXPECT_TRUE(result == nullptr);
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by App_Gallery_ConnectAppGallery_0100.";
}
GTEST_LOG_(INFO) << "ServiceTest-end App_Gallery_ConnectAppGallery_0100";
}
/**
* @tc.number: App_Gallery_StartRestore_0100
* @tc.name: App_Gallery_StartRestore_0100
* @tc.desc: 测试 StartRestore
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: issueIAKC3I
*/
HWTEST_F(AppGalleryTest, App_Gallery_StartRestore_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "ServiceTest-begin App_Gallery_StartRestore_0100";
try {
auto instance = AppGalleryDisposeProxy::GetInstance();
EXPECT_TRUE(instance != nullptr);
std::string bundleName = "1234";
int32_t userId = 102;
auto result = instance->StartRestore(bundleName, userId);
EXPECT_EQ(result, DisposeErr::OK);
result = instance->EndRestore(bundleName, userId);
EXPECT_EQ(result, DisposeErr::OK);
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by App_Gallery_StartRestore_0100.";
}
GTEST_LOG_(INFO) << "ServiceTest-end App_Gallery_StartRestore_0100";
}
/**
* @tc.number: App_Gallery_StartRestore_0200
* @tc.name: App_Gallery_StartRestore_0200
* @tc.desc: 测试 StartRestore
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: issueIAKC3I
*/
HWTEST_F(AppGalleryTest, App_Gallery_StartRestore_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "ServiceTest-begin App_Gallery_StartRestore_0200";
try {
auto instance = AppGalleryDisposeProxy::GetInstance();
EXPECT_TRUE(instance != nullptr);
std::string bundleName = "testapp";
int32_t userId = 102;
EXPECT_CALL(*bms, GetAppGalleryBundleName()).WillOnce(Return(""));
auto result = instance->StartRestore(bundleName, userId);
EXPECT_EQ(result, DisposeErr::CONN_FAIL);
EXPECT_CALL(*bms, GetAppGalleryBundleName()).WillOnce(Return(""));
result = instance->EndRestore(bundleName, userId);
EXPECT_EQ(result, DisposeErr::CONN_FAIL);
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by App_Gallery_StartRestore_0200.";
}
GTEST_LOG_(INFO) << "ServiceTest-end App_Gallery_StartRestore_0200";
}
/**
* @tc.number: App_Gallery_StartBackup_0100
* @tc.name: App_Gallery_StartBackup_0100
* @tc.desc: 测试 StartBackup
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 1
* @tc.require: issueIAKC3I
*/
HWTEST_F(AppGalleryTest, App_Gallery_StartBackup_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "ServiceTest-begin App_Gallery_StartBackup_0100";
try {
auto instance = AppGalleryDisposeProxy::GetInstance();
EXPECT_TRUE(instance != nullptr);
std::string bundleName = "1234";
int32_t userId = 102;
EXPECT_CALL(*bms, GetAppGalleryBundleName()).WillOnce(Return(""));
auto result = instance->StartBackup(bundleName, userId);
EXPECT_EQ(result, DisposeErr::CONN_FAIL);
EXPECT_CALL(*bms, GetAppGalleryBundleName()).WillOnce(Return(""));
result = instance->EndBackup(bundleName, userId);
EXPECT_EQ(result, DisposeErr::CONN_FAIL);
} catch (...) {
EXPECT_TRUE(false);
GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by App_Gallery_StartBackup_0100.";
}
GTEST_LOG_(INFO) << "ServiceTest-end App_Gallery_StartBackup_0100";
}
}
# Copyright (c) 2024 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.
import("//build/test.gni")
import("//foundation/filemanagement/app_file_service/backup.gni")
ohos_unittest("app_gallery_dispose_proxy_test") {
branch_protector_ret = "pac_ret"
module_out_path = path_module_out_tests
sources = [
"${path_backup_mock}/module_external/src/bms_adapter_mock.cpp",
"${path_backup}/services/backup_sa/src/module_app_gallery/app_gallery_dispose_proxy.cpp",
"${path_backup}/services/backup_sa/src/module_app_gallery/app_gallery_service_connection.cpp",
"app_gallery_dispose_proxy_test.cpp",
]
include_dirs = [
"${path_backup}/services/backup_sa/include",
"${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl",
"${path_backup}/tests/unittests/backup_api/backup_impl/include",
"${path_backup_mock}/module_external/include",
]
deps = [
"${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner",
"${path_backup}/tests/utils:backup_test_utils",
"${path_backup}/utils:backup_utils",
]
external_deps = [
"ability_base:want",
"ability_runtime:ability_manager",
"access_token:libaccesstoken_sdk",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"storage_service:storage_manager_sa_proxy",
]
defines = [
"LOG_TAG=\"app_file_service\"",
"LOG_DOMAIN=0xD004303",
"private = public",
]
use_exceptions = true
}
group("app_gallery_test") {
testonly = true
deps = [ ":app_gallery_dispose_proxy_test" ]
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。