!1446 DT用例补充

Merge pull request !1446 from taojuncun/bug_0926_02
This commit is contained in:
openharmony_ci 2024-09-27 07:48:11 +00:00 committed by Gitee
commit 1da020c2ba
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 1893 additions and 0 deletions

View File

@ -0,0 +1,660 @@
/*
* Copyright (C) 2022 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>
#include "ability_info.h"
#include "a11y_element_info.h"
#include "a11y_display_manager.h"
#include "a11y_event_info.h"
#include "a11y_ut_helper.h"
#include "a11y_window_manager.h"
#include "accessible_ability_manager_service.h"
#include "hilog_wrapper.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "utils.h"
namespace OHOS {
namespace A11y {
namespace {
constexpr int32_t ACCOUNT_ID = 100;
} // namespace
const bool REGISTER_RESULT =
SystemAbility::MakeAndRegisterAbility(&Singleton<A11yManagerService>::GetInstance());
A11yManagerService::A11yManagerService()
: SystemAbility(A11y_MANAGER_SERVICE_ID, true)
{
}
A11yManagerService::~A11yManagerService()
{
}
void A11yManagerService::OnStart()
{
GTEST_LOG_(INFO) << "###A11yManagerService::OnStart";
runner_ = AppExecFwk::EventRunner::Create("A11yManagerService", AppExecFwk::ThreadMode::FFRT);
handler_ = std::make_shared<AAMSEventHandler>(runner_);
Singleton<A11yWindowManager>::GetInstance().RegisterWindowListener(handler_);
Singleton<A11yCommonEvent>::GetInstance().SubscriberEvent(handler_);
}
void A11yManagerService::OnStop()
{
Singleton<A11yCommonEvent>::GetInstance().UnSubscriberEvent();
Singleton<A11yWindowManager>::GetInstance().DeregisterWindowListener();
runner_.reset();
handler_.reset();
}
void A11yManagerService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
{
(void)systemAbilityId;
(void)deviceId;
}
void A11yManagerService::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
{
(void)systemAbilityId;
(void)deviceId;
}
int A11yManagerService::Dump(int fd, const std::vector<std::u16string>& args)
{
(void)fd;
(void)args;
return 0;
}
RetError A11yManagerService::SendEvent(const A11yEventInfo& uiEvent, const int32_t flag)
{
HILOG_INFO("A11yManagerService::SendEvent successfully");
EventType uTeventType = uiEvent.GetEventType();
A11yAbilityHelper::GetInstance().SetGestureId(uiEvent.GetGestureType());
A11yAbilityHelper::GetInstance().SetEventTypeVector(uTeventType);
A11yAbilityHelper::GetInstance().SetEventWindowId(uiEvent.GetWindowId());
A11yAbilityHelper::GetInstance().SetEventWindowChangeType(uiEvent.GetWindowChangeTypes());
GTEST_LOG_(INFO) << "###A11yManagerService::SendEvent GetGestureType="
<< (int32_t)uiEvent.GetGestureType();
GTEST_LOG_(INFO) << "###A11yManagerService::SendEvent uTeventType=0x" << std::hex
<< (int32_t)uTeventType;
handler_->PostTask(std::bind([=]() -> void {
HILOG_DEBUG("start");
A11yAbilityHelper::GetInstance().AddSendEventTimes();
}), "TASK_SEND_EVENT");
return RET_OK;
}
uint32_t A11yManagerService::RegisterStateObserver(
const sptr<IA11yManagerStateObserver>& callback)
{
(void)callback;
return 0;
}
RetError A11yManagerService::GetAbilityList(const uint32_t abilityTypes, const int32_t stateType,
std::vector<A11yAbilityInfo> &infos)
{
(void)abilityTypes;
(void)stateType;
(void)infos;
return RET_OK;
}
RetError A11yManagerService::RegisterElementOperator(
const int32_t windowId, const sptr<IA11yElementOperator>& operation, bool isApp)
{
(void)windowId;
(void)operation;
(void)isApp;
return RET_OK;
}
RetError A11yManagerService::RegisterElementOperator(Registration parameter,
const sptr<IA11yElementOperator> &operation, bool isApp)
{
(void)parameter;
(void)operation;
(void)isApp;
return RET_OK;
}
RetError A11yManagerService::DeregisterElementOperator(int32_t windowId)
{
(void)windowId;
return RET_OK;
}
RetError A11yManagerService::DeregisterElementOperator(int32_t windowId, int32_t treeId)
{
(void)windowId;
(void)treeId;
return RET_OK;
}
sptr<A11yAccountData> A11yManagerService::GetCurrentAccountData()
{
bool needNullFlag = A11yAbilityHelper::GetInstance().GetNeedAccountDataNullFlag();
if (needNullFlag) {
return nullptr;
}
auto accountData = a11yAccountsData_.GetCurrentAccountData(ACCOUNT_ID);
accountData->Init();
return accountData;
}
sptr<A11yAccountData> A11yManagerService::GetAccountData(int32_t accountId)
{
return a11yAccountsData_.GetAccountData(accountId);
}
RetError A11yManagerService::GetCaptionProperty(A11yConfig::CaptionProperty &caption)
{
(void)caption;
return RET_OK;
}
RetError A11yManagerService::SetCaptionProperty(const A11yConfig::CaptionProperty& caption)
{
(void)caption;
return RET_OK;
}
RetError A11yManagerService::SetCaptionState(const bool state)
{
(void)state;
return RET_OK;
}
bool A11yManagerService::GetEnabledState()
{
return true;
}
RetError A11yManagerService::GetCaptionState(bool &state)
{
state = true;
return RET_OK;
}
bool A11yManagerService::GetTouchGuideState()
{
return true;
}
bool A11yManagerService::GetGestureState()
{
return true;
}
bool A11yManagerService::GetKeyEventObserverState()
{
return true;
}
RetError A11yManagerService::EnableAbility(const std::string &name, const uint32_t capabilities)
{
(void)name;
(void)capabilities;
return RET_OK;
}
RetError A11yManagerService::GetEnabledAbilities(std::vector<std::string> &enabledAbilities)
{
(void)enabledAbilities;
return RET_OK;
}
uint32_t A11yManagerService::RegisterCaptionObserver(
const sptr<IA11yManagerCaptionObserver>& callback)
{
(void)callback;
return NO_ERROR;
}
RetError A11yManagerService::SetCurtainScreenUsingStatus(bool isEnable)
{
(void)isEnable;
return RET_OK;
}
RetError A11yManagerService::DisableAbility(const std::string &name)
{
(void)name;
return RET_OK;
}
RetError A11yManagerService::EnableUITestAbility(const sptr<IRemoteObject>& obj)
{
(void)obj;
return RET_OK;
}
RetError A11yManagerService::DisableUITestAbility()
{
return RET_OK;
}
int32_t A11yManagerService::GetActiveWindow()
{
return 0;
}
RetError A11yManagerService::SetScreenMagnificationState(const bool state)
{
(void)state;
return RET_OK;
}
void A11yManagerService::UpdateAllSetting()
{
return;
}
void A11yManagerService::UpdateInputFilter()
{
return;
}
void A11yManagerService::UpdateShortKeyRegister()
{
return;
}
RetError A11yManagerService::SetShortKeyState(const bool state)
{
(void)state;
return RET_OK;
}
RetError A11yManagerService::SetMouseKeyState(const bool state)
{
(void)state;
return RET_OK;
}
RetError A11yManagerService::SetMouseAutoClick(const int32_t time)
{
(void)time;
return RET_OK;
}
RetError A11yManagerService::SetShortkeyTarget(const std::string &name)
{
(void)name;
return RET_OK;
}
RetError A11yManagerService::SetShortkeyMultiTarget(const std::vector<std::string> &name)
{
(void)name;
return RET_OK;
}
RetError A11yManagerService::SetHighContrastTextState(const bool state)
{
(void)state;
return RET_OK;
}
RetError A11yManagerService::SetDaltonizationState(const bool state)
{
(void)state;
return RET_OK;
}
RetError A11yManagerService::SetInvertColorState(const bool state)
{
(void)state;
return RET_OK;
}
RetError A11yManagerService::SetAnimationOffState(const bool state)
{
(void)state;
return RET_OK;
}
RetError A11yManagerService::SetAudioMonoState(const bool state)
{
(void)state;
return RET_OK;
}
RetError A11yManagerService::SetDaltonizationColorFilter(const uint32_t filter)
{
(void)filter;
return RET_OK;
}
RetError A11yManagerService::SetContentTimeout(const uint32_t time)
{
(void)time;
return RET_OK;
}
RetError A11yManagerService::SetBrightnessDiscount(const float discount)
{
(void)discount;
return RET_OK;
}
RetError A11yManagerService::SetAudioBalance(const float balance)
{
(void)balance;
return RET_OK;
}
RetError A11yManagerService::SetClickResponseTime(const uint32_t time)
{
(void)time;
return RET_OK;
}
RetError A11yManagerService::SetIgnoreRepeatClickState(const bool state)
{
(void)state;
return RET_OK;
}
RetError A11yManagerService::SetIgnoreRepeatClickTime(const uint32_t time)
{
(void)time;
return RET_OK;
}
RetError A11yManagerService::GetScreenMagnificationState(bool &state)
{
state = true;
return RET_OK;
}
RetError A11yManagerService::GetShortKeyState(bool &state)
{
state = true;
return RET_OK;
}
RetError A11yManagerService::GetMouseKeyState(bool &state)
{
state = true;
return RET_OK;
}
RetError A11yManagerService::GetMouseAutoClick(int32_t &time)
{
time = 0;
return RET_OK;
}
RetError A11yManagerService::GetShortkeyTarget(std::string &name)
{
name = "";
return RET_OK;
}
RetError A11yManagerService::GetShortkeyMultiTarget(std::vector<std::string> &name)
{
std::vector<std::string> vecName {};
name = vecName;
return RET_OK;
}
RetError A11yManagerService::GetHighContrastTextState(bool &state)
{
state = true;
return RET_OK;
}
RetError A11yManagerService::GetDaltonizationState(bool &state)
{
state = true;
return RET_OK;
}
RetError A11yManagerService::GetInvertColorState(bool &state)
{
state = true;
return RET_OK;
}
RetError A11yManagerService::GetAnimationOffState(bool &state)
{
state = true;
return RET_OK;
}
RetError A11yManagerService::GetAudioMonoState(bool &state)
{
state = true;
return RET_OK;
}
RetError A11yManagerService::GetDaltonizationColorFilter(uint32_t &type)
{
type = 0;
return RET_OK;
}
RetError A11yManagerService::GetContentTimeout(uint32_t &timer)
{
timer = 0;
return RET_OK;
}
RetError A11yManagerService::GetBrightnessDiscount(float &brightness)
{
brightness = 0.0f;
return RET_OK;
}
RetError A11yManagerService::GetAudioBalance(float &balance)
{
balance = 0.0f;
return RET_OK;
}
RetError A11yManagerService::GetClickResponseTime(uint32_t &time)
{
time = 0;
return RET_OK;
}
RetError A11yManagerService::GetIgnoreRepeatClickState(bool &state)
{
state = true;
return RET_OK;
}
RetError A11yManagerService::GetIgnoreRepeatClickTime(uint32_t &time)
{
time = 0;
return RET_OK;
}
void A11yManagerService::GetAllConfigs(A11yConfigData &configData)
{
(void)configData;
}
void A11yManagerService::RegisterEnableAbilityListsObserver(
const sptr<IA11yEnableAbilityListsObserver> &observer)
{
(void)observer;
}
uint32_t A11yManagerService::RegisterConfigObserver(
const sptr<IA11yManagerConfigObserver> &callback)
{
(void)callback;
return NO_ERROR;
}
void A11yManagerService::UpdateA11yManagerService()
{
}
sptr<AppExecFwk::IBundleMgr> A11yManagerService::GetBundleMgrProxy()
{
return nullptr;
}
void A11yManagerService::SetKeyEventFilter(const sptr<KeyEventFilter> &keyEventFilter)
{
HILOG_DEBUG();
keyEventFilter_ = keyEventFilter;
}
bool A11yManagerService::EnableShortKeyTargetAbility(const std::string &name)
{
A11yAbilityHelper::GetInstance().SetShortKeyTargetAbilityState(true);
return true;
}
void A11yManagerService::OnShortKeyProcess()
{
A11yAbilityHelper::GetInstance().SetShortKeyTargetAbilityState(true);
}
void A11yManagerService::AddedUser(int32_t accountId)
{
HILOG_DEBUG();
A11yAbilityHelper::GetInstance().AddUserId(accountId);
}
void A11yManagerService::RemovedUser(int32_t accountId)
{
HILOG_DEBUG();
A11yAbilityHelper::GetInstance().RemoveUserId(accountId);
}
void A11yManagerService::SwitchedUser(int32_t accountId)
{
HILOG_DEBUG();
A11yAbilityHelper::GetInstance().SetCurrentUserId(accountId);
}
void A11yManagerService::PackageChanged(const std::string &bundleName)
{
HILOG_DEBUG();
A11yAbilityHelper::GetInstance().ChangePackage(true);
}
void A11yManagerService::PackageRemoved(const std::string &bundleName)
{
HILOG_DEBUG();
A11yAbilityHelper::GetInstance().RemovePackage(bundleName);
}
void A11yManagerService::PackageAdd(const std::string &bundleName)
{
HILOG_DEBUG();
A11yAbilityHelper::GetInstance().AddPackage(bundleName);
}
void A11yManagerService::GetRealWindowAndElementId(int32_t& windowId, int64_t& elementId)
{
}
void A11yManagerService::GetSceneBoardInnerWinId(int32_t windowId, int64_t elementId, int32_t& innerWid)
{
}
bool A11yManagerService::ExecuteActionOnA11yFocused(const ActionType &action)
{
return true;
}
bool A11yManagerService::FindFocusedElement(A11yElementInfo &elementInfo)
{
return true;
}
RetError A11yManagerService::GetFocusedWindowId(int32_t &focusedWindowId)
{
focusedWindowId = 1;
return RET_OK;
}
void A11yManagerService::SetTouchEventInjector(const sptr<TouchEventInjector> &touchEventInjector)
{
HILOG_DEBUG();
touchEventInjector_ = touchEventInjector;
}
void A11yManagerService::InsertWindowIdEventPair(int32_t windowId, const A11yEventInfo &event)
{
(void)windowId;
(void)event;
}
bool A11yManagerService::CheckWindowRegister(int32_t windowId)
{
(void)windowId;
return true;
}
void A11yManagerService::PostDelayUnloadTask()
{
}
void A11yManagerService::SetFocusWindowId(const int32_t focusWindowId)
{
(void)focusWindowId;
}
void A11yManagerService::SetFocusElementId(const int64_t focusElementId)
{
(void)focusElementId;
}
int32_t A11yManagerService::GetTreeIdBySplitElementId(const int64_t elementId)
{
(void)elementId;
return 0;
}
void A11yManagerService::RemoveRequestId(int32_t requestId)
{
(void)requestId;
}
void A11yManagerService::AddRequestId(int32_t windowId, int32_t treeId, int32_t requestId,
sptr<IA11yElementOperatorCallback> callback)
{
(void)windowId;
(void)treeId;
(void)requestId;
(void)callback;
}
int64_t A11yManagerService::GetRootParentId(int32_t windowId, int32_t treeId)
{
(void)windowId;
(void)treeId;
return 0;
}
RetError A11yManagerService::GetAllTreeId(int32_t windowId, std::vector<int32_t> &treeIds)
{
(void)windowId;
(void)treeIds;
return RET_OK;
}
void A11yManagerService::OnDataClone()
{
}
} // namespace A11y
} // namespace OHOS

View File

@ -0,0 +1,243 @@
/*
* Copyright (C) 2022 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 <benchmark/benchmark.h>
#include "A11y_config.h"
#include "accesstoken_kit.h"
#include "ffrt_inner.h"
#include "nativetoken_kit.h"
#include "token_setproc.h"
using namespace OHOS::A11yConfig;
using namespace OHOS::Security::AccessToken;
namespace {
class A11yConfigObserverImpl : public OHOS::A11yConfig::A11yConfigObserver {
public:
A11yConfigObserverImpl() = default;
void OnConfigChanged(const CONFIG_ID id, const ConfigValue &value) override
{
complete_.set_value();
}
void SetCompletePromise(ffrt::promise<void> &promise)
{
complete_ = std::move(promise);
}
private:
ffrt::promise<void> complete_;
};
static bool g_flag = true;
void AddPermission()
{
if (g_flag) {
const char *perms[2];
perms[0] = OHOS::A11y::OHOS_PERMISSION_READ_A11y_CONFIG.c_str();
perms[1] = OHOS::A11y::OHOS_PERMISSION_WRITE_A11y_CONFIG.c_str();
NativeTokenInfoParams infoInstance = {
.dcapsNum = 0,
.permsNum = 2,
.aclsNum = 0,
.dcaps = nullptr,
.perms = perms,
.acls = nullptr,
.processName = "com.A11y.config.benchmark.test",
.aplStr = "normal",
};
uint64_t tokenId = GetAccessTokenId(&infoInstance);
SetSelfTokenID(tokenId);
AccessTokenKit::ReloadNativeTokenInfo();
g_flag = false;
}
}
/**
* @tc.name: BenchmarkTestForSetScreenMagnificationState
* @tc.desc: Testcase for testing 'SetScreenMagnificationState' function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
static void BenchmarkTestForSetScreenMagnificationState(benchmark::State &state)
{
bool value = false;
std::shared_ptr<A11yConfigObserverImpl> configObserver =
std::make_shared<A11yConfigObserverImpl>();
auto &config = OHOS::A11yConfig::A11yConfig::GetInstance();
(void)config.InitializeContext();
AddPermission();
config.SubscribeConfigObserver(CONFIG_SCREEN_MAGNIFICATION, configObserver, false);
config.GetScreenMagnificationState(value);
for (auto _ : state) {
/* @tc.steps: step1.call SetScreenMagnificationState in loop */
ffrt::promise<void> complete;
ffrt::future syncFuture = complete.get_future();
configObserver->SetCompletePromise(complete);
config.SetScreenMagnificationState(!value);
syncFuture.wait();
value = !value;
}
}
/**
* @tc.name: BenchmarkTestForGetScreenMagnificationState
* @tc.desc: Testcase for testing 'GetScreenMagnificationState' function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
static void BenchmarkTestForGetScreenMagnificationState(benchmark::State &state)
{
bool value = false;
auto &config = OHOS::A11yConfig::A11yConfig::GetInstance();
(void)config.InitializeContext();
AddPermission();
for (auto _ : state) {
/* @tc.steps: step1.call GetScreenMagnificationState in loop */
(void)config.GetScreenMagnificationState(value);
}
}
/**
* @tc.name: BenchmarkTestForSetShortkeyTarget
* @tc.desc: Testcase for testing 'SetShortkeyTarget' function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
static void BenchmarkTestForSetShortkeyTarget(benchmark::State &state)
{
std::string nameStr = "aaa";
std::shared_ptr<A11yConfigObserverImpl> configObserver =
std::make_shared<A11yConfigObserverImpl>();
auto &config = OHOS::A11yConfig::A11yConfig::GetInstance();
(void)config.InitializeContext();
AddPermission();
config.SubscribeConfigObserver(CONFIG_SHORT_KEY_TARGET, configObserver, false);
for (auto _ : state) {
/* @tc.steps: step1.call SetShortkeyTarget in loop */
ffrt::promise<void> complete;
ffrt::future syncFuture = complete.get_future();
configObserver->SetCompletePromise(complete);
config.SetShortkeyTarget(nameStr);
syncFuture.wait();
if (!nameStr.compare("aaa")) {
nameStr = "bbb";
} else {
nameStr = "aaa";
}
}
}
/**
* @tc.name: BenchmarkTestForGetShortkeyTarget
* @tc.desc: Testcase for testing 'GetShortkeyTarget' function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
static void BenchmarkTestForGetShortkeyTarget(benchmark::State &state)
{
std::string value = "";
auto &config = OHOS::A11yConfig::A11yConfig::GetInstance();
(void)config.InitializeContext();
AddPermission();
for (auto _ : state) {
/* @tc.steps: step1.call GetShortkeyTarget in loop */
(void)config.GetShortkeyTarget(value);
}
}
/**
* @tc.name: BenchmarkTestForSetContentTimeout
* @tc.desc: Testcase for testing 'SetContentTimeout' function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
static void BenchmarkTestForSetContentTimeout(benchmark::State &state)
{
uint32_t value = 0;
std::shared_ptr<A11yConfigObserverImpl> configObserver =
std::make_shared<A11yConfigObserverImpl>();
auto &config = OHOS::A11yConfig::A11yConfig::GetInstance();
(void)config.InitializeContext();
AddPermission();
config.SubscribeConfigObserver(CONFIG_CONTENT_TIMEOUT, configObserver, false);
config.GetContentTimeout(value);
for (auto _ : state) {
/* @tc.steps: step1.call SetContentTimeout in loop */
value++;
ffrt::promise<void> complete;
ffrt::future syncFuture = complete.get_future();
configObserver->SetCompletePromise(complete);
config.SetContentTimeout(value);
syncFuture.wait();
}
}
/**
* @tc.name: BenchmarkTestForGetContentTimeout
* @tc.desc: Testcase for testing 'GetContentTimeout' function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
static void BenchmarkTestForGetContentTimeout(benchmark::State &state)
{
uint32_t value = 0;
auto &config = OHOS::A11yConfig::A11yConfig::GetInstance();
(void)config.InitializeContext();
AddPermission();
for (auto _ : state) {
/* @tc.steps: step1.call GetContentTimeout in loop */
(void)config.GetContentTimeout(value);
}
}
/**
* @tc.name: BenchmarkTestForSubscribeConfigObserver
* @tc.desc: Testcase for testing 'SubscribeConfigObserver' and 'UnsubscribeConfigObserver' function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
static void BenchmarkTestForSubscribeConfigObserver(benchmark::State &state)
{
std::shared_ptr<A11yConfigObserverImpl> configObserver =
std::make_shared<A11yConfigObserverImpl>();
auto &config = OHOS::A11yConfig::A11yConfig::GetInstance();
(void)config.InitializeContext();
AddPermission();
for (auto _ : state) {
/* @tc.steps: step1.call SubscribeConfigObserver in loop */
config.SubscribeConfigObserver(CONFIG_SCREEN_MAGNIFICATION, configObserver, false);
config.UnsubscribeConfigObserver(CONFIG_SCREEN_MAGNIFICATION, configObserver);
}
}
BENCHMARK(BenchmarkTestForSetScreenMagnificationState)->Iterations(1000)->ReportAggregatesOnly();
BENCHMARK(BenchmarkTestForGetScreenMagnificationState)->Iterations(1000)->ReportAggregatesOnly();
BENCHMARK(BenchmarkTestForSetShortkeyTarget)->Iterations(1000)->ReportAggregatesOnly();
BENCHMARK(BenchmarkTestForGetShortkeyTarget)->Iterations(1000)->ReportAggregatesOnly();
BENCHMARK(BenchmarkTestForSetContentTimeout)->Iterations(1000)->ReportAggregatesOnly();
BENCHMARK(BenchmarkTestForGetContentTimeout)->Iterations(1000)->ReportAggregatesOnly();
BENCHMARK(BenchmarkTestForSubscribeConfigObserver)->Iterations(1000)->ReportAggregatesOnly();
}
BENCHMARK_MAIN();

