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/event.h"
17
18 #include <climits>
19 #include <gtest/gtest.h>
20
21 using namespace testing::ext;
22 namespace OHOS {
23 namespace {
24 const Point INIT_POS = { 100, 200 };
25 const TimeType TIME_STAMP = 10;
26 }
27
28 class EventTest : public testing::Test {
29 public:
30 static void SetUpTestCase(void);
31 static void TearDownTestCase(void);
32 static Event* event_;
33 };
34
35 Event* EventTest::event_ = nullptr;
36
SetUpTestCase(void)37 void EventTest::SetUpTestCase(void)
38 {
39 if (event_ == nullptr) {
40 event_ = new Event(INIT_POS);
41 }
42 }
43
TearDownTestCase(void)44 void EventTest::TearDownTestCase(void)
45 {
46 if (event_ != nullptr) {
47 delete event_;
48 event_ = nullptr;
49 }
50 }
51 /**
52 * @tc.name: EventConstructor_001
53 * @tc.desc: Verify Constructor function, equal.
54 * @tc.type: FUNC
55 * @tc.require: SR000DRSH4
56 */
57 HWTEST_F(EventTest, EventConstructor_001, TestSize.Level1)
58 {
59 if (event_ == nullptr) {
60 EXPECT_EQ(1, 0);
61 return;
62 }
63 EXPECT_EQ(event_->GetCurrentPos().x, INIT_POS.x);
64 EXPECT_EQ(event_->GetCurrentPos().y, INIT_POS.y);
65 }
66
67 /**
68 * @tc.name: EventSetTimeStamp_001
69 * @tc.desc: Verify SetTimeStamp function, equal.
70 * @tc.type: FUNC
71 * @tc.require: SR000DRSH4
72 */
73 HWTEST_F(EventTest, EventSetTimeStamp_001, TestSize.Level0)
74 {
75 if (event_ == nullptr) {
76 EXPECT_EQ(1, 0);
77 return;
78 }
79 event_->SetTimeStamp(TIME_STAMP);
80 EXPECT_EQ(event_->GetTimeStamp(), TIME_STAMP);
81 }
82 } // namespace OHOS
83