mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-24 07:09:58 +00:00
简化tdd用例
Signed-off-by: cy7717 <chenyu301@huawei.com>
This commit is contained in:
parent
636cde357d
commit
4003e476e9
@ -48,7 +48,7 @@ public:
|
||||
static void TriggerHideCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel);
|
||||
static void RestoreSelfTokenID();
|
||||
static void AllocTestTokenID(const std::string &bundleName);
|
||||
static void SetTestTokenID(bool isCurrentIme);
|
||||
static void SetTestTokenID();
|
||||
static void ImcPanelListeningTestCheck(
|
||||
InputWindowStatus realStatus, InputWindowStatus waitStatus, const InputWindowInfo &windowInfo);
|
||||
static void ImcPanelListeningTestCheck(InputWindowStatus realStatus, InputWindowStatus waitStatus);
|
||||
@ -79,8 +79,7 @@ public:
|
||||
static uint32_t windowWidth_;
|
||||
static uint32_t windowHeight_;
|
||||
static uint64_t selfTokenId_;
|
||||
static uint64_t systemAppTokenIdEx_;
|
||||
static uint64_t currentImeTokenID_;
|
||||
static uint64_t testTokenIdEx_;
|
||||
static bool showPanel_;
|
||||
static bool hidePanel_;
|
||||
static std::condition_variable panelListenerCv_;
|
||||
@ -120,12 +119,10 @@ sptr<InputMethodController> InputMethodPanelTest::imc_;
|
||||
uint32_t InputMethodPanelTest::windowWidth_ = 0;
|
||||
uint32_t InputMethodPanelTest::windowHeight_ = 0;
|
||||
uint64_t InputMethodPanelTest::selfTokenId_ = 0;
|
||||
uint64_t InputMethodPanelTest::systemAppTokenIdEx_ = 0;
|
||||
uint64_t InputMethodPanelTest::currentImeTokenID_ = 0;
|
||||
uint64_t InputMethodPanelTest::testTokenIdEx_ = 0;
|
||||
void InputMethodPanelTest::SetUpTestCase(void)
|
||||
{
|
||||
selfTokenId_ = GetSelfTokenID();
|
||||
AllocTestTokenID("");
|
||||
std::shared_ptr<Property> property = InputMethodController::GetInstance()->GetCurrentInputMethod();
|
||||
std::string bundleName = property != nullptr ? property->name : "default.inputmethod.unittest";
|
||||
AllocTestTokenID(bundleName);
|
||||
@ -153,18 +150,6 @@ void InputMethodPanelTest::TearDown(void)
|
||||
|
||||
void InputMethodPanelTest::AllocTestTokenID(const std::string &bundleName)
|
||||
{
|
||||
if (bundleName.empty()) {
|
||||
HapInfoParams infoParams = {
|
||||
.userID = 1, .bundleName = "imf_panel_test", .instIndex = 0, .appIDDesc = "imf_test", .isSystemApp = true
|
||||
};
|
||||
HapPolicyParams policyParams = {
|
||||
.apl = APL_NORMAL, .domain = "test.domain", .permList = {}, .permStateList = {}
|
||||
};
|
||||
auto tokenInfo = AccessTokenKit::AllocHapToken(infoParams, policyParams);
|
||||
systemAppTokenIdEx_ = tokenInfo.tokenIDEx;
|
||||
return;
|
||||
}
|
||||
|
||||
IMSA_HILOGI("bundleName: %{public}s", bundleName.c_str());
|
||||
std::vector<int32_t> userIds;
|
||||
auto ret = OsAccountManager::QueryActiveOsAccountIds(userIds);
|
||||
@ -177,28 +162,17 @@ void InputMethodPanelTest::AllocTestTokenID(const std::string &bundleName)
|
||||
.instIndex = 0,
|
||||
.appIDDesc = "ohos.inputmethod_test.demo",
|
||||
.isSystemApp = true };
|
||||
PermissionStateFull permissionState = { .permissionName = "",
|
||||
.isGeneral = true,
|
||||
.resDeviceID = { "local" },
|
||||
.grantStatus = { PermissionState::PERMISSION_GRANTED },
|
||||
.grantFlags = { 1 } };
|
||||
HapPolicyParams policyParams = {
|
||||
.apl = APL_NORMAL, .domain = "test.domain.inputmethod", .permList = {}, .permStateList = { permissionState }
|
||||
.apl = APL_NORMAL, .domain = "test.domain.inputmethod", .permList = {}, .permStateList = {}
|
||||
};
|
||||
|
||||
AccessTokenKit::AllocHapToken(infoParams, policyParams);
|
||||
currentImeTokenID_ = AccessTokenKit::GetHapTokenID(infoParams.userID, infoParams.bundleName, infoParams.instIndex);
|
||||
auto tokenInfo = AccessTokenKit::AllocHapToken(infoParams, policyParams);
|
||||
testTokenIdEx_ = tokenInfo.tokenIDEx;
|
||||
}
|
||||
|
||||
void InputMethodPanelTest::SetTestTokenID(bool isCurrentIme)
|
||||
void InputMethodPanelTest::SetTestTokenID()
|
||||
{
|
||||
if (isCurrentIme) {
|
||||
auto ret = SetSelfTokenID(currentImeTokenID_);
|
||||
IMSA_HILOGD("ret = %{public}d", ret);
|
||||
return;
|
||||
}
|
||||
auto ret1 = SetSelfTokenID(systemAppTokenIdEx_);
|
||||
IMSA_HILOGD("ret1 = %{public}d", ret1);
|
||||
auto ret = SetSelfTokenID(testTokenIdEx_);
|
||||
IMSA_HILOGD("ret = %{public}d", ret);
|
||||
}
|
||||
|
||||
void InputMethodPanelTest::RestoreSelfTokenID()
|
||||
@ -545,18 +519,18 @@ HWTEST_F(InputMethodPanelTest, testRegisterListener, TestSize.Level0)
|
||||
|
||||
/*
|
||||
* @tc.name: testImcPanelListening_001
|
||||
* @tc.desc: SOFT_KEYBOARD FLG_FIXED no listening set up currentIme
|
||||
* @tc.desc: SOFT_KEYBOARD FLG_FIXED no listening set up systemApp currentIme
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodPanelTest, testImcPanelListening_001, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_001 start.");
|
||||
SetTestTokenID(false);
|
||||
SetTestTokenID();
|
||||
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
|
||||
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
|
||||
PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
|
||||
InputMethodPanelTest::ImcPanelListeningTestPrepare(inputMethodPanel, panelInfo, NONE);
|
||||
SetTestTokenID(true);
|
||||
|
||||
auto ret = inputMethodPanel->ShowPanel();
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::SHOW);
|
||||
@ -570,18 +544,18 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_001, TestSize.Level0)
|
||||
|
||||
/**
|
||||
* @tc.name: testImcPanelListening_002
|
||||
* @tc.desc: SOFT_KEYBOARD FLG_FIXED Set up listening currentIme
|
||||
* @tc.desc: SOFT_KEYBOARD FLG_FIXED Set up listening systemApp currentIme
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodPanelTest, testImcPanelListening_002, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_002 start.");
|
||||
SetTestTokenID(false);
|
||||
SetTestTokenID();
|
||||
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
|
||||
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
|
||||
PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
|
||||
InputMethodPanelTest::ImcPanelListeningTestPrepare(inputMethodPanel, panelInfo, ON);
|
||||
SetTestTokenID(true);
|
||||
|
||||
auto ret = inputMethodPanel->ShowPanel();
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::SHOW, InputWindowStatus::SHOW,
|
||||
@ -597,18 +571,18 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_002, TestSize.Level0)
|
||||
|
||||
/**
|
||||
* @tc.name: testImcPanelListening_003
|
||||
* @tc.desc: SOFT_KEYBOARD FLG_FIXED Cancel listening currentIme
|
||||
* @tc.desc: SOFT_KEYBOARD FLG_FIXED Cancel listening systemApp currentIme
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodPanelTest, testImcPanelListening_003, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_003 start.");
|
||||
SetTestTokenID(false);
|
||||
SetTestTokenID();
|
||||
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
|
||||
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
|
||||
PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
|
||||
InputMethodPanelTest::ImcPanelListeningTestPrepare(inputMethodPanel, panelInfo, OFF);
|
||||
SetTestTokenID(true);
|
||||
|
||||
auto ret = inputMethodPanel->ShowPanel();
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::SHOW);
|
||||
@ -622,7 +596,7 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_003, TestSize.Level0)
|
||||
|
||||
/**
|
||||
* @tc.name: testImcPanelListening_004
|
||||
* @tc.desc: SOFT_KEYBOARD FLG_FIXED Set up listening NO PERMISSION currentIme
|
||||
* @tc.desc: SOFT_KEYBOARD FLG_FIXED Set up listening not systemApp currentIme
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodPanelTest, testImcPanelListening_004, TestSize.Level0)
|
||||
@ -632,7 +606,8 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_004, TestSize.Level0)
|
||||
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
|
||||
PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
|
||||
InputMethodPanelTest::ImcPanelListeningTestPrepare(inputMethodPanel, panelInfo, ON);
|
||||
SetTestTokenID(true);
|
||||
|
||||
SetTestTokenID();
|
||||
auto ret = inputMethodPanel->ShowPanel();
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::SHOW);
|
||||
@ -646,17 +621,19 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_004, TestSize.Level0)
|
||||
|
||||
/**
|
||||
* @tc.name: testImcPanelListening_005
|
||||
* @tc.desc: SOFT_KEYBOARD FLG_FIXED Set up listening not currentIme
|
||||
* @tc.desc: SOFT_KEYBOARD FLG_FIXED Set up listening systemApp not currentIme
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodPanelTest, testImcPanelListening_005, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_005 start.");
|
||||
SetTestTokenID(false);
|
||||
SetTestTokenID();
|
||||
InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
|
||||
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
|
||||
PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
|
||||
InputMethodPanelTest::ImcPanelListeningTestPrepare(inputMethodPanel, panelInfo, ON);
|
||||
|
||||
RestoreSelfTokenID();
|
||||
auto ret = inputMethodPanel->ShowPanel();
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::SHOW);
|
||||
@ -665,7 +642,6 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_005, TestSize.Level0)
|
||||
ret = inputMethodPanel->HidePanel();
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::SHOW, InputWindowStatus::HIDE);
|
||||
RestoreSelfTokenID();
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user