• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #define private public
18 #define protected public
19 #include "input_method_ability.h"
20 #undef private
21 
22 using namespace testing::ext;
23 namespace OHOS {
24 namespace MiscServices {
25 constexpr int32_t DEALY_TIME = 20;
26 class InputMethodAbilityExecptionTest : public testing::Test {
27 public:
SetUpTestCase(void)28     static void SetUpTestCase(void)
29     {
30         IMSA_HILOGI("InputMethodAbilityExecptionTest::SetUpTestCase");
31         inputMethodAbility_ = InputMethodAbility::GetInstance();
32         inputMethodAbility_->OnImeReady();
33         imeListener_ = std::make_shared<ImeListenerImpl>();
34         inputMethodAbility_->setImeListener(imeListener_);
35         std::unique_lock<std::mutex> lock(lock_);
36         cv_.wait_for(lock, std::chrono::milliseconds(DEALY_TIME),
37             [] { return InputMethodAbilityExecptionTest::isInputStart_; });
38         inputMethodAbility_->dataChannel_ = nullptr;
39     }
TearDownTestCase(void)40     static void TearDownTestCase(void)
41     {
42         IMSA_HILOGI("InputMethodAbilityExecptionTest::TearDownTestCase");
43         inputMethodAbility_->imeListener_ = nullptr;
44     }
SetUp()45     void SetUp()
46     {
47     }
TearDown()48     void TearDown()
49     {
50     }
51     class ImeListenerImpl : public InputMethodEngineListener {
52     public:
ImeListenerImpl()53         ImeListenerImpl(){};
~ImeListenerImpl()54         ~ImeListenerImpl(){};
55         void OnKeyboardStatus(bool isShow) override;
56         void OnInputStart() override;
57         void OnInputStop(const std::string &imeId) override;
58         void OnSetCallingWindow(uint32_t windowId) override;
59         void OnSetSubtype(const SubProperty &property) override;
60     };
61     static sptr<InputMethodAbility> inputMethodAbility_;
62 
63 private:
64     static std::shared_ptr<ImeListenerImpl> imeListener_;
65     static std::mutex lock_;
66     static std::condition_variable cv_;
67     static bool isInputStart_;
68 };
OnKeyboardStatus(bool isShow)69 void InputMethodAbilityExecptionTest::ImeListenerImpl::OnKeyboardStatus(bool isShow)
70 {
71 }
OnInputStart()72 void InputMethodAbilityExecptionTest::ImeListenerImpl::OnInputStart()
73 {
74     std::unique_lock<std::mutex> lock(InputMethodAbilityExecptionTest::lock_);
75     InputMethodAbilityExecptionTest::isInputStart_ = true;
76     InputMethodAbilityExecptionTest::cv_.notify_one();
77 }
OnInputStop(const std::string & imeId)78 void InputMethodAbilityExecptionTest::ImeListenerImpl::OnInputStop(const std::string &imeId)
79 {
80 }
OnSetCallingWindow(uint32_t windowId)81 void InputMethodAbilityExecptionTest::ImeListenerImpl::OnSetCallingWindow(uint32_t windowId)
82 {
83 }
OnSetSubtype(const SubProperty & property)84 void InputMethodAbilityExecptionTest::ImeListenerImpl::OnSetSubtype(const SubProperty &property)
85 {
86 }
87 sptr<InputMethodAbility> InputMethodAbilityExecptionTest::inputMethodAbility_;
88 std::shared_ptr<InputMethodAbilityExecptionTest::ImeListenerImpl> InputMethodAbilityExecptionTest::imeListener_;
89 std::mutex InputMethodAbilityExecptionTest::lock_;
90 std::condition_variable InputMethodAbilityExecptionTest::cv_;
91 bool InputMethodAbilityExecptionTest::isInputStart_ = false;
92 
93 /**
94  * @tc.name: testMoveCursorExecption
95  * @tc.desc: InputMethodAbility MoveCursor
96  * @tc.type: FUNC
97  * @tc.require:
98  * @tc.author: Hollokin
99  */
100 HWTEST_F(InputMethodAbilityExecptionTest, testMoveCursorExecption, TestSize.Level0)
101 {
102     IMSA_HILOGI("InputMethodAbilityExecptionTest MoveCursor Test START");
103     auto ret = inputMethodAbility_->MoveCursor(4); // move cursor right
104     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
105 }
106 
107 /**
108  * @tc.name: testInsertTextExecption
109  * @tc.desc: InputMethodAbility InsertText
110  * @tc.type: FUNC
111  * @tc.require:
112  * @tc.author: Hollokin
113  */
114 HWTEST_F(InputMethodAbilityExecptionTest, testInsertTextExecption, TestSize.Level0)
115 {
116     IMSA_HILOGI("InputMethodAbilityExecptionTest InsertText Test START");
117     auto ret = inputMethodAbility_->InsertText("text");
118     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
119 }
120 
121 /**
122  * @tc.name: testSendFunctionKeyExecption
123  * @tc.desc: InputMethodAbility SendFunctionKey
124  * @tc.type: FUNC
125  * @tc.require:
126  * @tc.author: Hollokin
127  */
128 HWTEST_F(InputMethodAbilityExecptionTest, testSendFunctionKeyExecption, TestSize.Level0)
129 {
130     IMSA_HILOGI("InputMethodAbilityExecptionTest SendFunctionKey Test START");
131     auto ret = inputMethodAbility_->SendFunctionKey(0);
132     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
133 }
134 
135 /**
136  * @tc.name: testDeleteExecptionText
137  * @tc.desc: InputMethodAbility DeleteForward & DeleteBackward
138  * @tc.type: FUNC
139  * @tc.require:
140  * @tc.author: Hollokin
141  */
142 HWTEST_F(InputMethodAbilityExecptionTest, testDeleteExecptionText, TestSize.Level0)
143 {
144     IMSA_HILOGI("InputMethodAbilityExecptionTest testDelete Test START");
145     int32_t deleteForwardLenth = 1;
146     auto ret = inputMethodAbility_->DeleteForward(deleteForwardLenth);
147     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
148     int32_t deleteBackwardLenth = 2;
149     ret = inputMethodAbility_->DeleteBackward(deleteBackwardLenth);
150     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
151 }
152 
153 /**
154  * @tc.name: testGetTextExecption001
155  * @tc.desc: InputMethodAbility GetTextBeforeCursor & GetTextAfterCursor
156  * @tc.type: FUNC
157  * @tc.require:
158  * @tc.author: Hollokin
159  */
160 HWTEST_F(InputMethodAbilityExecptionTest, testGetTextExecption001, TestSize.Level0)
161 {
162     IMSA_HILOGI("InputMethodAbilityExecptionTest testGetText001 START");
163     std::u16string text;
164     auto ret = inputMethodAbility_->GetTextAfterCursor(8, text);
165     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
166     ret = inputMethodAbility_->GetTextBeforeCursor(3, text);
167     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
168 }
169 
170 /**
171  * @tc.name: testGetEnterKeyTypeExecption
172  * @tc.desc: InputMethodAbility GetEnterKeyType & GetInputPattern
173  * @tc.type: FUNC
174  * @tc.require:
175  * @tc.author: Hollokin
176  */
177 HWTEST_F(InputMethodAbilityExecptionTest, testGetEnterKeyTypeExecption, TestSize.Level0)
178 {
179     IMSA_HILOGI("InputMethodAbilityExecptionTest testGetEnterKeyType START");
180     int32_t keyType2;
181     auto ret = inputMethodAbility_->GetEnterKeyType(keyType2);
182     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
183     int32_t inputPattern;
184     ret = inputMethodAbility_->GetInputPattern(inputPattern);
185     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
186 }
187 } // namespace MiscServices
188 } // namespace OHOS
189