mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-23 23:30:44 +00:00
commit attach debug tdd
Signed-off-by: xinking129 <xinxin13@huawei.com>
This commit is contained in:
parent
c21c8f085e
commit
f8483640a8
@ -351,6 +351,7 @@ group("unittest") {
|
||||
"app_debug_info_test:unittest",
|
||||
"app_debug_listener_proxy_test:unittest",
|
||||
"app_debug_listener_stub_test:unittest",
|
||||
"app_debug_manager_test:unittest",
|
||||
"app_exit_reason_data_manager_test:unittest",
|
||||
"app_launch_data_test:unittest",
|
||||
"app_lifecycle_deal_test:unittest",
|
||||
@ -365,6 +366,7 @@ group("unittest") {
|
||||
"app_recovery_test:unittest",
|
||||
"app_running_manager_test:unittest",
|
||||
"app_running_processes_info_test:unittest",
|
||||
"app_running_record_test:unittest",
|
||||
"app_scheduler_host_test:unittest",
|
||||
"app_scheduler_proxy_test:unittest",
|
||||
"app_scheduler_test:unittest",
|
||||
|
@ -24,6 +24,7 @@ ohos_unittest("ability_manager_client_branch_test") {
|
||||
"${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/",
|
||||
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
|
||||
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
|
||||
"${ability_runtime_test_path}/unittest/app_debug_listener_stub_test",
|
||||
]
|
||||
|
||||
sources = [
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2021-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
|
||||
@ -21,10 +21,12 @@ ohos_unittest("ability_manager_proxy_test") {
|
||||
|
||||
include_dirs = [
|
||||
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock",
|
||||
"${ability_runtime_test_path}/unittest/ability_manager_proxy_test/",
|
||||
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/ability_scheduler_mock",
|
||||
"${ability_runtime_services_path}/common/include",
|
||||
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
|
||||
"${ability_runtime_test_path}/unittest/app_debug_listener_proxy_test",
|
||||
]
|
||||
|
||||
sources = [
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "mock_ability_token.h"
|
||||
#include "ability_scheduler_mock.h"
|
||||
#include "ability_record.h"
|
||||
#include "app_debug_listener_stub_mock.h"
|
||||
#include "ability_scheduler.h"
|
||||
#include "mission_snapshot.h"
|
||||
#include "want_sender_info.h"
|
||||
@ -37,6 +38,7 @@ namespace OHOS {
|
||||
namespace AAFwk {
|
||||
namespace {
|
||||
const int USER_ID = 100;
|
||||
constexpr int32_t REPLY_RESULT = 1;
|
||||
} // namespace
|
||||
|
||||
class AbilityManagerProxyTest : public testing::Test {
|
||||
@ -2396,6 +2398,84 @@ HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_IsAbilityControllerStart_0
|
||||
proxy_->IsAbilityControllerStart(want);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerProxy_RegisterAppDebugListener_0100
|
||||
* @tc.desc: Test the status of RegisterAppDebugListener.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_RegisterAppDebugListener_0100, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(proxy_, nullptr);
|
||||
sptr<AppExecFwk::AppDebugListenerStubMock> listener = new AppDebugListenerStubMock();
|
||||
auto result = proxy_->RegisterAppDebugListener(listener);
|
||||
EXPECT_EQ(result, NO_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerProxy_RegisterAppDebugListener_0200
|
||||
* @tc.desc: Test the status of RegisterAppDebugListener, check nullptr listener.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_RegisterAppDebugListener_0200, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(proxy_, nullptr);
|
||||
sptr<AppExecFwk::AppDebugListenerStubMock> listener = nullptr;
|
||||
auto result = proxy_->RegisterAppDebugListener(listener);
|
||||
EXPECT_EQ(result, INNER_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerProxy_UnregisterAppDebugListener_0100
|
||||
* @tc.desc: Test the status of UnregisterAppDebugListener.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_UnregisterAppDebugListener_0100, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(proxy_, nullptr);
|
||||
sptr<AppExecFwk::AppDebugListenerStubMock> listener = new AppDebugListenerStubMock();
|
||||
auto result = proxy_->UnregisterAppDebugListener(listener);
|
||||
EXPECT_EQ(result, NO_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerProxy_UnregisterAppDebugListener_0200
|
||||
* @tc.desc: Test the status of UnregisterAppDebugListener, check nullptr listener.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_UnregisterAppDebugListener_0200, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(proxy_, nullptr);
|
||||
sptr<AppExecFwk::AppDebugListenerStubMock> listener = nullptr;
|
||||
auto result = proxy_->UnregisterAppDebugListener(listener);
|
||||
EXPECT_EQ(result, INNER_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerProxy_AttachAppDebug_0100
|
||||
* @tc.desc: Test the state of AttachAppDebug
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_AttachAppDebug_0100, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(proxy_, nullptr);
|
||||
std::string bundleName = "bundleName";
|
||||
auto result = proxy_->AttachAppDebug(bundleName);
|
||||
EXPECT_EQ(result, NO_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerProxy_DetachAppDebug_0100
|
||||
* @tc.desc: Test the state of DetachAppDebug
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_DetachAppDebug_0100, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(proxy_, nullptr);
|
||||
std::string bundleName = "bundleName";
|
||||
auto result = proxy_->DetachAppDebug(bundleName);
|
||||
EXPECT_EQ(result, NO_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerProxy_GetForegroundUIAbilities_001
|
||||
* @tc.desc: Test function GetForegroundUIAbilities when normally.
|
||||
|
@ -20,10 +20,11 @@ ohos_unittest("ability_manager_stub_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
include_dirs = [
|
||||
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
|
||||
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock",
|
||||
"${ability_runtime_test_path}/unittest/app_debug_listener_proxy_test",
|
||||
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"${distributedschedule_path}/samgr/utils/native/include/",
|
||||
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
|
@ -14,9 +14,10 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "iremote_proxy.h"
|
||||
#include "ability_manager_stub_impl_mock.h"
|
||||
#include "ability_scheduler.h"
|
||||
#include "app_debug_listener_stub_mock.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "mock_ability_connect_callback.h"
|
||||
#include "mock_ability_token.h"
|
||||
|
||||
@ -2456,6 +2457,130 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_IsAbilityControllerStartInne
|
||||
EXPECT_EQ(stub_->IsAbilityControllerStartInner(data, reply), NO_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerStub_RegisterAppDebugListenerInner_001
|
||||
* @tc.desc: Test the status of RegisterAppDebugListenerInner, check empty AppDebugListener.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_RegisterAppDebugListenerInner_001, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(stub_, nullptr);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
auto res = stub_->RegisterAppDebugListenerInner(data, reply);
|
||||
EXPECT_EQ(res, ERR_INVALID_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerStub_RegisterAppDebugListenerInner_002
|
||||
* @tc.desc: Test the status of RegisterAppDebugListenerInner.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_RegisterAppDebugListenerInner_002, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(stub_, nullptr);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
auto token = new AppExecFwk::AppDebugListenerStubMock();
|
||||
EXPECT_NE(token, nullptr);
|
||||
auto ret = data.WriteRemoteObject(token);
|
||||
EXPECT_EQ(ret, true);
|
||||
int res = stub_->RegisterAppDebugListenerInner(data, reply);
|
||||
EXPECT_EQ(res, NO_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerStub_UnregisterAppDebugListenerInner_001
|
||||
* @tc.desc: Test the status of UnregisterAppDebugListenerInner, check empty appDebugListener.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_UnregisterAppDebugListenerInner_001, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(stub_, nullptr);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
auto res = stub_->UnregisterAppDebugListenerInner(data, reply);
|
||||
EXPECT_EQ(res, ERR_INVALID_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerStub_UnregisterAppDebugListenerInner_002
|
||||
* @tc.desc: Test the status of UnregisterAppDebugListenerInner.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_UnregisterAppDebugListenerInner_002, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(stub_, nullptr);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
auto token = new AppExecFwk::AppDebugListenerStubMock();
|
||||
EXPECT_NE(token, nullptr);
|
||||
bool ret = data.WriteRemoteObject(token);
|
||||
EXPECT_EQ(ret, true);
|
||||
auto res = stub_->UnregisterAppDebugListenerInner(data, reply);
|
||||
EXPECT_EQ(res, NO_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerStub_AttachAppDebugInner_001
|
||||
* @tc.desc: Test the state of AttachAppDebugInner.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_AttachAppDebugInner_001, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(stub_, nullptr);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
std::string bundleName = "bundleName";
|
||||
data.WriteString(bundleName);
|
||||
auto res = stub_->AttachAppDebugInner(data, reply);
|
||||
EXPECT_EQ(res, NO_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerStub_AttachAppDebugInner_002
|
||||
* @tc.desc: Test the state of AttachAppDebugInner, check empty bundleName;
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_AttachAppDebugInner_002, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(stub_, nullptr);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
auto res = stub_->AttachAppDebugInner(data, reply);
|
||||
EXPECT_EQ(res, ERR_INVALID_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerStub_DetachAppDebugInner_001
|
||||
* @tc.desc: Test the state of DetachAppDebugInner.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_DetachAppDebugInner_001, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(stub_, nullptr);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
std::string bundleName = "bundleName";
|
||||
data.WriteString(bundleName);
|
||||
auto res = stub_->DetachAppDebugInner(data, reply);
|
||||
EXPECT_EQ(res, NO_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerStub_DetachAppDebugInner_002
|
||||
* @tc.desc: Test the state of DetachAppDebugInner, check empty bundleName.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_DetachAppDebugInner_002, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(stub_, nullptr);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
auto res = stub_->DetachAppDebugInner(data, reply);
|
||||
EXPECT_EQ(res, ERR_INVALID_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityManagerStub_GetForegroundUIAbilitiesInner_001
|
||||
* @tc.desc: Test function GetForegroundUIAbilitiesInner when normally.
|
||||
|
@ -2553,5 +2553,31 @@ HWTEST_F(AbilityRecordTest, NotifyTerminateMission_001, TestSize.Level1)
|
||||
abilityRecord_->collaboratorType_ = 1;
|
||||
abilityRecord_->SetAbilityStateInner(AbilityState::TERMINATING);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityRecord_SetAttachDebug_001
|
||||
* @tc.desc: Test the correct value status of SetAttachDebug
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityRecordTest, AbilityRecord_SetAttachDebug_001, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(abilityRecord_, nullptr);
|
||||
bool isAttachDebug = true;
|
||||
abilityRecord_->SetAttachDebug(isAttachDebug);
|
||||
EXPECT_EQ(abilityRecord_->isAttachDebug_, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityRecord_SetAttachDebug_002
|
||||
* @tc.desc: Test the error value status of SetAttachDebug
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AbilityRecordTest, AbilityRecord_SetAttachDebug_002, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(abilityRecord_, nullptr);
|
||||
bool isAttachDebug = false;
|
||||
abilityRecord_->SetAttachDebug(isAttachDebug);
|
||||
EXPECT_EQ(abilityRecord_->isAttachDebug_, false);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
@ -850,5 +850,100 @@ HWTEST_F(AmsMgrSchedulerTest, SetCurrentUserId_001, TestSize.Level0)
|
||||
int userId = 1;
|
||||
amsMgrScheduler->SetCurrentUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RegisterAppDebugListener_001
|
||||
* @tc.desc: Test the state of RegisterAppDebugListener
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AmsMgrSchedulerTest, RegisterAppDebugListener_001, TestSize.Level0)
|
||||
{
|
||||
auto amsMgrScheduler = std::make_unique<AmsMgrScheduler>(nullptr, nullptr);
|
||||
EXPECT_NE(amsMgrScheduler, nullptr);
|
||||
sptr<IAppDebugListener> listener = nullptr;
|
||||
int32_t res = amsMgrScheduler->RegisterAppDebugListener(listener);
|
||||
EXPECT_EQ(res, ERR_INVALID_OPERATION);
|
||||
|
||||
amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner();
|
||||
amsMgrScheduler->amsHandler_ = GetAmsTaskHandler();
|
||||
res = amsMgrScheduler->RegisterAppDebugListener(listener);
|
||||
EXPECT_NE(res, ERR_INVALID_OPERATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UnregisterAppDebugListener_001
|
||||
* @tc.desc: Test the state of UnregisterAppDebugListener
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AmsMgrSchedulerTest, UnregisterAppDebugListener_001, TestSize.Level0)
|
||||
{
|
||||
auto amsMgrScheduler = std::make_unique<AmsMgrScheduler>(nullptr, nullptr);
|
||||
EXPECT_NE(amsMgrScheduler, nullptr);
|
||||
sptr<IAppDebugListener> listener = nullptr;
|
||||
int32_t res = amsMgrScheduler->UnregisterAppDebugListener(listener);
|
||||
EXPECT_EQ(res, ERR_INVALID_OPERATION);
|
||||
|
||||
amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner();
|
||||
amsMgrScheduler->amsHandler_ = GetAmsTaskHandler();
|
||||
res = amsMgrScheduler->UnregisterAppDebugListener(listener);
|
||||
EXPECT_NE(res, ERR_INVALID_OPERATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AttachAppDebug_001
|
||||
* @tc.desc: Test the state of AttachAppDebug
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AmsMgrSchedulerTest, AttachAppDebug_001, TestSize.Level0)
|
||||
{
|
||||
auto amsMgrScheduler = std::make_unique<AmsMgrScheduler>(nullptr, nullptr);
|
||||
EXPECT_NE(amsMgrScheduler, nullptr);
|
||||
std::string bundleName = "";
|
||||
int32_t res = amsMgrScheduler->AttachAppDebug(bundleName);
|
||||
EXPECT_EQ(res, ERR_INVALID_OPERATION);
|
||||
|
||||
amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner();
|
||||
amsMgrScheduler->amsHandler_ = GetAmsTaskHandler();
|
||||
res = amsMgrScheduler->AttachAppDebug(bundleName);
|
||||
EXPECT_NE(res, ERR_INVALID_OPERATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DetachAppDebug_001
|
||||
* @tc.desc: Test the state of DetachAppDebug
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AmsMgrSchedulerTest, DetachAppDebug_001, TestSize.Level0)
|
||||
{
|
||||
auto amsMgrScheduler = std::make_unique<AmsMgrScheduler>(nullptr, nullptr);
|
||||
EXPECT_NE(amsMgrScheduler, nullptr);
|
||||
std::string bundleName = "";
|
||||
int32_t res = amsMgrScheduler->DetachAppDebug(bundleName);
|
||||
EXPECT_EQ(res, ERR_INVALID_OPERATION);
|
||||
|
||||
amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner();
|
||||
amsMgrScheduler->amsHandler_ = GetAmsTaskHandler();
|
||||
res = amsMgrScheduler->DetachAppDebug(bundleName);
|
||||
EXPECT_NE(res, ERR_INVALID_OPERATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RegisterAbilityDebugResponse_001
|
||||
* @tc.desc: Test the state of RegisterAbilityDebugResponse
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AmsMgrSchedulerTest, RegisterAbilityDebugResponse_001, TestSize.Level0)
|
||||
{
|
||||
auto amsMgrScheduler = std::make_unique<AmsMgrScheduler>(nullptr, nullptr);
|
||||
EXPECT_NE(amsMgrScheduler, nullptr);
|
||||
sptr<IAbilityDebugResponse> response = nullptr;
|
||||
int32_t res = amsMgrScheduler->RegisterAbilityDebugResponse(response);
|
||||
EXPECT_EQ(res, ERR_INVALID_OPERATION);
|
||||
|
||||
amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner();
|
||||
amsMgrScheduler->amsHandler_ = GetAmsTaskHandler();
|
||||
res = amsMgrScheduler->RegisterAbilityDebugResponse(response);
|
||||
EXPECT_NE(res, ERR_INVALID_OPERATION);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
54
test/unittest/app_debug_manager_test/BUILD.gn
Normal file
54
test/unittest/app_debug_manager_test/BUILD.gn
Normal file
@ -0,0 +1,54 @@
|
||||
# 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.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
|
||||
module_output_path = "ability_runtime/appmgrservice"
|
||||
|
||||
ohos_unittest("app_debug_manager_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
include_dirs = [
|
||||
"${ability_runtime_services_path}/appmgr/include",
|
||||
"${ability_runtime_test_path}/mock/services_appmgr_test/include",
|
||||
"${ability_runtime_test_path}/unittest/app_debug_listener_stub_test",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp",
|
||||
"app_debug_manager_test.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"appspawn:appspawn_socket_client",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":app_debug_manager_test" ]
|
||||
}
|
240
test/unittest/app_debug_manager_test/app_debug_manager_test.cpp
Normal file
240
test/unittest/app_debug_manager_test/app_debug_manager_test.cpp
Normal file
@ -0,0 +1,240 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#define private public
|
||||
#include "app_debug_manager.h"
|
||||
#include "app_debug_listener_proxy.h"
|
||||
#undef private
|
||||
|
||||
#include "mock_app_debug_listener_stub.h"
|
||||
#include "parcel.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
namespace {
|
||||
std::string DEBUG_START_NAME = "debugStartBundle";
|
||||
std::string NO_DEBUG_START_NAME = "noDebugStartBundle";
|
||||
const bool IS_DEBUG_START = true;
|
||||
const bool NO_DEBUG_START = false;
|
||||
const unsigned int SIZE_ONE = 1;
|
||||
const unsigned int SIZE_TWO = 2;
|
||||
}
|
||||
class AppDebugManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
|
||||
std::shared_ptr<AppDebugManager> manager_;
|
||||
sptr<MockAppDebugListenerStub> listener_;
|
||||
};
|
||||
|
||||
void AppDebugManagerTest::SetUpTestCase(void)
|
||||
{}
|
||||
|
||||
void AppDebugManagerTest::TearDownTestCase(void)
|
||||
{}
|
||||
|
||||
void AppDebugManagerTest::SetUp()
|
||||
{
|
||||
manager_ = std::make_shared<AppDebugManager>();
|
||||
listener_ = new MockAppDebugListenerStub();
|
||||
manager_->listeners_.insert(listener_);
|
||||
}
|
||||
|
||||
void AppDebugManagerTest::TearDown()
|
||||
{}
|
||||
|
||||
/**
|
||||
* @tc.name: RegisterAppDebugListener_0100
|
||||
* @tc.desc: Register listener for app debug listener, check nullptr listener.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppDebugManagerTest, RegisterAppDebugListener_0100, TestSize.Level1)
|
||||
{
|
||||
sptr<MockAppDebugListenerStub> listener = new MockAppDebugListenerStub();
|
||||
AppDebugInfo appDebugInfo;
|
||||
manager_->debugInfos_.push_back(appDebugInfo);
|
||||
|
||||
EXPECT_CALL(*listener, OnAppDebugStarted(_)).Times(1);
|
||||
auto result = manager_->RegisterAppDebugListener(listener);
|
||||
EXPECT_EQ(result, ERR_OK);
|
||||
EXPECT_EQ(manager_->listeners_.size(), SIZE_TWO);
|
||||
|
||||
listener = nullptr;
|
||||
result = manager_->RegisterAppDebugListener(listener);
|
||||
EXPECT_EQ(result, ERR_INVALID_DATA);
|
||||
EXPECT_EQ(manager_->listeners_.size(), SIZE_TWO);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UnregisterAppDebugListener_0100
|
||||
* @tc.desc: Unregister listener for app debug listener, check nullptr listener.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppDebugManagerTest, UnregisterAppDebugListener_0100, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(manager_, nullptr);
|
||||
sptr<MockAppDebugListenerStub> listener = nullptr;
|
||||
auto result = manager_->UnregisterAppDebugListener(listener);
|
||||
EXPECT_EQ(result, ERR_INVALID_DATA);
|
||||
EXPECT_EQ(manager_->listeners_.size(), SIZE_ONE);
|
||||
|
||||
EXPECT_NE(listener_, nullptr);
|
||||
result = manager_->UnregisterAppDebugListener(listener_);
|
||||
EXPECT_EQ(result, ERR_OK);
|
||||
EXPECT_TRUE(manager_->listeners_.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StartDebug_0100
|
||||
* @tc.desc: Start debug by AppDebugInfo, notify AppDebugListener.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppDebugManagerTest, StartDebug_0100, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(manager_, nullptr);
|
||||
EXPECT_TRUE(manager_->debugInfos_.empty());
|
||||
std::vector<AppDebugInfo> debugInfos;
|
||||
AppDebugInfo info;
|
||||
debugInfos.push_back(info);
|
||||
|
||||
EXPECT_NE(listener_, nullptr);
|
||||
EXPECT_CALL(*listener_, OnAppDebugStarted(_)).Times(1);
|
||||
manager_->StartDebug(debugInfos);
|
||||
EXPECT_FALSE(manager_->debugInfos_.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StopDebug_0100
|
||||
* @tc.desc: Start debug by AppDebugInfo, notify AppDebugListener.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppDebugManagerTest, StopDebug_0100, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(manager_, nullptr);
|
||||
EXPECT_TRUE(manager_->debugInfos_.empty());
|
||||
std::vector<AppDebugInfo> debugInfos;
|
||||
AppDebugInfo info;
|
||||
info.bundleName = DEBUG_START_NAME;
|
||||
info.isDebugStart = IS_DEBUG_START;
|
||||
info.pid = 10;
|
||||
info.uid = 12345;
|
||||
debugInfos.push_back(info);
|
||||
manager_->debugInfos_ = debugInfos;
|
||||
|
||||
EXPECT_NE(listener_, nullptr);
|
||||
EXPECT_CALL(*listener_, OnAppDebugStoped(_)).Times(1);
|
||||
manager_->StopDebug(debugInfos);
|
||||
EXPECT_TRUE(manager_->debugInfos_.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsAttachDebug_0100
|
||||
* @tc.desc: Given the bundleName, return true if not DebugStart, otherwise return false.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppDebugManagerTest, IsAttachDebug_0100, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(manager_, nullptr);
|
||||
AppDebugInfo debugStart_info;
|
||||
debugStart_info.bundleName = DEBUG_START_NAME;
|
||||
debugStart_info.isDebugStart = IS_DEBUG_START;
|
||||
manager_->debugInfos_.push_back(debugStart_info);
|
||||
|
||||
AppDebugInfo noDebugStart_info;
|
||||
noDebugStart_info.bundleName = NO_DEBUG_START_NAME;
|
||||
noDebugStart_info.isDebugStart = NO_DEBUG_START;
|
||||
manager_->debugInfos_.push_back(noDebugStart_info);
|
||||
|
||||
auto result = manager_->IsAttachDebug(DEBUG_START_NAME);
|
||||
EXPECT_FALSE(result);
|
||||
|
||||
result = manager_->IsAttachDebug(NO_DEBUG_START_NAME);
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetIncrementAppDebugInfo_0100
|
||||
* @tc.desc: Add new debug info into debugInfos, or update the isDebugStart flag.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppDebugManagerTest, GetIncrementAppDebugInfo_0100, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(manager_, nullptr);
|
||||
EXPECT_TRUE(manager_->debugInfos_.empty());
|
||||
|
||||
std::vector<AppDebugInfo> debugInfos;
|
||||
std::vector<AppDebugInfo> increment;
|
||||
AppDebugInfo debugStart_info;
|
||||
debugStart_info.bundleName = DEBUG_START_NAME;
|
||||
debugStart_info.isDebugStart = IS_DEBUG_START;
|
||||
|
||||
int pid = 10;
|
||||
int uid = 12345;
|
||||
AppDebugInfo noDebugStart_info;
|
||||
noDebugStart_info.bundleName = NO_DEBUG_START_NAME;
|
||||
noDebugStart_info.isDebugStart = NO_DEBUG_START;
|
||||
noDebugStart_info.pid = pid;
|
||||
noDebugStart_info.pid = uid;
|
||||
debugInfos.push_back(debugStart_info);
|
||||
debugInfos.push_back(noDebugStart_info);
|
||||
|
||||
manager_->GetIncrementAppDebugInfos(debugInfos, increment);
|
||||
EXPECT_EQ(manager_->debugInfos_.size(), SIZE_TWO);
|
||||
|
||||
increment.clear();
|
||||
debugInfos.clear();
|
||||
noDebugStart_info.isDebugStart = IS_DEBUG_START;
|
||||
debugInfos.push_back(noDebugStart_info);
|
||||
|
||||
manager_->GetIncrementAppDebugInfos(debugInfos, increment);
|
||||
EXPECT_EQ(manager_->debugInfos_.size(), SIZE_TWO);
|
||||
EXPECT_TRUE(manager_->debugInfos_.at(1).isDebugStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RemoveAppDebugInfo_0100
|
||||
* @tc.desc: Remove app debug info with bundleName, pid, uid and isDebugStart flag.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppDebugManagerTest, RemoveAppDebugInfo_0100, TestSize.Level1)
|
||||
{
|
||||
EXPECT_NE(manager_, nullptr);
|
||||
EXPECT_TRUE(manager_->debugInfos_.empty());
|
||||
|
||||
std::vector<AppDebugInfo> debugInfos;
|
||||
int pid = 10;
|
||||
int uid = 12345;
|
||||
AppDebugInfo debugInfo;
|
||||
debugInfo.bundleName = DEBUG_START_NAME;
|
||||
debugInfo.pid = pid;
|
||||
debugInfo.uid = uid;
|
||||
debugInfo.isDebugStart = IS_DEBUG_START;
|
||||
|
||||
manager_->debugInfos_.push_back(debugInfo);
|
||||
EXPECT_EQ(manager_->debugInfos_.size(), SIZE_ONE);
|
||||
|
||||
EXPECT_CALL(*listener_, OnAppDebugStoped(_)).Times(1);
|
||||
manager_->RemoveAppDebugInfo(debugInfo);
|
||||
EXPECT_TRUE(manager_->debugInfos_.empty());
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -39,6 +39,11 @@ using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
namespace {
|
||||
constexpr int32_t RECORD_ID = 1;
|
||||
constexpr int32_t APP_DEBUG_INFO_PID = 0;
|
||||
constexpr int32_t APP_DEBUG_INFO_UID = 0;
|
||||
}
|
||||
static int recordId_ = 0;
|
||||
class AppMgrServiceInnerTest : public testing::Test {
|
||||
public:
|
||||
@ -3506,6 +3511,180 @@ HWTEST_F(AppMgrServiceInnerTest, NotifyAppFaultBySA_001, TestSize.Level1)
|
||||
HILOG_INFO("NotifyAppFaultBySA_001 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RegisterAppDebugListener_001
|
||||
* @tc.desc: Test the status of RegisterAppDebugListener.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerTest, RegisterAppDebugListener_001, TestSize.Level0)
|
||||
{
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
EXPECT_NE(appMgrServiceInner, nullptr);
|
||||
sptr<IAppDebugListener> listener = nullptr;
|
||||
appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
|
||||
auto result = appMgrServiceInner->RegisterAppDebugListener(listener);
|
||||
EXPECT_EQ(result, ERR_INVALID_DATA);
|
||||
appMgrServiceInner->appDebugManager_ = nullptr;
|
||||
result = appMgrServiceInner->RegisterAppDebugListener(listener);
|
||||
EXPECT_EQ(result, ERR_NO_INIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UnregisterAppDebugListener_001
|
||||
* @tc.desc: Test the status of UnregisterAppDebugListener.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerTest, UnregisterAppDebugListener_001, TestSize.Level0)
|
||||
{
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
EXPECT_NE(appMgrServiceInner, nullptr);
|
||||
sptr<IAppDebugListener> listener = nullptr;
|
||||
appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
|
||||
auto result = appMgrServiceInner->UnregisterAppDebugListener(listener);
|
||||
EXPECT_EQ(result, ERR_INVALID_DATA);
|
||||
appMgrServiceInner->appDebugManager_ = nullptr;
|
||||
result = appMgrServiceInner->UnregisterAppDebugListener(listener);
|
||||
EXPECT_EQ(result, ERR_NO_INIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AttachAppDebug_001
|
||||
* @tc.desc: Test the status of AttachAppDebug.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerTest, AttachAppDebug_001, TestSize.Level0)
|
||||
{
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
EXPECT_NE(appMgrServiceInner, nullptr);
|
||||
std::string bundleName;
|
||||
appMgrServiceInner->appRunningManager_ = std::make_shared<AppRunningManager>();
|
||||
appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
|
||||
auto result = appMgrServiceInner->AttachAppDebug(bundleName);
|
||||
EXPECT_EQ(result, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AttachAppDebug_002
|
||||
* @tc.desc: Test the status of AttachAppDebug, check nullptr AppRunningManager.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerTest, AttachAppDebug_002, TestSize.Level0)
|
||||
{
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
EXPECT_NE(appMgrServiceInner, nullptr);
|
||||
std::string bundleName;
|
||||
appMgrServiceInner->appRunningManager_ = nullptr;
|
||||
appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
|
||||
auto result = appMgrServiceInner->AttachAppDebug(bundleName);
|
||||
EXPECT_EQ(result, ERR_NO_INIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DetachAppDebug_001
|
||||
* @tc.desc: Test the status of DetachAppDebug.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerTest, DetachAppDebug_001, TestSize.Level0)
|
||||
{
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
EXPECT_NE(appMgrServiceInner, nullptr);
|
||||
std::string bundleName;
|
||||
appMgrServiceInner->appRunningManager_ = std::make_shared<AppRunningManager>();
|
||||
appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
|
||||
auto result = appMgrServiceInner->DetachAppDebug(bundleName);
|
||||
EXPECT_EQ(result, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DetachAppDebug_002
|
||||
* @tc.desc: Test the status of DetachAppDebug, check nullptr AppRunningManager.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerTest, DetachAppDebug_002, TestSize.Level0)
|
||||
{
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
EXPECT_NE(appMgrServiceInner, nullptr);
|
||||
std::string bundleName;
|
||||
appMgrServiceInner->appRunningManager_ = nullptr;
|
||||
appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
|
||||
auto result = appMgrServiceInner->DetachAppDebug(bundleName);
|
||||
EXPECT_EQ(result, ERR_NO_INIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RegisterAbilityDebugResponse_001
|
||||
* @tc.desc: Test the status of RegisterAbilityDebugResponse.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerTest, RegisterAbilityDebugResponse_001, TestSize.Level0)
|
||||
{
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
EXPECT_NE(appMgrServiceInner, nullptr);
|
||||
sptr<IAbilityDebugResponse> response = nullptr;
|
||||
auto result = appMgrServiceInner->RegisterAbilityDebugResponse(response);
|
||||
EXPECT_EQ(result, ERR_INVALID_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: NotifyAbilitysDebugChange_001
|
||||
* @tc.desc: Test the status of NotifyAbilitysDebugChange.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerTest, NotifyAbilitysDebugChange_001, TestSize.Level0)
|
||||
{
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
EXPECT_NE(appMgrServiceInner, nullptr);
|
||||
std::string bundleName;
|
||||
bool isAppDebug = true;
|
||||
appMgrServiceInner->appRunningManager_ = std::make_shared<AppRunningManager>();
|
||||
appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
|
||||
auto result = appMgrServiceInner->NotifyAbilitysDebugChange(bundleName, isAppDebug);
|
||||
EXPECT_EQ(result, ERR_NO_INIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProcessAppDebug_001
|
||||
* @tc.desc: Test the status of ProcessAppDebug.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerTest, ProcessAppDebug_001, TestSize.Level0)
|
||||
{
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
EXPECT_NE(appMgrServiceInner, nullptr);
|
||||
appMgrServiceInner->appRunningManager_ = std::make_shared<AppRunningManager>();
|
||||
std::shared_ptr<ApplicationInfo> info = std::make_shared<ApplicationInfo>();
|
||||
int32_t recordId = RECORD_ID;
|
||||
std::string processName = "processName";
|
||||
std::shared_ptr<AppRunningRecord> appRecord = std::make_shared<AppRunningRecord>(info, recordId, processName);
|
||||
bool isDebugStart = true;
|
||||
appRecord->SetDebugApp(false);
|
||||
appMgrServiceInner->ProcessAppDebug(appRecord, isDebugStart);
|
||||
EXPECT_EQ(appRecord->IsDebugApp(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MakeAppDebugInfo_001
|
||||
* @tc.desc: Test the status of MakeAppDebugInfo.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerTest, MakeAppDebugInfo_001, TestSize.Level0)
|
||||
{
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
EXPECT_NE(appMgrServiceInner, nullptr);
|
||||
appMgrServiceInner->appRunningManager_ = std::make_shared<AppRunningManager>();
|
||||
std::shared_ptr<ApplicationInfo> info = std::make_shared<ApplicationInfo>();
|
||||
int32_t recordId = RECORD_ID;
|
||||
std::string processName = "processName";
|
||||
std::shared_ptr<AppRunningRecord> appRecord = std::make_shared<AppRunningRecord>(info, recordId, processName);
|
||||
bool isDebugStart = true;
|
||||
appRecord->SetDebugApp(false);
|
||||
auto appDebugInfo = appMgrServiceInner->MakeAppDebugInfo(appRecord, isDebugStart);
|
||||
EXPECT_EQ(appDebugInfo.bundleName, "");
|
||||
EXPECT_EQ(appDebugInfo.pid, APP_DEBUG_INFO_PID);
|
||||
EXPECT_EQ(appDebugInfo.uid, APP_DEBUG_INFO_UID);
|
||||
EXPECT_EQ(appDebugInfo.isDebugStart, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ChangeAppGcState_001
|
||||
* @tc.desc: Change app Gc state
|
||||
|
73
test/unittest/app_running_record_test/BUILD.gn
Normal file
73
test/unittest/app_running_record_test/BUILD.gn
Normal file
@ -0,0 +1,73 @@
|
||||
# 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.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
|
||||
module_output_path = "ability_runtime/appmgrservice"
|
||||
|
||||
ohos_unittest("app_running_record_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
include_dirs = [
|
||||
"${ability_runtime_services_path}/appmgr/include",
|
||||
"${ability_runtime_test_path}/mock/services_appmgr_test/include/",
|
||||
]
|
||||
|
||||
configs = [ "${ability_runtime_services_path}/appmgr:appmgr_config" ]
|
||||
|
||||
sources = [ "app_running_record_test.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${ability_runtime_innerkits_path}/app_manager:app_manager",
|
||||
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:configuration",
|
||||
"ability_base:want",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"appspawn:appspawn_socket_client",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"ffrt:libffrt",
|
||||
"hicollie:libhicollie",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"init:libbeget_proxy",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"kv_store:distributeddata_mgr",
|
||||
"memory_utils:libmeminfo",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
"window_manager:libwm",
|
||||
"window_manager:libwsutils",
|
||||
]
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":app_running_record_test" ]
|
||||
}
|
@ -0,0 +1,180 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#define private public
|
||||
#include "app_running_record.h"
|
||||
#undef private
|
||||
#include "mock_ability_token.h"
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
namespace {
|
||||
constexpr int64_t TIMEOUT = 1;
|
||||
constexpr int32_t RECORD_ID = 1;
|
||||
constexpr int32_t EVENT_ID_1 = 1;
|
||||
constexpr int32_t EVENT_ID_2 = 2;
|
||||
constexpr int32_t START_PROCESS_SPECIFY_ABILITY_EVENT_ID = 1;
|
||||
constexpr int32_t ADD_ABILITY_STAGE_INFO_EVENT_ID = 2;
|
||||
constexpr int32_t TERMINATE_ABILITY_SIZE = 0;
|
||||
}
|
||||
class AppRunningRecordTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
};
|
||||
|
||||
void AppRunningRecordTest::SetUpTestCase(void)
|
||||
{}
|
||||
|
||||
void AppRunningRecordTest::TearDownTestCase(void)
|
||||
{}
|
||||
|
||||
void AppRunningRecordTest::SetUp()
|
||||
{}
|
||||
|
||||
void AppRunningRecordTest::TearDown()
|
||||
{}
|
||||
|
||||
/**
|
||||
* @tc.name: AppRunningRecord_SendEvent_0100
|
||||
* @tc.desc: Test the status of SendEvent when msg is a value of 4.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppRunningRecordTest, AppRunningRecord_SendEvent_0100, TestSize.Level1)
|
||||
{
|
||||
uint32_t msg = AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG;
|
||||
int64_t timeOut = TIMEOUT;
|
||||
std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
|
||||
int32_t recordId = RECORD_ID;
|
||||
std::string processName;
|
||||
auto appRunningRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
|
||||
EXPECT_NE(appRunningRecord, nullptr);
|
||||
appRunningRecord->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME);
|
||||
appRunningRecord->eventHandler_ =
|
||||
std::make_shared<AMSEventHandler>(appRunningRecord->taskHandler_, appRunningRecord->appMgrServiceInner_);
|
||||
appRunningRecord->isDebugApp_ = false;
|
||||
appRunningRecord->isNativeDebug_ = false;
|
||||
appRunningRecord->isAttachDebug_ = false;
|
||||
appRunningRecord->SendEvent(msg, timeOut);
|
||||
EXPECT_EQ(appRunningRecord->eventId_, EVENT_ID_1);
|
||||
EXPECT_EQ(appRunningRecord->startProcessSpecifiedAbilityEventId_, START_PROCESS_SPECIFY_ABILITY_EVENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AppRunningRecord_SendEvent_0200
|
||||
* @tc.desc: Test the status of SendEvent when msg is a value of 2.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppRunningRecordTest, AppRunningRecord_SendEvent_0200, TestSize.Level1)
|
||||
{
|
||||
uint32_t msg = AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG;
|
||||
int64_t timeOut = TIMEOUT;
|
||||
std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
|
||||
int32_t recordId = RECORD_ID;
|
||||
std::string processName;
|
||||
auto appRunningRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
|
||||
EXPECT_NE(appRunningRecord, nullptr);
|
||||
appRunningRecord->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME);
|
||||
appRunningRecord->eventHandler_ =
|
||||
std::make_shared<AMSEventHandler>(appRunningRecord->taskHandler_, appRunningRecord->appMgrServiceInner_);
|
||||
appRunningRecord->isDebugApp_ = false;
|
||||
appRunningRecord->isNativeDebug_ = false;
|
||||
appRunningRecord->isAttachDebug_ = false;
|
||||
appRunningRecord->SendEvent(msg, timeOut);
|
||||
EXPECT_EQ(appRunningRecord->eventId_, EVENT_ID_2);
|
||||
EXPECT_EQ(appRunningRecord->addAbilityStageInfoEventId_, ADD_ABILITY_STAGE_INFO_EVENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AppRunningRecord_SetAttachDebug_0100
|
||||
* @tc.desc: Test the status of SetAttachDebug based on the isAttachDebug value being true.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppRunningRecordTest, AppRunningRecord_SetAttachDebug_0100, TestSize.Level1)
|
||||
{
|
||||
bool isAttachDebug = true;
|
||||
std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
|
||||
int32_t recordId = RECORD_ID;
|
||||
std::string processName;
|
||||
auto appRunningRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
|
||||
EXPECT_NE(appRunningRecord, nullptr);
|
||||
appRunningRecord->SetAttachDebug(isAttachDebug);
|
||||
EXPECT_EQ(appRunningRecord->isAttachDebug_, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AppRunningRecord_SetAttachDebug_0200
|
||||
* @tc.desc: Test the status of SetAttachDebug based on the isAttachDebug value being false.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppRunningRecordTest, AppRunningRecord_SetAttachDebug_0200, TestSize.Level1)
|
||||
{
|
||||
bool isAttachDebug = false;
|
||||
std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
|
||||
int32_t recordId = RECORD_ID;
|
||||
std::string processName;
|
||||
auto appRunningRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
|
||||
EXPECT_NE(appRunningRecord, nullptr);
|
||||
appRunningRecord->SetAttachDebug(isAttachDebug);
|
||||
EXPECT_EQ(appRunningRecord->isAttachDebug_, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AppRunningRecord_TerminateAbility_0100
|
||||
* @tc.desc: Test the status of TerminateAbility.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppRunningRecordTest, AppRunningRecord_TerminateAbility_0100, TestSize.Level1)
|
||||
{
|
||||
bool isForce = true;
|
||||
std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
|
||||
int32_t recordId = RECORD_ID;
|
||||
std::string processName;
|
||||
auto appRunningRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
|
||||
EXPECT_NE(appRunningRecord, nullptr);
|
||||
sptr<IRemoteObject> token = new (std::nothrow) MockAbilityToken();
|
||||
auto info = nullptr;
|
||||
auto eventHandler = nullptr;
|
||||
auto moduleRecord = std::make_shared<ModuleRunningRecord>(info, eventHandler);
|
||||
EXPECT_NE(moduleRecord, nullptr);
|
||||
appRunningRecord->TerminateAbility(token, isForce);
|
||||
EXPECT_EQ(moduleRecord->terminateAbilities_.size(), TERMINATE_ABILITY_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AppRunningRecord_AbilityTerminated_0100
|
||||
* @tc.desc: Test the status of AbilityTerminated.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppRunningRecordTest, AppRunningRecord_AbilityTerminated_0100, TestSize.Level1)
|
||||
{
|
||||
sptr<IRemoteObject> token;
|
||||
bool isForce = true;
|
||||
std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
|
||||
int32_t recordId = RECORD_ID;
|
||||
std::string processName;
|
||||
auto appRunningRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
|
||||
EXPECT_NE(appRunningRecord, nullptr);
|
||||
appRunningRecord->AbilityTerminated(token);
|
||||
EXPECT_EQ(appRunningRecord->processType_, ProcessType::NORMAL);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -22,9 +22,10 @@ ohos_unittest("app_scheduler_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
include_dirs = [
|
||||
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock",
|
||||
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"${ability_runtime_services_path}/abilitymgr/include",
|
||||
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock",
|
||||
"${ability_runtime_test_path}/unittest/app_debug_listener_proxy_test",
|
||||
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
]
|
||||
|
||||
sources = [ "app_scheduler_test.cpp" ]
|
||||
|
@ -22,10 +22,11 @@
|
||||
#include "app_scheduler.h"
|
||||
#undef private
|
||||
#undef protected
|
||||
#include "app_state_call_back_mock.h"
|
||||
#include "app_process_data.h"
|
||||
#include "element_name.h"
|
||||
#include "app_debug_listener_stub_mock.h"
|
||||
#include "app_mgr_client_mock.h"
|
||||
#include "app_process_data.h"
|
||||
#include "app_state_call_back_mock.h"
|
||||
#include "element_name.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
@ -1160,5 +1161,89 @@ HWTEST_F(AppSchedulerTest, AppScheduler_NotifyFault_001, TestSize.Level1)
|
||||
int res = DelayedSingleton<AppScheduler>::GetInstance()->NotifyFault(faultData);
|
||||
EXPECT_EQ(res, INNER_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AppScheduler_RegisterAppDebugListener_001
|
||||
* @tc.desc: Test the state of RegisterAppDebugListener
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAppDebugListener_001, TestSize.Level1)
|
||||
{
|
||||
sptr<AppExecFwk::IAppDebugListener> listener = nullptr;
|
||||
int res = DelayedSingleton<AppScheduler>::GetInstance()->RegisterAppDebugListener(listener);
|
||||
EXPECT_EQ(res, INNER_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AppScheduler_RegisterAppDebugListener_002
|
||||
* @tc.desc: Test the state of RegisterAppDebugListener
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAppDebugListener_002, TestSize.Level1)
|
||||
{
|
||||
auto listener = new AppDebugListenerStubMock();
|
||||
int res = DelayedSingleton<AppScheduler>::GetInstance()->RegisterAppDebugListener(listener);
|
||||
EXPECT_EQ(res, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AppScheduler_UnregisterAppDebugListener_001
|
||||
* @tc.desc: Test the state of UnregisterAppDebugListener
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppSchedulerTest, AppScheduler_UnregisterAppDebugListener_001, TestSize.Level1)
|
||||
{
|
||||
sptr<AppExecFwk::IAppDebugListener> listener = nullptr;
|
||||
int res = DelayedSingleton<AppScheduler>::GetInstance()->UnregisterAppDebugListener(listener);
|
||||
EXPECT_EQ(res, INNER_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AppScheduler_UnregisterAppDebugListener_002
|
||||
* @tc.desc: Test the state of UnregisterAppDebugListener
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppSchedulerTest, AppScheduler_UnregisterAppDebugListener_002, TestSize.Level1)
|
||||
{
|
||||
auto listener = new AppDebugListenerStubMock();
|
||||
int res = DelayedSingleton<AppScheduler>::GetInstance()->UnregisterAppDebugListener(listener);
|
||||
EXPECT_EQ(res, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AppScheduler_AttachAppDebug_001
|
||||
* @tc.desc: Test the state of AttachAppDebug
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppSchedulerTest, AppScheduler_AttachAppDebug_001, TestSize.Level1)
|
||||
{
|
||||
std::string bundleName = "bundleName";
|
||||
int res = DelayedSingleton<AppScheduler>::GetInstance()->AttachAppDebug(bundleName);
|
||||
EXPECT_EQ(res, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AppScheduler_DetachAppDebug_001
|
||||
* @tc.desc: Test the state of DetachAppDebug
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppSchedulerTest, AppScheduler_DetachAppDebug_001, TestSize.Level1)
|
||||
{
|
||||
std::string bundleName = "bundleName";
|
||||
int res = DelayedSingleton<AppScheduler>::GetInstance()->DetachAppDebug(bundleName);
|
||||
EXPECT_EQ(res, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AppScheduler_RegisterAbilityDebugResponse_001
|
||||
* @tc.desc: Test the state of RegisterAbilityDebugResponse
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAbilityDebugResponse_001, TestSize.Level1)
|
||||
{
|
||||
sptr<AppExecFwk::IAbilityDebugResponse> response = nullptr;
|
||||
int res = DelayedSingleton<AppScheduler>::GetInstance()->RegisterAbilityDebugResponse(response);
|
||||
EXPECT_EQ(res, INNER_ERR);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user