1 /*
2  * Copyright (c) 2020-2021 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 "events/key_event.h"
17 
18 #include <climits>
19 #include <gtest/gtest.h>
20 
21 using namespace testing::ext;
22 namespace OHOS {
23 namespace {
24     const uint16_t KEY_ID = 10;
25     const uint16_t STATE = 20;
26 }
27 
28 class KeyEventTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     static KeyEvent* keyEvent_;
33 };
34 
35 KeyEvent* KeyEventTest::keyEvent_ = nullptr;
36 
SetUpTestCase(void)37 void KeyEventTest::SetUpTestCase(void)
38 {
39     if (keyEvent_ == nullptr) {
40         keyEvent_ = new KeyEvent(KEY_ID, STATE);
41     }
42 }
43 
TearDownTestCase(void)44 void KeyEventTest::TearDownTestCase(void)
45 {
46     if (keyEvent_ != nullptr) {
47         delete keyEvent_;
48         keyEvent_ = nullptr;
49     }
50 }
51 
52 /**
53  * @tc.name: KeyEventGetKeyId_001
54  * @tc.desc: Verify GetKeyId function, equal.
55  * @tc.type: FUNC
56  * @tc.require: SR000DRSH4
57  */
58 HWTEST_F(KeyEventTest, KeyEventGetKeyId_001, TestSize.Level1)
59 {
60     if (keyEvent_ == nullptr) {
61         EXPECT_EQ(1, 0);
62         return;
63     }
64     EXPECT_EQ(keyEvent_->GetKeyId(), KEY_ID);
65 }
66 
67 /**
68  * @tc.name: KeyEventGetState_001
69  * @tc.desc: Verify GetState function, equal.
70  * @tc.type: FUNC
71  * @tc.require: SR000DRSH4
72  */
73 HWTEST_F(KeyEventTest, KeyEventGetState_001, TestSize.Level0)
74 {
75     if (keyEvent_ == nullptr) {
76         EXPECT_EQ(1, 0);
77         return;
78     }
79     EXPECT_EQ(keyEvent_->GetState(), STATE);
80 }
81 } // namespace OHOS
82