• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "gtest/gtest.h"
17 
18 #include "frameworks/bridge/card_frontend/js_card_parser.h"
19 #include "frameworks/bridge/common/utils/utils.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS::Ace::Framework {
25 namespace {
26 
27 constexpr int32_t COMMAND_SIZE = 1;
28 
29 } // namespace
30 
31 class CardFrontendTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37 };
38 
SetUpTestCase()39 void CardFrontendTest::SetUpTestCase() {}
TearDownTestCase()40 void CardFrontendTest::TearDownTestCase() {}
SetUp()41 void CardFrontendTest::SetUp() {}
TearDown()42 void CardFrontendTest::TearDown() {}
43 
44 /**
45  * @tc.name: CardFrontendTest001
46  * @tc.desc: Test data binding.
47  * @tc.type: FUNC
48  * @tc.require: AR000F2BC2
49  * @tc.author: jiangyingjie
50  */
51 HWTEST_F(CardFrontendTest, CardFrontendTest001, TestSize.Level1)
52 {
53     /**
54      * @tc.steps: step1. construct json string.
55      */
56     const std::string rootJson = "{\n"
57                                  "\t\"template\": {\n"
58                                  "\t\t\"attr\": {\n"
59                                  "\t\t\t\"value\": \"{{variable}}\"\n"
60                                  "\t\t},\n"
61                                  "\t\t\"type\": \"text\",\n"
62                                  "\t\t\"shown\": \"{{show}}\"\n"
63                                  "\t},\n"
64                                  "\t\"styles\": {},\n"
65                                  "\t\"actions\": {},\n"
66                                  "\t\"data\": {\n"
67                                  "\t\t\"show\": false,\n"
68                                  "\t\t\"variable\": \"hello!\"\n"
69                                  "\t}\n"
70                                  "}";
71     auto rootBody = JsonUtil::ParseJsonString(rootJson);
72     auto rootTemplate = rootBody->GetValue("template");
73     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
74     jsCardParser->Initialize();
75     auto shown = rootTemplate->GetValue("shown");
76     auto shownValue = shown->GetString();
77     int32_t nodeId = 1;
78 
79     /**
80      * @tc.steps: step2. Get the value of the shown attribute.
81      * @tc.expected: step2. shown value is false.
82      */
83     jsCardParser->GetShownValue(shownValue);
84     ASSERT_TRUE(shownValue == "false");
85 
86     /**
87      * @tc.steps: step3. Get the value of the attribute.
88      * @tc.expected: step3. Property value is correct.
89      */
90     std::vector<std::pair<std::string, std::string>> attrs;
91     auto type = rootTemplate->GetValue("type")->GetString();
92     RefPtr<Framework::JsCommandDomElementCreator> command =
93         Referenced::MakeRefPtr<Framework::JsCommandAddDomElement>(type, nodeId, 0);
94     auto ptr = Referenced::RawPtr(command);
95     jsCardParser->ParseAttributes(rootTemplate, nodeId, attrs, (Framework::JsCommandDomElementOperator*)ptr);
96     ASSERT_TRUE(attrs.size() == COMMAND_SIZE);
97     ASSERT_TRUE(attrs[0].first == "value" && attrs[0].second == "hello!");
98 }
99 
100 /**
101  * @tc.name: CardFrontendTest002
102  * @tc.desc: Test data binding.
103  * @tc.type: FUNC
104  * @tc.require: AR000F2BC2
105  * @tc.author: jiangyingjie
106  */
107 HWTEST_F(CardFrontendTest, CardFrontendTest002, TestSize.Level1)
108 {
109     /**
110      * @tc.steps: step1. construct json string.
111      */
112     const std::string rootJson = "{\n"
113                                  "\t\"template\": {\n"
114                                  "\t\t\"attr\": {\n"
115                                  "\t\t\t\"value\": \"{{}}\"\n"
116                                  "\t\t},\n"
117                                  "\t\t\"type\": \"text\",\n"
118                                  "\t\t\"shown\": \"{{}\"\n"
119                                  "\t},\n"
120                                  "\t\"styles\": {},\n"
121                                  "\t\"actions\": {},\n"
122                                  "\t\"data\": {}\n"
123                                  "}";
124     auto rootBody = JsonUtil::ParseJsonString(rootJson);
125     auto rootTemplate = rootBody->GetValue("template");
126     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
127     jsCardParser->Initialize();
128 
129     /**
130      * @tc.steps: step2. Get the value of the shown attribute.
131      * @tc.expected: step2. shown value is not true.
132      */
133     auto shown = rootTemplate->GetValue("shown");
134     auto shownValue = shown->GetString();
135     int32_t nodeId = 1;
136     jsCardParser->GetShownValue(shownValue);
137     ASSERT_TRUE(shownValue != "true");
138 
139     /**
140      * @tc.steps: step3. Get the value of the attribute.
141      * @tc.expected: step3. Property value is "{{}}".
142      */
143     std::vector<std::pair<std::string, std::string>> attrs;
144     auto type = rootTemplate->GetValue("type")->GetString();
145     RefPtr<Framework::JsCommandDomElementCreator> command =
146         Referenced::MakeRefPtr<Framework::JsCommandAddDomElement>(type, nodeId, 0);
147     auto ptr = Referenced::RawPtr(command);
148     jsCardParser->ParseAttributes(rootTemplate, nodeId, attrs, (Framework::JsCommandDomElementOperator*)ptr);
149     ASSERT_TRUE(attrs.size() == COMMAND_SIZE);
150     ASSERT_TRUE(attrs[0].first == "value" && attrs[0].second == "{{}}");
151 }
152 
153 /**
154  * @tc.name: CardFrontendTest003
155  * @tc.desc: Test data binding.
156  * @tc.type: FUNC
157  * @tc.require: AR000F2BC2
158  * @tc.author: jiangyingjie
159  */
160 HWTEST_F(CardFrontendTest, CardFrontendTest003, TestSize.Level1)
161 {
162     /**
163      * @tc.steps: step1. construct json string.
164      */
165     const std::string rootJson = "{\n"
166                                  "\t\"template\": {\n"
167                                  "\t\t\"attr\": {},\n"
168                                  "\t\t\"type\": \"text\",\n"
169                                  "\t\t\"style\": {\n"
170                                  "\t\t\t\"color\": \"{{{variable}}\",\n"
171                                  "\t\t\t\"strokeColor\": \"{{variable}}\"\n"
172                                  "\t\t}\n"
173                                  "\t},\n"
174                                  "\t\"styles\": {},\n"
175                                  "\t\"actions\": {},\n"
176                                  "\t\"data\": {\n"
177                                  "\t\t\"variable\": \"0xffffff\"\n"
178                                  "\t}\n"
179                                  "}";
180     auto rootBody = JsonUtil::ParseJsonString(rootJson);
181     auto rootTemplate = rootBody->GetValue("template");
182     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
183     jsCardParser->Initialize();
184 
185     /**
186      * @tc.steps: step2. Get the value of the style.
187      * @tc.expected: step2. The style value meets expectations.
188      */
189     int32_t nodeId = 1;
190     std::vector<std::pair<std::string, std::string>> styles;
191     auto type = rootTemplate->GetValue("type")->GetString();
192     jsCardParser->ParseStyles(rootTemplate, nodeId, styles);
193     ASSERT_TRUE(styles.size() == 2);
194     ASSERT_TRUE(styles[0].first == "color" && styles[0].second == "{{{variable}}");
195     ASSERT_TRUE(styles[1].first == "strokeColor" && styles[1].second == "0xffffff");
196 }
197 
198 /**
199  * @tc.name: CardFrontendTest004
200  * @tc.desc: Test condition rendering.
201  * @tc.type: FUNC
202  * @tc.require: AR000F2BC4
203  * @tc.author: jiangyingjie
204  */
205 HWTEST_F(CardFrontendTest, CardFrontendTest004, TestSize.Level1)
206 {
207     /**
208      * @tc.steps: step1. construct json string.
209      */
210     const std::string rootJson = "{\n"
211                                  "\t\"template\": {\n"
212                                  "\t\t\"attr\": {},\n"
213                                  "\t\t\"type\": \"text\",\n"
214                                  "\t\t\"shown\": \"{{show}} && {{display}}\"\n"
215                                  "\t},\n"
216                                  "\t\"styles\": {},\n"
217                                  "\t\"actions\": {},\n"
218                                  "\t\"data\": {\n"
219                                  "\t\t\"display\": true,\n"
220                                  "\t\t\"show\": false\n"
221                                  "\t}\n"
222                                  "}";
223     auto rootBody = JsonUtil::ParseJsonString(rootJson);
224     auto rootTemplate = rootBody->GetValue("template");
225     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
226     jsCardParser->Initialize();
227 
228     /**
229      * @tc.steps: step2. Get the value of the shown.
230      * @tc.expected: step2. The shown value meets expectations.
231      */
232     auto shown = rootTemplate->GetValue("shown");
233     auto shownValue = shown->GetString();
234     jsCardParser->GetShownValue(shownValue);
235     ASSERT_TRUE(shownValue == "false");
236 }
237 
238 /**
239  * @tc.name: CardFrontendTest005
240  * @tc.desc: Test condition rendering.
241  * @tc.type: FUNC
242  * @tc.require: AR000F2BC4
243  * @tc.author: jiangyingjie
244  */
245 HWTEST_F(CardFrontendTest, CardFrontendTest005, TestSize.Level1)
246 {
247     /**
248      * @tc.steps: step1. construct json string.
249      */
250     const std::string rootJson = "{\n"
251                                  "\t\"template\": {\n"
252                                  "\t\t\"attr\": {},\n"
253                                  "\t\t\"type\": \"text\",\n"
254                                  "\t\t\"shown\": \"{{show}} && !{{display}}\"\n"
255                                  "\t},\n"
256                                  "\t\"styles\": {},\n"
257                                  "\t\"actions\": {},\n"
258                                  "\t\"data\": {\n"
259                                  "\t\t\"display\": false,\n"
260                                  "\t\t\"show\": false\n"
261                                  "\t}\n"
262                                  "}";
263     auto rootBody = JsonUtil::ParseJsonString(rootJson);
264     auto rootTemplate = rootBody->GetValue("template");
265     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
266     jsCardParser->Initialize();
267 
268     /**
269      * @tc.steps: step2. Get the value of the shown.
270      * @tc.expected: step2. The shown value meets expectations.
271      */
272     auto shown = rootTemplate->GetValue("shown");
273     auto shownValue = shown->GetString();
274     jsCardParser->GetShownValue(shownValue);
275     ASSERT_TRUE(shownValue == "false");
276 }
277 
278 /**
279  * @tc.name: CardFrontendTest006
280  * @tc.desc: Test condition rendering.
281  * @tc.type: FUNC
282  * @tc.require: AR000F2BC4
283  * @tc.author: jiangyingjie
284  */
285 HWTEST_F(CardFrontendTest, CardFrontendTest006, TestSize.Level1)
286 {
287     /**
288      * @tc.steps: step1. construct json string.
289      */
290     const std::string rootJson = "{\n"
291                                  "\t\"template\": {\n"
292                                  "\t\t\"attr\": {},\n"
293                                  "\t\t\"type\": \"text\",\n"
294                                  "\t\t\"shown\": \"!{{show}} && !{{display}}\"\n"
295                                  "\t},\n"
296                                  "\t\"styles\": {},\n"
297                                  "\t\"actions\": {},\n"
298                                  "\t\"data\": {\n"
299                                  "\t\t\"display\": false,\n"
300                                  "\t\t\"show\": false\n"
301                                  "\t}\n"
302                                  "}";
303     auto rootBody = JsonUtil::ParseJsonString(rootJson);
304     auto rootTemplate = rootBody->GetValue("template");
305     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
306     jsCardParser->Initialize();
307 
308     /**
309      * @tc.steps: step2. Get the value of the shown.
310      * @tc.expected: step2. The shown value meets expectations.
311      */
312     auto shown = rootTemplate->GetValue("shown");
313     auto shownValue = shown->GetString();
314     jsCardParser->GetShownValue(shownValue);
315     ASSERT_TRUE(shownValue == "true");
316 }
317 
318 /**
319  * @tc.name: CardFrontendTest007
320  * @tc.desc: Test condition rendering.
321  * @tc.type: FUNC
322  * @tc.require: AR000F2BC4
323  * @tc.author: jiangyingjie
324  */
325 HWTEST_F(CardFrontendTest, CardFrontendTest007, TestSize.Level1)
326 {
327     /**
328      * @tc.steps: step1. construct json string.
329      */
330     const std::string rootJson = "{\n"
331                                  "\t\"template\": {\n"
332                                  "\t\t\"attr\": {},\n"
333                                  "\t\t\"type\": \"text\",\n"
334                                  "\t\t\"shown\": \"{{show}} && {{xdisplay}}\"\n"
335                                  "\t},\n"
336                                  "\t\"styles\": {},\n"
337                                  "\t\"actions\": {},\n"
338                                  "\t\"data\": {\n"
339                                  "\t\t\"display\": true,\n"
340                                  "\t\t\"show\": true\n"
341                                  "\t}\n"
342                                  "}";
343     auto rootBody = JsonUtil::ParseJsonString(rootJson);
344     auto rootTemplate = rootBody->GetValue("template");
345     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
346     jsCardParser->Initialize();
347 
348     /**
349      * @tc.steps: step2. Get the value of the shown.
350      * @tc.expected: step2. The shown value meets expectations.
351      */
352     auto shown = rootTemplate->GetValue("shown");
353     auto shownValue = shown->GetString();
354     jsCardParser->GetShownValue(shownValue);
355     ASSERT_TRUE(shownValue != "true");
356 }
357 
358 /**
359  * @tc.name: CardFrontendTest008
360  * @tc.desc: Test "repeat" attr: for = "{{list}}".
361  * @tc.type: FUNC
362  * @tc.require: AR000F2BC4
363  * @tc.author: jiangdayuan
364  */
365 HWTEST_F(CardFrontendTest, CardFrontendTest008, TestSize.Level1)
366 {
367     /**
368      * @tc.steps: step1. construct json string.
369      */
370     const std::string rootJson = "{\n"
371                                  "\t\"template\": {\n"
372                                  "\t\t\"attr\": {},\n"
373                                  "\t\t\"type\": \"text\",\n"
374                                  "\t\t\"repeat\": \"{{list}}\"\n"
375                                  "\t},\n"
376                                  "\t\"styles\": {},\n"
377                                  "\t\"actions\": {},\n"
378                                  "\t\"data\": {\n"
379                                  "\t\t\"list\": [\n"
380                                  "\t\t\t{\n"
381                                  "\t\t\t\t\"name\": \"aa\",\n"
382                                  "\t\t\t\t\"idx\": 1\n"
383                                  "\t\t\t},\n"
384                                  "\t\t\t{\n"
385                                  "\t\t\t\t\"name\": \"bb\",\n"
386                                  "\t\t\t\t\"idx\": 2\n"
387                                  "\t\t\t},\n"
388                                  "\t\t\t{\n"
389                                  "\t\t\t\t\"name\": \"cc\",\n"
390                                  "\t\t\t\t\"idx\": 1\n"
391                                  "\t\t\t}\n"
392                                  "\t\t]\n"
393                                  "\t}\n"
394                                  "}";
395     auto rootBody = JsonUtil::ParseJsonString(rootJson);
396     auto rootTemplate = rootBody->GetValue("template");
397     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
398     jsCardParser->Initialize();
399 
400     /**
401      * @tc.steps: step2. Get the value of the repeat.
402      * @tc.expected: step2. The repeat value meets expectations.
403      */
404     auto repeatValue = rootTemplate->GetValue("repeat");
405     std::string key;
406     jsCardParser->GetRepeatData(repeatValue, key);
407 
408     ASSERT_EQ(repeatValue->GetArraySize(), 3);
409     auto item = repeatValue->GetChild();
410     auto itemName = item->GetValue("name")->GetString();
411     auto itemIndex = item->GetValue("idx")->GetInt();
412     ASSERT_EQ(itemName, "aa");
413     ASSERT_EQ(itemIndex, 1);
414 }
415 
416 /**
417  * @tc.name: CardFrontendTest009
418  * @tc.desc: Test "repeat" attr: for = "value in list".
419  * @tc.type: FUNC
420  * @tc.require: AR000F2BC4
421  * @tc.author: jiangdayuan
422  */
423 HWTEST_F(CardFrontendTest, CardFrontendTest009, TestSize.Level1)
424 {
425     /**
426      * @tc.steps: step1. construct json string.
427      */
428     const std::string rootJson = "{\n"
429                                  "\t\"template\": {\n"
430                                  "\t\t\"attr\": {\n"
431                                  "\t\t\t\"value\": \"{{item.name}}\",\n"
432                                  "\t\t\t\"index\": \"{{item.idx}}\"\n"
433                                  "\t\t},\n"
434                                  "\t\t\"type\": \"text\",\n"
435                                  "\t\t\"repeat\": {\n"
436                                  "\t\t\t\"exp\": \"{{list}}\",\n"
437                                  "\t\t\t\"value\": \"item\"\n"
438                                  "\t\t}\n"
439                                  "\t},\n"
440                                  "\t\"styles\": {},\n"
441                                  "\t\"actions\": {},\n"
442                                  "\t\"data\": {\n"
443                                  "\t\t\"list\": [\n"
444                                  "\t\t\t{\n"
445                                  "\t\t\t\t\"name\": \"aa\",\n"
446                                  "\t\t\t\t\"idx\": 1\n"
447                                  "\t\t\t},\n"
448                                  "\t\t\t{\n"
449                                  "\t\t\t\t\"name\": \"bb\",\n"
450                                  "\t\t\t\t\"idx\": 2\n"
451                                  "\t\t\t},\n"
452                                  "\t\t\t{\n"
453                                  "\t\t\t\t\"name\": \"cc\",\n"
454                                  "\t\t\t\t\"idx\": 1\n"
455                                  "\t\t\t}\n"
456                                  "\t\t]\n"
457                                  "\t}\n"
458                                  "}";
459     auto rootBody = JsonUtil::ParseJsonString(rootJson);
460     auto rootTemplate = rootBody->GetValue("template");
461     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
462     jsCardParser->Initialize();
463     jsCardParser->SetIsRepeat(true);
464 
465     /**
466      * @tc.steps: step2. Get the value of the repeat and parse data.
467      */
468     auto repeatValue = rootTemplate->GetValue("repeat");
469     jsCardParser->ParseRepeatIndexItem(repeatValue);
470     auto expValue = repeatValue->GetValue("exp");
471     std::string key;
472     jsCardParser->GetRepeatData(expValue, key);
473     jsCardParser->SetRepeatItemValue(0, expValue, true);
474 
475     /**
476      * @tc.steps: step3. Parse repeat attr and assert value of repeat.
477      * @tc.expected: step3. The repeat value meets expectations.
478      */
479     std::vector<std::pair<std::string, std::string>> attrs;
480     auto type = rootTemplate->GetValue("type")->GetString();
481     RefPtr<Framework::JsCommandDomElementCreator> command =
482         Referenced::MakeRefPtr<Framework::JsCommandAddDomElement>(type, 1, 0);
483     auto ptr = Referenced::RawPtr(command);
484     jsCardParser->ParseAttributes(rootTemplate, 1, attrs, (Framework::JsCommandDomElementOperator*)ptr);
485 
486     ASSERT_EQ(attrs.begin()->first, "value");
487     ASSERT_EQ(attrs.begin()->second, "aa");
488 
489     ASSERT_EQ(attrs.rbegin()->first, "index");
490     ASSERT_EQ(attrs.rbegin()->second, "1");
491 
492     jsCardParser->SetRepeatItemValue(1, expValue, true);
493     attrs.clear();
494     jsCardParser->ParseAttributes(rootTemplate, 1, attrs, (Framework::JsCommandDomElementOperator*)ptr);
495     ASSERT_EQ(attrs.begin()->first, "value");
496     ASSERT_EQ(attrs.begin()->second, "bb");
497 
498     ASSERT_EQ(attrs.rbegin()->first, "index");
499     ASSERT_EQ(attrs.rbegin()->second, "2");
500 }
501 
502 /**
503  * @tc.name: CardFrontendTest010
504  * @tc.desc: Test "repeat" attr: for = "(index, item) in list".
505  * @tc.type: FUNC
506  * @tc.require: AR000F2BC4
507  * @tc.author: jiangdayuan
508  */
509 HWTEST_F(CardFrontendTest, CardFrontendTest010, TestSize.Level1)
510 {
511     /**
512      * @tc.steps: step1. construct json string.
513      */
514     const std::string rootJson = "{\n"
515                                  "\t\"template\": {\n"
516                                  "\t\t\"attr\": {\n"
517                                  "\t\t\t\"value\": \"{{$item.name}}\",\n"
518                                  "\t\t\t\"index\": \"{{$idx}}\"\n"
519                                  "\t\t},\n"
520                                  "\t\t\"type\": \"text\",\n"
521                                  "\t\t\"repeat\": {\n"
522                                  "\t\t\t\"exp\": \"{{list}}\",\n"
523                                  "\t\t\t\"key\": \"index\",\n"
524                                  "\t\t\t\"value\": \"item\"\n"
525                                  "\t\t}\n"
526                                  "\t},\n"
527                                  "\t\"styles\": {},\n"
528                                  "\t\"actions\": {},\n"
529                                  "\t\"data\": {\n"
530                                  "\t\t\"list\": [\n"
531                                  "\t\t\t{\n"
532                                  "\t\t\t\t\"name\": \"aa\",\n"
533                                  "\t\t\t\t\"idx\": 1\n"
534                                  "\t\t\t},\n"
535                                  "\t\t\t{\n"
536                                  "\t\t\t\t\"name\": \"bb\",\n"
537                                  "\t\t\t\t\"idx\": 2\n"
538                                  "\t\t\t},\n"
539                                  "\t\t\t{\n"
540                                  "\t\t\t\t\"name\": \"cc\",\n"
541                                  "\t\t\t\t\"idx\": 3\n"
542                                  "\t\t\t}\n"
543                                  "\t\t]\n"
544                                  "\t}\n"
545                                  "}";
546     auto rootBody = JsonUtil::ParseJsonString(rootJson);
547     auto rootTemplate = rootBody->GetValue("template");
548     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
549     jsCardParser->Initialize();
550     jsCardParser->SetIsRepeat(true);
551 
552     /**
553      * @tc.steps: step2. Get the value of the repeat and parse data.
554      */
555     auto repeatValue = rootTemplate->GetValue("repeat");
556     jsCardParser->ParseRepeatIndexItem(repeatValue);
557     auto expValue = repeatValue->GetValue("exp");
558     std::string key;
559     jsCardParser->GetRepeatData(expValue, key);
560     jsCardParser->SetRepeatItemValue(2, expValue, true);
561 
562     /**
563      * @tc.steps: step3. Parse repeat attr and assert value of repeat.
564      * @tc.expected: step3. The repeat value meets expectations.
565      */
566     std::vector<std::pair<std::string, std::string>> attrs;
567     auto type = rootTemplate->GetValue("type")->GetString();
568     RefPtr<Framework::JsCommandDomElementCreator> command =
569         Referenced::MakeRefPtr<Framework::JsCommandAddDomElement>(type, 1, 0);
570     auto ptr = Referenced::RawPtr(command);
571     jsCardParser->ParseAttributes(rootTemplate, 1, attrs, (Framework::JsCommandDomElementOperator*)ptr);
572 
573     ASSERT_EQ(attrs.begin()->first, "value");
574     ASSERT_EQ(attrs.begin()->second, "cc");
575 
576     ASSERT_EQ(attrs.rbegin()->first, "index");
577     ASSERT_EQ(attrs.rbegin()->second, "2");
578 
579     jsCardParser->SetRepeatItemValue(1, expValue, true);
580     attrs.clear();
581     jsCardParser->ParseAttributes(rootTemplate, 1, attrs, (Framework::JsCommandDomElementOperator*)ptr);
582     ASSERT_EQ(attrs.begin()->first, "value");
583     ASSERT_EQ(attrs.begin()->second, "bb");
584 
585     ASSERT_EQ(attrs.rbegin()->first, "index");
586     ASSERT_EQ(attrs.rbegin()->second, "1");
587 }
588 
589 /**
590  * @tc.name: CardFrontendTest011
591  * @tc.desc: Test point operation.
592  * @tc.type: FUNC
593  * @tc.require: AR000FDGO7
594  * @tc.author: jiangyingjie
595  */
596 HWTEST_F(CardFrontendTest, CardFrontendTest011, TestSize.Level1)
597 {
598     const std::string rootJson = "{\n"
599                                  "\t\"template\": {\n"
600                                  "\t\t\"attr\": {},\n"
601                                  "\t\t\"type\": \"text\"\n"
602                                  "\t},\n"
603                                  "\t\"styles\": {},\n"
604                                  "\t\"actions\": {},\n"
605                                  "\t\"data\": {\n"
606                                  "\t\t\"number\": {\n"
607                                  "\t\t\t\"key\": 1\n"
608                                  "\t\t}\n"
609                                  "\t}\n"
610                                  "}";
611     auto rootBody = JsonUtil::ParseJsonString(rootJson);
612     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
613     jsCardParser->Initialize();
614     std::string value = "{{number.key}}";
615     jsCardParser->ParseVariable(value);
616     ASSERT_EQ(value, "1");
617 }
618 
619 /**
620  * @tc.name: CardFrontendTest012
621  * @tc.desc: Test array operations.
622  * @tc.type: FUNC
623  * @tc.require: AR000FDGO8
624  * @tc.author: jiangyingjie
625  */
626 HWTEST_F(CardFrontendTest, CardFrontendTest012, TestSize.Level1)
627 {
628     const std::string rootJson = "{\n"
629                                  "\t\"template\": {\n"
630                                  "\t\t\"attr\": {},\n"
631                                  "\t\t\"type\": \"text\"\n"
632                                  "\t},\n"
633                                  "\t\"styles\": {},\n"
634                                  "\t\"actions\": {},\n"
635                                  "\t\"data\": {\n"
636                                  "\t\t\"index\": [\n"
637                                  "\t\t\t0,\n"
638                                  "\t\t\t3,\n"
639                                  "\t\t\t4\n"
640                                  "\t\t]\n"
641                                  "\t}\n"
642                                  "}";
643     auto rootBody = JsonUtil::ParseJsonString(rootJson);
644     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
645     jsCardParser->Initialize();
646     std::string value = "{{index[0]}}";
647     jsCardParser->ParseVariable(value);
648     ASSERT_EQ(value, "0");
649     value = "{{index[1]}}";
650     jsCardParser->ParseVariable(value);
651     ASSERT_EQ(value, "3");
652     value = "{{index[2]}}";
653     jsCardParser->ParseVariable(value);
654     ASSERT_EQ(value, "4");
655 }
656 
657 /**
658  * @tc.name: CardFrontendTest013
659  * @tc.desc: Test complex expressions.
660  * @tc.type: FUNC
661  * @tc.require: AR000FDGO9
662  * @tc.author: jiangyingjie
663  */
664 HWTEST_F(CardFrontendTest, CardFrontendTest013, TestSize.Level1)
665 {
666     const std::string rootJson = "{\n"
667                                  "\t\"template\": {\n"
668                                  "\t\t\"attr\": {},\n"
669                                  "\t\t\"type\": \"text\"\n"
670                                  "\t},\n"
671                                  "\t\"styles\": {},\n"
672                                  "\t\"actions\": {},\n"
673                                  "\t\"data\": {\n"
674                                  "\t\t\"hours\": [\n"
675                                  "\t\t\t{\n"
676                                  "\t\t\t\t\"time\": [\n"
677                                  "\t\t\t\t\t8,\n"
678                                  "\t\t\t\t\t2,\n"
679                                  "\t\t\t\t\t3\n"
680                                  "\t\t\t\t],\n"
681                                  "\t\t\t\t\"src\": \"src/XXX.png\",\n"
682                                  "\t\t\t\t\"prop\": 10,\n"
683                                  "\t\t\t\t\"isPast\": false,\n"
684                                  "\t\t\t\t\"temperature\": \"22°\",\n"
685                                  "\t\t\t\t\"description\": \"\"\n"
686                                  "\t\t\t},\n"
687                                  "\t\t\t{\n"
688                                  "\t\t\t\t\"time\": \"3:00\",\n"
689                                  "\t\t\t\t\"src\": \"src/XXX.png\",\n"
690                                  "\t\t\t\t\"prop\": 11,\n"
691                                  "\t\t\t\t\"isPast\": false,\n"
692                                  "\t\t\t\t\"temperature\": \"22°\",\n"
693                                  "\t\t\t\t\"description\": \"\"\n"
694                                  "\t\t\t}\n"
695                                  "\t\t],\n"
696                                  "\t\t\"number\": {\n"
697                                  "\t\t\t\"key\": 1\n"
698                                  "\t\t}\n"
699                                  "\t}\n"
700                                  "}";
701     auto rootBody = JsonUtil::ParseJsonString(rootJson);
702     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
703     jsCardParser->Initialize();
704     std::string value = "{{hours[0].time[0]}}";
705     jsCardParser->ParseVariable(value);
706     ASSERT_EQ(value, "8");
707     value = "{{hours[number.key].time}}";
708     jsCardParser->ParseVariable(value);
709     ASSERT_EQ(value, "3:00");
710     value = "{{hours[0].time}}";
711     jsCardParser->ParseVariable(value);
712     ASSERT_EQ(value, "[8,2,3]");
713 }
714 
715 /**
716  * @tc.name: CardFrontendTest014
717  * @tc.desc: Test error expression.
718  * @tc.type: FUNC
719  * @tc.require: AR000FDGO8
720  * @tc.author: jiangyingjie
721  */
722 HWTEST_F(CardFrontendTest, CardFrontendTest014, TestSize.Level1)
723 {
724     const std::string rootJson = "{\n"
725                                  "\t\"template\": {\n"
726                                  "\t\t\"attr\": {},\n"
727                                  "\t\t\"type\": \"text\"\n"
728                                  "\t},\n"
729                                  "\t\"styles\": {},\n"
730                                  "\t\"actions\": {},\n"
731                                  "\t\"data\": {\n"
732                                  "\t\t\"hours\": [\n"
733                                  "\t\t\t{\n"
734                                  "\t\t\t\t\"time\": [\n"
735                                  "\t\t\t\t\t8,\n"
736                                  "\t\t\t\t\t2,\n"
737                                  "\t\t\t\t\t3\n"
738                                  "\t\t\t\t],\n"
739                                  "\t\t\t\t\"src\": \"src/XXX.png\",\n"
740                                  "\t\t\t\t\"prop\": 10,\n"
741                                  "\t\t\t\t\"isPast\": false,\n"
742                                  "\t\t\t\t\"temperature\": \"22°\",\n"
743                                  "\t\t\t\t\"description\": \"\"\n"
744                                  "\t\t\t},\n"
745                                  "\t\t\t{\n"
746                                  "\t\t\t\t\"time\": \"3:00\",\n"
747                                  "\t\t\t\t\"src\": \"src/XXX.png\",\n"
748                                  "\t\t\t\t\"prop\": 11,\n"
749                                  "\t\t\t\t\"isPast\": false,\n"
750                                  "\t\t\t\t\"temperature\": \"22°\",\n"
751                                  "\t\t\t\t\"description\": \"\"\n"
752                                  "\t\t\t}\n"
753                                  "\t\t],\n"
754                                  "\t\t\"number\": {\n"
755                                  "\t\t\t\"key\": 1\n"
756                                  "\t\t}\n"
757                                  "\t}\n"
758                                  "}";
759     auto rootBody = JsonUtil::ParseJsonString(rootJson);
760     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
761     jsCardParser->Initialize();
762     std::string value = "{{hours[key].time}}";
763     jsCardParser->ParseVariable(value);
764     ASSERT_EQ(value, "{{hours[key].time}}");
765     value = "{{key.number}}";
766     jsCardParser->ParseVariable(value);
767     ASSERT_EQ(value, "{{key.number}}");
768     value = "{{number.key}}}";
769     jsCardParser->ParseVariable(value);
770     ASSERT_EQ(value, "{{number.key}}}");
771 }
772 
773 /**
774  * @tc.name: CardFrontendDataBindingTest001
775  * @tc.desc: Test data binding for {{key1}}.{{key2}
776  * @tc.type: FUNC
777  * @tc.require: AR000FLCJU
778  * @tc.author: jiangdayuan
779  */
780 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest001, TestSize.Level1)
781 {
782     const std::string rootJson = "{\n"
783                                  "\t\"template\": {\n"
784                                  "\t\t\"attr\": {\n"
785                                  "\t\t\t\"value\": \"$f({{aaa}}.{{ddd}})\",\n"
786                                  "\t\t\t\"index\": \"$f({{bbb}}.{{ccc}})\"\n"
787                                  "\t\t},\n"
788                                  "\t\t\"type\": \"text\"\n"
789                                  "\t},\n"
790                                  "\t\"styles\": {},\n"
791                                  "\t\"actions\": {},\n"
792                                  "\t\"data\": {\n"
793                                  "\t\t\"aaa\": \"abc\",\n"
794                                  "\t\t\"bbb\": \"true\",\n"
795                                  "\t\t\"ccc\": \"false\",\n"
796                                  "\t\t\"ddd\": \"123\"\n"
797                                  "\t}\n"
798                                  "}";
799     auto rootBody = JsonUtil::ParseJsonString(rootJson);
800     auto rootTemplate = rootBody->GetValue("template");
801     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
802     jsCardParser->Initialize();
803 
804     auto attrValue = rootTemplate->GetValue("attr");
805     auto value = attrValue->GetValue("value")->GetString();
806 
807     // {{aaa}}.{{ddd}} == abc.123
808     jsCardParser->ParseMultiVariable(value);
809     ASSERT_EQ(value, "abc.123");
810 
811     // {{bbb}}.{{ccc}} = true.false
812     value = attrValue->GetValue("index")->GetString();
813     jsCardParser->ParseMultiVariable(value);
814     ASSERT_EQ(value, "true.false");
815 }
816 
817 /**
818  * @tc.name: CardFrontendDataBindingTest002
819  * @tc.desc: Test data binding for {{key1}}.{{key2}.{{key3}}
820  * @tc.type: FUNC
821  * @tc.require: AR000FLCJU
822  * @tc.author: jiangdayuan
823  */
824 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest002, TestSize.Level1)
825 {
826     const std::string rootJson = "{\n"
827                                  "\t\"template\": {\n"
828                                  "\t\t\"attr\": {\n"
829                                  "\t\t\t\"value\": \"$f({{aaa}}.{{bbb}}.{{ccc}})\",\n"
830                                  "\t\t\t\"index\": \"$f({{aaa}}.{{bbb}}.{{ccc}}.{{ddd}})\"\n"
831                                  "\t\t},\n"
832                                  "\t\t\"type\": \"text\"\n"
833                                  "\t},\n"
834                                  "\t\"styles\": {},\n"
835                                  "\t\"actions\": {},\n"
836                                  "\t\"data\": {\n"
837                                  "\t\t\"aaa\": \"abc\",\n"
838                                  "\t\t\"bbb\": \"true\",\n"
839                                  "\t\t\"ccc\": \"false\",\n"
840                                  "\t\t\"ddd\": \"123\"\n"
841                                  "\t}\n"
842                                  "}";
843     auto rootBody = JsonUtil::ParseJsonString(rootJson);
844     auto rootTemplate = rootBody->GetValue("template");
845     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
846     jsCardParser->Initialize();
847 
848     auto attrValue = rootTemplate->GetValue("attr");
849     auto value = attrValue->GetValue("value")->GetString();
850 
851     // {{aaa}}.{{bbb}}.{{ccc}} == abc.true.false
852     jsCardParser->ParseMultiVariable(value);
853     ASSERT_EQ(value, "abc.true.false");
854 
855     // {{aaa}}.{{bbb}}.{{ccc}}.{{ddd}} = abc.true.false.123
856     value = attrValue->GetValue("index")->GetString();
857     jsCardParser->ParseMultiVariable(value);
858     ASSERT_EQ(value, "abc.true.false.123");
859 }
860 
861 /**
862  * @tc.name: CardFrontendDataBindingTest003
863  * @tc.desc: Test data binding for {{flag1 ? key1 : key2}}.
864  * @tc.type: FUNC
865  * @tc.require: AR000FLCKP
866  * @tc.author: jiangdayuan
867  */
868 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest003, TestSize.Level1)
869 {
870     const std::string rootJson = "{\n"
871                                  "\t\"template\": {\n"
872                                  "\t\t\"attr\": {\n"
873                                  "\t\t\t\"value\": \"{{bbb ? aaa : bbb}}\",\n"
874                                  "\t\t\t\"index\": \"{{ccc ? aaa : ddd}}\"\n"
875                                  "\t\t},\n"
876                                  "\t\t\"type\": \"text\"\n"
877                                  "\t},\n"
878                                  "\t\"styles\": {},\n"
879                                  "\t\"actions\": {},\n"
880                                  "\t\"data\": {\n"
881                                  "\t\t\"aaa\": \"abc\",\n"
882                                  "\t\t\"bbb\": \"true\",\n"
883                                  "\t\t\"ccc\": \"false\",\n"
884                                  "\t\t\"ddd\": \"123\"\n"
885                                  "\t}\n"
886                                  "}";
887     auto rootBody = JsonUtil::ParseJsonString(rootJson);
888     auto rootTemplate = rootBody->GetValue("template");
889     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
890     jsCardParser->Initialize();
891 
892     auto attrValue = rootTemplate->GetValue("attr");
893     auto value = attrValue->GetValue("value")->GetString();
894 
895     // bbb = true, value = {{aaa}}
896     jsCardParser->ParseVariable(value);
897     ASSERT_EQ(value, "abc");
898 
899     // ccc = false, value = {{ddd}}
900     value = attrValue->GetValue("index")->GetString();
901     jsCardParser->ParseVariable(value);
902     ASSERT_EQ(value, "123");
903 }
904 
905 /**
906  * @tc.name: CardFrontendDataBindingTest004
907  * @tc.desc: Test data binding for illegal {{flag1 ? key1 : key2}}.
908  * @tc.type: FUNC
909  * @tc.require: AR000FLCKP
910  * @tc.author: jiangdayuan
911  */
912 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest004, TestSize.Level1)
913 {
914     const std::string rootJson = "{\n"
915                                  "\t\"template\": {\n"
916                                  "\t\t\"attr\": {\n"
917                                  "\t\t\t\"value\": \"{{aaa ? bbb : ccc}}\",\n"
918                                  "\t\t\t\"index\": \"{{ccc ? aaa : eee}}\"\n"
919                                  "\t\t},\n"
920                                  "\t\t\"type\": \"text\"\n"
921                                  "\t},\n"
922                                  "\t\"styles\": {},\n"
923                                  "\t\"actions\": {},\n"
924                                  "\t\"data\": {\n"
925                                  "\t\t\"aaa\": \"abc\",\n"
926                                  "\t\t\"bbb\": \"true\",\n"
927                                  "\t\t\"ccc\": \"false\",\n"
928                                  "\t\t\"ddd\": \"123\"\n"
929                                  "\t}\n"
930                                  "}";
931     auto rootBody = JsonUtil::ParseJsonString(rootJson);
932     auto rootTemplate = rootBody->GetValue("template");
933     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
934     jsCardParser->Initialize();
935 
936     auto attrValue = rootTemplate->GetValue("attr");
937     auto value = attrValue->GetValue("value")->GetString();
938 
939     // aaa if not a bool value, set aaa = false, and value = {{ccc}}
940     jsCardParser->ParseVariable(value);
941     ASSERT_EQ(value, "false");
942 
943     // ccc = false, value = {{eee}}, eee does not belong to the data domain.
944     value = attrValue->GetValue("index")->GetString();
945     jsCardParser->ParseVariable(value);
946     ASSERT_EQ(value, "eee");
947 }
948 
949 /**
950  * @tc.name: CardFrontendDataBindingTest005
951  * @tc.desc: Test data binding for {{flag1 && flag2}}.
952  * @tc.type: FUNC
953  * @tc.require: AR000FLCK0
954  * @tc.author: jiangdayuan
955  */
956 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest005, TestSize.Level1)
957 {
958     const std::string rootJson = "{\n"
959                                  "\t\"template\": {\n"
960                                  "\t\t\"attr\": {\n"
961                                  "\t\t\t\"value\": \"{{bbb && ccc}}\",\n"
962                                  "\t\t\t\"index\": \"{{bbb && bbb}}\"\n"
963                                  "\t\t},\n"
964                                  "\t\t\"type\": \"text\"\n"
965                                  "\t},\n"
966                                  "\t\"styles\": {},\n"
967                                  "\t\"actions\": {},\n"
968                                  "\t\"data\": {\n"
969                                  "\t\t\"aaa\": \"abc\",\n"
970                                  "\t\t\"bbb\": \"true\",\n"
971                                  "\t\t\"ccc\": \"false\",\n"
972                                  "\t\t\"ddd\": \"123\"\n"
973                                  "\t}\n"
974                                  "}";
975     auto rootBody = JsonUtil::ParseJsonString(rootJson);
976     auto rootTemplate = rootBody->GetValue("template");
977     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
978     jsCardParser->Initialize();
979 
980     auto attrValue = rootTemplate->GetValue("attr");
981     auto value = attrValue->GetValue("value")->GetString();
982 
983     // bbb = true, ccc = false, value = (bbb && ccc) = false.
984     jsCardParser->ParseVariable(value);
985     ASSERT_EQ(value, "false");
986 
987     // bbb = true, value = (bbb && bbb) = true.
988     value = attrValue->GetValue("index")->GetString();
989     jsCardParser->ParseVariable(value);
990     ASSERT_EQ(value, "true");
991 }
992 
993 /**
994  * @tc.name: CardFrontendDataBindingTest006
995  * @tc.desc: Test data binding for {{flag1 || flag2}}.
996  * @tc.type: FUNC
997  * @tc.require: AR000FLCK0
998  * @tc.author: jiangdayuan
999  */
1000 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest006, TestSize.Level1)
1001 {
1002     const std::string rootJson = "{\n"
1003                                  "\t\"template\": {\n"
1004                                  "\t\t\"attr\": {\n"
1005                                  "\t\t\t\"value\": \"{{bbb || ccc}}\",\n"
1006                                  "\t\t\t\"index\": \"{{ccc || ccc}}\"\n"
1007                                  "\t\t},\n"
1008                                  "\t\t\"type\": \"text\"\n"
1009                                  "\t},\n"
1010                                  "\t\"styles\": {},\n"
1011                                  "\t\"actions\": {},\n"
1012                                  "\t\"data\": {\n"
1013                                  "\t\t\"aaa\": \"abc\",\n"
1014                                  "\t\t\"bbb\": \"true\",\n"
1015                                  "\t\t\"ccc\": \"false\",\n"
1016                                  "\t\t\"ddd\": \"123\"\n"
1017                                  "\t}\n"
1018                                  "}";
1019     auto rootBody = JsonUtil::ParseJsonString(rootJson);
1020     auto rootTemplate = rootBody->GetValue("template");
1021     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
1022     jsCardParser->Initialize();
1023 
1024     auto attrValue = rootTemplate->GetValue("attr");
1025     auto value = attrValue->GetValue("value")->GetString();
1026 
1027     // bbb = true, ccc = false, value = (bbb || ccc) = true.
1028     jsCardParser->ParseVariable(value);
1029     ASSERT_EQ(value, "true");
1030 
1031     // ccc = false, value = (ccc || ccc) = false.
1032     value = attrValue->GetValue("index")->GetString();
1033     jsCardParser->ParseVariable(value);
1034     ASSERT_EQ(value, "false");
1035 }
1036 
1037 /**
1038  * @tc.name: CardFrontendDataBindingTest007
1039  * @tc.desc: Test data binding for {{!flag1}}.
1040  * @tc.type: FUNC
1041  * @tc.require: AR000FLCK0
1042  * @tc.author: jiangdayuan
1043  */
1044 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest007, TestSize.Level1)
1045 {
1046     const std::string rootJson = "{\n"
1047                                  "\t\"template\": {\n"
1048                                  "\t\t\"attr\": {\n"
1049                                  "\t\t\t\"value\": \"{{!bbb}}\",\n"
1050                                  "\t\t\t\"index\": \"{{!ccc}}\"\n"
1051                                  "\t\t},\n"
1052                                  "\t\t\"type\": \"text\"\n"
1053                                  "\t},\n"
1054                                  "\t\"styles\": {},\n"
1055                                  "\t\"actions\": {},\n"
1056                                  "\t\"data\": {\n"
1057                                  "\t\t\"aaa\": \"abc\",\n"
1058                                  "\t\t\"bbb\": \"true\",\n"
1059                                  "\t\t\"ccc\": \"false\",\n"
1060                                  "\t\t\"ddd\": \"123\"\n"
1061                                  "\t}\n"
1062                                  "}";
1063     auto rootBody = JsonUtil::ParseJsonString(rootJson);
1064     auto rootTemplate = rootBody->GetValue("template");
1065     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
1066     jsCardParser->Initialize();
1067 
1068     auto attrValue = rootTemplate->GetValue("attr");
1069     auto value = attrValue->GetValue("value")->GetString();
1070 
1071     // bbb = true, !bbb =  false.
1072     jsCardParser->ParseVariable(value);
1073     ASSERT_EQ(value, "false");
1074 
1075     // ccc = false, !ccc = true.
1076     value = attrValue->GetValue("index")->GetString();
1077     jsCardParser->ParseVariable(value);
1078     ASSERT_EQ(value, "true");
1079 }
1080 
1081 /**
1082  * @tc.name: CardFrontendDataBindingTest008
1083  * @tc.desc: Test data binding for {{flag1 && flag2 && flag3}} (not support now).
1084  * @tc.type: FUNC
1085  * @tc.require: AR000FLCK0
1086  * @tc.author: jiangdayuan
1087  */
1088 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest008, TestSize.Level1)
1089 {
1090     const std::string rootJson = "{\n"
1091                                  "\t\"template\": {\n"
1092                                  "\t\t\"attr\": {\n"
1093                                  "\t\t\t\"value\": \"{{bbb && ccc && aaa}}\",\n"
1094                                  "\t\t\t\"index\": \"{{bbb && bbb && ccc}}\"\n"
1095                                  "\t\t},\n"
1096                                  "\t\t\"type\": \"text\"\n"
1097                                  "\t},\n"
1098                                  "\t\"styles\": {},\n"
1099                                  "\t\"actions\": {},\n"
1100                                  "\t\"data\": {\n"
1101                                  "\t\t\"aaa\": \"abc\",\n"
1102                                  "\t\t\"bbb\": \"true\",\n"
1103                                  "\t\t\"ccc\": \"false\",\n"
1104                                  "\t\t\"ddd\": \"123\"\n"
1105                                  "\t}\n"
1106                                  "}";
1107     auto rootBody = JsonUtil::ParseJsonString(rootJson);
1108     auto rootTemplate = rootBody->GetValue("template");
1109     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
1110     jsCardParser->Initialize();
1111 
1112     auto attrValue = rootTemplate->GetValue("attr");
1113     auto value = attrValue->GetValue("value")->GetString();
1114 
1115     // When more than two variables want to &&, return itself.
1116     jsCardParser->ParseVariable(value);
1117     ASSERT_EQ(value, "{{bbb && ccc && aaa}}");
1118 
1119     value = attrValue->GetValue("index")->GetString();
1120     jsCardParser->ParseVariable(value);
1121     ASSERT_EQ(value, "{{bbb && bbb && ccc}}");
1122 }
1123 
1124 /**
1125  * @tc.name: CardFrontendDataBindingTest009
1126  * @tc.desc: Test data binding for {{flag1 || flag2 || flag3}} (not support now).
1127  * @tc.type: FUNC
1128  * @tc.require: AR000FLCK0
1129  * @tc.author: jiangdayuan
1130  */
1131 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest009, TestSize.Level1)
1132 {
1133     const std::string rootJson = "{\n"
1134                                  "\t\"template\": {\n"
1135                                  "\t\t\"attr\": {\n"
1136                                  "\t\t\t\"value\": \"{{bbb || ccc || aaa}}\",\n"
1137                                  "\t\t\t\"index\": \"{{bbb || bbb || ccc}}\"\n"
1138                                  "\t\t},\n"
1139                                  "\t\t\"type\": \"text\"\n"
1140                                  "\t},\n"
1141                                  "\t\"styles\": {},\n"
1142                                  "\t\"actions\": {},\n"
1143                                  "\t\"data\": {\n"
1144                                  "\t\t\"aaa\": \"abc\",\n"
1145                                  "\t\t\"bbb\": \"true\",\n"
1146                                  "\t\t\"ccc\": \"false\",\n"
1147                                  "\t\t\"ddd\": \"123\"\n"
1148                                  "\t}\n"
1149                                  "}";
1150     auto rootBody = JsonUtil::ParseJsonString(rootJson);
1151     auto rootTemplate = rootBody->GetValue("template");
1152     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
1153     jsCardParser->Initialize();
1154 
1155     auto attrValue = rootTemplate->GetValue("attr");
1156     auto value = attrValue->GetValue("value")->GetString();
1157 
1158     // When more than two variables want to ||, return itself.
1159     jsCardParser->ParseVariable(value);
1160     ASSERT_EQ(value, "{{bbb || ccc || aaa}}");
1161 
1162     value = attrValue->GetValue("index")->GetString();
1163     jsCardParser->ParseVariable(value);
1164     ASSERT_EQ(value, "{{bbb || bbb || ccc}}");
1165 }
1166 
1167 /**
1168  * @tc.name: CardFrontendDataBindingTest010
1169  * @tc.desc: Test data binding for {{flag1 && flag2 || flag3}} (not support now).
1170  * @tc.type: FUNC
1171  * @tc.require: AR000FLCK0
1172  * @tc.author: jiangdayuan
1173  */
1174 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest010, TestSize.Level1)
1175 {
1176     const std::string rootJson = "{\n"
1177                                  "\t\"template\": {\n"
1178                                  "\t\t\"attr\": {\n"
1179                                  "\t\t\t\"value\": \"{{bbb && ccc || aaa}}\",\n"
1180                                  "\t\t\t\"index\": \"{{bbb || bbb && ccc}}\"\n"
1181                                  "\t\t},\n"
1182                                  "\t\t\"type\": \"text\"\n"
1183                                  "\t},\n"
1184                                  "\t\"styles\": {},\n"
1185                                  "\t\"actions\": {},\n"
1186                                  "\t\"data\": {\n"
1187                                  "\t\t\"aaa\": \"abc\",\n"
1188                                  "\t\t\"bbb\": \"true\",\n"
1189                                  "\t\t\"ccc\": \"false\",\n"
1190                                  "\t\t\"ddd\": \"123\"\n"
1191                                  "\t}\n"
1192                                  "}";
1193     auto rootBody = JsonUtil::ParseJsonString(rootJson);
1194     auto rootTemplate = rootBody->GetValue("template");
1195     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
1196     jsCardParser->Initialize();
1197 
1198     auto attrValue = rootTemplate->GetValue("attr");
1199     auto value = attrValue->GetValue("value")->GetString();
1200 
1201     // When more than two variables want to || or &&, return itself.
1202     jsCardParser->ParseVariable(value);
1203     ASSERT_EQ(value, "{{bbb && ccc || aaa}}");
1204 
1205     value = attrValue->GetValue("index")->GetString();
1206     jsCardParser->ParseVariable(value);
1207     ASSERT_EQ(value, "{{bbb || bbb && ccc}}");
1208 }
1209 
1210 /**
1211  * @tc.name: CardFrontendDataBindingTest011
1212  * @tc.desc: Test data binding for {{!flag1 && flag2}} (not support now).
1213  * @tc.type: FUNC
1214  * @tc.require: AR000FLCK0
1215  * @tc.author: jiangdayuan
1216  */
1217 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest011, TestSize.Level1)
1218 {
1219     const std::string rootJson = "{\n"
1220                                  "\t\"template\": {\n"
1221                                  "\t\t\"attr\": {\n"
1222                                  "\t\t\t\"value\": \"{{!bbb && ccc}}\",\n"
1223                                  "\t\t\t\"index\": \"{{!ccc || bbb}}\"\n"
1224                                  "\t\t},\n"
1225                                  "\t\t\"type\": \"text\"\n"
1226                                  "\t},\n"
1227                                  "\t\"styles\": {},\n"
1228                                  "\t\"actions\": {},\n"
1229                                  "\t\"data\": {\n"
1230                                  "\t\t\"aaa\": \"abc\",\n"
1231                                  "\t\t\"bbb\": \"true\",\n"
1232                                  "\t\t\"ccc\": \"false\",\n"
1233                                  "\t\t\"ddd\": \"123\"\n"
1234                                  "\t}\n"
1235                                  "}";
1236     auto rootBody = JsonUtil::ParseJsonString(rootJson);
1237     auto rootTemplate = rootBody->GetValue("template");
1238     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
1239     jsCardParser->Initialize();
1240 
1241     auto attrValue = rootTemplate->GetValue("attr");
1242     auto value = attrValue->GetValue("value")->GetString();
1243 
1244     jsCardParser->ParseVariable(value);
1245     ASSERT_EQ(value, "{{!bbb && ccc}}");
1246 
1247     value = attrValue->GetValue("index")->GetString();
1248     jsCardParser->ParseVariable(value);
1249     ASSERT_EQ(value, "{{!ccc || bbb}}");
1250 }
1251 
1252 /**
1253  * @tc.name: CardFrontendDataBindingTest012
1254  * @tc.desc: Test data binding for {{!flag1}}.{{!flag2}}.
1255  * @tc.type: FUNC
1256  * @tc.require: AR000FLCK0
1257  * @tc.author: jiangdayuan
1258  */
1259 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest012, TestSize.Level1)
1260 {
1261     const std::string rootJson = "{\n"
1262                                  "\t\"template\": {\n"
1263                                  "\t\t\"attr\": {\n"
1264                                  "\t\t\t\"value\": \"$f({{!bbb}}.{{!ccc}})\",\n"
1265                                  "\t\t\t\"index\": \"$f({{!aaa}}.{{!ccc}})\"\n"
1266                                  "\t\t},\n"
1267                                  "\t\t\"type\": \"text\"\n"
1268                                  "\t},\n"
1269                                  "\t\"styles\": {},\n"
1270                                  "\t\"actions\": {},\n"
1271                                  "\t\"data\": {\n"
1272                                  "\t\t\"aaa\": \"abc\",\n"
1273                                  "\t\t\"bbb\": \"true\",\n"
1274                                  "\t\t\"ccc\": \"false\",\n"
1275                                  "\t\t\"ddd\": \"123\"\n"
1276                                  "\t}\n"
1277                                  "}";
1278     auto rootBody = JsonUtil::ParseJsonString(rootJson);
1279     auto rootTemplate = rootBody->GetValue("template");
1280     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
1281     jsCardParser->Initialize();
1282 
1283     auto attrValue = rootTemplate->GetValue("attr");
1284     auto value = attrValue->GetValue("value")->GetString();
1285 
1286     // !bbb = false, !ccc = true.
1287     jsCardParser->ParseMultiVariable(value);
1288     ASSERT_EQ(value, "false.true");
1289 
1290     // aaa is not bool value, so aaa = false, !aaa = true.
1291     value = attrValue->GetValue("index")->GetString();
1292     jsCardParser->ParseMultiVariable(value);
1293     ASSERT_EQ(value, "true.true");
1294 }
1295 
1296 /**
1297  * @tc.name: CardFrontendDataBindingTest013
1298  * @tc.desc: Test data binding for {{key1}}.{{!flag1}}.
1299  * @tc.type: FUNC
1300  * @tc.require: AR000FLCK0
1301  * @tc.author: jiangdayuan
1302  */
1303 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest013, TestSize.Level1)
1304 {
1305     const std::string rootJson = "{\n"
1306                                  "\t\"template\": {\n"
1307                                  "\t\t\"attr\": {\n"
1308                                  "\t\t\t\"value\": \"$f({{bbb}}.{{!ccc}})\",\n"
1309                                  "\t\t\t\"index\": \"$f({{aaa}}.{{!ccc}})\"\n"
1310                                  "\t\t},\n"
1311                                  "\t\t\"type\": \"text\"\n"
1312                                  "\t},\n"
1313                                  "\t\"styles\": {},\n"
1314                                  "\t\"actions\": {},\n"
1315                                  "\t\"data\": {\n"
1316                                  "\t\t\"aaa\": \"abc\",\n"
1317                                  "\t\t\"bbb\": \"true\",\n"
1318                                  "\t\t\"ccc\": \"false\",\n"
1319                                  "\t\t\"ddd\": \"123\"\n"
1320                                  "\t}\n"
1321                                  "}";
1322     auto rootBody = JsonUtil::ParseJsonString(rootJson);
1323     auto rootTemplate = rootBody->GetValue("template");
1324     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
1325     jsCardParser->Initialize();
1326 
1327     auto attrValue = rootTemplate->GetValue("attr");
1328     auto value = attrValue->GetValue("value")->GetString();
1329 
1330     jsCardParser->ParseMultiVariable(value);
1331     ASSERT_EQ(value, "true.true");
1332 
1333     value = attrValue->GetValue("index")->GetString();
1334     jsCardParser->ParseMultiVariable(value);
1335     ASSERT_EQ(value, "abc.true");
1336 }
1337 
1338 /**
1339  * @tc.name: CardFrontendDataBindingTest014
1340  * @tc.desc: Test data binding for constant + variable.
1341  * @tc.type: FUNC
1342  * @tc.require: AR000FLCK0
1343  * @tc.author: jiangdayuan
1344  */
1345 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest014, TestSize.Level1)
1346 {
1347     const std::string rootJson = "{\n"
1348                                  "\t\"template\": {\n"
1349                                  "\t\t\"attr\": {\n"
1350                                  "\t\t\t\"value\": \"$f(value1 is : {{aaa}})\",\n"
1351                                  "\t\t\t\"index\": \"$f(ccc is: {{ccc}}, bbb is {{bbb}}.)\"\n"
1352                                  "\t\t},\n"
1353                                  "\t\t\"type\": \"text\"\n"
1354                                  "\t},\n"
1355                                  "\t\"styles\": {},\n"
1356                                  "\t\"actions\": {},\n"
1357                                  "\t\"data\": {\n"
1358                                  "\t\t\"aaa\": \"abc\",\n"
1359                                  "\t\t\"bbb\": \"true\",\n"
1360                                  "\t\t\"ccc\": \"false\",\n"
1361                                  "\t\t\"ddd\": \"123\"\n"
1362                                  "\t}\n"
1363                                  "}";
1364     auto rootBody = JsonUtil::ParseJsonString(rootJson);
1365     auto rootTemplate = rootBody->GetValue("template");
1366     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
1367     jsCardParser->Initialize();
1368 
1369     auto attrValue = rootTemplate->GetValue("attr");
1370     auto value = attrValue->GetValue("value")->GetString();
1371 
1372     jsCardParser->ParseMultiVariable(value);
1373     ASSERT_EQ(value, "value1 is : abc");
1374 
1375     value = attrValue->GetValue("index")->GetString();
1376     jsCardParser->ParseMultiVariable(value);
1377     ASSERT_EQ(value, "ccc is: false, bbb is true.");
1378 }
1379 
1380 /**
1381  * @tc.name: CardFrontendDataBindingTest015
1382  * @tc.desc: Test data binding for {{!flag1}}.{{flag2 && flag3}}
1383  * @tc.type: FUNC
1384  * @tc.require: AR000FLCK0
1385  * @tc.author: jiangdayuan
1386  */
1387 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest015, TestSize.Level1)
1388 {
1389     const std::string rootJson = "{\n"
1390                                  "\t\"template\": {\n"
1391                                  "\t\t\"attr\": {\n"
1392                                  "\t\t\t\"value\": \"$f({{!bbb}}.{{bbb && ccc}})\",\n"
1393                                  "\t\t\t\"index\": \"$f({{aaa}}.{{bbb || ccc}})\"\n"
1394                                  "\t\t},\n"
1395                                  "\t\t\"type\": \"text\"\n"
1396                                  "\t},\n"
1397                                  "\t\"styles\": {},\n"
1398                                  "\t\"actions\": {},\n"
1399                                  "\t\"data\": {\n"
1400                                  "\t\t\"aaa\": \"abc\",\n"
1401                                  "\t\t\"bbb\": \"true\",\n"
1402                                  "\t\t\"ccc\": \"false\",\n"
1403                                  "\t\t\"ddd\": \"123\"\n"
1404                                  "\t}\n"
1405                                  "}";
1406     auto rootBody = JsonUtil::ParseJsonString(rootJson);
1407     auto rootTemplate = rootBody->GetValue("template");
1408     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
1409     jsCardParser->Initialize();
1410 
1411     auto attrValue = rootTemplate->GetValue("attr");
1412     auto value = attrValue->GetValue("value")->GetString();
1413 
1414     jsCardParser->ParseMultiVariable(value);
1415     ASSERT_EQ(value, "false.false");
1416 
1417     value = attrValue->GetValue("index")->GetString();
1418     jsCardParser->ParseMultiVariable(value);
1419     ASSERT_EQ(value, "abc.true");
1420 }
1421 
1422 /**
1423  * @tc.name: CardFrontendDataBindingTest016
1424  * @tc.desc: Test data binding for error expression.
1425  * @tc.type: FUNC
1426  * @tc.require: SR000FLCGT
1427  * @tc.author: jiangdayuan
1428  */
1429 HWTEST_F(CardFrontendTest, CardFrontendDataBindingTest016, TestSize.Level1)
1430 {
1431     const std::string rootJson = "{\n"
1432                                  "\t\"template\": {\n"
1433                                  "\t\t\"attr\": {\n"
1434                                  "\t\t\t\"value\": \"$f({{aaa}}.{{eee}})\",\n"
1435                                  "\t\t\t\"value1\": \"{{aaa ? bbb : ddd}}\",\n"
1436                                  "\t\t\t\"value2\": \"{{aaa && ddd}}\",\n"
1437                                  "\t\t\t\"value3\": \"{{aaa || ddd}}\",\n"
1438                                  "\t\t\t\"value4\": \"{{!ddd}}\"\n"
1439                                  "\t\t},\n"
1440                                  "\t\t\"type\": \"text\"\n"
1441                                  "\t},\n"
1442                                  "\t\"styles\": {},\n"
1443                                  "\t\"actions\": {},\n"
1444                                  "\t\"data\": {\n"
1445                                  "\t\t\"aaa\": \"abc\",\n"
1446                                  "\t\t\"bbb\": \"true\",\n"
1447                                  "\t\t\"ccc\": \"false\",\n"
1448                                  "\t\t\"ddd\": \"123\"\n"
1449                                  "\t}\n"
1450                                  "}";
1451     auto rootBody = JsonUtil::ParseJsonString(rootJson);
1452     auto rootTemplate = rootBody->GetValue("template");
1453     auto jsCardParser = AceType::MakeRefPtr<JsCardParser>(nullptr, nullptr, std::move(rootBody));
1454     jsCardParser->Initialize();
1455 
1456     auto attrValue = rootTemplate->GetValue("attr");
1457     auto value = attrValue->GetValue("value")->GetString();
1458 
1459     // {{aaa}}.{{eee}}, eee does not belong to the data field.
1460     jsCardParser->ParseMultiVariable(value);
1461     ASSERT_EQ(value, "abc.{{eee}}");
1462 
1463     // aaa ? bbb : ddd, aaa is not bool variable, the default setting is false.
1464     value = attrValue->GetValue("value1")->GetString();
1465     jsCardParser->ParseVariable(value);
1466     ASSERT_EQ(value, "123");
1467 
1468     // aaa && ddd, aaa and ddd are not bool variables, the default setting is false.
1469     value = attrValue->GetValue("value2")->GetString();
1470     jsCardParser->ParseVariable(value);
1471     ASSERT_EQ(value, "false");
1472 
1473     // aaa || ddd, aaa and ddd are not bool variables, the default setting is false.
1474     value = attrValue->GetValue("value3")->GetString();
1475     jsCardParser->ParseVariable(value);
1476     ASSERT_EQ(value, "false");
1477 
1478     // ddd is not a bool variable, the default setting is false.
1479     value = attrValue->GetValue("value4")->GetString();
1480     jsCardParser->ParseVariable(value);
1481     ASSERT_EQ(value, "true");
1482 }
1483 
1484 } // namespace OHOS::Ace::Framework