• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include <string>
17 #include <map>
18 #include <gtest/gtest.h>
19 #include "secodeFuzz.h"
20 #include "common.h"
21 #include "CommandParse.h"
22 #include "CommandLineInterface.h"
23 #define private public
24 #include "CommandParser.h"
25 using namespace fuzztest;
26 
27 namespace {
28 std::map<std::string, std::string> richDataMap = {
29     {"BackClicked", ""},
30     {"inspector", ""},
31     {"inspectorDefault", ""},
32     {"ColorMode", R"({"ColorMode":"dark"})"},
33     {"Orientation", R"({"Orientation":"landscape","screenDensity":480,"width":2340,
34         "height":1080,"originWidth":2340,"originHeight":1080})"},
35     {"ResolutionSwitch", R"({"originWidth":1080,"originHeight":2340,"width":1080,
36         "height":2340,"screenDensity":480})"},
37     {"CurrentRouter", ""},
38     {"ReloadRuntimePage", R"({"ReloadRuntimePage":"aaa"})"},
39     {"FontSelect", R"({"FontSelect":true})"},
40     {"MemoryRefresh", R"({"jsCode":"UEFOREEAAAAAAAAAAAAAA+wDAADEAAAAFQAAAAMoDAAA=\r\n",
41         "propertyVariable":[],"viewID":"1","offset":{"line":11,"column":9},
42         "globalVariable":[],"slot":0,"type":"UpdateComponent","parentID":2})"},
43     {"LoadDocument", R"({"url":"pages/Index","className":"Index","previewParam":{"width":1080,
44         "height":2340,"locale":"zh_CN","colorMode":"light","orientation":"portrait",
45         "deviceType":"phone","dpi":480}})"},
46     {"FastPreviewMsg", ""},
47     {"DropFrame", R"({"frequency":1000})"},
48     {"KeyPress", R"({"isInputMethod":false,"keyCode":2033,"keyAction":0,"pressedCodes":[2033]})"},
49     {"PointEvent", R"({"x":365,"y":1071,"duration":"","button":-1,"action": 3,"axisValues":[0,0,0,0],
50         "sourceType":1,"sourceTool": 7,"pressedButtons":[0,1]})"},
51     {"FoldStatus", R"({"FoldStatus":"fold","width":1080,"height":2504})"},
52     {"AvoidArea", R"({"topRect":{"posX":0,"posY":0,"width":2340,"height":117},"bottomRect":{"posX":
53         0,"posY":0,"width":0,"height":0},"leftRect":{"posX":0,"posY":0,"width":0,"height":0},
54         "rightRect":{"posX":0,"posY":0,"width":2340,"height":84}})"},
55     {"AvoidAreaChanged", ""}
56 };
57 
TEST(RichCommandParseFuzzTest,test_command)58 TEST(RichCommandParseFuzzTest, test_command)
59 {
60     std::cout << "--> RichCommandParseFuzzTest for rich start <--" << std::endl;
61     DT_FUZZ_START(0, TEST_TIMES, (char*)"RichCommandParseFuzzTest", 0)
62     {
63         CommandParse parse;
64         CommandParser::GetInstance().deviceType = "phone";
65         parse.CreateAndExecuteCommand(richDataMap);
66     }
67     DT_FUZZ_END()
68     printf("end ---- RichCommandParseFuzzTest\r\n");
69     if (DT_GetIsPass() == 0) {
70         printf("test RichCommandParseFuzzTest is not ok\r\n");
71     } else {
72         printf("test RichCommandParseFuzzTest is ok\r\n");
73     }
74     std::cout << "--> RichCommandParseFuzzTest for rich end <--" << std::endl;
75 }
76 }