1/*
2 * Copyright (c) 2024 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 <string>
17#include <vector>
18#include "gtest/gtest.h"
19#define protected public
20#include "KeyInputImpl.h"
21#include "MockGlobalResult.h"
22
23namespace {
24    TEST(KeyInputImplTest, DispatchOsInputMethodEventTest)
25    {
26        int code = 10;
27        KeyInputImpl::GetInstance().SetCodePoint(code);
28        EXPECT_EQ(KeyInputImpl::GetInstance().codePoint, code);
29        g_dispatchInputMethodEvent = false;
30        KeyInputImpl::GetInstance().DispatchOsInputMethodEvent();
31        EXPECT_TRUE(g_dispatchInputMethodEvent);
32    }
33
34    TEST(KeyInputImplTest, DispatchOsKeyEventTest)
35    {
36        int32_t keyCode = 2047;
37        int32_t keyAction = 1;
38        std::vector<int32_t> pressedCodesVec;
39        for (unsigned int i = 0; i < 3; i++) {
40            pressedCodesVec.push_back(keyCode + i);
41        }
42        std::string keyString = "ctrl";
43        KeyInputImpl::GetInstance().SetKeyEvent(keyCode, keyAction, pressedCodesVec, keyString);
44        EXPECT_EQ(KeyInputImpl::GetInstance().keyCode, keyCode);
45        EXPECT_EQ(KeyInputImpl::GetInstance().keyAction, keyAction);
46        EXPECT_EQ(KeyInputImpl::GetInstance().keyString, keyString);
47
48        g_dispatchKeyEvent = false;
49        KeyInputImpl::GetInstance().DispatchOsKeyEvent();
50        EXPECT_TRUE(g_dispatchKeyEvent);
51    }
52}