View File

@ -0,0 +1,84 @@
/*
* Copyright (C) 2022 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 <benchmark/benchmark.h>
#include "A11y_system_ability_client.h"
using namespace OHOS::A11y;
namespace {
/**
* @tc.name: BenchmarkTestForIsEnabled
* @tc.desc: Testcase for testing 'IsEnabled' function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
static void BenchmarkTestForIsEnabled(benchmark::State &state)
{
auto asaClient = A11ySystemAbilityClient::GetInstance();
if (!asaClient) {
return;
}
bool isEnable = false;
for (auto _ : state) {
/* @tc.steps: step1.call IsEnabled in loop */
(void)asaClient->IsEnabled(isEnable);
}
}
/**
* @tc.name: BenchmarkTestForGetEnabledAbilities
* @tc.desc: Testcase for testing 'GetEnabledAbilities' function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
static void BenchmarkTestForGetEnabledAbilities(benchmark::State &state)
{
auto asaClient = A11ySystemAbilityClient::GetInstance();
if (!asaClient) {
return;
}
for (auto _ : state) {
/* @tc.steps: step1.call GetEnabledAbilities in loop */
std::vector<std::string> enabledAbilities;
(void)asaClient->GetEnabledAbilities(enabledAbilities);
}
}
/**
* @tc.name: BenchmarkTestForSendEvent
* @tc.desc: Testcase for testing 'SendEvent' function.
* @tc.type: FUNC
* @tc.require: Issue Number
*/
static void BenchmarkTestForSendEvent(benchmark::State &state)
{
auto asaClient = A11ySystemAbilityClient::GetInstance();
if (!asaClient) {
return;
}
for (auto _ : state) {
/* @tc.steps: step1.call SendEvent in loop */
A11yEventInfo event;
event.SetEventType(TYPE_VIEW_TEXT_UPDATE_EVENT);
(void)asaClient->SendEvent(event);
}
}
BENCHMARK(BenchmarkTestForIsEnabled)->Iterations(1000)->ReportAggregatesOnly();
BENCHMARK(BenchmarkTestForGetEnabledAbilities)->Iterations(1000)->ReportAggregatesOnly();
BENCHMARK(BenchmarkTestForSendEvent)->Iterations(1000)->ReportAggregatesOnly();
}
BENCHMARK_MAIN();

