• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_abstract_progress.h"
17 
18 #include <climits>
19 #include <gtest/gtest.h>
20 
21 using namespace testing::ext;
22 namespace OHOS {
23 namespace {
24     const int16_t MAX_VALUE = 80;
25     const int16_t MEDIAN_VALUE = 50;
26     const int16_t MIN_VALUE = 20;
27 }
28 class UIAbsatrctProgressTest : public testing::Test {
29 public:
UIAbsatrctProgressTest()30     UIAbsatrctProgressTest() : abstractProgress_(nullptr) {}
~UIAbsatrctProgressTest()31     virtual ~UIAbsatrctProgressTest() {}
32     static void SetUpTestCase();
33     static void TearDownTestCase();
34     void SetUp();
35     void TearDown();
36     UIAbstractProgress* abstractProgress_;
37 };
38 
SetUpTestCase()39 void UIAbsatrctProgressTest::SetUpTestCase()
40 {
41 }
42 
TearDownTestCase()43 void UIAbsatrctProgressTest::TearDownTestCase()
44 {
45 }
46 
SetUp()47 void UIAbsatrctProgressTest::SetUp()
48 {
49     if (abstractProgress_ == nullptr) {
50         abstractProgress_ = new UIAbstractProgress();
51     }
52 }
53 
TearDown()54 void UIAbsatrctProgressTest::TearDown()
55 {
56     if (abstractProgress_ != nullptr) {
57         delete abstractProgress_;
58         abstractProgress_ = nullptr;
59     }
60 }
61 /**
62  * @tc.name: UIAbsatrctProgressGetViewType_001
63  * @tc.desc: Verify GetViewType function, equal.
64  * @tc.type: FUNC
65  * @tc.require: AR000DSMQG
66  */
67 HWTEST_F(UIAbsatrctProgressTest, UIAbsatrctProgressGetViewType_001, TestSize.Level1)
68 {
69     if (abstractProgress_ == nullptr) {
70         EXPECT_NE(0, 0);
71         return;
72     }
73     EXPECT_EQ(abstractProgress_->GetViewType(), UI_ABSTRACT_PROGRESS);
74 }
75 
76 /**
77  * @tc.name: UIAbsatrctProgressSetValue_001
78  * @tc.desc: Verify SetValue function, equal.
79  * @tc.type: FUNC
80  * @tc.require: AR000DSMQG
81  */
82 HWTEST_F(UIAbsatrctProgressTest, UIAbsatrctProgressSetValue_001, TestSize.Level0)
83 {
84     if (abstractProgress_ == nullptr) {
85         EXPECT_NE(0, 0);
86         return;
87     }
88     abstractProgress_->SetRange(MAX_VALUE, MIN_VALUE);
89     EXPECT_EQ(abstractProgress_->GetRangeMin(), MIN_VALUE);
90     EXPECT_EQ(abstractProgress_->GetRangeMax(), MAX_VALUE);
91 
92     abstractProgress_->SetValue(MEDIAN_VALUE);
93     EXPECT_EQ(abstractProgress_->GetValue(), MEDIAN_VALUE);
94 
95     abstractProgress_->SetValue(MAX_VALUE + 1);
96     EXPECT_EQ(abstractProgress_->GetValue(), MAX_VALUE);
97 
98     abstractProgress_->SetValue(MIN_VALUE - 1);
99     EXPECT_EQ(abstractProgress_->GetValue(), MIN_VALUE);
100 }
101 
102 /**
103  * @tc.name: UIAbsatrctProgressSetValue_002
104  * @tc.desc: Verify SetValue function, equal.
105  * @tc.type: FUNC
106  * @tc.require: AR000DSMQG
107  */
108 HWTEST_F(UIAbsatrctProgressTest, UIAbsatrctProgressSetValue_002, TestSize.Level1)
109 {
110     if (abstractProgress_ == nullptr) {
111         EXPECT_NE(0, 0);
112         return;
113     }
114     abstractProgress_->SetRange(MAX_VALUE, MIN_VALUE);
115     EXPECT_EQ(abstractProgress_->GetRangeMin(), MIN_VALUE);
116     EXPECT_EQ(abstractProgress_->GetRangeMax(), MAX_VALUE);
117 
118     abstractProgress_->SetRange(MIN_VALUE, MAX_VALUE);
119     EXPECT_EQ(abstractProgress_->GetRangeMin(), MIN_VALUE);
120     EXPECT_EQ(abstractProgress_->GetRangeMax(), MAX_VALUE);
121 }
122 
123 /**
124  * @tc.name: UIAbsatrctProgressSetStep_001
125  * @tc.desc: Verify SetStep function, equal.
126  * @tc.type: FUNC
127  * @tc.require: AR000DSMQG
128  */
129 HWTEST_F(UIAbsatrctProgressTest, UIAbsatrctProgressSetStep_001, TestSize.Level1)
130 {
131     if (abstractProgress_ == nullptr) {
132         EXPECT_NE(0, 0);
133         return;
134     }
135     abstractProgress_->SetStep(MEDIAN_VALUE);
136     EXPECT_EQ(abstractProgress_->GetStep(), MEDIAN_VALUE);
137 }
138 
139 /**
140  * @tc.name: UIAbsatrctProgressSetBackgroundStyle_001
141  * @tc.desc: Verify SetBackgroundStyle function, equal.
142  * @tc.type: FUNC
143  * @tc.require: AR000DSMQG
144  */
145 HWTEST_F(UIAbsatrctProgressTest, UIAbsatrctProgressSetBackgroundStyle_001, TestSize.Level1)
146 {
147     if (abstractProgress_ == nullptr) {
148         EXPECT_NE(0, 0);
149         return;
150     }
151     Style style;
152     style.imageOpa_ = OPA_TRANSPARENT;
153     style.lineOpa_ = OPA_TRANSPARENT;
154     style.borderRadius_ = 1;
155 
156     abstractProgress_->SetBackgroundStyle(style);
157     EXPECT_EQ(abstractProgress_->GetBackgroundStyle().imageOpa_, OPA_TRANSPARENT);
158     EXPECT_EQ(abstractProgress_->GetBackgroundStyle().lineOpa_, OPA_TRANSPARENT);
159     EXPECT_EQ(abstractProgress_->GetBackgroundStyle().borderRadius_, 1);
160 
161     abstractProgress_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::Silver().full);
162     EXPECT_EQ(abstractProgress_->GetBackgroundStyle(STYLE_BACKGROUND_COLOR), Color::Silver().full);
163 }
164 
165 /**
166  * @tc.name: UIAbsatrctProgressSetForegroundStyle_001
167  * @tc.desc: Verify SetForegroundStyle function, equal.
168  * @tc.type: FUNC
169  * @tc.require: AR000DSMQG
170  */
171 HWTEST_F(UIAbsatrctProgressTest, UIAbsatrctProgressSetForegroundStyle_001, TestSize.Level1)
172 {
173     if (abstractProgress_ == nullptr) {
174         EXPECT_NE(0, 0);
175         return;
176     }
177     Style style;
178     style.imageOpa_ = OPA_TRANSPARENT;
179     style.lineOpa_ = OPA_TRANSPARENT;
180     style.borderRadius_ = 1;
181 
182     abstractProgress_->SetForegroundStyle(style);
183     EXPECT_EQ(abstractProgress_->GetForegroundStyle().imageOpa_, OPA_TRANSPARENT);
184     EXPECT_EQ(abstractProgress_->GetForegroundStyle().lineOpa_, OPA_TRANSPARENT);
185     EXPECT_EQ(abstractProgress_->GetForegroundStyle().borderRadius_, 1);
186 
187     abstractProgress_->SetForegroundStyle(STYLE_BACKGROUND_COLOR, Color::White().full);
188     EXPECT_EQ(abstractProgress_->GetForegroundStyle(STYLE_BACKGROUND_COLOR), Color::White().full);
189 }
190 
191 /**
192  * @tc.name: UIAbsatrctProgressSetCapType_001
193  * @tc.desc: Verify SetCapType function, equal.
194  * @tc.type: FUNC
195  * @tc.require: AR000DSMQG
196  */
197 HWTEST_F(UIAbsatrctProgressTest, UIAbsatrctProgressSetCapType_001, TestSize.Level1)
198 {
199     if (abstractProgress_ == nullptr) {
200         EXPECT_NE(0, 0);
201         return;
202     }
203     EXPECT_EQ(abstractProgress_->GetForegroundStyle(STYLE_LINE_CAP), CapType::CAP_NONE);
204     EXPECT_EQ(abstractProgress_->GetBackgroundStyle(STYLE_LINE_CAP), CapType::CAP_NONE);
205     abstractProgress_->SetCapType(CapType::CAP_ROUND);
206     EXPECT_EQ(abstractProgress_->GetForegroundStyle(STYLE_LINE_CAP), CapType::CAP_ROUND);
207     EXPECT_EQ(abstractProgress_->GetBackgroundStyle(STYLE_LINE_CAP), CapType::CAP_ROUND);
208 }
209 } // namespace OHOS
210