• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2024 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/*
17 * This test case is used to verify that a static variable is initialized through the component constructor.
18 */
19import { StaticChildThree, StaticChildFour } from './exportStaticVariables';
20
21@Entry
22@Component
23struct TestStaticVariableAssignment {
24  build() {
25    Column() {
26      StaticChildOne({ a1: 'a11', a2: 'a22' })
27      StaticChildTwo({
28        b1: 'b11',
29        b4: 'b44',
30        b5: 'b55'
31      })
32      StaticChildThree({ c1: 'c11', c2: 'c22' })
33      StaticChildFour({
34        d1: 'd11',
35        d4: 'd44',
36        d5: 'd55'
37      })
38    }
39    .height('100%')
40    .width('100%')
41  }
42}
43
44@Component
45struct StaticChildOne {
46  static a1: string;
47  a2: string = 'a2';
48  build() {
49    Column() {
50      Text('a1: ' + StaticChildOne.a1)
51      Text('a2: ' + this.a2)
52    }
53  }
54}
55
56@ComponentV2
57struct StaticChildTwo {
58  static b1: string;
59  @Param static b4: string = 'b4';
60  @Require @Param static b5: string = 'b5';
61  build() {
62    Column() {
63      Text('b1: ' + StaticChildTwo.b1)
64      Text('b4: ' + StaticChildTwo.b4)
65      Text('b5: ' + StaticChildTwo.b5)
66    }
67  }
68}
69