1 /* 2 * Copyright (c) 2023 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 #ifndef INPUTMETHOD_IMF_KEYBOARD_LISTENER_TEST_IMPL_H 17 #define INPUTMETHOD_IMF_KEYBOARD_LISTENER_TEST_IMPL_H 18 19 #include <condition_variable> 20 #include <mutex> 21 22 #include "keyboard_listener.h" 23 24 namespace OHOS { 25 namespace MiscServices { 26 class KeyboardListenerTestImpl : public KeyboardListener { 27 public: KeyboardListenerTestImpl()28 KeyboardListenerTestImpl(){}; ~KeyboardListenerTestImpl()29 ~KeyboardListenerTestImpl(){}; 30 bool OnKeyEvent(int32_t keyCode, int32_t keyStatus, sptr<KeyEventConsumerProxy> &consumer) override; OnKeyEvent(const std::shared_ptr<MMI::KeyEvent> & keyEvent,sptr<KeyEventConsumerProxy> & consumer)31 bool OnKeyEvent(const std::shared_ptr<MMI::KeyEvent> &keyEvent, sptr<KeyEventConsumerProxy> &consumer) override 32 { 33 return false; 34 } 35 bool OnDealKeyEvent( 36 const std::shared_ptr<MMI::KeyEvent> &keyEvent, sptr<KeyEventConsumerProxy> &consumer) override; 37 void OnCursorUpdate(int32_t positionX, int32_t positionY, int32_t height) override; 38 void OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd) override; 39 void OnTextChange(const std::string &text) override; 40 void OnEditorAttributeChange(const InputAttribute &inputAttribute) override; 41 static void ResetParam(); 42 static bool WaitKeyEvent(int32_t keyCode); 43 static bool WaitCursorUpdate(); 44 static bool WaitSelectionChange(int32_t newBegin); 45 static bool WaitTextChange(const std::string &text); 46 static bool WaitEditorAttributeChange(const InputAttribute &inputAttribute); 47 48 private: 49 static std::mutex kdListenerLock_; 50 static std::condition_variable kdListenerCv_; 51 static int32_t keyCode_; 52 static int32_t cursorHeight_; 53 static int32_t newBegin_; 54 static std::string text_; 55 static InputAttribute inputAttribute_; 56 }; 57 } // namespace MiscServices 58 } // namespace OHOS 59 60 #endif //INPUTMETHOD_IMF_KEYBOARD_LISTENER_TEST_IMPL_H 61