• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 iSoftStone Information Technology (Group) 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 <functional>
17 #include <tuple>
18 #include <vector>
19 
20 #include "gtest/gtest.h"
21 
22 #define protected public
23 #define private public
24 
25 #include "core/components_ng/property/templates_parser.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS::Ace::NG {
31 namespace {}
32 
33 class TemplatesParserTestNg : public testing::Test {
34 public:
SetUpTestSuite()35     static void SetUpTestSuite() {};
TeardownTestSuite()36     static void TeardownTestSuite() {};
37 };
38 
39 /**
40  * @tc.name: TemplatesParserTestNg001
41  * @tc.desc: Test ParseTemplateArgs.
42  * @tc.type: FUNC
43  */
44 HWTEST_F(TemplatesParserTestNg, TemplatesParserTestNg001, TestSize.Level1)
45 {
46     /**
47      * @tc.steps: step1 init args of ParseTemplateArgs and
48                 call ParseTemplateArgs.
49      * @tc.expected: the return value is same as the forth val of tuple.
50      */
51     double size = 0;
52     double gap = 0;
53     int32_t childrenCount = 0;
54     std::vector<std::tuple<std::function<std::string(void)>, double, double, int32_t, std::vector<double>>> parms = {
__anon8479840f0202() 55         { [&]() {
56             size = 200;
57             gap = 10;
58             childrenCount = 5;
59             return "";
60         },
61             size, gap, childrenCount, {} },
__anon8479840f0402() 62         { [&]() {
63             size = 200;
64             gap = 10;
65             childrenCount = 5;
66             return "abc";
67         },
68             size, gap, childrenCount, {} },
__anon8479840f0602() 69         { [&]() {
70             size = 200;
71             gap = 10;
72             childrenCount = 5;
73             return "1fr 2px 3%";
74         },
75             size, gap, childrenCount, { -2, 0, 0 } },
__anon8479840f0802() 76         { [&]() {
77             size = 200;
78             gap = 10;
79             childrenCount = 5;
80             return "1fr 2px 900%";
81         },
82             size, gap, childrenCount, { -2, 0, 0 } },
__anon8479840f0a02() 83         { [&]() {
84             size = 200;
85             gap = 10;
86             childrenCount = 5;
87             return "auto-fill 1fr 3fr";
88         },
89             size, gap, childrenCount, {} },
__anon8479840f0c02() 90         { [&]() {
91             size = 200;
92             gap = 100;
93             childrenCount = 5;
94             return "0.1fr 20px 100px";
95         },
96             size, gap, childrenCount, { -12, 0, 0 } },
__anon8479840f0e02() 97         { [&]() {
98             size = 200;
99             gap = 10;
100             childrenCount = 5;
101             return "repeat";
102         },
103             size, gap, childrenCount, {} },
__anon8479840f1002() 104         { [&]() {
105             size = 200;
106             gap = 10;
107             childrenCount = 5;
108             return "auto-fill";
109         },
110             size, gap, childrenCount, {} },
__anon8479840f1202() 111         { [&]() {
112             size = 200;
113             gap = 10;
114             childrenCount = 5;
115             return "repeat(1, 100px 2px 3px 4px 5px 6px 7px 8px)";
116         },
117             size, gap, childrenCount, { 0, 0, 0, 0, 0, 0, 0, 0 } },
__anon8479840f1402() 118         { [&]() {
119             size = 200;
120             gap = 10;
121             childrenCount = 5;
122             return "repeatabcdefghi";
123         },
124             size, gap, childrenCount, {} },
__anon8479840f1602() 125         { [&]() {
126             size = 200;
127             gap = 10;
128             childrenCount = 5;
129             return "repeat(3, 100px a b c d e f g)";
130         },
131             size, gap, childrenCount, {} },
__anon8479840f1802() 132         { [&]() {
133             size = 200;
134             gap = 10;
135             childrenCount = 5;
136             return "repeat auto-fill 1fr 2px 900%";
137         },
138             size, gap, childrenCount, { 0 } },
__anon8479840f1a02() 139         { [&]() {
140             size = 200;
141             gap = 10;
142             childrenCount = 5;
143             return "auto-fill arepeatpx10vp10 10)2";
144         },
145             size, gap, childrenCount, { 0 } },
__anon8479840f1c02() 146         { [&]() {
147             size = 200;
148             gap = 10;
149             childrenCount = 5;
150             return "repeat(auto-fill, 2px )repeat(auto-fill, 2px )repeat(auto-fill, 2vp)";
151         },
152             size, gap, childrenCount, { 0 } },
__anon8479840f1e02() 153         { [&]() {
154             size = 200;
155             gap = 10;
156             childrenCount = 5;
157             return "repeat(auto-fill, 2px 2% 2vp 2 )";
158         },
159             size, gap, childrenCount, { 2, 0, 2, 2 } },
__anon8479840f2002() 160         { [&]() {
161             size = 200;
162             gap = 10;
163             childrenCount = 5;
164             return "2px 2px repeat(auto-fill, 2px 2% 2 ) 2px";
165         },
166             size, gap, childrenCount, { 2, 2, 2, 0, 2, 2 } },
__anon8479840f2202() 167         { [&]() {
168             size = 200;
169             gap = 10;
170             childrenCount = 5;
171             return "(auto-fit, 2px 2)";
172         },
173             size, gap, childrenCount, {} },
__anon8479840f2402() 174         { [&]() {
175             size = 200;
176             gap = 10;
177             childrenCount = 5;
178             return "repeat(auto-fit, ) 2px";
179         },
180             size, gap, childrenCount, { 0 } }
181     };
182     for (auto [args, size, gap, childrenCount, rt] : parms) {
183         auto result = ParseTemplateArgs(args(), size, gap, childrenCount);
184         EXPECT_EQ(result.first.size(), rt.size());
185         for (int i = 0; i < rt.size() && i < result.first.size(); i++) {
186             EXPECT_EQ(rt[i], result.first[i]);
187         }
188     }
189 }
190 } // namespace OHOS::Ace::NG
191