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 "ui_test_qrcode.h"
17 #include "common/screen.h"
18 #include "font/ui_font.h"
19
20 namespace OHOS {
21 namespace {
22 const int16_t TITLE_HEIGHT = 29;
23 } // namespace
24
SetUp()25 void UITestQrcode::SetUp()
26 {
27 if (container_ == nullptr) {
28 container_ = new UIScrollView();
29 container_->SetThrowDrag(true);
30 container_->SetHorizontalScrollState(false);
31 container_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
32 }
33 }
34
TearDown()35 void UITestQrcode::TearDown()
36 {
37 DeleteChildren(container_);
38 container_ = nullptr;
39 }
40
GetTestView()41 const UIView* UITestQrcode::GetTestView()
42 {
43 UIKitUIQrcodeTestDisplay001();
44 UIKitUIQrcodeTestDisplay002();
45 UIKitUIQrcodeTestDisplay003();
46 UIKitUIQrcodeTestDisplay004();
47 UIKitUIQrcodeTestDisplay005();
48 UIKitUIQrcodeTestDisplay006();
49 UIKitUIQrcodeTestDisplay007();
50 UIKitUIQrcodeTestDisplay008();
51 UIKitUIQrcodeTestDisplay009();
52 return container_;
53 }
54
CreateTestCaseGroup(const char * title) const55 UIViewGroup* UITestQrcode::CreateTestCaseGroup(const char* title) const
56 {
57 UIViewGroup* group = new UIViewGroup();
58 group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
59 group->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
60 group->SetPosition(0, 0);
61 UILabel* titleLabel = new UILabel();
62 titleLabel->SetPosition(0, 0, Screen::GetInstance().GetWidth(), TITLE_HEIGHT);
63 titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
64 titleLabel->SetText(title);
65 group->Add(titleLabel);
66 return group;
67 }
68
UIKitUIQrcodeTestDisplay001()69 void UITestQrcode::UIKitUIQrcodeTestDisplay001()
70 {
71 if (container_ != nullptr) {
72 UIViewGroup* group = CreateTestCaseGroup(" display qrcode 60 * 60");
73 group->Resize(Screen::GetInstance().GetWidth(), 100); // 100 : height
74 group->SetViewId("UIKitUIQrcodeTestDisplay001");
75
76 UIQrcode* qrcode = new UIQrcode();
77 qrcode->SetPosition(20, 30, 60, 60); // 20 x 30 y 150 width 60 height
78 const char* str = "Hello\n Test of GUI";
79 qrcode->SetQrcodeInfo(str);
80 group->Add(qrcode);
81 container_->Add(group);
82 }
83 }
UIKitUIQrcodeTestDisplay002()84 void UITestQrcode::UIKitUIQrcodeTestDisplay002()
85 {
86 if (container_ != nullptr) {
87 UIViewGroup* group = CreateTestCaseGroup(" display qrcode 120 * 250");
88 group->Resize(Screen::GetInstance().GetWidth(), 300); // 300 : height
89 group->SetViewId("UIKitUIQrcodeTestDisplay002");
90
91 UIQrcode* qrcode = new UIQrcode();
92 qrcode->SetPosition(20, 30); // 20 x 30 y
93 const char* str = "Hello\n Test of GUI";
94 qrcode->SetQrcodeInfo(str);
95 qrcode->SetWidth(120); // 120 width
96 qrcode->SetHeight(250); // 250 height
97 group->Add(qrcode);
98 container_->Add(group);
99 group->LayoutBottomToSibling("UIKitUIQrcodeTestDisplay001", 10); // 10: height
100 }
101 }
102
UIKitUIQrcodeTestDisplay003()103 void UITestQrcode::UIKitUIQrcodeTestDisplay003()
104 {
105 if (container_ != nullptr) {
106 UIViewGroup* group = CreateTestCaseGroup(" display qrcode 400 * 200");
107 group->Resize(Screen::GetInstance().GetWidth(), 450); // 450 : height
108 group->SetViewId("UIKitUIQrcodeTestDisplay003");
109
110 UIQrcode* qrcode = new UIQrcode();
111 qrcode->SetPosition(20, 30); // 20 x 30 y
112 const char* str =
113 "Hello\n GUIddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd \
114 ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd \
115 ddddddddddddddddddddddddddddddddddddddddddddddddddddddd";
116 ColorType backgroundColor = Color::Green();
117 ColorType qrColor = Color::Blue();
118 qrcode->SetQrcodeInfo(str, backgroundColor, qrColor);
119 qrcode->SetWidth(400); // 400 width
120 qrcode->SetHeight(200); // 200 height
121 group->Add(qrcode);
122 container_->Add(group);
123 group->LayoutBottomToSibling("UIKitUIQrcodeTestDisplay002", 10); // 10: height
124 }
125 }
126
UIKitUIQrcodeTestDisplay004()127 void UITestQrcode::UIKitUIQrcodeTestDisplay004()
128 {
129 if (container_ != nullptr) {
130 UIViewGroup* group = CreateTestCaseGroup("qrcode 50 * 50, width is less than minimum qrcode size, error!");
131 group->Resize(Screen::GetInstance().GetWidth(), 100); // 100 : height
132 group->SetViewId("UIKitUIQrcodeTestDisplay004");
133
134 UIQrcode* qrcode = new UIQrcode();
135 qrcode->SetPosition(20, 30, 50, 50); // 20 x 30 y 50 width 50 height
136 const char* str =
137 "Hello\n GUIddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd \
138 ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd \
139 dddddddddddddddddddddddddddddddddddddddddddddddddddddd";
140 qrcode->SetQrcodeInfo(str);
141 group->Add(qrcode);
142 container_->Add(group);
143 group->LayoutBottomToSibling("UIKitUIQrcodeTestDisplay003", 10); // 10: height
144 }
145 }
146
UIKitUIQrcodeTestDisplay005()147 void UITestQrcode::UIKitUIQrcodeTestDisplay005()
148 {
149 if (container_ != nullptr) {
150 UIViewGroup* group = CreateTestCaseGroup("qrcode 250 * 250, val length is greater than MAX_LENGTH, error!");
151 group->Resize(Screen::GetInstance().GetWidth(), 300); // 300 : height
152 group->SetViewId("UIKitUIQrcodeTestDisplay005");
153
154 UIQrcode* qrcode = new UIQrcode();
155 qrcode->SetPosition(20, 30, 250, 250); // 20 x 30 y 250 width 250 height
156 const int16_t length = 2050; // 2050 length
157 char text[length];
158 for (int16_t i = 0; i < length - 1; i++) {
159 text[i] = 'd';
160 }
161 text[length - 1] = '\0';
162 qrcode->SetQrcodeInfo(text);
163 group->Add(qrcode);
164 container_->Add(group);
165 group->LayoutBottomToSibling("UIKitUIQrcodeTestDisplay004", 10); // 10: height
166 }
167 }
168
UIKitUIQrcodeTestDisplay006()169 void UITestQrcode::UIKitUIQrcodeTestDisplay006()
170 {
171 if (container_ != nullptr) {
172 UIViewGroup* group = CreateTestCaseGroup("qrcode 250 * 250, str = \"\" ");
173 group->Resize(Screen::GetInstance().GetWidth(), 300); // 300 : height
174 group->SetViewId("UIKitUIQrcodeTestDisplay006");
175
176 UIQrcode* qrcode = new UIQrcode();
177 qrcode->SetPosition(20, 30, 250, 250); // 20 x 30 y 250 width 250 height
178 const char* str = "";
179 qrcode->SetQrcodeInfo(str);
180 group->Add(qrcode);
181 container_->Add(group);
182 group->LayoutBottomToSibling("UIKitUIQrcodeTestDisplay005", 10); // 10: height
183 }
184 }
185
UIKitUIQrcodeTestDisplay007()186 void UITestQrcode::UIKitUIQrcodeTestDisplay007()
187 {
188 if (container_ != nullptr) {
189 UIViewGroup* group = CreateTestCaseGroup("qrcode 250 * 250, str = \" \"");
190 group->Resize(Screen::GetInstance().GetWidth(), 300); // 300 : height
191 group->SetViewId("UIKitUIQrcodeTestDisplay007");
192
193 UIQrcode* qrcode = new UIQrcode();
194 qrcode->SetPosition(20, 30, 250, 250); // 20 x 30 y 250 width 250 height
195 const char* str = " ";
196 qrcode->SetQrcodeInfo(str);
197 group->Add(qrcode);
198 container_->Add(group);
199 group->LayoutBottomToSibling("UIKitUIQrcodeTestDisplay006", 10); // 10: height
200 }
201 }
202
UIKitUIQrcodeTestDisplay008()203 void UITestQrcode::UIKitUIQrcodeTestDisplay008()
204 {
205 if (container_ != nullptr) {
206 UIViewGroup* group = CreateTestCaseGroup("qrcode 250 * 250, str = nullptr");
207 group->Resize(Screen::GetInstance().GetWidth(), 300); // 300 : height
208 group->SetViewId("UIKitUIQrcodeTestDisplay008");
209
210 UIQrcode* qrcode = new UIQrcode();
211 qrcode->SetPosition(20, 30, 250, 250); // 20 x 30 y 250 width 250 height
212 const char* str = nullptr;
213 qrcode->SetQrcodeInfo(str);
214 group->Add(qrcode);
215 container_->Add(group);
216 group->LayoutBottomToSibling("UIKitUIQrcodeTestDisplay007", 10); // 10: height
217 }
218 }
219
UIKitUIQrcodeTestDisplay009()220 void UITestQrcode::UIKitUIQrcodeTestDisplay009()
221 {
222 if (container_ != nullptr) {
223 UIViewGroup* group = CreateTestCaseGroup("qrcode 250 * 250, position x = -50");
224 group->Resize(Screen::GetInstance().GetWidth(), 300); // 300 : height
225 group->SetViewId("UIKitUIQrcodeTestDisplay009");
226
227 UIQrcode* qrcode = new UIQrcode();
228 qrcode->SetPosition(-50, 30, 250, 250); // -50 x 30 y 250 width 250 height
229 const char* str = "Hello GUI";
230 qrcode->SetQrcodeInfo(str);
231 group->Add(qrcode);
232 container_->Add(group);
233 group->LayoutBottomToSibling("UIKitUIQrcodeTestDisplay008", 10); // 10: height
234 }
235 }
236 } // namespace OHOS
237