mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-28 01:10:38 +00:00
modify code
Signed-off-by: zhaolinglan <zhaolinglan@huawei.com>
This commit is contained in:
parent
034240d925
commit
8e2dfec4fc
@ -493,6 +493,23 @@ HWTEST_F(InputMethodAbilityTest, testGetTextAfterCursor, TestSize.Level0)
|
||||
EXPECT_EQ(text, Str8ToStr16(TextListener::TEXT_AFTER_CURSOR));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGetTextAfterCursor_timeout
|
||||
* @tc.desc:
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testGetTextAfterCursor_timeout, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility testGetTextAfterCursor_timeout START");
|
||||
TextListener::setTimeout(true);
|
||||
int32_t number = 3;
|
||||
std::u16string text;
|
||||
auto ret = inputMethodAbility_->GetTextAfterCursor(number, text);
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_CONTROLLER_INVOKING_FAILED);
|
||||
TextListener::setTimeout(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGetTextBeforeCursor
|
||||
* @tc.desc:
|
||||
@ -509,6 +526,23 @@ HWTEST_F(InputMethodAbilityTest, testGetTextBeforeCursor, TestSize.Level0)
|
||||
EXPECT_EQ(text, Str8ToStr16(TextListener::TEXT_BEFORE_CURSOR));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGetTextBeforeCursor_timeout
|
||||
* @tc.desc:
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testGetTextBeforeCursor_timeout, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility testGetTextBeforeCursor_timeout START");
|
||||
TextListener::setTimeout(true);
|
||||
int32_t number = 5;
|
||||
std::u16string text;
|
||||
auto ret = inputMethodAbility_->GetTextBeforeCursor(number, text);
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_CONTROLLER_INVOKING_FAILED);
|
||||
TextListener::setTimeout(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGetTextIndexAtCursor
|
||||
* @tc.desc:
|
||||
@ -524,6 +558,22 @@ HWTEST_F(InputMethodAbilityTest, testGetTextIndexAtCursor, TestSize.Level0)
|
||||
EXPECT_EQ(index, TextListener::TEXT_INDEX);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGetTextIndexAtCursor_timeout
|
||||
* @tc.desc:
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testGetTextIndexAtCursor_timeout, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility testGetTextIndexAtCursor_timeout START");
|
||||
TextListener::setTimeout(true);
|
||||
int32_t index;
|
||||
auto ret = inputMethodAbility_->GetTextIndexAtCursor(index);
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_CONTROLLER_INVOKING_FAILED);
|
||||
TextListener::setTimeout(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testCreatePanel001
|
||||
* @tc.desc: It's allowed to create one SOFT_KEYBOARD panel, but two is denied.
|
||||
|
@ -36,8 +36,6 @@ public:
|
||||
static void CheckCurrentProp(const std::string &extName);
|
||||
static void CheckCurrentSubProp(const std::string &extName);
|
||||
static void CheckCurrentSubProps();
|
||||
static std::mutex imeChangeFlagLock;
|
||||
static std::condition_variable conditionVar;
|
||||
static sptr<InputMethodController> imc_;
|
||||
static bool imeChangeFlag;
|
||||
static std::string newImeBundleName;
|
||||
@ -46,8 +44,6 @@ public:
|
||||
static std::vector<std::string> extName;
|
||||
static std::vector<std::string> language;
|
||||
};
|
||||
std::mutex InputMethodSwitchTest::imeChangeFlagLock;
|
||||
std::condition_variable InputMethodSwitchTest::conditionVar;
|
||||
bool InputMethodSwitchTest::imeChangeFlag = false;
|
||||
sptr<InputMethodController> InputMethodSwitchTest::imc_;
|
||||
std::string InputMethodSwitchTest::newImeBundleName = "com.example.newTestIme";
|
||||
@ -59,8 +55,6 @@ constexpr uint32_t IME_EXT_NUM = 2;
|
||||
constexpr uint32_t NEW_IME_SUBTYPE_NUM = 3;
|
||||
constexpr uint32_t TOTAL_IME_MIN_NUM = 2;
|
||||
constexpr uint32_t ENABLE_IME_NUM = 1;
|
||||
constexpr uint32_t SUBTYPE_SWITCH_DELAY_TIME = 20;
|
||||
constexpr uint32_t IME_SWITCH_DELAY_TIME = 200;
|
||||
constexpr uint32_t WAIT_IME_READY_TIME = 1;
|
||||
class InputMethodSettingListenerImpl : public InputMethodSettingListener {
|
||||
public:
|
||||
@ -68,11 +62,7 @@ public:
|
||||
~InputMethodSettingListenerImpl() = default;
|
||||
void OnImeChange(const Property &property, const SubProperty &subProperty)
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(InputMethodSwitchTest::imeChangeFlagLock);
|
||||
InputMethodSwitchTest::imeChangeFlag = true;
|
||||
}
|
||||
InputMethodSwitchTest::conditionVar.notify_one();
|
||||
InputMethodSwitchTest::imeChangeFlag = true;
|
||||
IMSA_HILOGI("InputMethodSettingListenerImpl OnImeChange");
|
||||
}
|
||||
void OnPanelStatusChange(const InputWindowStatus &status, const std::vector<InputWindowInfo> &windowInfo)
|
||||
@ -147,12 +137,10 @@ void InputMethodSwitchTest::CheckCurrentSubProps()
|
||||
HWTEST_F(InputMethodSwitchTest, testImeSwitch, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("oldIme testImeSwitch Test START");
|
||||
std::unique_lock<std::mutex> lock(imeChangeFlagLock);
|
||||
imeChangeFlag = false;
|
||||
// switch to ext testIme
|
||||
auto ret = imc_->SwitchInputMethod(bundleName);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
conditionVar.wait_for(lock, std::chrono::milliseconds(IME_SWITCH_DELAY_TIME), [] { return imeChangeFlag == true; });
|
||||
EXPECT_TRUE(imeChangeFlag);
|
||||
CheckCurrentProp(extName[0]);
|
||||
CheckCurrentSubProp(extName[0]);
|
||||
@ -170,12 +158,9 @@ HWTEST_F(InputMethodSwitchTest, testImeSwitch, TestSize.Level0)
|
||||
HWTEST_F(InputMethodSwitchTest, testSubTypeSwitch_001, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("oldIme testSubTypeSwitch_001 Test START");
|
||||
std::unique_lock<std::mutex> lock(imeChangeFlagLock);
|
||||
imeChangeFlag = false;
|
||||
int32_t ret = imc_->SwitchInputMethod(bundleName, extName[0]);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
conditionVar.wait_for(
|
||||
lock, std::chrono::milliseconds(SUBTYPE_SWITCH_DELAY_TIME), [] { return imeChangeFlag == true; });
|
||||
EXPECT_FALSE(imeChangeFlag);
|
||||
CheckCurrentProp(extName[0]);
|
||||
CheckCurrentSubProp(extName[0]);
|
||||
@ -192,12 +177,9 @@ HWTEST_F(InputMethodSwitchTest, testSubTypeSwitch_001, TestSize.Level0)
|
||||
HWTEST_F(InputMethodSwitchTest, testSubTypeSwitch_002, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("oldIme testSubTypeSwitch_002 Test START");
|
||||
std::unique_lock<std::mutex> lock(imeChangeFlagLock);
|
||||
imeChangeFlag = false;
|
||||
int32_t ret = imc_->SwitchInputMethod(bundleName, extName[1]);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
conditionVar.wait_for(
|
||||
lock, std::chrono::milliseconds(SUBTYPE_SWITCH_DELAY_TIME), [] { return imeChangeFlag == true; });
|
||||
EXPECT_TRUE(imeChangeFlag);
|
||||
CheckCurrentProp(extName[1]);
|
||||
CheckCurrentSubProp(extName[1]);
|
||||
@ -232,13 +214,10 @@ HWTEST_F(InputMethodSwitchTest, testSubTypeSwitchWithErrorSubName, TestSize.Leve
|
||||
HWTEST_F(InputMethodSwitchTest, testSwitchToCurrentImeWithEmptySubName, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("oldIme testSwitchToCurrentImeWithEmptySubName Test START");
|
||||
std::unique_lock<std::mutex> lock(imeChangeFlagLock);
|
||||
imeChangeFlag = false;
|
||||
std::string subName = InputMethodSwitchTest::imc_->GetCurrentInputMethodSubtype()->id;
|
||||
int32_t ret = imc_->SwitchInputMethod(bundleName);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
InputMethodSwitchTest::conditionVar.wait_for(
|
||||
lock, std::chrono::milliseconds(SUBTYPE_SWITCH_DELAY_TIME), [] { return imeChangeFlag == true; });
|
||||
EXPECT_FALSE(imeChangeFlag);
|
||||
CheckCurrentProp(subName);
|
||||
CheckCurrentSubProp(subName);
|
||||
|
@ -36,8 +36,6 @@ public:
|
||||
static void CheckCurrentProp();
|
||||
static void CheckCurrentSubProp(const std::string &subName);
|
||||
static void CheckCurrentSubProps();
|
||||
static std::mutex imeChangeFlagLock;
|
||||
static std::condition_variable conditionVar;
|
||||
static bool imeChangeFlag;
|
||||
static sptr<InputMethodController> imc_;
|
||||
static std::string bundleName;
|
||||
@ -46,8 +44,6 @@ public:
|
||||
static std::vector<std::string> locale;
|
||||
static std::vector<std::string> language;
|
||||
};
|
||||
std::mutex NewImeSwitchTest::imeChangeFlagLock;
|
||||
std::condition_variable NewImeSwitchTest::conditionVar;
|
||||
bool NewImeSwitchTest::imeChangeFlag = false;
|
||||
sptr<InputMethodController> NewImeSwitchTest::imc_;
|
||||
std::string NewImeSwitchTest::bundleName = "com.example.newTestIme";
|
||||
@ -56,8 +52,6 @@ std::vector<std::string> NewImeSwitchTest::subName{ "lowerInput", "upperInput",
|
||||
std::vector<std::string> NewImeSwitchTest::locale{ "en-US", "en-US", "zh-CN" };
|
||||
std::vector<std::string> NewImeSwitchTest::language{ "english", "english", "chinese" };
|
||||
constexpr uint32_t IME_SUBTYPE_NUM = 3;
|
||||
constexpr uint32_t SUBTYPE_SWITCH_DELAY_TIME = 10;
|
||||
constexpr uint32_t IME_SWITCH_DELAY_TIME = 200;
|
||||
constexpr uint32_t WAIT_IME_READY_TIME = 1;
|
||||
class InputMethodSettingListenerImpl : public InputMethodSettingListener {
|
||||
public:
|
||||
@ -65,11 +59,7 @@ public:
|
||||
~InputMethodSettingListenerImpl() = default;
|
||||
void OnImeChange(const Property &property, const SubProperty &subProperty)
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(NewImeSwitchTest::imeChangeFlagLock);
|
||||
NewImeSwitchTest::imeChangeFlag = true;
|
||||
}
|
||||
NewImeSwitchTest::conditionVar.notify_one();
|
||||
NewImeSwitchTest::imeChangeFlag = true;
|
||||
IMSA_HILOGI("InputMethodSettingListenerImpl OnImeChange");
|
||||
}
|
||||
void OnPanelStatusChange(const InputWindowStatus &status, const std::vector<InputWindowInfo> &windowInfo)
|
||||
@ -143,12 +133,10 @@ void NewImeSwitchTest::CheckCurrentSubProps()
|
||||
HWTEST_F(NewImeSwitchTest, testNewImeSwitch, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("newIme testNewImeSwitch Test START");
|
||||
std::unique_lock<std::mutex> lock(imeChangeFlagLock);
|
||||
imeChangeFlag = false;
|
||||
// switch to newTestIme
|
||||
auto ret = imc_->SwitchInputMethod(bundleName);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
conditionVar.wait_for(lock, std::chrono::milliseconds(IME_SWITCH_DELAY_TIME), [] { return imeChangeFlag == true; });
|
||||
EXPECT_TRUE(imeChangeFlag);
|
||||
CheckCurrentProp();
|
||||
CheckCurrentSubProp(subName[0]);
|
||||
@ -166,12 +154,9 @@ HWTEST_F(NewImeSwitchTest, testNewImeSwitch, TestSize.Level0)
|
||||
HWTEST_F(NewImeSwitchTest, testSubTypeSwitch_001, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("newIme testSubTypeSwitch_001 Test START");
|
||||
std::unique_lock<std::mutex> lock(imeChangeFlagLock);
|
||||
imeChangeFlag = false;
|
||||
int32_t ret = imc_->SwitchInputMethod(bundleName, subName[0]);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
conditionVar.wait_for(
|
||||
lock, std::chrono::milliseconds(SUBTYPE_SWITCH_DELAY_TIME), [] { return imeChangeFlag == true; });
|
||||
EXPECT_FALSE(imeChangeFlag);
|
||||
CheckCurrentProp();
|
||||
CheckCurrentSubProp(subName[0]);
|
||||
@ -188,12 +173,9 @@ HWTEST_F(NewImeSwitchTest, testSubTypeSwitch_001, TestSize.Level0)
|
||||
HWTEST_F(NewImeSwitchTest, testSubTypeSwitch_002, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("newIme testSubTypeSwitch_002 Test START");
|
||||
std::unique_lock<std::mutex> lock(imeChangeFlagLock);
|
||||
imeChangeFlag = false;
|
||||
int32_t ret = imc_->SwitchInputMethod(bundleName, subName[1]);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
conditionVar.wait_for(
|
||||
lock, std::chrono::milliseconds(SUBTYPE_SWITCH_DELAY_TIME), [] { return imeChangeFlag == true; });
|
||||
EXPECT_TRUE(imeChangeFlag);
|
||||
CheckCurrentProp();
|
||||
CheckCurrentSubProp(subName[1]);
|
||||
@ -210,13 +192,9 @@ HWTEST_F(NewImeSwitchTest, testSubTypeSwitch_002, TestSize.Level0)
|
||||
HWTEST_F(NewImeSwitchTest, testSubTypeSwitch_003, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("newIme testSubTypeSwitch_003 Test START");
|
||||
std::unique_lock<std::mutex> lock(imeChangeFlagLock);
|
||||
imeChangeFlag = false;
|
||||
int32_t ret = imc_->SwitchInputMethod(bundleName, subName[2]);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
conditionVar.wait_for(
|
||||
lock, std::chrono::milliseconds(SUBTYPE_SWITCH_DELAY_TIME), [] { return imeChangeFlag == true; });
|
||||
EXPECT_TRUE(imeChangeFlag);
|
||||
EXPECT_TRUE(imeChangeFlag);
|
||||
CheckCurrentProp();
|
||||
CheckCurrentSubProp(subName[2]);
|
||||
@ -233,12 +211,9 @@ HWTEST_F(NewImeSwitchTest, testSubTypeSwitch_003, TestSize.Level0)
|
||||
HWTEST_F(NewImeSwitchTest, testSubTypeSwitch_004, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("newIme testSubTypeSwitch_004 Test START");
|
||||
std::unique_lock<std::mutex> lock(imeChangeFlagLock);
|
||||
imeChangeFlag = false;
|
||||
int32_t ret = imc_->SwitchInputMethod(bundleName, subName[0]);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
conditionVar.wait_for(
|
||||
lock, std::chrono::milliseconds(SUBTYPE_SWITCH_DELAY_TIME), [] { return imeChangeFlag == true; });
|
||||
EXPECT_TRUE(imeChangeFlag);
|
||||
CheckCurrentProp();
|
||||
CheckCurrentSubProp(subName[0]);
|
||||
@ -272,12 +247,9 @@ HWTEST_F(NewImeSwitchTest, testSubTypeSwitchWithErrorSubName, TestSize.Level0)
|
||||
HWTEST_F(NewImeSwitchTest, testSwitchToCurrentImeWithEmptySubName, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("newIme testSwitchToCurrentImeWithEmptySubName Test START");
|
||||
std::unique_lock<std::mutex> lock(imeChangeFlagLock);
|
||||
imeChangeFlag = false;
|
||||
int32_t ret = imc_->SwitchInputMethod(bundleName);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
conditionVar.wait_for(
|
||||
lock, std::chrono::milliseconds(SUBTYPE_SWITCH_DELAY_TIME), [] { return imeChangeFlag == true; });
|
||||
EXPECT_FALSE(imeChangeFlag);
|
||||
CheckCurrentProp();
|
||||
CheckCurrentSubProp(subName[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user