/* * 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. */ #ifndef UI_RECORD_H #define UI_RECORD_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "least_square_impl.h" #include "touch_event.h" #include "offset.h" #include "velocity.h" #include "velocity_tracker.h" #include "keyevent_tracker.h" #include "ui_driver.h" #include "ui_action.h" #include "input_manager.h" #include "i_input_event_consumer.h" #include "pointer_event.h" #include "widget_operator.h" #include "window_operator.h" #include "widget_selector.h" #include "ui_model.h" #include "find_widget.h" #include "pointer_tracker.h" #include "pointer_info.h" #include "input_manager.h" namespace OHOS::uitest { class InputEventCallback : public MMI::IInputEventConsumer { public: void RecordInitEnv(const std::string &modeOpt); bool InitReportFolder(); bool InitEventRecordFile(); bool dealSpecialKey(std::shared_ptr keyEvent) const; void OnInputEvent(std::shared_ptr keyEvent) const override; void HandleDownEvent(TouchEventInfo& event) const; void HandleMoveEvent(const TouchEventInfo& event) const; void HandleUpEvent(const TouchEventInfo& event) const; void WriteDataAndFindWidgets(const TouchEventInfo& event) const; void WritePointerInfo() const; void OnInputEvent(std::shared_ptr pointerEvent) const override; void OnInputEvent(std::shared_ptr axisEvent) const override; void SubscribeMonitorInit(); void KeyEventSubscribeTemplate(SubscribeKeyevent& subscribeKeyevent); void SubscribeMonitorCancel(); void TimerReprintClickFunction(); void TimerTouchCheckFunction(); void FindWidgetsandWriteData(); void DoAbcCallBack(nlohmann::json jsonData) const; void SetAbcCallBack(std::function handler) { abcCallBack = handler; } auto GetAbcCallBack() { return abcCallBack; } static constexpr int TIMEINTERVAL = 5000; static constexpr int KEY_DOWN_DURATION = 0; static const std::string DEFAULT_DIR; mutable volatile int touchTime = 0; mutable volatile bool isLastClick_ = false; mutable shared_ptr cout_lock = make_shared(); mutable shared_ptr csv_lock = make_shared(); mutable std::mutex g_clickMut; mutable std::condition_variable clickCon; mutable volatile bool findWidgetsAllow_ = false; mutable std::mutex widgetsMut; mutable std::condition_variable widgetsCon; bool stopFlag = false; std::mutex timerMut; std::condition_variable timerCon; private: shared_ptr> eventQueue_; std::string recordMode = ""; std::string filePath; WidgetSelector selector = WidgetSelector(); vector> rev; std::function abcCallBack = nullptr; mutable std::ofstream outFile; mutable UiDriver driver = UiDriver(); mutable PointerTracker pointerTracker_; mutable KeyeventTracker keyeventTracker_; }; class TestUtils { public: TestUtils() = default; virtual ~TestUtils() = default; static std::vector split(const std::string &in, const std::string &delim) { std::regex reg(delim); std::vector res = { std::sregex_token_iterator(in.begin(), in.end(), reg, -1), std::sregex_token_iterator() }; return res; }; }; class EventData { public: void WriteEventData(const VelocityTracker &velocityTracker, const std::string &actionType) const; static void ReadEventLine(); private: static std::string defaultDir; }; class DataWrapper { public: template void ProcessData(Function userFunc) { std::lock_guard lock(mut); userFunc(data); } private: EventData data; UiDriver d; std::mutex mut; }; int32_t UiDriverRecordStart(std::string modeOpt); int32_t UiDriverRecordStart(std::function handler, std::string modeOpt); int32_t UiDriverRecordStartTemplate(std::string modeOpt); void UiDriverRecordStop(); } // namespace OHOS::uitest #endif // UI_RECORD_H