View File

@ -0,0 +1,906 @@
/*
* Copyright (C) 2022-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>
#include "A11y_ability_ut_helper.h"
#include "A11y_ui_test_ability_impl.h"
#include "mock_accessible_ability_listener.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace A11y {
namespace {
const std::string TEST = "test";
constexpr int32_t FOCUS_TYPE = 1;
constexpr int32_t WINDOW_ID = 1;
constexpr uint64_t DISPLAY_ID = 1;
constexpr int32_t CACHE_MODE = 2;
} // namespace
class A11yUITestAbilityImplTest : public ::testing::Test {
public:
A11yUITestAbilityImplTest()
{}
~A11yUITestAbilityImplTest()
{}
std::shared_ptr<A11yUITestAbilityImpl> instance_ = nullptr;
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "A11yUITestAbilityImplTest Start";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "A11yUITestAbilityImplTest End";
}
void SetUp()
{
GTEST_LOG_(INFO) << "A11yUITestAbilityImplTest SetUp()";
instance_ = std::make_shared<A11yUITestAbilityImpl>();
}
void TearDown()
{
GTEST_LOG_(INFO) << "A11yUITestAbilityImplTest TearDown()";
instance_ = nullptr;
}
};
/**
* @tc.number: GetInstance_001
* @tc.name: GetInstance
* @tc.desc: Test function GetInstance
*/
HWTEST_F(A11yUITestAbilityImplTest, GetInstance_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetInstance_001 start";
EXPECT_TRUE(A11yUITestAbility::GetInstance());
GTEST_LOG_(INFO) << "GetInstance_001 end";
}
/**
* @tc.number: RegisterAbilityListener_001
* @tc.name: RegisterAbilityListener
* @tc.desc: Test function RegisterAbilityListener(listener is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, RegisterAbilityListener_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "RegisterAbilityListener_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
std::shared_ptr<AccessibleAbilityListener> listener = nullptr;
EXPECT_EQ(instance_->RegisterAbilityListener(listener), RET_ERR_INVALID_PARAM);
GTEST_LOG_(INFO) << "RegisterAbilityListener_001 end";
}
/**
* @tc.number: RegisterAbilityListener_002
* @tc.name: RegisterAbilityListener
* @tc.desc: Test function RegisterAbilityListener(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, RegisterAbilityListener_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "RegisterAbilityListener_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
std::shared_ptr<AccessibleAbilityListener> listener = std::make_shared<MockAccessibleAbilityListener>();
EXPECT_EQ(instance_->RegisterAbilityListener(listener), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "RegisterAbilityListener_002 end";
}
/**
* @tc.number: RegisterAbilityListener_003
* @tc.name: RegisterAbilityListener
* @tc.desc: Test function RegisterAbilityListener(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, RegisterAbilityListener_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "RegisterAbilityListener_003 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
std::shared_ptr<AccessibleAbilityListener> listener = std::make_shared<MockAccessibleAbilityListener>();
EXPECT_EQ(instance_->RegisterAbilityListener(listener), RET_OK);
GTEST_LOG_(INFO) << "RegisterAbilityListener_003 end";
}
/**
* @tc.number: Connect_001
* @tc.name: Connect
* @tc.desc: Test function Connect
*/
HWTEST_F(A11yUITestAbilityImplTest, Connect_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "Connect_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
EXPECT_EQ(RET_OK, instance_->Connect());
GTEST_LOG_(INFO) << "Connect_001 end";
}
/**
* @tc.number: Disconnect_001
* @tc.name: Disconnect
* @tc.desc: Test function Disconnect
*/
HWTEST_F(A11yUITestAbilityImplTest, Disconnect_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "Disconnect_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
EXPECT_EQ(instance_->Disconnect(), RET_OK);
GTEST_LOG_(INFO) << "Disconnect_001 end";
}
/**
* @tc.number: GetFocus_001
* @tc.name: GetFocus
* @tc.desc: Test function GetFocus(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetFocus_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetFocus_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
A11yElementInfo elementInfo {};
EXPECT_EQ(instance_->GetFocus(FOCUS_TYPE, elementInfo), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetFocus_001 end";
}
/**
* @tc.number: GetFocus_002
* @tc.name: GetFocus
* @tc.desc: Test function GetFocus(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetFocus_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetFocus_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yElementInfo elementInfo {};
EXPECT_EQ(instance_->GetFocus(FOCUS_TYPE, elementInfo), RET_OK);
GTEST_LOG_(INFO) << "GetFocus_002 end";
}
/**
* @tc.number: GetFocusByElementInfo_001
* @tc.name: GetFocusByElementInfo
* @tc.desc: Test function GetFocusByElementInfo(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetFocusByElementInfo_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetFocusByElementInfo_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
A11yElementInfo sourceInfo {};
A11yElementInfo elementInfo {};
EXPECT_EQ(instance_->GetFocusByElementInfo(sourceInfo, FOCUS_TYPE, elementInfo), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetFocusByElementInfo_001 end";
}
/**
* @tc.number: GetFocusByElementInfo_002
* @tc.name: GetFocusByElementInfo
* @tc.desc: Test function GetFocusByElementInfo(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetFocusByElementInfo_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetFocusByElementInfo_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yElementInfo sourceInfo {};
A11yElementInfo elementInfo {};
EXPECT_EQ(instance_->GetFocusByElementInfo(sourceInfo, FOCUS_TYPE, elementInfo), RET_OK);
GTEST_LOG_(INFO) << "GetFocusByElementInfo_002 end";
}
/**
* @tc.number: InjectGesture_001
* @tc.name: InjectGesture
* @tc.desc: Test function InjectGesture(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, InjectGesture_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "InjectGesture_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
std::shared_ptr<A11yGestureInjectPath> gesturePath = std::make_shared<A11yGestureInjectPath>();
EXPECT_EQ(instance_->InjectGesture(gesturePath), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "InjectGesture_001 end";
}
/**
* @tc.number: InjectGesture_002
* @tc.name: InjectGesture
* @tc.desc: Test function InjectGesture(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, InjectGesture_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "InjectGesture_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
std::shared_ptr<A11yGestureInjectPath> gesturePath = std::make_shared<A11yGestureInjectPath>();
EXPECT_EQ(instance_->InjectGesture(gesturePath), RET_OK);
GTEST_LOG_(INFO) << "InjectGesture_002 end";
}
/**
* @tc.number: GetRoot_001
* @tc.name: GetRoot
* @tc.desc: Test function GetRoot(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetRoot_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetRoot_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
A11yElementInfo elementInfo {};
EXPECT_EQ(instance_->GetRoot(elementInfo), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetRoot_001 end";
}
/**
* @tc.number: GetRoot_002
* @tc.name: GetRoot
* @tc.desc: Test function GetRoot(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetRoot_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetRoot_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yElementInfo elementInfo {};
EXPECT_EQ(instance_->GetRoot(elementInfo), RET_OK);
GTEST_LOG_(INFO) << "GetRoot_002 end";
}
/**
* @tc.number: GetRootByWindow_001
* @tc.name: GetRootByWindow
* @tc.desc: Test function GetRootByWindow(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetRootByWindow_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetRootByWindow_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
A11yWindowInfo windowInfo {};
A11yElementInfo elementInfo {};
EXPECT_EQ(instance_->GetRootByWindow(windowInfo, elementInfo), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetRootByWindow_001 end";
}
/**
* @tc.number: GetRootByWindow_002
* @tc.name: GetRootByWindow
* @tc.desc: Test function GetRootByWindow(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetRootByWindow_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetRootByWindow_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yWindowInfo windowInfo {};
A11yElementInfo elementInfo {};
EXPECT_EQ(instance_->GetRootByWindow(windowInfo, elementInfo), RET_OK);
GTEST_LOG_(INFO) << "GetRootByWindow_002 end";
}
/**
* @tc.number: GetWindow_001
* @tc.name: GetWindow
* @tc.desc: Test function GetWindow(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetWindow_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetWindow_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
A11yWindowInfo winInfo {};
EXPECT_EQ(instance_->GetWindow(WINDOW_ID, winInfo), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetWindow_001 end";
}
/**
* @tc.number: GetWindow_002
* @tc.name: GetWindow
* @tc.desc: Test function GetWindow(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetWindow_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetWindow_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yWindowInfo winInfo {};
EXPECT_EQ(instance_->GetWindow(WINDOW_ID, winInfo), RET_OK);
GTEST_LOG_(INFO) << "GetWindow_002 end";
}
/**
* @tc.number: GetWindows_001
* @tc.name: GetWindows
* @tc.desc: Test function GetWindows(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetWindows_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetWindows_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
std::vector<A11yWindowInfo> res {};
EXPECT_EQ(instance_->GetWindows(res), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetWindows_001 end";
}
/**
* @tc.number: GetWindows_002
* @tc.name: GetWindows
* @tc.desc: Test function GetWindows(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetWindows_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetWindows_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
std::vector<A11yWindowInfo> res {};
EXPECT_EQ(instance_->GetWindows(res), RET_OK);
GTEST_LOG_(INFO) << "GetWindows_002 end";
}
/**
* @tc.number: GetWindows_003
* @tc.name: GetWindows
* @tc.desc: Test function GetWindows(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetWindows_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetWindows_003 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
std::vector<A11yWindowInfo> res {};
EXPECT_EQ(instance_->GetWindows(DISPLAY_ID, res), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetWindows_003 end";
}
/**
* @tc.number: GetWindows_004
* @tc.name: GetWindows
* @tc.desc: Test function GetWindows(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetWindows_004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetWindows_004 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
std::vector<A11yWindowInfo> res {};
EXPECT_EQ(instance_->GetWindows(DISPLAY_ID, res), RET_OK);
GTEST_LOG_(INFO) << "GetWindows_004 end";
}
/**
* @tc.number: GetNext_001
* @tc.name: GetNext
* @tc.desc: Test function GetNext(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetNext_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetNext_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
A11yElementInfo nextElementInfo {};
A11yElementInfo elementInfo {};
FocusMoveDirection direction = DIRECTION_INVALID;
EXPECT_EQ(instance_->GetNext(elementInfo, direction, elementInfo), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetNext_001 end";
}
/**
* @tc.number: GetNext_002
* @tc.name: GetNext
* @tc.desc: Test function GetNext(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetNext_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetNext_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yElementInfo nextElementInfo {};
A11yElementInfo elementInfo {};
FocusMoveDirection direction = DIRECTION_INVALID;
EXPECT_EQ(instance_->GetNext(elementInfo, direction, elementInfo), RET_OK);
GTEST_LOG_(INFO) << "GetNext_002 end";
}
/**
* @tc.number: GetChildElementInfo_001
* @tc.name: GetChildElementInfo
* @tc.desc: Test function GetChildElementInfo(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetChildElementInfo_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetChildElementInfo_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
A11yElementInfo parent {};
A11yElementInfo child {};
int32_t index = 1;
EXPECT_EQ(instance_->GetChildElementInfo(index, parent, child), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetChildElementInfo_001 end";
}
/**
* @tc.number: GetChildElementInfo_002
* @tc.name: GetChildElementInfo
* @tc.desc: Test function GetChildElementInfo(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetChildElementInfo_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetChildElementInfo_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yElementInfo parent {};
A11yElementInfo child {};
int32_t index = 1;
EXPECT_EQ(instance_->GetChildElementInfo(index, parent, child), RET_OK);
GTEST_LOG_(INFO) << "GetChildElementInfo_002 end";
}
/**
* @tc.number: GetByContent_001
* @tc.name: GetByContent
* @tc.desc: Test function GetByContent(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetByContent_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetByContent_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
A11yElementInfo parent {};
std::vector<A11yElementInfo> elementInfos {};
EXPECT_EQ(instance_->GetByContent(parent, TEST, elementInfos), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetByContent_001 end";
}
/**
* @tc.number: GetByContent_002
* @tc.name: GetByContent
* @tc.desc: Test function GetByContent(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetByContent_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetByContent_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yElementInfo parent {};
std::vector<A11yElementInfo> elementInfos {};
EXPECT_EQ(instance_->GetByContent(parent, TEST, elementInfos), RET_OK);
GTEST_LOG_(INFO) << "GetByContent_002 end";
}
/**
* @tc.number: GetSource_001
* @tc.name: GetSource
* @tc.desc: Test function GetSource(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetSource_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetSource_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
A11yEventInfo eventInfo {};
A11yElementInfo elementInfo {};
EXPECT_EQ(instance_->GetSource(eventInfo, elementInfo), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetSource_001 end";
}
/**
* @tc.number: GetSource_002
* @tc.name: GetSource
* @tc.desc: Test function GetSource(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetSource_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetSource_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yEventInfo eventInfo {};
A11yElementInfo elementInfo {};
EXPECT_EQ(instance_->GetSource(eventInfo, elementInfo), RET_OK);
GTEST_LOG_(INFO) << "GetSource_002 end";
}
/**
* @tc.number: GetParentElementInfo_001
* @tc.name: GetParentElementInfo
* @tc.desc: Test function GetParentElementInfo(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetParentElementInfo_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetParentElementInfo_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
A11yElementInfo child {};
A11yElementInfo parent {};
EXPECT_EQ(instance_->GetParentElementInfo(child, parent), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetParentElementInfo_001 end";
}
/**
* @tc.number: GetParentElementInfo_002
* @tc.name: GetParentElementInfo
* @tc.desc: Test function GetParentElementInfo(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetParentElementInfo_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetParentElementInfo_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yElementInfo child {};
A11yElementInfo parent {};
EXPECT_EQ(instance_->GetParentElementInfo(child, parent), RET_OK);
GTEST_LOG_(INFO) << "GetParentElementInfo_002 end";
}
/**
* @tc.number: ExecuteAction_001
* @tc.name: ExecuteAction
* @tc.desc: Test function ExecuteAction(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, ExecuteAction_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "ExecuteAction_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
A11yElementInfo elementInfo {};
ActionType action = A11y_ACTION_INVALID;
std::map<std::string, std::string> actionArguments {};
EXPECT_EQ(instance_->ExecuteAction(elementInfo, action, actionArguments), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "ExecuteAction_001 end";
}
/**
* @tc.number: ExecuteAction_002
* @tc.name: ExecuteAction
* @tc.desc: Test function ExecuteAction(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, ExecuteAction_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "ExecuteAction_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yElementInfo elementInfo {};
ActionType action = A11y_ACTION_INVALID;
std::map<std::string, std::string> actionArguments {};
EXPECT_EQ(instance_->ExecuteAction(elementInfo, action, actionArguments), RET_OK);
GTEST_LOG_(INFO) << "ExecuteAction_002 end";
}
/**
* @tc.number: SetTargetBundleName_001
* @tc.name: SetTargetBundleName
* @tc.desc: Test function SetTargetBundleName(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, SetTargetBundleName_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SetTargetBundleName_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
std::vector<std::string> targetBundleNames;
EXPECT_EQ(instance_->SetTargetBundleName(targetBundleNames), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "SetTargetBundleName_001 end";
}
/**
* @tc.number: SetTargetBundleName_002
* @tc.name: SetTargetBundleName
* @tc.desc: Test function SetTargetBundleName(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, SetTargetBundleName_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SetTargetBundleName_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
std::vector<std::string> targetBundleNames;
EXPECT_EQ(instance_->SetTargetBundleName(targetBundleNames), RET_OK);
GTEST_LOG_(INFO) << "SetTargetBundleName_002 end";
}
/**
* @tc.number: GetChildren_001
* @tc.name: GetChildren
* @tc.desc: Test function GetChildren
*/
HWTEST_F(A11yUITestAbilityImplTest, GetChildren_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetChildren_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yElementInfo parent;
std::vector<A11yElementInfo> children;
EXPECT_EQ(instance_->GetChildren(parent, children), RET_OK);
GTEST_LOG_(INFO) << "GetChildren_001 end";
}
/**
* @tc.number: SetCacheMode_001
* @tc.name: SetCacheMode
* @tc.desc: Test function SetCacheMode
*/
HWTEST_F(A11yUITestAbilityImplTest, SetCacheMode_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SetCacheMode_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
instance_->SetCacheMode(CACHE_MODE);
EXPECT_EQ(CACHE_MODE, A11yAbilityUtHelper::GetInstance().GetCacheMode());
GTEST_LOG_(INFO) << "SetCacheMode_001 end";
}
/**
* @tc.number: GetRootBatch_001
* @tc.name: GetRootBatch
* @tc.desc: Test function GetRootBatch(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetRootBatch_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetRootBatch_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
std::vector<A11yElementInfo> elementInfos;
EXPECT_EQ(instance_->GetRootBatch(elementInfos), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetRootBatch_001 end";
}
/**
* @tc.number: GetRootBatch_002
* @tc.name: GetRootBatch
* @tc.desc: Test function GetRootBatch(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetRootBatch_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetRootBatch_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
std::vector<A11yElementInfo> elementInfos;
EXPECT_EQ(instance_->GetRootBatch(elementInfos), RET_OK);
GTEST_LOG_(INFO) << "GetRootBatch_002 end";
}
/**
* @tc.number: GetRootByWindowBatch_001
* @tc.name: GetRootByWindowbatch
* @tc.desc: Test function GetRootByWindow(AccessibleAbilityClient is null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetRootByWindowBatch_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetRootByWindowBatch_001 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true);
A11yWindowInfo windowInfo {};
std::vector<A11yElementInfo> elementInfos;
EXPECT_EQ(instance_->GetRootByWindowBatch(windowInfo, elementInfos, true), RET_ERR_NULLPTR);
A11yAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false);
GTEST_LOG_(INFO) << "GetRootByWindowBatch_001 end";
}
/**
* @tc.number: GetRootByWindowBatch_002
* @tc.name: GetRootByWindowBatch
* @tc.desc: Test function GetRootByWindowBatch(AccessibleAbilityClient is not null)
*/
HWTEST_F(A11yUITestAbilityImplTest, GetRootByWindowBatch_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetRootByWindowBatch_002 start";
if (!instance_) {
GTEST_LOG_(INFO) << "Cann't get A11yUITestAbilityImpl instance_";
return;
}
A11yWindowInfo windowInfo {};
std::vector<A11yElementInfo> elementInfos;
EXPECT_EQ(instance_->GetRootByWindowBatch(windowInfo, elementInfos, true), RET_OK);
GTEST_LOG_(INFO) << "GetRootByWindowBatch_002 end";
}
} // namespace A11y
} // namespace OHOS