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_axis.h"
17
18 #include <climits>
19 #include <gtest/gtest.h>
20
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace {
25 const int16_t LARGER_VALUE = 10;
26 const int16_t SMALLER_VALUE = 2;
27 }
28 class UIAxisTest : public testing::Test {
29 public:
30 static void SetUpTestCase(void);
31 static void TearDownTestCase(void);
32 static UIXAxis* axisX_;
33 static UIYAxis* axisY_;
34 };
35 UIXAxis* UIAxisTest::axisX_ = nullptr;
36 UIYAxis* UIAxisTest::axisY_ = nullptr;
37
SetUpTestCase(void)38 void UIAxisTest::SetUpTestCase(void)
39 {
40 if (axisX_ == nullptr) {
41 axisX_ = new UIXAxis();
42 }
43 if (axisY_ == nullptr) {
44 axisY_ = new UIYAxis();
45 }
46 }
47
TearDownTestCase(void)48 void UIAxisTest::TearDownTestCase(void)
49 {
50 if (axisX_ != nullptr) {
51 delete axisX_;
52 axisX_ = nullptr;
53 }
54 if (axisY_ != nullptr) {
55 delete axisY_;
56 axisY_ = nullptr;
57 }
58 }
59 /**
60 * @tc.name: UIAxisGetViewType_001
61 * @tc.desc: Verify GetViewType function, equal.
62 * @tc.type: FUNC
63 * @tc.require: AR000EEMQ8
64 */
65 HWTEST_F(UIAxisTest, UIAxisGetViewType_001, TestSize.Level1)
66 {
67 if (axisX_ == nullptr) {
68 EXPECT_EQ(1, 0);
69 return;
70 }
71 EXPECT_EQ(axisX_->GetViewType(), UI_AXIS);
72 }
73
74 /**
75 * @tc.name: UIAxisSetLineColor_001
76 * @tc.desc: Verify SetLineColor function, equal.
77 * @tc.type: FUNC
78 * @tc.require: AR000EEMQ8
79 */
80 HWTEST_F(UIAxisTest, UIAxisSetLineColor_001, TestSize.Level1)
81 {
82 if (axisY_ == nullptr) {
83 EXPECT_EQ(1, 0);
84 return;
85 }
86 axisY_->SetLineColor(Color::Gray());
87 EXPECT_EQ(axisY_->GetStyle(STYLE_LINE_COLOR), Color::Gray().full);
88 }
89
90 /**
91 * @tc.name: UIXAxisSetDataRange_001
92 * @tc.desc: Verify SetDataRange function, equal.
93 * @tc.type: FUNC
94 * @tc.require: AR000EEMQ8
95 */
96 HWTEST_F(UIAxisTest, UIXAxisSetDataRange_001, TestSize.Level0)
97 {
98 if (axisX_ == nullptr) {
99 EXPECT_EQ(1, 0);
100 return;
101 }
102 EXPECT_EQ(axisX_->SetDataRange(SMALLER_VALUE, LARGER_VALUE), true);
103 }
104
105 /**
106 * @tc.name: UIXAxisSetDataRange_002
107 * @tc.desc: Verify SetDataRange function, equal.
108 * @tc.type: FUNC
109 * @tc.require: AR000EEMQ8
110 */
111 HWTEST_F(UIAxisTest, UIXAxisSetDataRange_002, TestSize.Level1)
112 {
113 if (axisX_ == nullptr) {
114 EXPECT_EQ(1, 0);
115 return;
116 }
117 EXPECT_EQ(axisX_->SetDataRange(LARGER_VALUE, SMALLER_VALUE), false);
118 }
119
120 /**
121 * @tc.name: UIYAxisSetDataRange_001
122 * @tc.desc: Verify SetDataRange function, equal.
123 * @tc.type: FUNC
124 * @tc.require: AR000EEMQ8
125 */
126 HWTEST_F(UIAxisTest, UIYAxisSetDataRange_001, TestSize.Level1)
127 {
128 if (axisY_ == nullptr) {
129 EXPECT_EQ(1, 0);
130 return;
131 }
132 EXPECT_EQ(axisY_->SetDataRange(SMALLER_VALUE, LARGER_VALUE), true);
133 }
134
135 /**
136 * @tc.name: UIYAxisSetDataRange_002
137 * @tc.desc: Verify SetDataRange function, equal.
138 * @tc.type: FUNC
139 * @tc.require: AR000EEMQ8
140 */
141 HWTEST_F(UIAxisTest, UIYAxisSetDataRange_002, TestSize.Level1)
142 {
143 if (axisY_ == nullptr) {
144 EXPECT_EQ(1, 0);
145 return;
146 }
147 EXPECT_EQ(axisY_->SetDataRange(LARGER_VALUE, SMALLER_VALUE), false);
148 }
149 } // namespace OHOS