• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 
18 #include "long_press_event_subscribe_manager.h"
19 #include <cinttypes>
20 #include "bytrace_adapter.h"
21 #include "define_multimodal.h"
22 #include "error_multimodal.h"
23 #include "multimodal_event_handler.h"
24 
25 #undef MMI_LOG_TAG
26 #define MMI_LOG_TAG "LongPressEventSubscribeManagerTest"
27 
28 namespace OHOS {
29 namespace MMI {
30 namespace {
31 using namespace testing::ext;
32 } // namespace
33 
34 class LongPressEventSubscribeManagerTest : public testing::Test {
35 public:
SetUpTestCase(void)36     static void SetUpTestCase(void) {}
TearDownTestCase(void)37     static void TearDownTestCase(void) {}
38 };
39 /**
40  * @tc.name: LongPressEventSubscribeManagerTest_OnSubscribeLongPressEventCallback001
41  * @tc.desc: Verify OnSubscribeLongPressEventCallback
42  * @tc.type: FUNC
43  * @tc.require:
44  */
45 HWTEST_F(LongPressEventSubscribeManagerTest, LongPressEventSubscribeManagerTest_OnSubscribeLongPressEventCallback001,
46     TestSize.Level1)
47 {
48     LongPressEvent longPressEvent;
49     int32_t subscribeId = -1;
50 
51     LongPressEventSubscribeManager manager;
52     auto ret = manager.OnSubscribeLongPressEventCallback(longPressEvent, subscribeId);
53     EXPECT_EQ(ret, RET_ERR);
54 
55     subscribeId = 1;
56     ret = manager.OnSubscribeLongPressEventCallback(longPressEvent, subscribeId);
57     EXPECT_EQ(ret, ERROR_NULL_POINTER);
58 
__anone48cef0d0202(LongPressEvent event) 59     auto myCallback = [](LongPressEvent event) {
60         MMI_HILOGD("Add event success");
61     };
62 
63     LongPressRequest longPressRequest;
64     LongPressEventSubscribeManager::SubscribeLongPressEventInfo info(longPressRequest, myCallback);
65     manager.subscribeInfos_.emplace(std::make_pair(subscribeId, info));
66     ret = manager.OnSubscribeLongPressEventCallback(longPressEvent, subscribeId);
67     EXPECT_EQ(ret, RET_OK);
68 }
69 
70 /**
71  * @tc.name: LongPressEventSubscribeManagerTest_OnConnected001
72  * @tc.desc: Verify OnConnected
73  * @tc.type: FUNC
74  * @tc.require:
75  */
76 HWTEST_F(LongPressEventSubscribeManagerTest, LongPressEventSubscribeManagerTest_OnConnected001,
77     TestSize.Level1)
78 {
79     LongPressEventSubscribeManager manager;
80     EXPECT_NO_FATAL_FAILURE(manager.OnConnected());
81 
__anone48cef0d0302(LongPressEvent event) 82     auto myCallback = [](LongPressEvent event) {
83         MMI_HILOGD("Add event success");
84     };
85 
86     int32_t subscribeId = 1;
87     LongPressRequest longPressRequest;
88     LongPressEventSubscribeManager::SubscribeLongPressEventInfo info(longPressRequest, myCallback);
89     manager.subscribeInfos_.emplace(std::make_pair(subscribeId, info));
90     EXPECT_NO_FATAL_FAILURE(manager.OnConnected());
91 }
92 } // namespace MMI
93 } // namespace OHOS