• 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_list.h"
17 #include "components/text_adapter.h"
18 
19 #include <climits>
20 #include <gtest/gtest.h>
21 
22 using namespace testing::ext;
23 namespace OHOS {
24 class UIListTest : public testing::Test {
25 public:
26     static void SetUpTestCase(void);
27     static void TearDownTestCase(void);
28     static UIList* list_;
29     static TextAdapter* adapter1_;
30     static List<const char*>* adapterData1_;
31 };
32 
33 UIList* UIListTest::list_ = nullptr;
34 TextAdapter* UIListTest::adapter1_ = nullptr;
35 List<const char*>* UIListTest::adapterData1_ = nullptr;
36 
SetUpTestCase(void)37 void UIListTest::SetUpTestCase(void)
38 {
39     if (list_ == nullptr) {
40         list_ = new UIList(UIList::VERTICAL);
41     }
42     if (adapterData1_ == nullptr) {
43         adapterData1_ = new List<const char*>();
44         adapterData1_->PushBack("abcd0");
45         adapterData1_->PushBack("abcd1");
46         adapterData1_->PushBack("abcd2");
47         adapterData1_->PushBack("abcd3");
48     }
49     if (adapter1_ == nullptr) {
50         adapter1_ = new TextAdapter();
51     }
52 }
53 
TearDownTestCase(void)54 void UIListTest::TearDownTestCase(void)
55 {
56     if (list_ != nullptr) {
57         delete list_;
58         list_ = nullptr;
59     }
60     if (adapterData1_ != nullptr) {
61         adapterData1_->Clear();
62         delete adapterData1_;
63         adapterData1_ = nullptr;
64     }
65     if (adapter1_ != nullptr) {
66         delete adapter1_;
67         adapter1_ = nullptr;
68     }
69 }
70 
71 /**
72  * @tc.name: UIListListScrollListener_001
73  * @tc.desc: Verify SetScrollState function.
74  * @tc.type: FUNC
75  * @tc.require: AR000DSMQE
76  */
77 HWTEST_F(UIListTest, UIListListScrollListener_001, TestSize.Level1)
78 {
79     auto listener = new ListScrollListener();
80     EXPECT_EQ(0, listener->GetScrollState());
81 
82     listener->SetScrollState(1);
83     EXPECT_EQ(1, listener->GetScrollState());
84 
85     delete listener;
86 }
87 
88 /**
89  * @tc.name: UIListGetViewType_001
90  * @tc.desc: Verify GetViewType function.
91  * @tc.type: FUNC
92  * @tc.require: AR000DSMQE
93  */
94 HWTEST_F(UIListTest, UIListGetViewType_001, TestSize.Level2)
95 {
96     if (list_ == nullptr) {
97         EXPECT_EQ(1, 0);
98         return;
99     }
100     EXPECT_EQ(UI_LIST, list_->GetViewType());
101 }
102 
103 /**
104  * @tc.name: UIListSetDirection_001
105  * @tc.desc: Verify SetDirection function.
106  * @tc.type: FUNC
107  * @tc.require: AR000DSMQE
108  */
109 HWTEST_F(UIListTest, UIListSetDirection_001, TestSize.Level1)
110 {
111     if (list_ == nullptr) {
112         EXPECT_EQ(1, 0);
113         return;
114     }
115     EXPECT_EQ(1, list_->GetDirection());
116 
117     list_->SetDirection(0);
118     EXPECT_EQ(0, list_->GetDirection());
119     list_->SetDirection(1);
120     EXPECT_EQ(1, list_->GetDirection());
121 }
122 
123 /**
124  * @tc.name: UIListSetLoopState_001
125  * @tc.desc: Verify SetLoopState function.
126  * @tc.type: FUNC
127  * @tc.require: AR000DSMQE
128  */
129 HWTEST_F(UIListTest, UIListSetLoopState_001, TestSize.Level1)
130 {
131     if (list_ == nullptr) {
132         EXPECT_EQ(1, 0);
133         return;
134     }
135     EXPECT_EQ(false, list_->GetLoopState());
136 
137     list_->SetLoopState(true);
138     EXPECT_EQ(true, list_->GetLoopState());
139 }
140 
141 /**
142  * @tc.name: UIListSetStartIndex_001
143  * @tc.desc: Verify SetStartIndex function.
144  * @tc.type: FUNC
145  * @tc.require: AR000DSMQE
146  */
147 HWTEST_F(UIListTest, UIListSetStartIndex_001, TestSize.Level1)
148 {
149     if (list_ == nullptr) {
150         EXPECT_EQ(1, 0);
151         return;
152     }
153     EXPECT_EQ(0, list_->GetStartIndex());
154 
155     list_->SetStartIndex(1);
156     EXPECT_EQ(1, list_->GetStartIndex());
157 }
158 
159 /**
160  * @tc.name: UIListSetAutoAlignTime_001
161  * @tc.desc: Verify SetAutoAlignTime function.
162  * @tc.type: FUNC
163  * @tc.require: AR000DSMQE
164  */
165 HWTEST_F(UIListTest, UIListSetAutoAlignTime_001, TestSize.Level1)
166 {
167     if (list_ == nullptr) {
168         EXPECT_EQ(1, 0);
169         return;
170     }
171     EXPECT_EQ(100, list_->GetAutoAlignTime()); // 100: DEFAULT_ALINE_TIMES
172 
173     uint16_t alignTime = 200;   // 200: align time
174     list_->SetAutoAlignTime(alignTime);
175     EXPECT_EQ(alignTime, list_->GetAutoAlignTime());
176 }
177 } // namespace OHOS