1c29fa5a6Sopenharmony_ci/* 2c29fa5a6Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License. 5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at 6c29fa5a6Sopenharmony_ci * 7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8c29fa5a6Sopenharmony_ci * 9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and 13c29fa5a6Sopenharmony_ci * limitations under the License. 14c29fa5a6Sopenharmony_ci */ 15c29fa5a6Sopenharmony_ci 16c29fa5a6Sopenharmony_ci#include <cstdio> 17c29fa5a6Sopenharmony_ci#include <gtest/gtest.h> 18c29fa5a6Sopenharmony_ci 19c29fa5a6Sopenharmony_ci#include "event_statistic.h" 20c29fa5a6Sopenharmony_ci#include "mmi_log.h" 21c29fa5a6Sopenharmony_ci 22c29fa5a6Sopenharmony_ci#undef MMI_LOG_TAG 23c29fa5a6Sopenharmony_ci#define MMI_LOG_TAG "EventStatisticTest" 24c29fa5a6Sopenharmony_ci 25c29fa5a6Sopenharmony_cinamespace OHOS { 26c29fa5a6Sopenharmony_cinamespace MMI { 27c29fa5a6Sopenharmony_ciusing namespace testing; 28c29fa5a6Sopenharmony_ciusing namespace testing::ext; 29c29fa5a6Sopenharmony_ci 30c29fa5a6Sopenharmony_ciclass EventStatisticTest : public testing::Test { 31c29fa5a6Sopenharmony_cipublic: 32c29fa5a6Sopenharmony_ci static void SetUpTestCase(void); 33c29fa5a6Sopenharmony_ci static void TearDownTestCase(void); 34c29fa5a6Sopenharmony_ci void SetUp(); 35c29fa5a6Sopenharmony_ci void TearDown(); 36c29fa5a6Sopenharmony_ci}; 37c29fa5a6Sopenharmony_ci 38c29fa5a6Sopenharmony_civoid EventStatisticTest::SetUpTestCase(void) 39c29fa5a6Sopenharmony_ci{} 40c29fa5a6Sopenharmony_ci 41c29fa5a6Sopenharmony_civoid EventStatisticTest::TearDownTestCase(void) 42c29fa5a6Sopenharmony_ci{} 43c29fa5a6Sopenharmony_ci 44c29fa5a6Sopenharmony_civoid EventStatisticTest::SetUp() 45c29fa5a6Sopenharmony_ci{} 46c29fa5a6Sopenharmony_ci 47c29fa5a6Sopenharmony_civoid EventStatisticTest::TearDown() 48c29fa5a6Sopenharmony_ci{} 49c29fa5a6Sopenharmony_ci 50c29fa5a6Sopenharmony_ci/** 51c29fa5a6Sopenharmony_ci * @tc.name: EventStatisticTest_PushPointerEvent_01 52c29fa5a6Sopenharmony_ci * @tc.desc: Test PushPointerEvent 53c29fa5a6Sopenharmony_ci * @tc.type: FUNC 54c29fa5a6Sopenharmony_ci * @tc.require: 55c29fa5a6Sopenharmony_ci */ 56c29fa5a6Sopenharmony_ciHWTEST_F(EventStatisticTest, EventStatisticTest_PushPointerEvent_01, TestSize.Level1) 57c29fa5a6Sopenharmony_ci{ 58c29fa5a6Sopenharmony_ci CALL_TEST_DEBUG; 59c29fa5a6Sopenharmony_ci EventStatistic eventStatistic; 60c29fa5a6Sopenharmony_ci std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 61c29fa5a6Sopenharmony_ci ASSERT_NE(pointerEvent, nullptr); 62c29fa5a6Sopenharmony_ci pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE; 63c29fa5a6Sopenharmony_ci pointerEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE); 64c29fa5a6Sopenharmony_ci ASSERT_NO_FATAL_FAILURE(eventStatistic.PushPointerEvent(pointerEvent)); 65c29fa5a6Sopenharmony_ci} 66c29fa5a6Sopenharmony_ci 67c29fa5a6Sopenharmony_ci/** 68c29fa5a6Sopenharmony_ci * @tc.name: EventStatisticTest_PushPointerEvent_02 69c29fa5a6Sopenharmony_ci * @tc.desc: Test PushPointerEvent 70c29fa5a6Sopenharmony_ci * @tc.type: FUNC 71c29fa5a6Sopenharmony_ci * @tc.require: 72c29fa5a6Sopenharmony_ci */ 73c29fa5a6Sopenharmony_ciHWTEST_F(EventStatisticTest, EventStatisticTest_PushPointerEvent_02, TestSize.Level1) 74c29fa5a6Sopenharmony_ci{ 75c29fa5a6Sopenharmony_ci CALL_TEST_DEBUG; 76c29fa5a6Sopenharmony_ci EventStatistic eventStatistic; 77c29fa5a6Sopenharmony_ci std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 78c29fa5a6Sopenharmony_ci ASSERT_NE(pointerEvent, nullptr); 79c29fa5a6Sopenharmony_ci pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 80c29fa5a6Sopenharmony_ci pointerEvent->HasFlag(InputEvent::EVENT_FLAG_SIMULATE); 81c29fa5a6Sopenharmony_ci ASSERT_NO_FATAL_FAILURE(eventStatistic.PushPointerEvent(pointerEvent)); 82c29fa5a6Sopenharmony_ci} 83c29fa5a6Sopenharmony_ci 84c29fa5a6Sopenharmony_ci/** 85c29fa5a6Sopenharmony_ci * @tc.name: EventStatisticTest_PopEvent_02 86c29fa5a6Sopenharmony_ci * @tc.desc: Test PopEvent 87c29fa5a6Sopenharmony_ci * @tc.type: FUNC 88c29fa5a6Sopenharmony_ci * @tc.require: 89c29fa5a6Sopenharmony_ci */ 90c29fa5a6Sopenharmony_ciHWTEST_F(EventStatisticTest, EventStatisticTest_PopEvent_02, TestSize.Level1) 91c29fa5a6Sopenharmony_ci{ 92c29fa5a6Sopenharmony_ci CALL_TEST_DEBUG; 93c29fa5a6Sopenharmony_ci EventStatistic eventStatistic; 94c29fa5a6Sopenharmony_ci eventStatistic.eventQueue_.push("event1"); 95c29fa5a6Sopenharmony_ci eventStatistic.eventQueue_.push("event2"); 96c29fa5a6Sopenharmony_ci eventStatistic.eventQueue_.push("event3"); 97c29fa5a6Sopenharmony_ci ASSERT_NO_FATAL_FAILURE(eventStatistic.PopEvent()); 98c29fa5a6Sopenharmony_ci} 99c29fa5a6Sopenharmony_ci 100c29fa5a6Sopenharmony_ci/** 101c29fa5a6Sopenharmony_ci * @tc.name: EventStatisticTest_ConvertTimeToStr_01 102c29fa5a6Sopenharmony_ci * @tc.desc: Test ConvertTimeToStr 103c29fa5a6Sopenharmony_ci * @tc.type: FUNC 104c29fa5a6Sopenharmony_ci * @tc.require: 105c29fa5a6Sopenharmony_ci */ 106c29fa5a6Sopenharmony_ciHWTEST_F(EventStatisticTest, EventStatisticTest_ConvertTimeToStr_01, TestSize.Level1) 107c29fa5a6Sopenharmony_ci{ 108c29fa5a6Sopenharmony_ci CALL_TEST_DEBUG; 109c29fa5a6Sopenharmony_ci EventStatistic eventStatistic; 110c29fa5a6Sopenharmony_ci int64_t timestamp = 50000; 111c29fa5a6Sopenharmony_ci ASSERT_NO_FATAL_FAILURE(eventStatistic.ConvertTimeToStr(timestamp)); 112c29fa5a6Sopenharmony_ci} 113c29fa5a6Sopenharmony_ci 114c29fa5a6Sopenharmony_ci/** 115c29fa5a6Sopenharmony_ci * @tc.name: EventStatisticTest_PushEvent_01 116c29fa5a6Sopenharmony_ci * @tc.desc: Test PushEvent 117c29fa5a6Sopenharmony_ci * @tc.type: FUNC 118c29fa5a6Sopenharmony_ci * @tc.require: 119c29fa5a6Sopenharmony_ci */ 120c29fa5a6Sopenharmony_ciHWTEST_F(EventStatisticTest, EventStatisticTest_PushEvent_01, TestSize.Level1) 121c29fa5a6Sopenharmony_ci{ 122c29fa5a6Sopenharmony_ci CALL_TEST_DEBUG; 123c29fa5a6Sopenharmony_ci EventStatistic eventStatistic; 124c29fa5a6Sopenharmony_ci std::shared_ptr<InputEvent> inputEvent = InputEvent::Create(); 125c29fa5a6Sopenharmony_ci EXPECT_NE(inputEvent, nullptr); 126c29fa5a6Sopenharmony_ci EventStatistic::writeFileEnabled_ = true; 127c29fa5a6Sopenharmony_ci ASSERT_NO_FATAL_FAILURE(eventStatistic.PushEvent(inputEvent)); 128c29fa5a6Sopenharmony_ci EventStatistic::writeFileEnabled_ = false; 129c29fa5a6Sopenharmony_ci ASSERT_NO_FATAL_FAILURE(eventStatistic.PushEvent(inputEvent)); 130c29fa5a6Sopenharmony_ci} 131c29fa5a6Sopenharmony_ci} // namespace MMI 132c29fa5a6Sopenharmony_ci} // namespace OHOS