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 "components/ui_time_picker.h"
17 #include <climits>
18 #include <gtest/gtest.h>
19 
20 using namespace testing::ext;
21 namespace OHOS {
22 class UITimePickerTest : public testing::Test {
23 public:
24     static void SetUpTestCase(void);
25     static void TearDownTestCase(void);
26     static UITimePicker* timePicker_;
27 };
28 
29 UITimePicker* UITimePickerTest::timePicker_ = nullptr;
30 
SetUpTestCase(void)31 void UITimePickerTest::SetUpTestCase(void)
32 {
33     if (timePicker_ == nullptr) {
34         timePicker_ = new UITimePicker();
35     }
36 }
37 
TearDownTestCase(void)38 void UITimePickerTest::TearDownTestCase(void)
39 {
40     if (timePicker_ != nullptr) {
41         delete timePicker_;
42         timePicker_ = nullptr;
43     }
44 }
45 /**
46  * @tc.name: UITimePickerGetViewType_001
47  * @tc.desc: Verify GetViewType function, equal.
48  * @tc.type: FUNC
49  * @tc.require: AR000EEMQ7
50  */
51 HWTEST_F(UITimePickerTest, UITimePickerGetViewType_001, TestSize.Level1)
52 {
53     if (timePicker_ == nullptr) {
54         EXPECT_EQ(1, 0);
55         return;
56     }
57     EXPECT_EQ(timePicker_->GetViewType(), UI_TIME_PICKER);
58 }
59 
60 /**
61  * @tc.name: UITimePickerSetWidth_001
62  * @tc.desc: Verify SetWidth function, equal.
63  * @tc.type: FUNC
64  * @tc.require: AR000EEMQ7
65  */
66 HWTEST_F(UITimePickerTest, UITimePickerSetWidth_001, TestSize.Level0)
67 {
68     if (timePicker_ == nullptr) {
69         EXPECT_EQ(1, 0);
70         return;
71     }
72     const int16_t width = 50;
73 
74     timePicker_->SetWidth(width);
75     EXPECT_EQ(timePicker_->GetWidth(), width);
76 }
77 
78 /**
79  * @tc.name: UITimePickerSetHeight_001
80  * @tc.desc: Verify SetHeight function, equal.
81  * @tc.type: FUNC
82  * @tc.require: AR000EEMQ7
83  */
84 HWTEST_F(UITimePickerTest, UITimePickerSetHeight_001, TestSize.Level0)
85 {
86     if (timePicker_ == nullptr) {
87         EXPECT_EQ(1, 0);
88         return;
89     }
90     const int16_t height = 50;
91 
92     timePicker_->SetHeight(height);
93     EXPECT_EQ(timePicker_->GetHeight(), height);
94 }
95 } // namespace OHOS
96